]> www.infradead.org Git - users/hch/misc.git/commitdiff
selftests/bpf: Add tests for raw_tp NULL args
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Fri, 13 Dec 2024 22:19:29 +0000 (14:19 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 14 Dec 2024 00:24:53 +0000 (16:24 -0800)
Add tests to ensure that arguments are correctly marked based on their
specified positions, and whether they get marked correctly as maybe
null. For modules, all tracepoint parameters should be marked
PTR_MAYBE_NULL by default.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20241213221929.3495062-4-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/raw_tp_null.c
tools/testing/selftests/bpf/progs/raw_tp_null_fail.c [new file with mode: 0644]

index 6fa19449297e9b5bf8c45139087d0147b0c5c9cc..43676a9922dce70945eff7cde8da822af535ac1e 100644 (file)
@@ -3,11 +3,14 @@
 
 #include <test_progs.h>
 #include "raw_tp_null.skel.h"
+#include "raw_tp_null_fail.skel.h"
 
 void test_raw_tp_null(void)
 {
        struct raw_tp_null *skel;
 
+       RUN_TESTS(raw_tp_null_fail);
+
        skel = raw_tp_null__open_and_load();
        if (!ASSERT_OK_PTR(skel, "raw_tp_null__open_and_load"))
                return;
diff --git a/tools/testing/selftests/bpf/progs/raw_tp_null_fail.c b/tools/testing/selftests/bpf/progs/raw_tp_null_fail.c
new file mode 100644 (file)
index 0000000..38d6699
--- /dev/null
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
+
+#include <vmlinux.h>
+#include <bpf/bpf_tracing.h>
+#include "bpf_misc.h"
+
+char _license[] SEC("license") = "GPL";
+
+/* Ensure module parameter has PTR_MAYBE_NULL */
+SEC("tp_btf/bpf_testmod_test_raw_tp_null")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_bpf_testmod_test_raw_tp_null_arg_1(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}
+
+/* Check NULL marking */
+SEC("tp_btf/sched_pi_setprio")
+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
+int test_raw_tp_null_sched_pi_setprio_arg_2(void *ctx) {
+    asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
+    return 0;
+}