_bfd_clear_contents bounds checking
authorAlan Modra <amodra@gmail.com>
Sat, 13 Oct 2018 11:33:02 +0000 (22:03 +1030)
committerAlan Modra <amodra@gmail.com>
Sat, 13 Oct 2018 13:24:33 +0000 (23:54 +1030)
commit0930cb3021b8078b34cf216e79eb8608d017864f
treec5368b36cb84da2d40b57d14e28432773ef161c9
parent2bf2bf23da5237f465fdbb759657aeb7825a08a3
_bfd_clear_contents bounds checking

This PR shows a fuzzed binary triggering a segfault via a bad
relocation in .debug_line.  It turns out that unlike normal
relocations applied to a section, the linker applies those with
symbols from discarded sections via _bfd_clear_contents without
checking that the relocation is within the section bounds.  The same
thing now happens when reading debug sections since commit
a4cd947aca23, the PR23425 fix.

PR 23770
PR 23425
* reloc.c (_bfd_clear_contents): Replace "location" param with
"buf" and "off".  Bounds check "off".  Return status.
* cofflink.c (_bfd_coff_generic_relocate_section): Update
_bfd_clear_contents call.
* elf-bfd.h (RELOC_AGAINST_DISCARDED_SECTION): Likewise.
* elf32-arc.c (elf_arc_relocate_section): Likewise.
* elf32-i386.c (elf_i386_relocate_section): Likewise.
* elf32-metag.c (metag_final_link_relocate): Likewise.
* elf32-nds32.c (nds32_elf_get_relocated_section_contents): Likewise.
* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
* elf32-visium.c (visium_elf_relocate_section): Likewise.
* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
* elf64-x86-64.c *(elf_x86_64_relocate_section): Likewise.
* libbfd-in.h (_bfd_clear_contents): Update prototype.
* libbfd.h: Regenerate.
14 files changed:
bfd/ChangeLog
bfd/cofflink.c
bfd/elf-bfd.h
bfd/elf32-arc.c
bfd/elf32-i386.c
bfd/elf32-metag.c
bfd/elf32-nds32.c
bfd/elf32-ppc.c
bfd/elf32-visium.c
bfd/elf64-ppc.c
bfd/elf64-x86-64.c
bfd/libbfd-in.h
bfd/libbfd.h
bfd/reloc.c
This page took 0.025148 seconds and 4 git commands to generate.