The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Thorsten Blum <blum@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>,
	Song Liu <song@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Yonghong Song <yonghong.song@linux.dev>,
	Emil Tsalapatis <emil@etsalapatis.com>
Cc: Thorsten Blum <blum@kernel.org>,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH bpf-next v2] lib/buildid: Avoid wraparound when aligning ELF note sizes
Date: Sat,  5 Dec 2026 14:11:20 +0100	[thread overview]
Message-ID: <20261205131119.105160-2-blum@kernel.org> (raw)

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

 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;
 

             reply	other threads:[~2026-12-05 13:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 13:11 Thorsten Blum [this message]
2026-12-05 13:43 ` [PATCH bpf-next v2] lib/buildid: Avoid wraparound when aligning ELF note sizes bot+bpf-ci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261205131119.105160-2-blum@kernel.org \
    --to=blum@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox