From: sashiko-bot@kernel.org
To: chenyuan_fl@163.com, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v7 2/2] selftests/bpf: strengthen bpf_kfunc_implicit_arg to verify aux injection
Date: Mon, 23 Nov 2026 06:10:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-228755@kernel.org> (raw)
In-Reply-To: <20261123055708.684107-3-chenyuan_fl@163.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] selftests/bpf: unsafe dereference of stale aux in
bpf_kfunc_implicit_arg()
--
commit e250ac53eb106d5e314d3c6e696fc288a2644a2c
Author: Yuan Chen <chenyuan@kylinos.cn>
selftests/bpf: strengthen bpf_kfunc_implicit_arg to verify aux injection
This commit updates bpf_kfunc_implicit_arg() in bpf_testmod to verify that
aux->prog->aux points back to the implicit aux argument rather than only
checking for a non-NULL pointer.
> diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
> index 1fbc0061cc240..b97fcbcf249a7 100644
> --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
> +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
> @@ -2529,7 +2529,13 @@ int bpf_kfunc_multi_st_ops_test_1_assoc(struct st_ops_args *args, struct bpf_pro
>
> int bpf_kfunc_implicit_arg(int a, struct bpf_prog_aux *aux)
> {
> - if (aux && a > 0)
> + /*
> + * Verify that the verifier injected a real bpf_prog_aux instead
> + * of leaving a stale register value.
> + */
> + if (!aux || aux->prog->aux != aux)
> + return -EINVAL;
> + if (a > 0)
> return a;
> return -EINVAL;
> }
[Severity: Medium]
Can dereferencing aux->prog->aux crash the kernel when aux holds a stale
non-NULL register value?
If the verifier fails to inject aux (for instance, in
implicit_arg_after_may_goto where timed may_goto expansion leaves a
per-CPU struct bpf_timed_may_goto pointer in R2, or when R2 holds a stale
scalar), directly reading aux->prog and aux->prog->aux will fault or read
out of bounds instead of returning -EINVAL. Using
copy_from_kernel_nofault() for both pointer reads would safely reject
arbitrary stale values.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123055708.684107-1-chenyuan_fl@163.com?part=2
prev parent reply other threads:[~2026-11-23 6:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 5:57 [PATCH bpf-next v7 0/2] bpf: Fix kfunc implicit arg injection and add selftest chenyuan_fl
2026-11-23 5:57 ` [PATCH bpf-next v7 1/2] bpf: Fix kfunc implicit arg inject type detection to prevent invalid pointer deref chenyuan_fl
2026-11-23 6:09 ` sashiko-bot
2026-11-23 6:34 ` bot+bpf-ci
2026-11-23 5:57 ` [PATCH bpf-next v7 2/2] selftests/bpf: strengthen bpf_kfunc_implicit_arg to verify aux injection chenyuan_fl
2026-11-23 6:10 ` sashiko-bot [this message]
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-228755@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chenyuan_fl@163.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox