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

--- Comment #1 from Sourceware Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Alan Modra <[email protected]>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f76de399e17da60954e3698d3a685db2fc8827e2

commit f76de399e17da60954e3698d3a685db2fc8827e2
Author: Harshit Kumar <[email protected]>
Date:   Tue Nov 3 21:37:37 2026 +0530

    bfd: xcofflink: validate line-number offsets

    xcoff_link_add_symbols (Pass 1) and xcoff_link_input_bfd (Pass 2)
    compute linoff as the function's x_lnnoptr minus
    enclosing->line_filepos.  x_lnnoptr is uint64_t, so a corrupt value
    below line_filepos produces a large unsigned linoff.  A corrupt
    x_lnnoptr can also place linoff past the end of the enclosing
    line-number table, or leave it misaligned, meaning not a multiple of the
    record size.

    In the old signed variable, a value below line_filepos became negative.
    Pass 1 accepted a negative linoff.  Pass 1 then read the first record
    before the start of the table.  The read is a heap-buffer-overflow.  A
    misaligned linoff can make the scan read a record that starts inside the
    table and ends past it.  Pass 2 had no bounds check.

    Pass 1 now rejects a linoff that wraps below the table start, is
    misaligned, or lies outside the table.  The rejection reports an error
    and sets bfd_error_bad_value.  Pass 2 checks the first record and all
    *lineno_counts records against amt, the table size in bytes.  Pass 2
    also checks that linoff is a multiple of linesz.  The Pass 2 check is
    defensive.  Pass 1 already guarantees these bounds and alignment.

    Behaviour change: Pass 1 used to skip an out-of-table linoff silently.
    The function then lost its line numbers.  Pass 1 also accepted a
    misaligned linoff.  Both cases now fail the link.  This includes the case
    where the enclosing section has no line numbers but the function still
    carries an x_lnnoptr.

    Valid input gives the same result with and without this patch.

    Extend ld/testsuite/ld-powerpc/xcoff-aux.exp.  The new tests use a valid
    216-byte XCOFF32 input with one line-numbered function.  The tests cover
    a positive control, a negative offset, an inflated offset, and a
    misaligned offset.  Each malformed input must exit with status 1.  Each
    malformed input must print the diagnostic "invalid line number offset".
    Each malformed input must leave no output file and no crash output.  The
    test deletes its inputs and outputs.

    On an unpatched linker, the negative and misaligned inputs cause
    heap-buffer-overflow reads under AddressSanitizer.  On an unpatched
    linker, the inflated input exits with status 0.

    No test covers the Pass 2 check.

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

    bfd/
            PR ld/34883
            * xcofflink.c (xcoff_link_add_symbols): Validate line-number offset
            bounds and record alignment.
            (xcoff_link_input_bfd): Check line-number offset bounds and record
            alignment defensively.

    ld/
            PR ld/34883
            * testsuite/ld-powerpc/xcoff-aux.exp (expect_lineno_rejection): New
            procedure.
            (xcoff_aux_test): Add tests for positive control, negative,
            inflated, and misaligned line-number offsets.

    Signed-off-by: Harshit Kumar <[email protected]>

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

Reply via email to