bfd: decline a non-XCOFF output in build_dynamic_sections
Prevents heap read overflows in AIX linker emulations by ensuring `bfd_xcoff_build_dynamic_sections` only runs for XCOFF outputs.
This patch prevents heap read overflows in AIX linker emulations by adding a check to bfd_xcoff_build_dynamic_sections. The function previously ran even when a linker script specified a non-XCOFF output format (like elf32-little), leading to out-of-bounds reads when accessing the link hash table. The fix ensures this function only operates on XCOFF outputs, aligning with existing guards in related functions.
- proposer
Proposes to add a guard in `bfd_xcoff_build_dynamic_sections` to ensure it only runs for XCOFF outputs, preventing out-of-bounds reads when non-XCOFF formats are selected.
“The AIX emulations allow a linker script to select a non-XCOFF output format via OUTPUT_FORMAT (such as elf32-little). When that happens, the link hash table is a generic bfd_link_hash_table, not the larger xcoff_link_hash_table.”
In Details
This patch addresses a vulnerability where the bfd_xcoff_build_dynamic_sections function, which expects an xcoff_link_hash_table, can be called even when the linker script has selected a generic ELF output format. In such cases, a generic bfd_link_hash_table is used, and accessing xcoff_hash_table(info) results in an out-of-bounds read. The fix adds a check at the beginning of the function to ensure bfd_get_flavour(output_bfd) is bfd_target_xcoff_flavour before proceeding, mirroring a similar guard in bfd_xcoff_size_dynamic_sections.
- XCOFF
- Extended Common Object File Format, a file format used on IBM AIX systems.
- bfd
- The Binary File Descriptor library, used by GNU Binutils for object file manipulation.
- link hash table
- A data structure used by the linker to store and quickly access symbol information.
- heap read overflow
- A security vulnerability where a program reads data beyond the allocated buffer on the heap, potentially accessing sensitive information or causing crashes.
- OUTPUT_FORMAT
- A linker script command used to specify the output file format.