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.

selftests/bpf: update verifier test for default trusted pointer semantics

Replace the verifier test for default trusted pointer semantics, which
previously relied on BPF kfunc bpf_get_root_mem_cgroup(), with a new
test utilizing dedicated BPF kfuncs defined within the bpf_testmod.

bpf_get_root_mem_cgroup() was modified such that it again relies on
KF_ACQUIRE semantics, therefore no longer making it a suitable
candidate to test BPF verifier default trusted pointer semantics
against.

Link: https://lore.kernel.org/bpf/20260113083949.2502978-2-mattbobrowski@google.com
Signed-off-by: Matt Bobrowski <mattbobrowski@google.com>
Link: https://lore.kernel.org/r/20260120091630.3420452-1-mattbobrowski@google.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Matt Bobrowski and committed by
Alexei Starovoitov
dd341eac 2516a9c5

+52 -34
+2 -2
tools/testing/selftests/bpf/prog_tests/verifier.c
··· 30 30 #include "verifier_ctx.skel.h" 31 31 #include "verifier_ctx_sk_msg.skel.h" 32 32 #include "verifier_d_path.skel.h" 33 + #include "verifier_default_trusted_ptr.skel.h" 33 34 #include "verifier_direct_packet_access.skel.h" 34 35 #include "verifier_direct_stack_access_wraparound.skel.h" 35 36 #include "verifier_div0.skel.h" ··· 63 62 #include "verifier_masking.skel.h" 64 63 #include "verifier_may_goto_1.skel.h" 65 64 #include "verifier_may_goto_2.skel.h" 66 - #include "verifier_memcontrol.skel.h" 67 65 #include "verifier_meta_access.skel.h" 68 66 #include "verifier_movsx.skel.h" 69 67 #include "verifier_mtu.skel.h" ··· 173 173 void test_verifier_ctx(void) { RUN(verifier_ctx); } 174 174 void test_verifier_ctx_sk_msg(void) { RUN(verifier_ctx_sk_msg); } 175 175 void test_verifier_d_path(void) { RUN(verifier_d_path); } 176 + void test_verifier_default_trusted_ptr(void) { RUN_TESTS(verifier_default_trusted_ptr); } 176 177 void test_verifier_direct_packet_access(void) { RUN(verifier_direct_packet_access); } 177 178 void test_verifier_direct_stack_access_wraparound(void) { RUN(verifier_direct_stack_access_wraparound); } 178 179 void test_verifier_div0(void) { RUN(verifier_div0); } ··· 206 205 void test_verifier_masking(void) { RUN(verifier_masking); } 207 206 void test_verifier_may_goto_1(void) { RUN(verifier_may_goto_1); } 208 207 void test_verifier_may_goto_2(void) { RUN(verifier_may_goto_2); } 209 - void test_verifier_memcontrol(void) { RUN(verifier_memcontrol); } 210 208 void test_verifier_meta_access(void) { RUN(verifier_meta_access); } 211 209 void test_verifier_movsx(void) { RUN(verifier_movsx); } 212 210 void test_verifier_mul(void) { RUN(verifier_mul); }
+29
tools/testing/selftests/bpf/progs/verifier_default_trusted_ptr.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright 2026 Google LLC. 4 + */ 5 + 6 + #include <vmlinux.h> 7 + #include <bpf/bpf_helpers.h> 8 + #include <bpf/bpf_tracing.h> 9 + 10 + #include "bpf_misc.h" 11 + #include "../test_kmods/bpf_testmod_kfunc.h" 12 + 13 + SEC("syscall") 14 + __success __retval(0) 15 + int test_default_trusted_ptr(void *ctx) 16 + { 17 + struct prog_test_member *trusted_ptr; 18 + 19 + trusted_ptr = bpf_kfunc_get_default_trusted_ptr_test(); 20 + /* 21 + * Test BPF kfunc bpf_get_default_trusted_ptr_test() returns a 22 + * PTR_TO_BTF_ID | PTR_TRUSTED, therefore it should be accepted when 23 + * passed to a BPF kfunc only accepting KF_TRUSTED_ARGS. 24 + */ 25 + bpf_kfunc_put_default_trusted_ptr_test(trusted_ptr); 26 + return 0; 27 + } 28 + 29 + char _license[] SEC("license") = "GPL";
-32
tools/testing/selftests/bpf/progs/verifier_memcontrol.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Copyright 2026 Google LLC. 4 - */ 5 - 6 - #include <vmlinux.h> 7 - #include <bpf/bpf_helpers.h> 8 - #include <bpf/bpf_tracing.h> 9 - #include "bpf_misc.h" 10 - 11 - SEC("syscall") 12 - __success __retval(0) 13 - int root_mem_cgroup_default_trusted(void *ctx) 14 - { 15 - unsigned long usage; 16 - struct mem_cgroup *root_mem_cgroup; 17 - 18 - root_mem_cgroup = bpf_get_root_mem_cgroup(); 19 - if (!root_mem_cgroup) 20 - return 1; 21 - 22 - /* 23 - * BPF kfunc bpf_get_root_mem_cgroup() returns a PTR_TO_BTF_ID | 24 - * PTR_TRUSTED | PTR_MAYBE_NULL, therefore it should be accepted when 25 - * passed to a BPF kfunc only accepting KF_TRUSTED_ARGS. 26 - */ 27 - usage = bpf_mem_cgroup_usage(root_mem_cgroup); 28 - __sink(usage); 29 - return 0; 30 - } 31 - 32 - char _license[] SEC("license") = "GPL";
+18
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
··· 254 254 return NULL; 255 255 } 256 256 257 + static struct prog_test_member trusted_ptr; 258 + 259 + __bpf_kfunc struct prog_test_member *bpf_kfunc_get_default_trusted_ptr_test(void) 260 + { 261 + return &trusted_ptr; 262 + } 263 + 264 + __bpf_kfunc void bpf_kfunc_put_default_trusted_ptr_test(struct prog_test_member *trusted_ptr) 265 + { 266 + /* 267 + * This BPF kfunc doesn't actually have any put/KF_ACQUIRE 268 + * semantics. We're simply wanting to simulate a BPF kfunc that takes a 269 + * struct prog_test_member pointer as an argument. 270 + */ 271 + } 272 + 257 273 __bpf_kfunc struct bpf_testmod_ctx * 258 274 bpf_testmod_ctx_create(int *err) 259 275 { ··· 725 709 BTF_ID_FLAGS(func, bpf_testmod_ctx_release, KF_RELEASE) 726 710 BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_1) 727 711 BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_2) 712 + BTF_ID_FLAGS(func, bpf_kfunc_get_default_trusted_ptr_test); 713 + BTF_ID_FLAGS(func, bpf_kfunc_put_default_trusted_ptr_test); 728 714 BTF_KFUNCS_END(bpf_testmod_common_kfunc_ids) 729 715 730 716 BTF_ID_LIST(bpf_testmod_dtor_ids)
+3
tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
··· 166 166 extern int bpf_kfunc_multi_st_ops_test_1_assoc(struct st_ops_args *args) __weak __ksym; 167 167 #endif 168 168 169 + struct prog_test_member *bpf_kfunc_get_default_trusted_ptr_test(void) __ksym; 170 + void bpf_kfunc_put_default_trusted_ptr_test(struct prog_test_member *trusted_ptr) __ksym; 171 + 169 172 #endif /* _BPF_TESTMOD_KFUNC_H */