bfd: harden in-place relaxation byte deletion against size underflow
Series hardens 18 ELF backends against heap corruption from relaxation byte deletion underflows.
This series addresses a heap corruption vulnerability in 18 ELF backends of the BFD library, caused by unsigned integer underflow during linker relaxation’s byte deletion operations. When memmove is used to shrink sections, an out-of-range offset or deletion count can cause the size calculation toaddr - addr - count to wrap around to SIZE_MAX. This series introduces a shared helper function _bfd_elf_relax_delete_range_ok to validate these ranges, ensuring that error conditions are correctly propagated and preventing buffer overflows. It also includes updates to specific backends (AVR, M68HC11, RISC-V, RL78, RX) to propagate failures and adds comprehensive testing.
- proposer
Proposes a series of patches to harden 18 ELF backends against heap corruption during relaxation byte deletion by adding range checks.
“This series hardens 18 ELF backends in BFD against buffer underflow and heap corruption during linker relaxation byte deletion. Problem Description =================== Linker relaxation backends that shrink code sections slide remaining section bytes downward over deleted space via memmove: memmove (contents + addr, contents + addr + count, toaddr - addr - count); When input relocations or…”
In Details
This is the cover letter for a series of patches fixing a heap corruption vulnerability across 18 ELF targets in binutils. The core issue lies in linker relaxation functions that shrink code sections using memmove. When the calculated deletion range is invalid (e.g., count exceeds the available space before toaddr), the toaddr - addr - count subtraction wraps around for unsigned integers, leading to a massive SIZE_MAX value. This causes memmove to write far beyond the intended buffer, corrupting the heap. The series introduces a shared validation helper (`_bfd_elf_relax_delete_ran…
- linker relaxation
- A linker optimization process that adjusts instruction addresses and sizes at link time to improve code density or enable features like position-independent code. It may involve deleting or replacing instructions.
- BFD
- Binary File Descriptor library, a GNU library used by binutils and other tools to abstract access to various executable file formats.
- ELF
- Executable and Linkable Format, a common standard file format for executables, object code, shared libraries, and core dumps on Unix-like systems.
- memmove
- A C standard library function that copies a block of memory from a source location to a destination location. It handles overlapping memory regions safely.
- underflow
- In the context of memory or arithmetic operations, underflow occurs when a value becomes smaller than the minimum representable value. For unsigned integers, this typically results in wrap-around to a very large positive number.
- heap buffer overflow
- A type of security vulnerability where a program writes data beyond the allocated buffer boundary on the heap, potentially corrupting adjacent memory or control structures.
- RISC-V
- An open-standard instruction set architecture (ISA) based on RISC principles, gaining traction in various computing domains.