* [PATCH bpf-next v2] lib/buildid: Avoid wraparound when aligning ELF note sizes
@ 2026-12-05 13:11 Thorsten Blum
2026-12-05 13:43 ` bot+bpf-ci
2026-12-05 16:34 ` Alexei Starovoitov
0 siblings, 2 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-12-05 13:11 UTC (permalink / raw)
To: Andrew Morton, Song Liu, Jiri Olsa, Ihor Solodrai,
Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Yonghong Song, Emil Tsalapatis
Cc: Thorsten Blum, bpf, linux-kernel
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;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next v2] lib/buildid: Avoid wraparound when aligning ELF note sizes
2026-12-05 13:11 [PATCH bpf-next v2] lib/buildid: Avoid wraparound when aligning ELF note sizes Thorsten Blum
@ 2026-12-05 13:43 ` bot+bpf-ci
2026-12-05 16:34 ` Alexei Starovoitov
1 sibling, 0 replies; 4+ messages in thread
From: bot+bpf-ci @ 2026-12-05 13:43 UTC (permalink / raw)
To: blum, akpm, song, jolsa, ihor.solodrai, ast, daniel, andrii,
eddyz87, memxor, martin.lau, yonghong.song, emil
Cc: blum, bpf, linux-kernel, ast, andrii, daniel, martin.lau, eddyz87,
yonghong.song, mason, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 2140 bytes --]
> lib/buildid: Avoid wraparound when aligning ELF note sizes
TL;DR: Commit message only: it claims note sizes 0xfffffffd-0xffffffff
wrapping to 0 is a problem, but the review finds no real behaviour change, and
asks what this u64 patch actually fixes.
> lib/buildid: Avoid wraparound when aligning ELF note sizes
>
> 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>
> diff --git a/lib/buildid.c b/lib/buildid.c
> --- 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;
An earlier version of this patch drew a review comment that only
0xfffffffd, 0xfffffffe and 0xffffffff wrap, that they behave like size 0,
and that size 0 is valid in n_namesz and n_descsz and gives the same
new_off. The thread is at:
https://lore.kernel.org/all/DN8ARGULOD13.2ES34FRWS1M2B@gmail.com/
The commit message still says "Parsing can then continue as if the affected
size were 0." Is that an actual problem?
In parse_build_id(), new_off still advances by at least
sizeof(Elf32_Nhdr) and stays within note_end for such a note. A note with
those sizes can never match, since a match needs name_sz == note_name_sz
and desc_sz <= BUILD_ID_SIZE_MAX.
Could the commit message explain what behavior changes with this patch,
given that analysis?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47525085165
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next v2] lib/buildid: Avoid wraparound when aligning ELF note sizes
2026-12-05 13:11 [PATCH bpf-next v2] lib/buildid: Avoid wraparound when aligning ELF note sizes Thorsten Blum
2026-12-05 13:43 ` bot+bpf-ci
@ 2026-12-05 16:34 ` Alexei Starovoitov
2026-12-05 17:14 ` Thorsten Blum
1 sibling, 1 reply; 4+ messages in thread
From: Alexei Starovoitov @ 2026-12-05 16:34 UTC (permalink / raw)
To: Thorsten Blum, Andrew Morton, Song Liu, Jiri Olsa, Ihor Solodrai,
Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Martin KaFai Lau, Yonghong Song,
Emil Tsalapatis
Cc: bpf, linux-kernel
On Sat, Dec 05, 2026 at 05:11 AM Thorsten Blum <blum@kernel.org> wrote:
> 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.
The code is the same as in v1. Only the log changed.
The reason for rejection is the same as before: nothing is broken.
It doesn't harden anything either. The owner of the file writes 0
instead of 0xffffffff and gets the same walk. Size 0 is valid.
I don't think we need this patch.
pw-bot: cr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next v2] lib/buildid: Avoid wraparound when aligning ELF note sizes
2026-12-05 16:34 ` Alexei Starovoitov
@ 2026-12-05 17:14 ` Thorsten Blum
0 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-12-05 17:14 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Andrew Morton, Song Liu, Jiri Olsa, Ihor Solodrai,
Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Martin KaFai Lau, Yonghong Song,
Emil Tsalapatis, bpf, linux-kernel
On Sat, Dec 05, 2026 at 04:34:44PM +0000, Alexei Starovoitov wrote:
> On Sat, Dec 05, 2026 at 05:11 AM Thorsten Blum <blum@kernel.org> wrote:
> > 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.
>
> The code is the same as in v1. Only the log changed.
> The reason for rejection is the same as before: nothing is broken.
> It doesn't harden anything either. The owner of the file writes 0
> instead of 0xffffffff and gets the same walk. Size 0 is valid.
> I don't think we need this patch.
OK, I misunderstood your first feedback then.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-05 17:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 13:11 [PATCH bpf-next v2] lib/buildid: Avoid wraparound when aligning ELF note sizes Thorsten Blum
2026-12-05 13:43 ` bot+bpf-ci
2026-12-05 16:34 ` Alexei Starovoitov
2026-12-05 17:14 ` Thorsten Blum
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.