[PATCH 2/2] ld: guard the vxworks ELF link hash table read
Jan Beulich
jbeulich@suse.com
Fri Nov 6 13:23:43 GMT 2026
On 24.10.2026 17:22, Harshit Kumar wrote:
> 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>
Okay, albeit ...
> --- a/ld/emultempl/vxworks.em
> +++ b/ld/emultempl/vxworks.em
> @@ -45,9 +45,14 @@ vxworks_after_open (void)
> && !bfd_elf_link_create_dynamic_sections (&link_info))
> einfo (_("%X%P: cannot create dynamic sections %E\n"));
>
> + /* An ELF output format does not imply an ELF link hash table: a
> + linker script can select an ELF flavour backed by a generic hash
> + table. Testing the flavour is not enough. */
... I'm not quite sure of the comment. If we added this in all places where
such a check is needed, we may end up with quite few instances of this not
exactly brief comment. Additionally you also put this a little apart from
the code being commented, which may end up being confusing e.g. when code
ends up inserted between comment and if(), or when the if() is further
extended.
Jan
> 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
mailing list