https://sourceware.org/bugzilla/show_bug.cgi?id=35112
Bug ID: 35112
Summary: GNU ld Xtensa relaxation reads four bytes past
malformed literal targets
Product: binutils
Version: 2.48 (HEAD)
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: ld
Assignee: unassigned at sourceware dot org
Reporter: emily.west286 at gmail dot com
Target Milestone: ---
Created attachment 17350
--> https://sourceware.org/bugzilla/attachment.cgi?id=17350&action=edit
reproducer
Product: binutils
Component: ld
Version: current master (a76487344054)
Host/target: Xtensa ELF (elf32xtensa)
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
-------
Xtensa relaxation asserts that an L32R literal target lies below the section
size, then reads four bytes at that offset in identify_literal_placement
(bfd/elf32-xtensa.c:9268-9269). For a malformed target, the read runs past the
end of the section buffer.
Reproduction
------------
1. Extract `bfd-xtensa-l32r-literal-target-oob-read-reproducer.tar.gz`.
2. Run:
LD=/path/to/ld-new sh repro.sh
Without a local build, use the `bfd-repro` image:
docker run --rm -v "$PWD:/queue:ro" bfd-repro \
/queue/attachments/bfd-xtensa-l32r-literal-target-oob-read-reproducer.tar.gz
Observed result
---------------
Master a76487344054, ASan build. Trigger:
/opt/bfd/ld-new: BFD (GNU Binutils) 2.47.50.20261204 assertion fail
../../bfd/elf32-xtensa.c:9268
==16==ERROR: AddressSanitizer: heap-buffer-overflow on address
0x60200000079c at pc 0x55864df695ef bp 0x7ffe3e8ab860 sp 0x7ffe3e8ab858
READ of size 1 at 0x60200000079c thread T0
#0 0x55864df695ee (/opt/bfd/ld-new+0x191b5ee) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#1 0x55864ec1488f (/opt/bfd/ld-new+0x25c688f) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#2 0x55864daa4b89 (/opt/bfd/ld-new+0x1456b89) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#3 0x55864daa4a02 (/opt/bfd/ld-new+0x1456a02) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
... (frames 4-14 omitted; full trace in the run output)
0x60200000079c is located 0 bytes to the right of 12-byte region
[0x602000000790,0x60200000079c)
SUMMARY: AddressSanitizer: heap-buffer-overflow (/opt/bfd/ld-new+0x191b5ee)
(BuildId: e954f11978a1462c93a1fefa94c533268ef8adb3)
==16==ABORTING
The control links cleanly and exits 0 with no sanitizer diagnostic.
Root cause
----------
Confirmed in gdb on master a76487344054:
- elf_xtensa_relax_section (bfd/elf32-xtensa.c:7106) calls
compute_removed_literals (line 9045), which calls identify_literal_placement.
- At the BFD_ASSERT (line 9268), rel->r_rel.target_offset is 12 and sec_size is
12. The offset equals the section size, so it is out of range.
- The assertion fails, execution continues, and bfd_get_32 (line 9269) reads
four bytes at contents + 12, which is past the end of the 12-byte buffer.
Expected result
---------------
ld should reject the input with a normal diagnostic, not read past the
section buffer.
Validation
----------
* Master a76487344054, ASan build: trigger fails an assertion at
elf32-xtensa.c:9268, then ASan reports a heap-buffer-overflow READ past the end
of the section; control exits 0.
* Duplicate check (2026-12-04): not yet run.
Scope
-----
Robustness issue. No invalid write across a security boundary is established.
Attachment
----------
- `bfd-xtensa-l32r-literal-target-oob-read-reproducer.tar.gz`
--
You are receiving this mail because:
You are on the CC list for the bug.