Re: [PATCH] lib/buildid: Prevent overflow when aligning ELF note sizes

From: Alexei Starovoitov

Date: Mon Nov 30 2026 - 00:30:42 EST


On Mon, Nov 23, 2026 at 06:25 AM Thorsten Blum <blum@xxxxxxxxxx> wrote:
> Commit de3ec364c3c3 ("lib/buildid: add single folio-based file reader
> abstraction") changed name_sz and desc_sz from u64 to u32. As a result,
> ALIGN() could wrap malformed sizes near U32_MAX to 0, which would allow
> such values to bypass the overflow checks and parsing to continue with
> an incorrect note offset.

That's not a fix. Nothing is broken.
Only 0xfffffffd, 0xfffffffe and 0xffffffff wrap. They act like size 0.
Size 0 is valid in n_namesz and n_descsz and gives the same new_off.
new_off still moves by 12 bytes or more and stays within note_end.
Such a note never matches: that needs name_sz == 4 and desc_sz <= 20.

pw-bot: cr