mirror of
https://github.com/torvalds/linux.git
synced 2026-06-02 19:43:40 +02:00
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>
This commit is contained in:
parent
2516a9c5a5
commit
dd341eacdb
|
|
@ -30,6 +30,7 @@
|
|||
#include "verifier_ctx.skel.h"
|
||||
#include "verifier_ctx_sk_msg.skel.h"
|
||||
#include "verifier_d_path.skel.h"
|
||||
#include "verifier_default_trusted_ptr.skel.h"
|
||||
#include "verifier_direct_packet_access.skel.h"
|
||||
#include "verifier_direct_stack_access_wraparound.skel.h"
|
||||
#include "verifier_div0.skel.h"
|
||||
|
|
@ -62,7 +63,6 @@
|
|||
#include "verifier_masking.skel.h"
|
||||
#include "verifier_may_goto_1.skel.h"
|
||||
#include "verifier_may_goto_2.skel.h"
|
||||
#include "verifier_memcontrol.skel.h"
|
||||
#include "verifier_meta_access.skel.h"
|
||||
#include "verifier_movsx.skel.h"
|
||||
#include "verifier_mtu.skel.h"
|
||||
|
|
@ -173,6 +173,7 @@ void test_verifier_const_or(void) { RUN(verifier_const_or); }
|
|||
void test_verifier_ctx(void) { RUN(verifier_ctx); }
|
||||
void test_verifier_ctx_sk_msg(void) { RUN(verifier_ctx_sk_msg); }
|
||||
void test_verifier_d_path(void) { RUN(verifier_d_path); }
|
||||
void test_verifier_default_trusted_ptr(void) { RUN_TESTS(verifier_default_trusted_ptr); }
|
||||
void test_verifier_direct_packet_access(void) { RUN(verifier_direct_packet_access); }
|
||||
void test_verifier_direct_stack_access_wraparound(void) { RUN(verifier_direct_stack_access_wraparound); }
|
||||
void test_verifier_div0(void) { RUN(verifier_div0); }
|
||||
|
|
@ -205,7 +206,6 @@ void test_verifier_map_ret_val(void) { RUN(verifier_map_ret_val); }
|
|||
void test_verifier_masking(void) { RUN(verifier_masking); }
|
||||
void test_verifier_may_goto_1(void) { RUN(verifier_may_goto_1); }
|
||||
void test_verifier_may_goto_2(void) { RUN(verifier_may_goto_2); }
|
||||
void test_verifier_memcontrol(void) { RUN(verifier_memcontrol); }
|
||||
void test_verifier_meta_access(void) { RUN(verifier_meta_access); }
|
||||
void test_verifier_movsx(void) { RUN(verifier_movsx); }
|
||||
void test_verifier_mul(void) { RUN(verifier_mul); }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright 2026 Google LLC.
|
||||
*/
|
||||
|
||||
#include <vmlinux.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_tracing.h>
|
||||
|
||||
#include "bpf_misc.h"
|
||||
#include "../test_kmods/bpf_testmod_kfunc.h"
|
||||
|
||||
SEC("syscall")
|
||||
__success __retval(0)
|
||||
int test_default_trusted_ptr(void *ctx)
|
||||
{
|
||||
struct prog_test_member *trusted_ptr;
|
||||
|
||||
trusted_ptr = bpf_kfunc_get_default_trusted_ptr_test();
|
||||
/*
|
||||
* Test BPF kfunc bpf_get_default_trusted_ptr_test() returns a
|
||||
* PTR_TO_BTF_ID | PTR_TRUSTED, therefore it should be accepted when
|
||||
* passed to a BPF kfunc only accepting KF_TRUSTED_ARGS.
|
||||
*/
|
||||
bpf_kfunc_put_default_trusted_ptr_test(trusted_ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright 2026 Google LLC.
|
||||
*/
|
||||
|
||||
#include <vmlinux.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_tracing.h>
|
||||
#include "bpf_misc.h"
|
||||
|
||||
SEC("syscall")
|
||||
__success __retval(0)
|
||||
int root_mem_cgroup_default_trusted(void *ctx)
|
||||
{
|
||||
unsigned long usage;
|
||||
struct mem_cgroup *root_mem_cgroup;
|
||||
|
||||
root_mem_cgroup = bpf_get_root_mem_cgroup();
|
||||
if (!root_mem_cgroup)
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* BPF kfunc bpf_get_root_mem_cgroup() returns a PTR_TO_BTF_ID |
|
||||
* PTR_TRUSTED | PTR_MAYBE_NULL, therefore it should be accepted when
|
||||
* passed to a BPF kfunc only accepting KF_TRUSTED_ARGS.
|
||||
*/
|
||||
usage = bpf_mem_cgroup_usage(root_mem_cgroup);
|
||||
__sink(usage);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
|
@ -254,6 +254,22 @@ __bpf_kfunc int *bpf_kfunc_ret_rcu_test_nostruct(int rdonly_buf_size)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static struct prog_test_member trusted_ptr;
|
||||
|
||||
__bpf_kfunc struct prog_test_member *bpf_kfunc_get_default_trusted_ptr_test(void)
|
||||
{
|
||||
return &trusted_ptr;
|
||||
}
|
||||
|
||||
__bpf_kfunc void bpf_kfunc_put_default_trusted_ptr_test(struct prog_test_member *trusted_ptr)
|
||||
{
|
||||
/*
|
||||
* This BPF kfunc doesn't actually have any put/KF_ACQUIRE
|
||||
* semantics. We're simply wanting to simulate a BPF kfunc that takes a
|
||||
* struct prog_test_member pointer as an argument.
|
||||
*/
|
||||
}
|
||||
|
||||
__bpf_kfunc struct bpf_testmod_ctx *
|
||||
bpf_testmod_ctx_create(int *err)
|
||||
{
|
||||
|
|
@ -709,6 +725,8 @@ BTF_ID_FLAGS(func, bpf_testmod_ctx_create, KF_ACQUIRE | KF_RET_NULL)
|
|||
BTF_ID_FLAGS(func, bpf_testmod_ctx_release, KF_RELEASE)
|
||||
BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_1)
|
||||
BTF_ID_FLAGS(func, bpf_testmod_ops3_call_test_2)
|
||||
BTF_ID_FLAGS(func, bpf_kfunc_get_default_trusted_ptr_test);
|
||||
BTF_ID_FLAGS(func, bpf_kfunc_put_default_trusted_ptr_test);
|
||||
BTF_KFUNCS_END(bpf_testmod_common_kfunc_ids)
|
||||
|
||||
BTF_ID_LIST(bpf_testmod_dtor_ids)
|
||||
|
|
|
|||
|
|
@ -166,4 +166,7 @@ extern int bpf_kfunc_multi_st_ops_test_1(struct st_ops_args *args, u32 id) __wea
|
|||
extern int bpf_kfunc_multi_st_ops_test_1_assoc(struct st_ops_args *args) __weak __ksym;
|
||||
#endif
|
||||
|
||||
struct prog_test_member *bpf_kfunc_get_default_trusted_ptr_test(void) __ksym;
|
||||
void bpf_kfunc_put_default_trusted_ptr_test(struct prog_test_member *trusted_ptr) __ksym;
|
||||
|
||||
#endif /* _BPF_TESTMOD_KFUNC_H */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user