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

            Bug ID: 35110
           Summary: GNU ld SFrame record count can read past the section
           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 17348
  --> https://sourceware.org/bugzilla/attachment.cgi?id=17348&action=edit
reproducer

Product: binutils
Component: ld
Version: current master (a76487344054)
Host/target: ELF (SFrame .sframe section)

Summary
-------

An SFrame section whose header advertises more FDEs than it has relocations
makes ld read past the end of its relocation array while building per-function
bookkeeping, causing a heap-buffer READ SEGV.

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

1. Extract `bfd-sframe-parse-header-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-sframe-parse-header-oob-read-reproducer.tar.gz

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

Master a76487344054, ASan build. Trigger:

    AddressSanitizer:DEADLYSIGNAL
    ==18==ERROR: AddressSanitizer: SEGV on unknown address 0x6060f0100690 (pc
0x560c44f9a7e9 bp 0x7ffe8066e890 sp 0x7ffe8066e870 T0)
    ==18==The signal is caused by a READ memory access.
    ==18==WARNING: invalid path to external symbolizer!
    ==18==WARNING: Failed to use and restart external symbolizer!
        #0 0x560c44f9a7e9  (/opt/bfd/ld-new+0x29427e9) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #1 0x560c44f981e6  (/opt/bfd/ld-new+0x29401e6) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #2 0x560c44016b91  (/opt/bfd/ld-new+0x19beb91) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #3 0x560c440d0c14  (/opt/bfd/ld-new+0x1a78c14) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #4 0x560c43ecf0bf  (/opt/bfd/ld-new+0x18770bf) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #5 0x560c43aeff71  (/opt/bfd/ld-new+0x1497f71) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #6 0x560c43abb439  (/opt/bfd/ld-new+0x1463439) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #7 0x560c43adda1a  (/opt/bfd/ld-new+0x1485a1a) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
        #8 0x7f49a5d74249  (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
        #9 0x7f49a5d74304  (/lib/x86_64-linux-gnu/libc.so.6+0x27304) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
        #10 0x560c439be690  (/opt/bfd/ld-new+0x1366690) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)

    AddressSanitizer can not provide additional info.
    SUMMARY: AddressSanitizer: SEGV (/opt/bfd/ld-new+0x29427e9) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
    ==18==ABORTING
    Aborted (core dumped)

The control exits 0.

Root cause
----------

Confirmed with gdb on master a76487344054 (SIGSEGV at libsframe/sframe.c:161):

- _bfd_elf_parse_sframe (bfd/elf-sframe.c:276) calls sframe_decode.
- sframe_decode (libsframe/sframe.c:1493) calls sframe_fde_tbl_init.
- For SFrame version 3 (libsframe/sframe.c:146-161), each FDE index entry's
  sfdi_func_start_fre_off is added to fre_buf and dereferenced
  (fattr->sfda_func_num_fres) with no check against the FRE section length.
- The crafted offset points the read outside the section. The faulting address
  in the ASan run (0x6060f0100690) is about 4 GB past fre_buf, which fits a
  32-bit offset field.

The fix is to validate sfdi_func_start_fre_off against the FRE length before
the dereference.

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

ld should reject the section with a normal diagnostic, not read past its
relocation array.

Validation
----------

* Master a76487344054, ASan build: trigger fails with a heap-buffer READ SEGV;
control exits 0.
* Duplicate check (2026-12-03): no matching Sourceware report found.

Scope
-----

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

Attachment
----------

- `bfd-sframe-parse-header-oob-read-reproducer.tar.gz`

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

Reply via email to