summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/nested_trust_failure.c
diff options
context:
space:
mode:
authorDavid Vernet <void@manifault.com>2023-01-25 17:38:12 +0300
committerAlexei Starovoitov <ast@kernel.org>2023-01-25 18:57:50 +0300
commita6541f4d280465e3dff08a45734c0d4ac3f363a4 (patch)
treeb2047f40d1758a6336be71a31a9867b0440d8e46 /tools/testing/selftests/bpf/progs/nested_trust_failure.c
parent516f4d3397c9e90f4da04f59986c856016269aa1 (diff)
downloadlinux-a6541f4d280465e3dff08a45734c0d4ac3f363a4.tar.xz
selftests/bpf: Add nested trust selftests suite
Now that defining trusted fields in a struct is supported, we should add selftests to verify the behavior. This patch adds a few such testcases. Signed-off-by: David Vernet <void@manifault.com> Link: https://lore.kernel.org/r/20230125143816.721952-4-void@manifault.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/nested_trust_failure.c')
-rw-r--r--tools/testing/selftests/bpf/progs/nested_trust_failure.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/nested_trust_failure.c b/tools/testing/selftests/bpf/progs/nested_trust_failure.c
new file mode 100644
index 000000000000..14aff7676436
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/nested_trust_failure.c
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
+
+#include <vmlinux.h>
+#include <bpf/bpf_tracing.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+
+#include "nested_trust_common.h"
+
+char _license[] SEC("license") = "GPL";
+
+/* Prototype for all of the program trace events below:
+ *
+ * TRACE_EVENT(task_newtask,
+ * TP_PROTO(struct task_struct *p, u64 clone_flags)
+ */
+
+SEC("tp_btf/task_newtask")
+__failure __msg("R2 must be referenced or trusted")
+int BPF_PROG(test_invalid_nested_user_cpus, struct task_struct *task, u64 clone_flags)
+{
+ bpf_cpumask_test_cpu(0, task->user_cpus_ptr);
+ return 0;
+}
+
+SEC("tp_btf/task_newtask")
+__failure __msg("R1 must have zero offset when passed to release func or trusted arg to kfunc")
+int BPF_PROG(test_invalid_nested_offset, struct task_struct *task, u64 clone_flags)
+{
+ bpf_cpumask_first_zero(&task->cpus_mask);
+ return 0;
+}