Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <mannkafai@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/bpf/20250423121329.3163461-3-mannkafai@gmail.com

authored by

KaFai Wan and committed by
Andrii Nakryiko
4c0a42c5 1271a40e

+19 -1
+7 -1
net/bpf/test_run.c
··· 569 569 return *a; 570 570 } 571 571 572 + int noinline bpf_fentry_test10(const void *a) 573 + { 574 + return (long)a; 575 + } 576 + 572 577 void noinline bpf_fentry_test_sinfo(struct skb_shared_info *sinfo) 573 578 { 574 579 } ··· 704 699 bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 || 705 700 bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 || 706 701 bpf_fentry_test8(&arg) != 0 || 707 - bpf_fentry_test9(&retval) != 0) 702 + bpf_fentry_test9(&retval) != 0 || 703 + bpf_fentry_test10((void *)0) != 0) 708 704 goto out; 709 705 break; 710 706 case BPF_MODIFY_RETURN:
+12
tools/testing/selftests/bpf/progs/verifier_btf_ctx_access.c
··· 65 65 " ::: __clobber_all); 66 66 } 67 67 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 + 68 80 char _license[] SEC("license") = "GPL";