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

            Bug ID: 35105
           Summary: GNU ld RISC-V attribute merging dereferences an empty
                    ISA subset list (bfd/elfxx-riscv.c:3722:28)
           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 17340
  --> https://sourceware.org/bugzilla/attachment.cgi?id=17340&action=edit
reproducer

Product: binutils
Component: ld
Version: current master (a76487344054)
Host/target: RISC-V ELF (elf32briscv)

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

An unversioned RISC-V Tag_RISCV_arch drops every subset during parsing.
Attribute
merging then passes a NULL subset to riscv_i_or_e_p, which reads subset->name
at bfd/elfxx-riscv.c:3722.

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

1. Extract `bfd-riscv-empty-subset-null-dereference-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-empty-subset-null-dereference-reproducer.tar.gz

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

Master a76487344054, Clang ASan+UBSan. Trigger:

    /opt/bfd/ld-new: cannot find default versions of the ISA extension `i'
    /opt/bfd/ld-new: cannot find default versions of the ISA extension `m'
    ../../bfd/elfxx-riscv.c:3722:28: runtime error: member access within null
pointer of type 'struct riscv_subset_t'
    ==15==WARNING: invalid path to external symbolizer!
    ==15==WARNING: Failed to use and restart external symbolizer!
        #0 0x559db17468b0  (/opt/bfd/ld-new+0x1f8b8b0) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #1 0x559db17459ad  (/opt/bfd/ld-new+0x1f8a9ad) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #2 0x559db1741775  (/opt/bfd/ld-new+0x1f86775) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #3 0x559db145014d  (/opt/bfd/ld-new+0x1c9514d) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #4 0x559db0c24693  (/opt/bfd/ld-new+0x1469693) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #5 0x559db0c1bff7  (/opt/bfd/ld-new+0x1460ff7) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #6 0x559db0c40a1a  (/opt/bfd/ld-new+0x1485a1a) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #7 0x7efdc2c13249  (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
        #8 0x7efdc2c13304  (/lib/x86_64-linux-gnu/libc.so.6+0x27304) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
        #9 0x559db0b21690  (/opt/bfd/ld-new+0x1366690) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)

    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../bfd/elfxx-riscv.c:3722:28 in
    Aborted (core dumped)

The control exits 0 with no diagnostics.

Expected result
---------------

ld should reject the input with a normal diagnostic, not read a member of a
NULL subset.

Validation
----------

* Master a76487344054, Clang ASan+UBSan: trigger aborts at
elfxx-riscv.c:3722:28; control exits 0.
* With the suggested patch: trigger exits 1 with no sanitizer diagnostic.
* Duplicate check (2026-12-03): no matching Sourceware report found.

Suggested fix
-------------

`bfd-riscv-empty-subset-null-dereference.patch` checks for an empty subset
list in riscv_merge_arch_attr_info and rejects the merge with a diagnostic,
instead of passing NULL to riscv_i_or_e_p.

Scope
-----

No invalid write across a security boundary is established.

Attachment
----------

- `bfd-riscv-empty-subset-null-dereference-reproducer.tar.gz`
- `bfd-riscv-empty-subset-null-dereference.patch`

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

Reply via email to