https://sourceware.org/bugzilla/show_bug.cgi?id=34449

            Bug ID: 34449
           Summary: ld: SEGV in elf_x86_64_common_section_index
                    (bfd/elf64-x86-64.c:6093) via malformed common symbol
                    with `-r`
           Product: binutils
           Version: 2.47
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: 2722900221 at qq dot com
  Target Milestone: ---

Created attachment 16881
  --> https://sourceware.org/bugzilla/attachment.cgi?id=16881&action=edit
PoC

Summary

During relocatable link (`-r`), `elf_x86_64_common_section_index`
(`bfd/elf64-x86-64.c:6093`) dereferences a NULL `sec` while computing the
common-section index for an output symbol (called from `elf_link_output_extsym`
→ `bfd_hash_traverse` → `_bfd_elf_final_link`). `elf_section_flags(sec)` on the
NULL pointer crashes.

Affected Version

- binutils 2.47 (release tarball, version date `20260726`) — reproduced.
- Originally triaged on dev snapshot `2.47.50.20260722` (commit `640a79623`).

Reproduction

Build (ASAN):
CC=gcc CFLAGS='-g -O1 -fsanitize=address -fno-omit-frame-pointer -fno-common' \
LDFLAGS='-fsanitize=address' \
./configure --disable-gdb --disable-gdbserver --disable-sim --disable-cet \
            --disable-werror --disable-nls --enable-targets=x86_64-linux-gnu
MAKEINFO=true
make -j

Run:
export
ASAN_OPTIONS="abort_on_error=0:symbolize=1:detect_leaks=0:allocator_may_return_null=1:halt_on_error=1"
ld -r -o /dev/null bug_0.o

Error Log

==64971==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000008 (pc
0x55a11ccb37ed bp 0x7ffdc898b0d0 sp 0x7ffdc898b0d0 T0)
The signal is caused by a READ memory access.
    #0 elf_x86_64_common_section_index
/home/user/build/binutils-2.47/bfd/elf64-x86-64.c:6093
    #1 elf_link_output_extsym         
/home/user/build/binutils-2.47/bfd/elflink.c:10941
    #2 bfd_hash_traverse              
/home/user/build/binutils-2.47/bfd/hash.c:814
    #3 _bfd_elf_final_link            
/home/user/build/binutils-2.47/bfd/elflink.c:13380
    #4 ldwrite                        
/home/user/build/binutils-2.47/ld/ldwrite.c:548
SUMMARY: AddressSanitizer: SEGV
/home/user/build/binutils-2.47/bfd/elf64-x86-64.c:6093 in
elf_x86_64_common_section_index

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to