https://sourceware.org/bugzilla/show_bug.cgi?id=34849
Bug ID: 34849
Summary: GNU ld RX --relax reads one relocation past the end of
the relocation array
Product: binutils
Version: 2.46
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: ld
Assignee: unassigned at sourceware dot org
Reporter: basavesh.shivakumar at wsu dot edu
Target Milestone: ---
Created attachment 17169
--> https://sourceware.org/bugzilla/attachment.cgi?id=17169&action=edit
repro
I'm reporting this bug on behalf of my team: Ananta Srikar Puranam, Emily West,
Dr. Swarn Priya, Dr. Peng Gao and Dr. Basavesh Ammanaghatta Shivakumar.
Summary
=======
GNU ld linking an RX static executable with --relax, given the exact object the
RX assembler (gas -relax) emits for bra target_fn; rts (R_RX_RH_RELAX marker +
R_RX_DIR24S_PCREL), makes elf32_rx_relax_section (bfd/elf32-rx.c:2760) read
srel[1].r_info, one Elf_Internal_Rela past the end of the two-entry relocation
array, while testing whether the branch marker neighbour is another relax
marker. An ASan build of master ab7102f76c08 reports heap-buffer-overflow READ
of size 8, 8 bytes past the 48-byte relocation array; a plain released GNU ld
2.47 reads adjacent heap and exits 0. The same object linked without --relax,
and a relocation-free object linked with --relax, link cleanly.
Reproduction
============
1. Download and extract
`bfd-rx-relax-branch-past-reloc-array-read-reproducer.tar.gz`.
2. Run the following command with an ld.bfd or all-target `ld-new` binary that
supports the emulation used by the reproducer:
LD=/path/to/ld-new sh repro.sh
The archive contains the fixed input files, independent controls, helper
scripts needed by `repro.sh`, and their checksums. The script uses a temporary
directory and does not modify the source tree.
Observed result
===============
GNU ld linking an RX static executable with --relax, given the exact object the
RX assembler (gas -relax) emits for bra target_fn; rts (R_RX_RH_RELAX marker +
R_RX_DIR24S_PCREL), makes elf32_rx_relax_section (bfd/elf32-rx.c:2760) read
srel[1].r_info, one Elf_Internal_Rela past the end of the two-entry relocation
array, while testing whether the branch marker neighbour is another relax
marker. An ASan build of master ab7102f76c08 reports heap-buffer-overflow READ
of size 8, 8 bytes past the 48-byte relocation array; a plain released GNU ld
2.47 reads adjacent heap and exits 0. The same object linked without --relax,
and a relocation-free object linked with --relax, link cleanly.
Expected result
===============
GNU ld should either produce the correct output or reject the input with a
normal diagnostic. It should not crash, hang, execute undefined behavior, read
outside an input-derived allocation, or produce the described malformed
output.
--
You are receiving this mail because:
You are on the CC list for the bug.