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

            Bug ID: 35102
           Summary: GNU ld dereferences a missing PLT section while
                    allocating an ELF IFUNC relocation
                    (bfd/elf-ifunc.c:233)
           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 17334
  --> https://sourceware.org/bugzilla/attachment.cgi?id=17334&action=edit
reproducer

Product: binutils
Component: ld
Version: 2.46
Host/target: Use an all-target GNU ld build, or a target build supporting the
emulation exercised by the attachment.

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
-------

Three standalone RV32 relocatables make a static GNU ld link enter
_bfd_elf_allocate_ifunc_dyn_relocs without a PLT section and read plt->size at
bfd/elf-ifunc.c:233.

Reproduction
------------

1. Extract `bfd-elf-ifunc-missing-plt-null-dereference-reproducer.tar.gz`.
2. Run its script with an all-target `ld-new` binary:

       LD_BFD=/path/to/ld-new sh repro.sh

   Or use the `bfd-repro` image from the queue root:

       docker run --rm -v "$PWD:/queue:ro" bfd-repro \
        
/queue/attachments/bfd-elf-ifunc-missing-plt-null-dereference-reproducer.tar.gz

To test the suggested patch, build the patch image from the queue root:

       docker build -f patches/patch.Dockerfile \
         --build-arg PATCH=bfd-elf-ifunc-missing-plt-null-dereference.patch \
         -t bfd-patched-ifunc .

   Then run the reproducer against it:

       docker run --rm -v "$PWD:/queue:ro" bfd-patched-ifunc \
        
/queue/attachments/bfd-elf-ifunc-missing-plt-null-dereference-reproducer.tar.gz

Observed result
---------------

Three standalone RV32 relocatables make a static GNU ld link enter
_bfd_elf_allocate_ifunc_dyn_relocs without a PLT section and read plt->size at
bfd/elf-ifunc.c:233; current plain and GNU ld 2.46 segfault, while a
relocatable-link control succeeds.

UBSan Report:
../../bfd/elf-ifunc.c:233:28: runtime error: member access within null pointer
of type 'asection' (aka 'struct bfd_section')
==14==WARNING: invalid path to external symbolizer!
==14==WARNING: Failed to use and restart external symbolizer!
    #0 0x55a59cfda688  (/opt/bfd/ld-new+0x19ad688) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
    #1 0x55a59d2f23e4  (/opt/bfd/ld-new+0x1cc53e4) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
    #2 0x55a59cf4c57c  (/opt/bfd/ld-new+0x191f57c) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
    #3 0x55a59d2d9fba  (/opt/bfd/ld-new+0x1cacfba) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
    #4 0x55a59d06a31c  (/opt/bfd/ld-new+0x1a3d31c) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
    #5 0x55a59cefcb7c  (/opt/bfd/ld-new+0x18cfb7c) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
    #6 0x55a59ce0034b  (/opt/bfd/ld-new+0x17d334b) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
    #7 0x55a59cac4fd1  (/opt/bfd/ld-new+0x1497fd1) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
    #8 0x55a59ca8fad5  (/opt/bfd/ld-new+0x1462ad5) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
    #9 0x55a59cab2a1a  (/opt/bfd/ld-new+0x1485a1a) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
    #10 0x7ff7d3ae4249  (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
    #11 0x7ff7d3ae4304  (/lib/x86_64-linux-gnu/libc.so.6+0x27304) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
    #12 0x55a59c993690  (/opt/bfd/ld-new+0x1366690) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../bfd/elf-ifunc.c:233:28 in 
Aborted (core dumped)

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
----------

* Current upstream source (PASS): Unmodified master, all targets, Clang
ASan+UBSan: the trigger aborts at bfd/elf-ifunc.c:233:28; the control links
with -r and exits 0.
* Suggested patch (PASS): With
`bfd-elf-ifunc-missing-plt-null-dereference.patch` applied to master, the
elf-ifunc.c:233 error no longer occurs.
* Independent control (PASS): The same three objects link successfully with -r.
* Duplicate review (REVIEWED): No exact matching Sourceware report was found in
the review completed on 2026-10-29.

Related Sourceware reports
--------------------------

* PR 34841: PPC64 undefined IFUNC static links dereference a missing PLT
section (same missing-PLT dereference, different backend).
* PR 34988: local IFUNC referenced only from .debug_info (x86-64 internal error
in elf_x86_64_relocate_section).
* PR 35099: sparc64 ld -r segfault over an IFUNC defined and referenced in
different objects.

Scope
-----

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-elf-ifunc-missing-plt-null-dereference-reproducer.tar.gz`
`bfd-elf-ifunc-missing-plt-null-dereference.patch`

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

Reply via email to