Skip to contentSkip to conversation

lib/buildid: Prevent overflow when aligning ELF note sizes

PATCH New Thorsten Blum 1 participant 1 message Nov 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

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")
---
 lib/buildid.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/buildid.c +2 -1
index 995a327f46ae..767243f424d6 100644
@@ -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;