All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gu Bin" <gubin@cmss.chinamobile.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v4 2/2] selftests/bpf: Add overflow test for BTF dump zero-scan
Date: Wed, 04 Nov 2026 03:23:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-196596@kernel.org> (raw)
In-Reply-To: <20261104025806.1693-3-gubin@cmss.chinamobile.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] selftests/bpf: test_btf_dump_struct_data() fails on ENODATA check
--

commit 1be6c5280eb4868315725b469eaa863a95165c0b
Author: Gu Bin <gubin@cmss.chinamobile.com>

selftests/bpf: Add overflow test for BTF dump zero-scan

This patch adds a TEST_BTF_DUMP_DATA_OVER() selftest case in
test_btf_dump_struct_data() that dumps an all-zero union bpf_iter_link_info
with a data_sz one byte short of the type size, expecting
btf_dump__dump_type_data() to return -E2BIG.

> diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
> index 35f214e254da8..68f33f8a54ab8 100644
> --- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c
> +++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
> @@ -1156,6 +1156,15 @@ static void test_btf_dump_struct_data(struct btf *btf, struct btf_dump *d,
>  			   "(union bpf_iter_link_info){.map = (struct){.map_fd = (__u32)1,},.cgroup = (struct){.order = (enum bpf_cgroup_iter_order)BPF_CGROUP_ITER_SELF_ONLY,.cgroup_fd = (__u32)1,},.task = (struct){.tid = (__u32)1,.pid = (__u32)1,},}",
>  			   { .cgroup = { .order = 1, .cgroup_fd = 1, }});
>  
> +	/*
> +	 * overflow test for all-zero union: with a data_sz one byte short
> +	 * of the type size, the zero-scan must not read past data_end and
> +	 * must return -E2BIG.
> +	 */
> +	TEST_BTF_DUMP_DATA_OVER(btf, d, "union", str, union bpf_iter_link_info,
> +				sizeof(union bpf_iter_link_info) - 1,
> +				"(union bpf_iter_link_info){\n", {});

[Severity: Medium]
As reported by Alexei Starovoitov on v3 [1], does this new test pass when
running test_progs?

When btf_dump_struct_data() iterates over the members of union
bpf_iter_link_info at depth 1, it invokes btf_dump_type_data_check_zero() on
the nested structs (.map, .cgroup, and .task). In
tools/lib/bpf/btf_dump.c:btf_dump_type_data_check_zero():

	case BTF_KIND_STRUCT:
	case BTF_KIND_UNION: {
		...
		for (i = 0; i < n; i++, m++) {
			...
			err = btf_dump_type_data_check_zero(d, mtype, m->type, data + moffset / 8,
							    moffset % 8, bit_sz);
			if (err != ENODATA)
				return err;
		}
		return -ENODATA;
	}

When checking the first member of .cgroup (.cgroup.order, a 4-byte enum at
offset 0), the recursive call sees a zero value within data_end and returns
-ENODATA. Because the loop compares err against positive ENODATA instead of
-ENODATA, -ENODATA != ENODATA evaluates to true and the loop returns
-ENODATA immediately after i == 0 without ever reaching .cgroup.cgroup_id at
offset 8 (the only member extending past sizeof(union bpf_iter_link_info) - 1).

Consequently, all union members are skipped as zeroed,
btf_dump__dump_type_data() returns 16 instead of -E2BIG, and str contains
"(union bpf_iter_link_info){\n}", failing the assertions in btf_dump_data().

[1] https://lore.kernel.org/r/DMLAKLO9AB4T.X5JCIISSONLF@gmail.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261104025806.1693-1-gubin@cmss.chinamobile.com?part=2

  reply	other threads:[~2026-11-04  3:23 UTC|newest]

Thread overview: 14+ 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
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
2026-11-04  2:58     ` [PATCH bpf-next v4 0/2] Fix OOB read in BTF dumper zero-scan Gu Bin
2026-11-04  2:58       ` [PATCH bpf-next v4 1/2] libbpf: " Gu Bin
2026-11-04  2:58       ` [PATCH bpf-next v4 2/2] selftests/bpf: Add overflow test for BTF dump zero-scan Gu Bin
2026-11-04  3:23         ` sashiko-bot [this message]
2026-11-05 16:33       ` [PATCH bpf-next v4 0/2] Fix OOB read in BTF dumper zero-scan 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=sashiko-outbox-196596@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=gubin@cmss.chinamobile.com \
    --cc=sashiko-reviews@lists.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 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.