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

            Bug ID: 35087
           Summary: GNU ld indexes a NULL AArch64 local TLS-descriptor GOT
                    array
           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 17314
  --> https://sourceware.org/bugzilla/attachment.cgi?id=17314&action=edit
Reproduction environment

Product: binutils
Component: ld
Version: current master (716b214ad8db)
Host/target: Use an all-target GNU ld build, or a target build supporting the
emulation exercised by the attachment.

Summary
-------

After elfNN_aarch64_check_relocs rejects an AArch64 shared-object input (here
an R_AARCH64_ABS32 relocation), ld still runs the final link.
elfNN_aarch64_relocate_section then handles a local TLS-descriptor GOT
relocation whose local-symbol bookkeeping was never allocated, so
elf_aarch64_locals (input_bfd) is NULL and symbol_tlsdesc_got_offset_ref
indexes it at bfd/elfnn-aarch64.c:5493. This has the same root cause as
Sourceware bug 35086 (the TLS-IE/GOT variant), and the same suggested fix
applies.


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

1. Download and extract
`bfd-aarch64-local-tlsdesc-got-offset-null-pointer-arithmetic-reproducer.tar.gz`.
2. Run the following command with an ld.bfd or all-target `ld-new` binary that
   supports the emulation used by the reproducer:

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

The archive contains the fixed input files, independent controls, helper
scripts needed by `repro.sh`, and their checksums. The script uses a temporary
directory and does not modify the source tree.

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

On current master (716b214ad8db, GNU ld 2.47.50.20261202) built for all
targets with Clang ASan+UBSan, the trigger link aborts with:

    ../../bfd/elfnn-aarch64.c:5493:15: runtime error: applying non-zero offset
9920 to null pointer

The trigger also reports "relocation R_AARCH64_ABS32 against `relay_s2_GN'
can not be used when making a shared object" before the abort, and exits
with status 134.

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

ld should stop when it rejects the R_AARCH64_ABS32 relocation and report a
normal link error. It should not continue into the final link, and it should
not compute a pointer from the NULL local-symbol TLS-descriptor GOT array at
bfd/elfnn-aarch64.c:5493.

Validation
----------

* Current upstream source (PASS): unmodified master 716b214ad8db (GNU ld
2.47.50.20261202), all targets, Clang ASan+UBSan, aborts at
elfnn-aarch64.c:5493 in symbol_tlsdesc_got_offset_ref.
* Instrumented build (PASS): Fail-fast UBSan reports non-zero offset 9920
applied to NULL in symbol_tlsdesc_got_offset_ref.
* Independent control (PASS): The independent direct-final-link route omitting
the successful -r stage exits 1 after ordinary diagnostics without a sanitizer
failure; the staged route is required.
* Duplicate review (REVIEWED): No exact matching Sourceware report was found in
the review completed on 2026-10-29.

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

The suggested fix from bfd-aarch64-local-got-offsets-null-pointer-arithmetic
(Sourceware
bug 35086) removes this crash too. The patch is
bfd-aarch64-local-got-offsets-null-pointer-arithmetic.patch, and a Dockerfile
that builds current master with the patch applied is provided as Dockerfile
(both in the patches directory of the filing queue). Tested on master
716b214ad8db: the trigger exits 1 with "final link failed: bad value" and no
sanitizer diagnostic.

Scope
-----

This is a public robustness or correctness report. 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-aarch64-local-tlsdesc-got-offset-null-pointer-arithmetic-reproducer.tar.gz`
 Dockerfile (patch environment)
 bfd-aarch64-local-got-offsets-null-pointer-arithmetic.patch

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

Reply via email to