ld: guard the vxworks ELF link hash table read
Fixes a heap-buffer-overflow in the VxWorks emulation by ensuring the link hash table is an ELF type before accessing its members.
This patch prevents a heap-buffer-overflow in the VxWorks emulation by adding a check to ensure the link hash table is specifically an ELF hash table before accessing the dynamic_sections_created member. Currently, a linker script can select a generic ELF flavor, which uses a generic bfd_link_hash_table instead of an elf_link_hash_table. Accessing dynamic_sections_created on a generic table results in an out-of-bounds read.
- proposer
Proposes to add a check for `is_elf_hash_table` before accessing `dynamic_sections_created` in the VxWorks emulation to prevent heap-buffer-overflows.
“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.”
In Details
This patch addresses a specific vulnerability in the VxWorks linker emulation. The vxworks_after_open function incorrectly assumes that if the output format is ELF, the underlying link hash table structure is elf_link_hash_table. However, a linker script can specify a generic ELF output format (OUTPUT_FORMAT("elf32-little")), which results in a generic bfd_link_hash_table being used. Accessing dynamic_sections_created (a member of elf_link_hash_table) on this generic structure leads to an out-of-bounds read.
- VxWorks
- A real-time operating system (RTOS) commonly used in embedded systems.
- link hash table
- A data structure used by the linker to efficiently manage symbols and sections during the linking process.
- ELF
- Executable and Linkable Format, a standard file format for executables, object code, shared libraries, and core dumps on Unix-like systems.
- heap-buffer-overflow
- A security vulnerability where data is written beyond the boundaries of an allocated buffer on the heap, potentially corrupting adjacent memory.