https://sourceware.org/bugzilla/show_bug.cgi?id=35109
Bug ID: 35109
Summary: GNU ld RISC-V subset comparison indexes before its
extension-order table
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 17347
--> https://sourceware.org/bugzilla/attachment.cgi?id=17347&action=edit
reproducer
Product: binutils
Component: ld
Version: current master (a76487344054)
Host/target: RISC-V ELF
Summary
-------
A RISC-V Tag_RISCV_arch containing the Z-prefixed name z9q1p0 makes
riscv_compare_subsets index the 26-element riscv_ext_order table with -40 at
bfd/elfxx-riscv.c:1929.
Reproduction
------------
1. Extract `bfd-riscv-z-category-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-riscv-z-category-oob-read-reproducer.tar.gz
Observed result
---------------
Master a76487344054, UBSan build. Trigger:
../../bfd/elfxx-riscv.c:1929:13: runtime error: index -40 out of bounds for
type 'int[26]'
==15==WARNING: invalid path to external symbolizer!
==15==WARNING: Failed to use and restart external symbolizer!
#0 0x565249a0d95b (/opt/bfd/ld-new+0x1f7f95b) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#1 0x565249a0db3d (/opt/bfd/ld-new+0x1f7fb3d) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#2 0x565249a11cde (/opt/bfd/ld-new+0x1f83cde) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#3 0x565249a0f8a5 (/opt/bfd/ld-new+0x1f818a5) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#4 0x565249a0f1ce (/opt/bfd/ld-new+0x1f811ce) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#5 0x565249a1469f (/opt/bfd/ld-new+0x1f8669f) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#6 0x56524972314d (/opt/bfd/ld-new+0x1c9514d) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#7 0x565248ef7693 (/opt/bfd/ld-new+0x1469693) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#8 0x565248eeeff7 (/opt/bfd/ld-new+0x1460ff7) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#9 0x565248f13a1a (/opt/bfd/ld-new+0x1485a1a) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#10 0x7f523b107249 (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
#11 0x7f523b107304 (/lib/x86_64-linux-gnu/libc.so.6+0x27304) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
#12 0x565248df4690 (/opt/bfd/ld-new+0x1366690) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../bfd/elfxx-riscv.c:1929:13 in
Aborted (core dumped)
The control (the same archive without z9q1p0) exits 0 with no diagnostics.
Root cause
----------
Source reading, consistent with the trigger's architecture string. The trigger
has the Z-prefixed name `z9q1p0`, so the character after `z` is `9`.
- riscv_compare_subsets (bfd/elfxx-riscv.c:1929-1930) handles the z class by
indexing riscv_ext_order with the character after the prefix, without
checking that it is `a`-`z`. `9` gives index -40.
- The same function indexes riscv_ext_order with the first character of each
name (lines 1908-1909), with the same missing check.
The unchecked index is the same class as bfd-riscv-extension-category-oob-read
(elfxx-riscv.c:2207).
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.
Validation
----------
* Master a76487344054, UBSan build: trigger aborts at elfxx-riscv.c:1929:13
with index -40; control exits 0.
* Duplicate check (2026-12-03): no matching Sourceware report found.
Scope
-----
This is a public robustness or correctness report. The observed behavior does
not establish an invalid write across a security boundary, code execution,
privilege gain, or a vulnerability introduced into otherwise safe generated
output.
Attachment
----------
- `bfd-riscv-z-category-oob-read-reproducer.tar.gz`
--
You are receiving this mail because:
You are on the CC list for the bug.