On 2024/11/7 04:18, Tao Lyu wrote:
This is a selftest for the type checking of iter arguments.
When passing a PTR_TO_MAP_VALUE to bpf_iter_num_* kfuncs, the program should be rejected.
Signed-off-by: Tao Lyu <tao.lyu@xxxxxxx>
---
tools/testing/selftests/bpf/progs/iters.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/iters.c b/tools/testing/selftests/bpf/progs/iters.c
index ef70b88bccb2..0a2df20afa30 100644
--- a/tools/testing/selftests/bpf/progs/iters.c
+++ b/tools/testing/selftests/bpf/progs/iters.c
@@ -1486,4 +1486,25 @@ int iter_subprog_check_stacksafe(const void *ctx)
return 0;
}
+SEC("raw_tp")
+__failure __msg("arg#0 expected pointer to the iterator")
+int iter_check_arg_type(const void *ctx)
+{
+ struct bpf_iter_num it;
+ int *v;
+
+ int *map_val = NULL;
+ int key = 0;
+
+ map_val = bpf_map_lookup_elem(&arr_map, &key);
+ if (!map_val)
+ return 0;
+
+ bpf_iter_num_new(&it, 0, 3);
+ while ((v = bpf_iter_num_next((struct bpf_iter_num*)map_val))) {}
+ bpf_iter_num_destroy(&it);
+
+ return 0;
+}
+
char _license[] SEC("license") = "GPL";
Hi, Tao. There are some style issues such as using spaces as
indentations. It's recommended to run `scripts/checkpatch.pl` before
commit patches.
--
Philo