Re: [PATCH bpf v5 2/2] selftests/bpf: strengthen bpf_kfunc_implicit_arg to verify aux injection

From: Ihor Solodrai

Date: Mon Jun 08 2026 - 21:00:59 EST


On 6/8/26 7:26 AM, chenyuan_fl@xxxxxxx wrote:
> From: Yuan Chen <chenyuan@xxxxxxxxxx>
>
> Verify that the KF_IMPLICIT_ARGS injection path correctly passes
> the bpf_prog_aux pointer by checking aux->name in
> bpf_kfunc_implicit_arg() for the expected program name prefix.
> If the verifier incorrectly skipped injection (as could happen
> with pahole 1.30's BTF mismatch), the stale register would not
> contain a valid aux pointer and the name check would fail.
>
> This is a positive test exercised by the existing kfunc_implicit_args
> selftest, which calls bpf_kfunc_implicit_arg(5) and expects a return
> value of 5.
>
> Signed-off-by: Yuan Chen <chenyuan@xxxxxxxxxx>

Acked-by: Ihor Solodrai <ihor.solodrai@xxxxxxxxx>

> ---
> tools/testing/selftests/bpf/test_kmods/bpf_testmod.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
> index 30f1cd23093c..624d57a5c79a 100644
> --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
> +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
> @@ -1906,7 +1906,11 @@ 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 the kernel injected the correct bpf_prog_aux pointer
> + * rather than leaving a stale register value. */
> + if (!aux || strncmp(aux->name, "test_kfunc", sizeof("test_kfunc") - 1))
> + return -EINVAL;
> + if (a > 0)
> return a;
> return -EINVAL;
> }