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

From: Thorsten Blum

Date: Mon Nov 23 2026 - 09:25:24 EST


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.

Restore u64 for name_sz and desc_sz to prevent alignment overflow. The
existing check_add_overflow() calls then reject sums that do not fit in
the u32 offset.

Fixes: de3ec364c3c3 ("lib/buildid: add single folio-based file reader abstraction")
Signed-off-by: Thorsten Blum <blum@xxxxxxxxxx>
---
lib/buildid.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/buildid.c b/lib/buildid.c
index 995a327f46ae..767243f424d6 100644
--- a/lib/buildid.c
+++ b/lib/buildid.c
@@ -161,7 +161,8 @@ static int parse_build_id(struct freader *r, unsigned char *build_id, __u32 *siz
{
const char note_name[] = "GNU";
const size_t note_name_sz = sizeof(note_name);
- u32 build_id_off, new_off, note_end, name_sz, desc_sz;
+ u32 build_id_off, new_off, note_end;
+ u64 name_sz, desc_sz;
const Elf32_Nhdr *nhdr;
const char *data;