From: Maciej W. Rozycki Date: Mon, 9 Apr 2018 12:42:00 +0000 (+0100) Subject: MIPS64/BFD: Fix a crash with STN_UNDEF in relocation X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=aec2e0d252342aa7575aff608e999a36f27a9147;p=binutils-gdb.git MIPS64/BFD: Fix a crash with STN_UNDEF in relocation Prevent a null BFD pointer dereference and a resulting segmentation fault in `mips_elf64_write_rel' or `mips_elf64_write_rela': Program received signal SIGSEGV, Segmentation fault. 0x0000000000437690 in mips_elf64_write_rela (abfd=0x71e130, sec=0x720700, rela_hdr=0x721ff8, count=0x7fffffffb82c, data=0x7fffffffb88c) at .../bfd/elf64-mips.c:4123 4123 if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec 4124 && ! _bfd_elf_validate_reloc (abfd, ptr)) in the MIPS64 (n64 MIPS) ELF backend whenever the STN_UNDEF symbol index is retrieved from the `r_sym' field of a relocation seen in input while running `objcopy' or `strip'. The reason for the null BFD pointer is that internally in BFD an STN_UNDEF symbol reference resolves to an absolute zero symbol that does not have a BFD associated. Check the pointer then before using it, like the generic ELF backend does in `elf_write_relocs'. This complements the same change made for generic ELF bundled with: commit e35765a9a2eaff0df62757f3e6480c8ba5ab8ee8 Author: Ian Lance Taylor Date: Sun Dec 15 19:59:18 1996 +0000 which (obviously due to a CVS -> GIT repository conversion inaccuracy) seems to be one corresponding to this ChangeLog entry: * elfcode.h (write_relocs): Handle absolute symbol. from: commit c86158e591edd8450f49f8cd75f82e4313d4b6d8 Author: Ian Lance Taylor Date: Fri Aug 30 22:09:51 1996 +0000 ("Add SH ELF support."), which also updated RELA only and not REL (which has been since fixed with: commit 947216bf8f34 ("ELF reloc code tidy"), ). bfd/ * elf64-mips.c (mips_elf64_write_rel): Handle a NULL BFD pointer in the BFD symbol referred by the relocation. (mips_elf64_write_rela): Likewise. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index d65d5a8a92e..33127be6f92 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2018-04-09 Maciej W. Rozycki + + * elf64-mips.c (mips_elf64_write_rel): Handle a NULL BFD pointer + in the BFD symbol referred by the relocation. + (mips_elf64_write_rela): Likewise. + 2018-04-09 Maciej W. Rozycki * elf64-mips.c (mips_elf64_slurp_one_reloc_table): Issue an diff --git a/bfd/elf64-mips.c b/bfd/elf64-mips.c index 86e55897cfe..4b9fdf65355 100644 --- a/bfd/elf64-mips.c +++ b/bfd/elf64-mips.c @@ -4038,7 +4038,8 @@ mips_elf64_write_rel (bfd *abfd, asection *sec, int_rel.r_sym = n; int_rel.r_ssym = RSS_UNDEF; - if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec + if ((*ptr->sym_ptr_ptr)->the_bfd != NULL + && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec && ! _bfd_elf_validate_reloc (abfd, ptr)) { *failedp = TRUE; @@ -4137,7 +4138,8 @@ mips_elf64_write_rela (bfd *abfd, asection *sec, int_rela.r_addend = ptr->addend; int_rela.r_ssym = RSS_UNDEF; - if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec + if ((*ptr->sym_ptr_ptr)->the_bfd != NULL + && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec && ! _bfd_elf_validate_reloc (abfd, ptr)) { *failedp = TRUE;