binutils Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
bfd/coff

BFD bounds-checks COFF relocation symbol indices across five backends

Malformed COFF objects with bad r_symndx values no longer cause out-of-bounds heap reads in SH, ARM, AArch64, MCore and XCOFF code.

Several COFF backends used a relocation’s r_symndx to index symbol tables without checking it against the table size. A crafted object with a negative or oversized index could trigger out-of-bounds heap reads in the linker or other BFD consumers. The patch adds a shared coff_symndx_in_range macro in libcoff-in.h (mirrored in libcoff.h). It checks that the index is non-negative and below obj_raw_syment_count, and the SH, ARM, AArch64, MCore, cofflink and xcofflink code now use it. Loops that can safely ignore a bad entry skip it. Functions that can’t return a partial result set bfd_error_bad_value and fail. Absolute relocations that use the -1 sentinel are skipped without diagnostics. A new SH COFF linker test covers the malformed cases.

In Details

COFF backends (coff-sh.c, coff-arm.c, coff-aarch64.c, coff-mcore.c) and the generic linker (cofflink.c, xcofflink.c) use reloc->r_symndx to index obj_coff_external_syms, sym_hashes and similar arrays. Only some paths, such as sh_relocate_section, validated the index. The new macro is checked against obj_raw_syment_count. The -1 sentinel for absolute relocs needs separate handling. AArch64 PE previously read sym_hashes before validating.

For Context
r_symndx
The field in a COFF relocation entry that holds the index of the target symbol in the object's symbol table. Linkers use it to look up the symbol a relocation refers to. In malformed files it can be negative or past the end of the table.
obj_raw_syment_count
A BFD macro giving the number of raw symbol-table entries declared in a COFF file header. Auxiliary entries count as entries. Parallel arrays such as sym_hashes are sized from it.
sym_hashes
An array of linker hash-table entries, parallel to a COFF object's symbol table and indexed by symbol number. A bad index into it reads beyond the allocated buffer.
sh_relax_section
The SH COFF linker-relaxation routine. It rewrites call sequences into shorter forms and examines relocations and symbols to do so.
bfd_error_bad_value
A BFD error code set when input data is invalid. Callers use it to signal failure instead of continuing with corrupt state.
Filed Under: securitycoffbfdhardeninglinker