From: sashiko-bot@kernel.org
To: "Amery Hung" <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 3/3] selftests/bpf: Use bpf_dynptr_slice() to read file dynptr in leak test
Date: Thu, 04 Jun 2026 22:21:56 +0000 [thread overview]
Message-ID: <20260604222157.449C21F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260604220904.1032145-4-ameryhung@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The negative selftest uses an uninitialized stack buffer `buf`, causing the verifier to reject the program early and bypass the intended reference leak check.
--
commit 2c90a2c3822df01ad7da448a72985505048a4374
Author: Amery Hung <ameryhung@gmail.com>
selftests/bpf: Use bpf_dynptr_slice() to read file dynptr in leak test
This commit updates the use_file_dynptr_slice_after_put_file test to
use bpf_dynptr_slice instead of bpf_dynptr_data, since bpf_dynptr_data
always returns NULL for read-only file dynptrs. The slice is read
rather than written to, while the test is still expected to fail.
> diff --git a/tools/testing/selftests/bpf/progs/file_reader_fail.c b/tools/testing/selftests/bpf/progs/file_reader_fail.c
> index d5fae5e4cf9ad..3bb9e2612f8f3 100644
> --- a/tools/testing/selftests/bpf/progs/file_reader_fail.c
> +++ b/tools/testing/selftests/bpf/progs/file_reader_fail.c
> @@ -87,7 +87,8 @@ int use_file_dynptr_slice_after_put_file(void *ctx)
> struct task_struct *task = bpf_get_current_task_btf();
> struct file *file = bpf_get_task_exe_file(task);
> struct bpf_dynptr dynptr;
> - char *data;
> + char buf[1];
> + const char *data;
>
> if (!file)
> return 0;
> @@ -95,15 +96,14 @@ int use_file_dynptr_slice_after_put_file(void *ctx)
> if (bpf_dynptr_from_file(file, 0, &dynptr))
> goto out;
>
> - data = bpf_dynptr_data(&dynptr, 0, 1);
> + data = bpf_dynptr_slice(&dynptr, 0, buf, sizeof(buf));
[Severity: Medium]
Will the BPF verifier reject this program early due to the uninitialized
stack buffer, masking the actual leak test?
The verifier requires memory passed to helpers like bpf_dynptr_slice() to be
initialized. Since buf is uninitialized, the verifier will likely fail with
an invalid read from stack error here, bypassing the intended reference leak
check.
Would initializing the buffer (e.g., char buf[1] = {0};) allow the test to
fail for the expected reason?
> if (!data)
> goto out;
>
> /* this should fail - file dynptr should be discarded first to prevent resource leak */
> bpf_put_file(file);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260604220904.1032145-1-ameryhung@gmail.com?part=3
next prev parent reply other threads:[~2026-06-04 22:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 22:09 [PATCH bpf-next v1 0/3] Object relationship refactor followup Amery Hung
2026-06-04 22:09 ` [PATCH bpf-next v1 1/3] bpf: Fix dead error check on acquire_reference() in check_kfunc_call Amery Hung
2026-06-04 22:28 ` sashiko-bot
2026-06-04 22:43 ` bot+bpf-ci
2026-06-04 23:16 ` Eduard Zingerman
2026-06-04 22:09 ` [PATCH bpf-next v1 2/3] bpf: Compare parent_id in refsafe() for REF_TYPE_PTR Amery Hung
2026-06-04 22:23 ` sashiko-bot
2026-06-04 22:59 ` bot+bpf-ci
2026-06-04 23:21 ` Eduard Zingerman
2026-06-04 23:27 ` Amery Hung
2026-06-05 17:57 ` Amery Hung
2026-06-05 18:04 ` Eduard Zingerman
2026-06-05 18:09 ` Amery Hung
2026-06-04 22:09 ` [PATCH bpf-next v1 3/3] selftests/bpf: Use bpf_dynptr_slice() to read file dynptr in leak test Amery Hung
2026-06-04 22:21 ` sashiko-bot [this message]
2026-06-04 23:22 ` Eduard Zingerman
2026-06-04 22:14 ` [PATCH bpf-next v1 0/3] Object relationship refactor followup Kumar Kartikeya Dwivedi
2026-06-04 23:20 ` Amery Hung
2026-06-05 21:20 ` patchwork-bot+netdevbpf
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=20260604222157.449C21F00898@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ameryhung@gmail.com \
--cc=bpf@vger.kernel.org \
--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.