From: sashiko-bot@kernel.org
To: "Sun Jian" <sun.jian.kdev@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v3 2/2] selftests/bpf: Cover partial copy of non-linear test_run output
Date: Wed, 17 Jun 2026 09:45:37 +0000 [thread overview]
Message-ID: <20260617094537.D1EEF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260617093557.63880-3-sun.jian.kdev@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Uninitialized stack buffer `out` is read if the BPF test run fails.
--
commit f204128d45018a80c7b9b142c6d9a253204b22bd
Author: Sun Jian <sun.jian.kdev@gmail.com>
selftests/bpf: Cover partial copy of non-linear test_run output
This commit adds selftest coverage for partial copies of non-linear test_run
output for TC and XDP programs. It verifies that test_run returns -ENOSPC,
reports the full packet length, and copies the packet prefix into the
provided buffer.
> diff --git a/tools/testing/selftests/bpf/prog_tests/prog_run_opts.c b/tools/testing/selftests/bpf/prog_tests/prog_run_opts.c
> index 01f1d1b6715a6..9cc898e6a9f71 100644
> --- a/tools/testing/selftests/bpf/prog_tests/prog_run_opts.c
> +++ b/tools/testing/selftests/bpf/prog_tests/prog_run_opts.c
[ ... ]
> @@ -20,6 +24,69 @@ static void check_run_cnt(int prog_fd, __u64 run_cnt)
> "incorrect number of repetitions, want %llu have %llu\n", run_cnt, info.run_cnt);
> }
>
> +static void init_pkt(__u8 *pkt, size_t len)
> +{
> + size_t i;
> +
> + for (i = 0; i < len; i++)
> + pkt[i] = i & 0xff;
> +}
> +
> +static void test_skb_nonlinear_data_out_partial(struct test_pkt_access *skel)
> +{
> + LIBBPF_OPTS(bpf_test_run_opts, topts);
> + __u8 pkt[NONLINEAR_PKT_LEN];
> + __u8 out[SHORT_OUT_LEN];
[Severity: Medium]
Should out[] be explicitly zero-initialized?
If bpf_prog_test_run_opts() fails with an unexpected error and doesn't write
to the userspace buffer, the ASSERT_EQ macros below won't abort the test.
This means the subsequent ASSERT_OK(memcmp(...)) call will read uninitialized
stack memory, which can trigger undefined behavior and Memory Sanitizer (MSAN)
warnings.
> + struct __sk_buff skb = {};
> + int prog_fd, err;
> +
[ ... ]
> + prog_fd = bpf_program__fd(skel->progs.tc_pass_prog);
> + err = bpf_prog_test_run_opts(prog_fd, &topts);
> +
> + ASSERT_EQ(err, -ENOSPC, "skb_nonlinear_partial_err");
> + ASSERT_EQ(topts.data_size_out, sizeof(pkt), "skb_nonlinear_partial_data_size_out");
> + ASSERT_OK(memcmp(out, pkt, sizeof(out)), "skb_nonlinear_partial_data_out");
> +}
> +
> +static void test_xdp_nonlinear_data_out_partial(struct test_pkt_access *skel)
> +{
> + LIBBPF_OPTS(bpf_test_run_opts, topts);
> + __u8 pkt[NONLINEAR_PKT_LEN];
> + __u8 out[SHORT_OUT_LEN];
[Severity: Medium]
Could we also zero-initialize this buffer for the same reason?
> + struct xdp_md ctx = {};
> + int prog_fd, err;
> +
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260617093557.63880-1-sun.jian.kdev@gmail.com?part=2
next prev parent reply other threads:[~2026-06-17 9:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 9:35 [PATCH bpf v3 0/2] Fix partial copy of non-linear test_run output Sun Jian
2026-06-17 9:35 ` [PATCH bpf v3 1/2] bpf: " Sun Jian
2026-06-17 9:35 ` [PATCH bpf v3 2/2] selftests/bpf: Cover " Sun Jian
2026-06-17 9:45 ` sashiko-bot [this message]
2026-06-17 10:31 ` bot+bpf-ci
2026-06-17 14:19 ` sun jian
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=20260617094537.D1EEF1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sun.jian.kdev@gmail.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