From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Gu Bin" <gubin@cmss.chinamobile.com>, <bpf@vger.kernel.org>
Cc: <daniel@iogearbox.net>, <andrii@kernel.org>, <alan.maguire@oracle.com>
Subject: Re: [PATCH v2] libbpf: Fix ENODATA comparison and unbounded zero-scan in btf_dump
Date: Mon, 02 Nov 2026 16:47:48 +0000 [thread overview]
Message-ID: <DMKVMPJUIHT1.T3WBE1MBIDA1@gmail.com> (raw)
In-Reply-To: <20261102131632.1124-1-gubin@cmss.chinamobile.com>
On Mon, Nov 02, 2026 at 05:16 AM Gu Bin <gubin@cmss.chinamobile.com> wrote:
> In btf_dump_type_data_check_zero(), the BTF_KIND_STRUCT/UNION branch
> compares the per-member result with ENODATA (no minus sign), unlike
> every other branch which uses -ENODATA. The function returns
This part is already fixed in bpf-next. See
commit ab332ec8953d ("libbpf: Fix struct and union zero detection in BTF dumper").
Pls rebase. Drop this part from the subject and from the commit log.
[...]
> @@ -2533,6 +2533,12 @@ static int btf_dump_type_data_check_zero(struct btf_dump *d,
> + err = btf_dump_type_data_check_overflow(d, elem_type,
> @@ -2565,9 +2571,15 @@ static int btf_dump_type_data_check_zero(struct btf_dump *d,
> + err = btf_dump_type_data_check_overflow(d, mtype, m->type,
No need for two copies. Do the check once at the top of
btf_dump_type_data_check_zero(). Every member and every element goes
through it.
The only other read is *(char *)data in the array branch. The recursion
for element 0 gives the same answer, so that line can go.
Something like this (not even compile tested):
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index ea9a34d..d842ae1 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -2504,6 +2504,11 @@ static int btf_dump_type_data_check_zero(struct btf_dump *d,
!d->typed_dump->is_array_char))
return 0;
+ /* members and elements get here without a check against data_end */
+ err = btf_dump_type_data_check_overflow(d, t, id, data, bits_offset, bit_sz);
+ if (err < 0)
+ return err;
+
t = skip_mods_and_typedefs(d->btf, id, NULL);
switch (btf_kind(t)) {
@@ -2533,14 +2538,12 @@ static int btf_dump_type_data_check_zero(struct btf_dump *d,
* non-zero because the string is terminated.
*/
for (i = 0; i < array->nelems; i++) {
- if (i == 0 && ischar && *(char *)data == 0)
- return -ENODATA;
err = btf_dump_type_data_check_zero(d, elem_type,
elem_type_id,
data +
(i * elem_size),
bits_offset, 0);
- if (err != -ENODATA)
+ if (err != -ENODATA || ischar)
return err;
}
return -ENODATA;
Pls add a selftest as patch 2. TEST_BTF_DUMP_DATA_OVER() with an all-zero
union bpf_iter_link_info and sizeof() - 1 is enough.
bpf-next returns 16 for it today. It has to return -E2BIG.
Pls tag the respin as [PATCH bpf-next v3].
pw-bot: cr
next prev parent reply other threads:[~2026-11-02 16:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 8:51 [PATCH] libbpf: fix missing minus sign in btf_dump struct zero-check Gu Bin
2026-11-02 9:25 ` bot+bpf-ci
2026-11-02 13:16 ` [PATCH v2] libbpf: Fix ENODATA comparison and unbounded zero-scan in btf_dump Gu Bin
2026-11-02 16:47 ` Alexei Starovoitov [this message]
2026-11-03 3:26 ` [PATCH bpf-next v3 0/2] Fix OOB read in BTF dumper zero-scan Gu Bin
2026-11-03 3:26 ` [PATCH bpf-next v3 1/2] libbpf: " Gu Bin
2026-11-03 3:26 ` [PATCH bpf-next v3 2/2] selftests/bpf: Add overflow test for BTF dump zero-scan Gu Bin
2026-11-03 3:32 ` sashiko-bot
2026-11-03 4:30 ` Alexei Starovoitov
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=DMKVMPJUIHT1.T3WBE1MBIDA1@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=gubin@cmss.chinamobile.com \
/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