BPF List
 help / color / mirror / Atom feed
* [PATCH] lib/buildid: Prevent overflow when aligning ELF note sizes
@ 2026-11-23 14:25 Thorsten Blum
  2026-11-30  5:30 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-11-23 14:25 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, Andrew Morton, Shakeel Butt
  Cc: Thorsten Blum, bpf, linux-kernel

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@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;
 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] lib/buildid: Prevent overflow when aligning ELF note sizes
  2026-11-23 14:25 [PATCH] lib/buildid: Prevent overflow when aligning ELF note sizes Thorsten Blum
@ 2026-11-30  5:30 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2026-11-30  5:30 UTC (permalink / raw)
  To: Thorsten Blum, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu,
	Yonghong Song, Jiri Olsa, Emil Tsalapatis, Ihor Solodrai,
	Andrew Morton, Shakeel Butt
  Cc: bpf, linux-kernel

On Mon, Nov 23, 2026 at 06:25 AM Thorsten Blum <blum@kernel.org> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30  5:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 14:25 [PATCH] lib/buildid: Prevent overflow when aligning ELF note sizes Thorsten Blum
2026-11-30  5:30 ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox