]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Add tests for iter arg check
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Tue, 3 Dec 2024 00:02:38 +0000 (16:02 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 3 Dec 2024 01:47:56 +0000 (17:47 -0800)
Add selftests to cover argument type check for iterator kfuncs, and
cover all three kinds (new, next, destroy). Without the fix in the
previous patch, the selftest would not cause a verifier error.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20241203000238.3602922-3-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/progs/iters.c

index ef70b88bccb252bf9a64525be27e257ba6227ee7..7c969c12757372c8a0bbd0613478a4fc3c1e7048 100644 (file)
@@ -1486,4 +1486,30 @@ int iter_subprog_check_stacksafe(const void *ctx)
        return 0;
 }
 
+struct bpf_iter_num global_it;
+
+SEC("raw_tp")
+__failure __msg("arg#0 expected pointer to an iterator on stack")
+int iter_new_bad_arg(const void *ctx)
+{
+       bpf_iter_num_new(&global_it, 0, 1);
+       return 0;
+}
+
+SEC("raw_tp")
+__failure __msg("arg#0 expected pointer to an iterator on stack")
+int iter_next_bad_arg(const void *ctx)
+{
+       bpf_iter_num_next(&global_it);
+       return 0;
+}
+
+SEC("raw_tp")
+__failure __msg("arg#0 expected pointer to an iterator on stack")
+int iter_destroy_bad_arg(const void *ctx)
+{
+       bpf_iter_num_destroy(&global_it);
+       return 0;
+}
+
 char _license[] SEC("license") = "GPL";