Bug 25306 - Null Pointer Dereference in bfd/pef.c:bfd_pef_parse_symbols()
Summary: Null Pointer Dereference in bfd/pef.c:bfd_pef_parse_symbols()
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-21 18:01 UTC by Nguyễn Đức Mạnh
Modified: 2020-01-03 14:58 UTC (History)
1 user (show)

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


Attachments
The crash PoC (4.23 KB, application/x-pef-executable)
2019-12-21 18:01 UTC, Nguyễn Đức Mạnh
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nguyễn Đức Mạnh 2019-12-21 18:01:48 UTC
Created attachment 12139 [details]
The crash PoC

Hello,

There is a null pointer dereference in bfd/pef.c:bfd_pef_parse_symbols().

## Analysis
Look at the following code in bfd/pef.c:bfd_pef_parse_symbols():
----------Code------------
  if (codesec != NULL)
    {
      codelen = codesec->size;
      codebuf = bfd_malloc (codelen);
      if (bfd_seek (abfd, codesec->filepos, SEEK_SET) < 0)
	goto end;
      if (bfd_bread ((void *) codebuf, codelen, abfd) != codelen)
	goto end;
    }
---------------------------
In the code above, codebuf is allocated without checking if the return pointer is null, which makes the writing to codebuf by bfd_bread invalid.

## Reproduce
The attachment makes objdump crashes provided objdump is built in 32-bit.
----------Log--------------
root@manh-ubuntu16:~/fuzz/fuzz_binutils# binutils-gdb-gcc-32/binutils/objdump -x crash-objdump 

crash-objdump:     file format pef
crash-objdump
architecture: powerpc:common64, flags 0x000001ff:
HAS_RELOC, EXEC_P, HAS_LINENO, HAS_DEBUG, HAS_SYMS, HAS_LOCALS, DYNAMIC, WP_TEXT, D_PAGED
start address 0x0000000000000630

Segmentation fault (core dumped)
---------------------------
Tested with version 39aa149769fd05fb6fade43bd41c1d7b6d63d06b of github.com/bminor/binutils-gdb

--
Thanks & Regards,
Nguyen Duc Manh
VinCSS (a member of Vingroup)
[M] (+84) 346136886
[E] v.manhnd@vincss.net
[W]  www.vincss.net
Comment 1 Nick Clifton 2020-01-03 14:58:24 UTC
Hi Nguyễn,

  This bug has already been fixed by the patch applied for PR 25308.

Cheers
  Nick