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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'bpf-allow-access-to-const-void-pointer-arguments-in-tracing-programs'

KaFai Wan says:

====================
bpf: Allow access to const void pointer arguments in tracing programs

If we try to access argument which is pointer to const void, it's an
UNKNOWN type, verifier will fail to load.

Use is_void_or_int_ptr to check if type is void or int pointer.
Add a selftest to check it.
---
====================

Link: https://patch.msgid.link/20250423121329.3163461-1-mannkafai@gmail.com
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

+26 -12
+7 -11
kernel/bpf/btf.c
··· 6383 6383 return prog->aux->attach_btf; 6384 6384 } 6385 6385 6386 - static bool is_int_ptr(struct btf *btf, const struct btf_type *t) 6386 + static bool is_void_or_int_ptr(struct btf *btf, const struct btf_type *t) 6387 6387 { 6388 6388 /* skip modifiers */ 6389 6389 t = btf_type_skip_modifiers(btf, t->type, NULL); 6390 - 6391 - return btf_type_is_int(t); 6390 + return btf_type_is_void(t) || btf_type_is_int(t); 6392 6391 } 6393 6392 6394 6393 static u32 get_ctx_arg_idx(struct btf *btf, const struct btf_type *func_proto, ··· 6775 6776 } 6776 6777 } 6777 6778 6778 - if (t->type == 0) 6779 - /* This is a pointer to void. 6780 - * It is the same as scalar from the verifier safety pov. 6781 - * No further pointer walking is allowed. 6782 - */ 6783 - return true; 6784 - 6785 - if (is_int_ptr(btf, t)) 6779 + /* 6780 + * If it's a pointer to void, it's the same as scalar from the verifier 6781 + * safety POV. Either way, no futher pointer walking is allowed. 6782 + */ 6783 + if (is_void_or_int_ptr(btf, t)) 6786 6784 return true; 6787 6785 6788 6786 /* this is a pointer to another type */
+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";