From: Yuan Chen The kfunc_implicit_args selftest calls bpf_kfunc_implicit_arg(5) and expects 5. The kfunc only checks that the implicit bpf_prog_aux argument is non-NULL, so the test still passes if the verifier fails to inject aux and the stale register happens to hold a non-NULL value. Verify the injected pointer by checking that aux->prog->aux points back to aux, which holds for every real bpf_prog_aux. Do not match on aux->name: the tracing selftest calls the same kfunc from programs named trace_implicit_arg_*, which do not share the syscall test's name prefix. Signed-off-by: Yuan Chen --- .../testing/selftests/bpf/test_kmods/bpf_testmod.c | 8 +++++++- 1 file changed, 7 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 --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c @@ -1906,7 +1906,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; } -- 2.54.0