https://sourceware.org/bugzilla/show_bug.cgi?id=35111
Bug ID: 35111
Summary: GNU ld packed RELR sizing dereferences a missing
local-symbol secti
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 17349
--> https://sourceware.org/bugzilla/attachment.cgi?id=17349&action=edit
reproducer
Product: binutils
Component: ld
Version: current master (a76487344054)
Host/target: x86-64 ELF (elf_x86_64, packed RELR)
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 whose section is missing makes packed RELR sizing read
sec->output_section through a NULL section at bfd/elf.c:13329.
Reproduction
------------
1. Extract `bfd-x86-relr-local-symbol-null-section-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-x86-relr-local-symbol-null-section-reproducer.tar.gz
Observed result
---------------
Master a76487344054, UBSan build. Trigger:
../../bfd/elf.c:13329:22: runtime error: member access within null pointer
of type 'asection' (aka 'struct bfd_section')
==18==WARNING: invalid path to external symbolizer!
==18==WARNING: Failed to use and restart external symbolizer!
#0 0x558f40f6f48c (/opt/bfd/ld-new+0x1a0148c) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#1 0x558f40efaadb (/opt/bfd/ld-new+0x198cadb) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#2 0x558f40ef9d77 (/opt/bfd/ld-new+0x198bd77) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#3 0x558f40f596c8 (/opt/bfd/ld-new+0x19eb6c8) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#4 0x558f40e45692 (/opt/bfd/ld-new+0x18d7692) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#5 0x558f40de50ce (/opt/bfd/ld-new+0x18770ce) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#6 0x558f40a05f71 (/opt/bfd/ld-new+0x1497f71) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#7 0x558f409d1439 (/opt/bfd/ld-new+0x1463439) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#8 0x558f409f3a1a (/opt/bfd/ld-new+0x1485a1a) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#9 0x7f581ddbc249 (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
#10 0x7f581ddbc304 (/lib/x86_64-linux-gnu/libc.so.6+0x27304) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
#11 0x558f408d4690 (/opt/bfd/ld-new+0x1366690) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../bfd/elf.c:13329:22 in
Aborted (core dumped)
The control exits 0 with no sanitizer diagnostics.
Root cause
----------
Confirmed in gdb on master a76487344054:
- The local symbol relr_target has st_shndx 17, but main.o has only section
indices 0-7 (readelf shows the index as BAD[0x11]).
- _bfd_x86_elf_link_relax_section maps the symbol with
bfd_section_from_elf_index (abfd, 17) (bfd/elfxx-x86.c:1197). That returns
NULL (gdb: 0x0; abfd->section_count is 3).
- The NULL is passed as sym_sec to elf_x86_relative_reloc_record_add
(bfd/elfxx-x86.c:1280) and stored at line 1060.
- elf_x86_size_or_finish_relative_reloc (bfd/elfxx-x86.c:1527) later passes it
to _bfd_elf_rela_local_sym, which reads sec->output_section at
bfd/elf.c:13329.
The section lookup at line 1197 does not check for NULL before the value is
used.
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 elf.c:13329:22; control
exits 0.
* Duplicate check (2026-12-04): see the Related Sourceware reports section.
Related Sourceware reports
--------------------------
Sourceware PR 34895 covers a NULL local-symbol buffer in
_bfd_x86_elf_link_relax_section. This report instead reaches packed RELR sizing
in bfd/elf.c with a local symbol whose section is missing.
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-x86-relr-local-symbol-null-section-reproducer.tar.gz`
--
You are receiving this mail because:
You are on the CC list for the bug.