aarch64: reject a relocation whose field lies outside the section
Binutils AArch64 ELF support now rejects relocations with fields outside section bounds.
This patch modifies binutils’ AArch64 ELF handling to reject relocations where the accessed field falls outside the section boundaries. This prevents crafted objects from causing the linker to read or write past section contents, addressing a security vulnerability.
- proposer
Proposes adding checks to reject relocations whose fields lie outside section boundaries in AArch64 ELF.
“elfNN_aarch64_relocate_section applied each relocation without checking that the relocated field lies inside the section, so a crafted object with a bad r_offset made the linker read and write past the section contents. elf64-x86-64.c and elf32-i386.c already range-check.”
In Details
This is the first patch in a series addressing security issues in binutils' AArch64 ELF processing. It introduces a bounds check at the start of the relocation loop in elfNN_aarch64_relocate_section. This check ensures that the memory location targeted by a relocation, considering its potentially wider write size (e.g., for 64-bit writes like R_AARCH64_TLS_DTPREL), is fully within the section's limits. This prevents heap overflows and other memory corruption when processing malformed object files, aligning with checks in other backends like x86. The patch also adds tests to verify this be…
- relocation
- A placeholder in object code that specifies how to modify an address or symbol reference when linking.
- r_offset
- The offset within the section where the relocation is to be applied.
- ELF
- Executable and Linkable Format, a common standard file format for object files, executables, and shared libraries on Unix-like systems.
- AArch64
- The 64-bit ARM architecture.
- heap-buffer-overflow
- A type of buffer overflow where the overflow occurs in dynamically allocated memory (the heap).
- R_AARCH64_TLS_DTPREL
- An AArch64 relocation type used for Thread-Local Storage (TLS) data access.
- bfd_put_64
- A BFD library function to write a 64-bit value to a file.
- R_AARCH64_NONE
- An AArch64 relocation type that indicates no operation is needed.