Skip to content

Commit 4c0a42c

Browse files
mannkafaianakryiko
authored andcommitted
selftests/bpf: Add test to access const void pointer argument in tracing program
Adding verifier test for accessing const void pointer argument in tracing programs. The test program loads 1st argument of bpf_fentry_test10 function which is const void pointer and checks that verifier allows that. Signed-off-by: KaFai Wan <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Jiri Olsa <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 1271a40 commit 4c0a42c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

net/bpf/test_run.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,11 @@ __bpf_kfunc u32 bpf_fentry_test9(u32 *a)
569569
return *a;
570570
}
571571

572+
int noinline bpf_fentry_test10(const void *a)
573+
{
574+
return (long)a;
575+
}
576+
572577
void noinline bpf_fentry_test_sinfo(struct skb_shared_info *sinfo)
573578
{
574579
}
@@ -699,7 +704,8 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
699704
bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 ||
700705
bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
701706
bpf_fentry_test8(&arg) != 0 ||
702-
bpf_fentry_test9(&retval) != 0)
707+
bpf_fentry_test9(&retval) != 0 ||
708+
bpf_fentry_test10((void *)0) != 0)
703709
goto out;
704710
break;
705711
case BPF_MODIFY_RETURN:

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

+12
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,16 @@ __naked void ctx_access_u32_pointer_reject_8(void)
6565
" ::: __clobber_all);
6666
}
6767

68+
SEC("fentry/bpf_fentry_test10")
69+
__description("btf_ctx_access const void pointer accept")
70+
__success __retval(0)
71+
__naked void ctx_access_const_void_pointer_accept(void)
72+
{
73+
asm volatile (" \
74+
r2 = *(u64 *)(r1 + 0); /* load 1st argument value (const void pointer) */\
75+
r0 = 0; \
76+
exit; \
77+
" ::: __clobber_all);
78+
}
79+
6880
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)