[2/3] bfd: decline a non-XCOFF output in build_dynamic_sections
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-arm |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Test passed
|
Commit Message
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.
bfd_xcoff_build_dynamic_sections runs in ldemul_after_allocation and
assumes an xcoff_link_hash_table. Accessing xcoff_hash_table (info)
performs an out-of-bounds read into adjacent heap memory (which
AddressSanitizer reported as a heap-use-after-free because an adjacent
heap region was freed).
Return true immediately when output_bfd does not have XCOFF flavour,
matching the existing guard in bfd_xcoff_size_dynamic_sections.
bfd/
* xcofflink.c (bfd_xcoff_build_dynamic_sections): Return early
when output_bfd flavour is not XCOFF.
Signed-off-by: Harshit Kumar <harshit7kr@gmail.com>
---
bfd/xcofflink.c | 5 +++++
1 file changed, 5 insertions(+)
@@ -4135,6 +4135,11 @@ bfd_xcoff_build_dynamic_sections (bfd *output_bfd,
bfd *sub;
asection *sec;
+ /* The AIX emulations allow a linker script to select a non-XCOFF
+ output format, which uses a generic hash table. */
+ if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
+ return true;
+
ldinfo = &(xcoff_hash_table (info)->ldinfo);
if (xcoff_hash_table (info)->loader_section