Bug 20892 - Segfault in objdump
Summary: Segfault in objdump
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.28
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-01 10:03 UTC by Thuan Pham
Modified: 2020-06-04 00:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thuan Pham 2016-12-01 10:03:05 UTC
Dear all,
Using AFLFast (https://github.com/mboehme/aflfast), a fork of AFL, we found an input causing objdump to crash. Valgrind says that it is an invalid write.

The bug was found on Ubuntu 14.04 & binutils was checked out from https://github.com/bminor/binutils-gdb repository. Its commit is  268ebe95201d2ebdcf68cad9dc67ff6d1e25be9e (Fri Nov 18 14:15:12 2016)

To reproduce:


printf "\x07\x01\x00\x30\x04\x00\x00\x00\x1a\x00\x00\x00\x30\x30\x30\x30\x0d\x00\x00\x00\x30\x30\x30\x30\x04\x00\x00\x00\x40\x00\x00\x00\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x00\x00\x00\x00\x24\x30\x30\x30\x30\x30\x30\x30\x30\x04\x00\x00\x00" > fd


objdump -x -l fd


ASAN says:
../../bfd/aoutx.h:2832:11: runtime error: store to null pointer of type 'char'


Valgrind says:
==52909== Invalid write of size 1
==52909==    at 0x7F8349: aout_32_find_nearest_line (aoutx.h:2832)
==52909==    by 0x41C8A9: dump_reloc_set (objdump.c:3162)
==52909==    by 0x41E502: dump_relocs_in_section (objdump.c:3328)
==52909==    by 0x5FB3AB: bfd_map_over_sections (section.c:1395)
==52909==    by 0x422A9E: dump_relocs (objdump.c:3337)
==52909==    by 0x422A9E: dump_bfd (objdump.c:3463)
==52909==    by 0x4234FF: display_object_bfd (objdump.c:3526)
==52909==    by 0x4234FF: display_any_bfd (objdump.c:3615)
==52909==    by 0x40CFC9: display_file (objdump.c:3636)
==52909==    by 0x40CFC9: main (objdump.c:3919)
==52909==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==52909== 
==52909== 
==52909== Process terminating with default action of signal 11 (SIGSEGV)
==52909==  Access not within mapped region at address 0x0
==52909==    at 0x7F8349: aout_32_find_nearest_line (aoutx.h:2832)
==52909==    by 0x41C8A9: dump_reloc_set (objdump.c:3162)
==52909==    by 0x41E502: dump_relocs_in_section (objdump.c:3328)
==52909==    by 0x5FB3AB: bfd_map_over_sections (section.c:1395)
==52909==    by 0x422A9E: dump_relocs (objdump.c:3337)
==52909==    by 0x422A9E: dump_bfd (objdump.c:3463)
==52909==    by 0x4234FF: display_object_bfd (objdump.c:3526)
==52909==    by 0x4234FF: display_any_bfd (objdump.c:3615)
==52909==    by 0x40CFC9: display_file (objdump.c:3636)
==52909==    by 0x40CFC9: main (objdump.c:3919)
Comment 1 cvs-commit@gcc.gnu.org 2016-12-01 10:50:44 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit e82ab856bb4689330c29fb9f1c57a8555b26380e
Author: Nick Clifton <nickc@redhat.com>
Date:   Thu Dec 1 10:49:39 2016 +0000

    Fix a seg-fault disassembling a corrupt binary.
    
    	PR binutils/20892
    	* aoutx.h (find_nearest_line): Handle the case where the function
    	name is empty.
Comment 2 Nick Clifton 2016-12-01 10:51:40 UTC
Hi Thuan,

  Thanks for reporting this bug.  I have checked in a small patch that adds a
  check for a NULL buffer pointer and then repsonds appropriately.

Cheers
  Nick
Comment 3 Thuan Pham 2017-04-13 06:12:38 UTC
This is CVE-2017-7224
Comment 4 cvs-commit@gcc.gnu.org 2020-06-04 00:44:17 UTC
The master branch has been updated by Stephen Casner <slcasner@sourceware.org>:

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

commit 31af1e68af26f5cae209de3530d0455b8a944b2d
Author: Stephen Casner <casner@acm.org>
Date:   Wed Jun 3 17:43:45 2020 -0700

    Copy several years of fixes from bfd/aoutx.h to bfd/pdp11.c.
    
    * pdp11.c (some_aout_object_p): 4c1534c7a2a - Don't set EXEC_P for
    files with relocs.
    (aout_get_external_symbols): 6b8f0fd579d - Return if count is zero.
    0301ce1486b PR 22306 - Handle stringsize of zero, and error for any
    other size that doesn't qcover the header word.
    bf82069dce1 PR 23056 - Allocate an extra byte at the end of the
    string table, and zero it.
    (translate_symbol_table): 0d329c0a83a PR 22887 - Print an error
    message and set bfd_error on finding an invalid name string offset.
    (add_to_stringtab): INLINE -> inline
    (pdp11_aout_swap_reloc_in): 116acb2c268 PR 22887 - Correct r_index
    bound check.
    (squirt_out_relocs): e2996cc315d PR 20921 - Check for and report
    any relocs that could not be recognised.
    92744f05809 PR 20929 - Check for relocs without an associated symbol.
    (find_nearest_line):  808346fcfcf PR 23055 - Check that the symbol
    name exists and is long enough, before attempting to see if it is
    for a .o file.
    c3864421222 - Correct case for N_SO being the last symbol.
    50455f1ab29 PR 20891 - Handle the case where the main file name
    and the directory name are both empty.
    e82ab856bb4 PR 20892 - Handle the case where function name is empty.
    (aout_link_add_symbols): e517df3dbf7 PR 19629 - Check for out of
    range string table offsets.
    531336e3a0b PR 20909 - Fix off-by-one error in check for an
    illegal string offset.
    (aout_link_includes_newfunc): Add comment.
    (pdp11_aout_link_input_section): ad756e3f9e6 - Return with an error
    on unexpected relocation type rather than ASSERT.