[PATCH v2 2/2] ld: guard the vxworks ELF link hash table read

Harshit Kumar harshit7kr@gmail.com
Fri Nov 6 14:28:28 GMT 2026


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>
---
v2: Drop the explanatory comment (Jan).

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

diff --git a/ld/emultempl/vxworks.em b/ld/emultempl/vxworks.em
index 8c6c1330..79177b36 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"));
 }
-- 
2.55.0




More information about the Binutils mailing list