binutils Newspaper
NOVEMBER 30, 2026
elfedit — Needs Revision

elfedit: Validate PT_NOTE segment bounds and alignment

Reviewer suggests improvements to a patch that validates PT_NOTE segments in elfedit, specifically regarding alignment handling and ChangeLog formatting.

A reviewer discussed a patch for elfedit that aims to validate the bounds and alignment of PT_NOTE segments within ELF files. The original patch fixed issues where elfedit could read or write past file mappings due to unchecked p_offset and p_filesz, and also addressed division-by-zero and infinite loops caused by invalid p_align values. The reviewer agreed with the core fixes but suggested refining the alignment normalization logic and improving the ChangeLog entry’s format, noting it repeated the patch description.

In the Thread 2 participants
  1. mustafa proposer

    Submitted a patch to `elfedit` to validate `PT_NOTE` segment bounds and alignment, preventing crashes and potential corruption.

    “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 the mapping. A crafted binary crashes it with SIGSEGV. Other fields in the same loop are also trusted: [...] p_align of 0 gives a…”
  2. Jan Beulich <jbeulich@suse.com> maintainer

    Provided feedback on the patch, suggesting improvements to alignment handling and ChangeLog formatting, while agreeing with the necessity of the validation.

    “I fear what readelf does cannot be directly mirrored here, where we actually alter the file (but we don't want to corrupt it). See also below. Nit: There's a binutils/ line missing ahead of the ChangeLog entry. Also the contents aren't really ChangeLog-like; it rather repeats the patch description.”

Technical Tradeoffs

  • Enhances security by preventing memory corruption through stricter validation of ELF note segments.
  • Requires careful handling of alignment values to maintain correctness and avoid division-by-zero issues.

In Details

This discussion revolves around security enhancements for elfedit, a tool for editing ELF files. The patch focuses on validating PT_NOTE (program segment notes) entries. It addresses two primary concerns: first, ensuring that the offset and file size of PT_NOTE segments do not point outside the file's mapped region to prevent buffer overflows; second, normalizing and validating the p_align (alignment) field to avoid division-by-zero errors and ensure correct calculations. The reviewer also provides feedback on the code changes and commit message style.

For Context
elfedit
A tool for editing ELF (Executable and Linkable Format) files.
PT_NOTE
A type of program header segment in an ELF file that contains arbitrary data, often used for versioning or other metadata.
ELF
Executable and Linkable Format, a standard file format for executables, object code, shared libraries, and core dumps on Unix-like systems.
p_offset
The offset of the segment in the file.
p_filesz
The size of the segment in the file.
p_align
The alignment requirement of the segment.
ChangeLog
A file that records changes made to a software project over time, typically organized by date and description of modifications.
Filed Under: binutilselfeditsecurityvalidationelf