elfedit: validate PT_NOTE bounds and alignment
A patch for `elfedit` adds validation for PT_NOTE segment bounds and alignment to prevent crashes and security issues when processing crafted binaries.
This patch enhances elfedit’s update_gnu_property function by adding crucial validation for Program Header table entries of type PT_NOTE. It checks that the p_offset and p_filesz values keep the note segment within the file’s boundaries, preventing potential SIGSEGV crashes or memory corruption from crafted binaries. Additionally, it normalizes and validates the p_align field to avoid division-by-zero errors and invalid alignments, and corrects a bounds-checking logic error.
- proposer
Submits a patch to `elfedit.c` that adds validation for PT_NOTE segment bounds and alignment, fixing potential crashes and security vulnerabilities.
“update_gnu_property maps the whole file read/write and then walks every PT_NOTE segment, editing the GNU property notes in place. The program header table is checked against the file size, but the PT_NOTE segments themselves are not: p_offset and p_filesz are used as they are to compute "map + p_offset", so a note segment that points outside the file makes elfedit read and write past the end of…”
In Details
This patch addresses security and robustness issues in elfedit, specifically within the update_gnu_property function. The function maps the ELF file and modifies GNU property notes in place. The vulnerability lies in not validating the bounds of PT_NOTE segments before accessing them. A malicious binary could provide p_offset and p_filesz values that point outside the mapped file, leading to a SIGSEGV or arbitrary memory writes. The patch also corrects alignment validation (p_align) to prevent division-by-zero and ensures power-of-two alignment, and refines the datasz bounds check…
- elfedit
- A tool within binutils for editing ELF (Executable and Linkable Format) files.
- PT_NOTE
- A segment type in an ELF file that contains arbitrary data, often used for versioning, OS-specific information, or custom metadata like GNU properties.
- p_offset
- A field in an ELF Program Header table entry that specifies the offset from the beginning of the file to the first byte of the segment.
- p_filesz
- A field in an ELF Program Header table entry that specifies the size in bytes of the segment in the file.
- p_align
- A field in an ELF Program Header table entry that specifies the alignment requirement of the segment.
- SIGSEGV
- A signal sent to a process when it attempts to access a memory location that it's not allowed to access, typically indicating a segmentation fault.