Skip to content

Commit 7f71197

Browse files
kkdwvdAlexei Starovoitov
authored andcommitted
selftests/bpf: Add tests for iter arg check
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>
1 parent 12659d2 commit 7f71197

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

  • tools/testing/selftests/bpf/progs

tools/testing/selftests/bpf/progs/iters.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,4 +1486,30 @@ int iter_subprog_check_stacksafe(const void *ctx)
14861486
return 0;
14871487
}
14881488

1489+
struct bpf_iter_num global_it;
1490+
1491+
SEC("raw_tp")
1492+
__failure __msg("arg#0 expected pointer to an iterator on stack")
1493+
int iter_new_bad_arg(const void *ctx)
1494+
{
1495+
bpf_iter_num_new(&global_it, 0, 1);
1496+
return 0;
1497+
}
1498+
1499+
SEC("raw_tp")
1500+
__failure __msg("arg#0 expected pointer to an iterator on stack")
1501+
int iter_next_bad_arg(const void *ctx)
1502+
{
1503+
bpf_iter_num_next(&global_it);
1504+
return 0;
1505+
}
1506+
1507+
SEC("raw_tp")
1508+
__failure __msg("arg#0 expected pointer to an iterator on stack")
1509+
int iter_destroy_bad_arg(const void *ctx)
1510+
{
1511+
bpf_iter_num_destroy(&global_it);
1512+
return 0;
1513+
}
1514+
14891515
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)