[PATCH bpf-next v2] lib/buildid: Avoid wraparound when aligning ELF note sizes

From: Thorsten Blum

Date: Sat Dec 05 2026 - 08:11:39 EST


For u32 note sizes, ALIGN() wraps the values 0xfffffffd through
0xffffffff to 0 before check_add_overflow() runs. Parsing can then
continue as if the affected size were 0.

Use u64 for name_sz and desc_sz to avoid alignment wraparound, allowing
check_add_overflow() to reject these malformed notes early.

Signed-off-by: Thorsten Blum <blum@xxxxxxxxxx>
---
Changes in v2:
- Reframe the change as hardening and drop the Fixes: tag (Alexei)
- v1: https://lore.kernel.org/r/20261123142510.51241-2-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;