Bug 24909 - Uninitialized use on stack in readelf
Summary: Uninitialized use on stack in readelf
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.33
: P2 normal
Target Milestone: 2.33
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-15 17:46 UTC by Bowen Wang
Modified: 2019-08-17 22:23 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2019-08-16 00:00:00


Attachments
PoC to trigger the vulnerability. (52.54 KB, application/x-sharedlib)
2019-08-15 17:46 UTC, Bowen Wang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bowen Wang 2019-08-15 17:46:44 UTC
Created attachment 11949 [details]
PoC to trigger the vulnerability.

There is a uninitialized use on stack in readelf.c may cause information leak.

The commit id for the gitrepo I tested is fc9e754460ccf1c893fc9e67c02c49f58f1bd38e

Compile command:

CC=clang \
CFLAGS="-DFORTIFY_SOURCE=2 -fno-omit-frame-pointer -g -Wno-error -ggdb" \
./configure \
--disable-shared --disable-gdb --disable-libdecnumber --disable-readline \
--disable-sim
make

How to trigger the bug:
./readelf -a input

I tested this program using clang, not sure if it also exists for gcc.

When compiling with -O2, on line 12018 in function process_symbol_table() in readelf.c, sym_info is first declared on stack.

It is supposed to be updated on line 12044 in function get_symbol_version_string().

The problem is that there are only two statements in get_symbol_version_string() to initialize sym_info and the input triggers neither of them, so sym_info is actually uninitialized when used in line 12051.

The input is attached.
Comment 1 Sourceware Commits 2019-08-16 06:00:57 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0b8b76098ff3d3dcd0c621f2e45cc0b4e7211d6a

commit 0b8b76098ff3d3dcd0c621f2e45cc0b4e7211d6a
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Aug 16 15:17:23 2019 +0930

    PR24909, Uninitialized use on stack in readelf
    
    	PR 24909
    	PR 23499
    	* readelf.c (get_symbol_version_string): Set sym_info earlier.
Comment 2 Alan Modra 2019-08-16 06:31:09 UTC
Fixed, thanks for the analysis!
Comment 3 Sourceware Commits 2019-08-17 22:23:43 UTC
The binutils-2_32-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e8d25d40456520c8890937915df77dbd2d748d76

commit e8d25d40456520c8890937915df77dbd2d748d76
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Aug 16 15:17:23 2019 +0930

    PR24909, Uninitialized use on stack in readelf
    
    	PR 24909
    	PR 23499
    	* readelf.c (get_symbol_version_string): Set sym_info earlier.
    
    (cherry picked from commit 0b8b76098ff3d3dcd0c621f2e45cc0b4e7211d6a)