https://sourceware.org/bugzilla/show_bug.cgi?id=35108
Bug ID: 35108
Summary: GNU ld RISC-V relaxation reads through an out-of-range
symbol section index
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 17346
--> https://sourceware.org/bugzilla/attachment.cgi?id=17346&action=edit
reproducer
Product: binutils
Component: ld
Version: current master (a76487344054)
Host/target: RISC-V ELF (elf64lriscv)
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
-------
A local symbol in a standalone RV64 object plus archive has an out-of-range
section index. ld asserts at bfd/elfnn-riscv.c:7169, then reads
elf_elfsections[st_shndx] at line 7170 without a bounds check and dereferences
out of range.
Reproduction
------------
1. Extract `bfd-riscv-relax-invalid-section-index-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-relax-invalid-section-index-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/elfnn-riscv.c:7169
AddressSanitizer:DEADLYSIGNAL
==16==ERROR: AddressSanitizer: SEGV on unknown address 0x621800040a98 (pc
0x5571e502b4cd bp 0x7fff5d1f9990 sp 0x7fff5d1f9740 T0)
==16==The signal is caused by a READ memory access.
==16==WARNING: invalid path to external symbolizer!
==16==WARNING: Failed to use and restart external symbolizer!
#0 0x5571e502b4cd (/opt/bfd/ld-new+0x1e964cd) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#1 0x5571e45ebb89 (/opt/bfd/ld-new+0x1456b89) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#2 0x5571e45eba02 (/opt/bfd/ld-new+0x1456a02) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#3 0x5571e45ed8a2 (/opt/bfd/ld-new+0x14588a2) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#4 0x5571e45f08be (/opt/bfd/ld-new+0x145b8be) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#5 0x5571e45f4654 (/opt/bfd/ld-new+0x145f654) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#6 0x5571e4a6bc9b (/opt/bfd/ld-new+0x18d6c9b) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#7 0x5571e49dcdb5 (/opt/bfd/ld-new+0x1847db5) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#8 0x5571e462cf71 (/opt/bfd/ld-new+0x1497f71) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#9 0x5571e45f8439 (/opt/bfd/ld-new+0x1463439) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#10 0x5571e461aa1a (/opt/bfd/ld-new+0x1485a1a) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#11 0x7f85e4e49249 (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
#12 0x7f85e4e49304 (/lib/x86_64-linux-gnu/libc.so.6+0x27304) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
#13 0x5571e44fb690 (/opt/bfd/ld-new+0x1366690) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/opt/bfd/ld-new+0x1e964cd) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
==16==ABORTING
Aborted (core dumped)
The --no-relax control exits nonzero with a clean diagnostic and no sanitizer
output:
input.a(leaf.o): in function `cross_3493997c1037_provider_s7_LF':
(.text.4+0x4): dangerous relocation: %pcrel_lo missing matching %pcrel_hi
Root cause
----------
Source reading (not yet confirmed at runtime): the code takes
isym->st_shndx from the input symbol table and checks it only with
BFD_ASSERT (bfd/elfnn-riscv.c:7169). The next line indexes
elf_elfsections(abfd) with it (7170), so an out-of-range section index reads
past the table.
Expected result
---------------
ld should reject the input with a normal diagnostic, not index the section
table with an out-of-range index.
Validation
----------
* Master a76487344054, ASan build: trigger aborts at elfnn-riscv.c:7169, then
ASan reports a READ SEGV at line 7170; --no-relax control exits nonzero with a
clean diagnostic.
* Duplicate check (2026-12-03): no matching Sourceware report found.
Scope
-----
Robustness issue. No invalid write across a security boundary is established.
Attachment
----------
- `bfd-riscv-relax-invalid-section-index-oob-read-reproducer.tar.gz`
--
You are receiving this mail because:
You are on the CC list for the bug.