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: assert BPF kfunc default trusted pointer semantics

The BPF verifier was recently updated to treat pointers to struct types
returned from BPF kfuncs as implicitly trusted by default. Add a new
test case to exercise this new implicit trust semantic.

The KF_ACQUIRE flag was dropped from the bpf_get_root_mem_cgroup()
kfunc because it returns a global pointer to root_mem_cgroup without
performing any explicit reference counting. This makes it an ideal
candidate to verify the new implicit trusted pointer semantics.

Signed-off-by: Matt Bobrowski <mattbobrowski@google.com>
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20260113083949.2502978-3-mattbobrowski@google.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Matt Bobrowski and committed by
Alexei Starovoitov
bbdbed19 e463b6de

+34
+2
tools/testing/selftests/bpf/prog_tests/verifier.c
··· 61 61 #include "verifier_masking.skel.h" 62 62 #include "verifier_may_goto_1.skel.h" 63 63 #include "verifier_may_goto_2.skel.h" 64 + #include "verifier_memcontrol.skel.h" 64 65 #include "verifier_meta_access.skel.h" 65 66 #include "verifier_movsx.skel.h" 66 67 #include "verifier_mtu.skel.h" ··· 203 202 void test_verifier_masking(void) { RUN(verifier_masking); } 204 203 void test_verifier_may_goto_1(void) { RUN(verifier_may_goto_1); } 205 204 void test_verifier_may_goto_2(void) { RUN(verifier_may_goto_2); } 205 + void test_verifier_memcontrol(void) { RUN(verifier_memcontrol); } 206 206 void test_verifier_meta_access(void) { RUN(verifier_meta_access); } 207 207 void test_verifier_movsx(void) { RUN(verifier_movsx); } 208 208 void test_verifier_mul(void) { RUN(verifier_mul); }
+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";