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

            Bug ID: 35106
           Summary: GNU ld RISC-V ISA parser indexes before its
                    extension-order table (bfd/elfxx-riscv.c:2207:8)
           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 17342
  --> https://sourceware.org/bugzilla/attachment.cgi?id=17342&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
-------

A malformed RISC-V Tag_RISCV_arch extension starting with a non-letter, such as
'9', makes riscv_parse_extensions index the 26-entry riscv_ext_order table
with a negative offset at bfd/elfxx-riscv.c:2207.

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

1. Extract `bfd-riscv-extension-category-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-extension-category-oob-read-reproducer.tar.gz

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

Master a76487344054, Clang ASan+UBSan. Trigger:

    ../../bfd/elfxx-riscv.c:2207:8: runtime error: index -40 out of bounds for
type 'int[26]'
    ==15==WARNING: invalid path to external symbolizer!
    ==15==WARNING: Failed to use and restart external symbolizer!
        #0 0x563db50b439a  (/opt/bfd/ld-new+0x1f8139a) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #1 0x563db50b969f  (/opt/bfd/ld-new+0x1f8669f) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #2 0x563db4dc814d  (/opt/bfd/ld-new+0x1c9514d) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #3 0x563db459c693  (/opt/bfd/ld-new+0x1469693) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #4 0x563db4593ff7  (/opt/bfd/ld-new+0x1460ff7) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #5 0x563db45b8a1a  (/opt/bfd/ld-new+0x1485a1a) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #6 0x7f6dd917c249  (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
        #7 0x7f6dd917c304  (/lib/x86_64-linux-gnu/libc.so.6+0x27304) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
        #8 0x563db4499690  (/opt/bfd/ld-new+0x1366690) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)

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

The control exits 0 with no diagnostics.

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

ld should reject the malformed extension with a normal diagnostic, not index
the table with a negative offset.

Validation
----------

* Master a76487344054, Clang ASan+UBSan: trigger aborts at
elfxx-riscv.c:2207:8; control exits 0.
* With the suggested patch: trigger exits 1 with "unknown standard ISA
extension or prefix class `9'" and "failed to merge target specific data";
control exits 0.
* Duplicate check (2026-12-03): no matching Sourceware report found.

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

`bfd-riscv-extension-category-oob-read.patch` checks that a single-letter
extension name is in 'a'-'z' before indexing riscv_ext_order, at both
bfd/elfxx-riscv.c:2207 and :2823. Characters outside that range take the
existing "unknown ISA extension" error path.

Scope
-----

Robustness issue. No invalid write across a security boundary is established.

Attachment
----------

- `bfd-riscv-extension-category-oob-read-reproducer.tar.gz`
- `bfd-riscv-extension-category-oob-read.patch`

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

Reply via email to