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

bfd: Add helper to validate ELF relaxation deletion ranges

Introduces a shared helper function to validate ELF section deletion intervals during relaxation, preventing underflows and buffer overflows.

This commit adds a new helper function, _bfd_elf_relax_delete_range_ok, to the BFD ELF backend. This function validates deletion intervals during the relaxation process, ensuring that offsets and counts do not cause unsigned integer underflows. Such underflows could previously lead to heap buffer overflows or crashes. By introducing this check, the patch enhances the robustness of ELF relaxation handling.

In Details

The BFD ELF backend's relaxation process sometimes involves memmove-ing section contents over deleted bytes. This can lead to unsigned integer underflows when calculating transfer sizes if relocations or section headers specify offsets or counts exceeding remaining section bytes. This change introduces _bfd_elf_relax_delete_range_ok in bfd/elf.c to validate offs, limit, and count against sec->size before performing the memmove, mitigating potential overflows. This function is intended for use by multiple ELF backends that perform similar relaxation operations.

For Context
BFD
Binary File Descriptor library, an abstraction layer within GNU Binutils for handling various executable and object file formats.
ELF
Executable and Linkable Format, a standard file format for executables, object code, shared libraries, and core dumps on many Unix-like systems.
Relaxation
A linking process where the linker adjusts certain instructions or data after initial assembly. This is often done to accommodate relative addressing or to optimize code layout.
Relocation
Information in an object file that tells the linker how to modify code or data addresses when combining object files into an executable or shared library.
Filed Under: binutilsbfdelfsecurityrelaxation