[binutils-gdb] ld: guard the vxworks ELF link hash table read

Jan Beulich jbeulich@sourceware.org
Mon Nov 9 10:13:09 GMT 2026


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

commit a3e26a5b7003a124a0f4c71b7cff772aee598d02
Author: Harshit Kumar <harshit7kr@gmail.com>
Date:   Mon Nov 9 11:09:44 2026 +0100

    ld: guard the vxworks ELF link hash table read
    
    vxworks_after_open reads dynamic_sections_created out of the link hash
    table after checking only that the output has the ELF flavour.
    
    An ELF output format does not imply an ELF link hash table.  A linker
    script can select a generic ELF flavour with OUTPUT_FORMAT, which
    allocates a generic bfd_link_hash_table.  dynamic_sections_created is
    a member of struct elf_link_hash_table, so reading it from a generic
    hash table performs an out-of-bounds read into adjacent heap memory.
    
    Test is_elf_hash_table first, matching the equivalent guards in
    ld/ldelf.c and bfd/elflink.c.
    
    AddressSanitizer detects this read as a heap-buffer-overflow in
    vxworks_after_open across all seven VxWorks emulations on unpatched
    trees; the check eliminates the sanitizer failure.  No in-tree test is
    added because on standard builds the only observable effect is an
    unreliable warning dependent on uninitialized heap memory.
    
    ld/
            * emultempl/vxworks.em (vxworks_after_open): Require
            is_elf_hash_table before reading dynamic_sections_created.
    
    Signed-off-by: Harshit Kumar <harshit7kr@gmail.com>

Diff:
---
 ld/emultempl/vxworks.em | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ld/emultempl/vxworks.em b/ld/emultempl/vxworks.em
index 8c6c1330054..79177b36f2c 100644
--- a/ld/emultempl/vxworks.em
+++ b/ld/emultempl/vxworks.em
@@ -48,6 +48,7 @@ vxworks_after_open (void)
   if (!force_dynamic
       && !bfd_link_pic (&link_info)
       && bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour
+      && is_elf_hash_table (link_info.hash)
       && elf_hash_table (&link_info)->dynamic_sections_created)
     einfo (_("%X%P: dynamic sections created in non-dynamic link\n"));
 }


More information about the Binutils-cvs mailing list