Skip to content

Commit 0da1955

Browse files
kkdwivediAlexei Starovoitov
authored andcommitted
selftests/bpf: Add tests for raw_tp NULL args
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>
1 parent 838a10b commit 0da1955

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

tools/testing/selftests/bpf/prog_tests/raw_tp_null.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33

44
#include <test_progs.h>
55
#include "raw_tp_null.skel.h"
6+
#include "raw_tp_null_fail.skel.h"
67

78
void test_raw_tp_null(void)
89
{
910
struct raw_tp_null *skel;
1011

12+
RUN_TESTS(raw_tp_null_fail);
13+
1114
skel = raw_tp_null__open_and_load();
1215
if (!ASSERT_OK_PTR(skel, "raw_tp_null__open_and_load"))
1316
return;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
3+
4+
#include <vmlinux.h>
5+
#include <bpf/bpf_tracing.h>
6+
#include "bpf_misc.h"
7+
8+
char _license[] SEC("license") = "GPL";
9+
10+
/* Ensure module parameter has PTR_MAYBE_NULL */
11+
SEC("tp_btf/bpf_testmod_test_raw_tp_null")
12+
__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
13+
int test_raw_tp_null_bpf_testmod_test_raw_tp_null_arg_1(void *ctx) {
14+
asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
15+
return 0;
16+
}
17+
18+
/* Check NULL marking */
19+
SEC("tp_btf/sched_pi_setprio")
20+
__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
21+
int test_raw_tp_null_sched_pi_setprio_arg_2(void *ctx) {
22+
asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
23+
return 0;
24+
}

0 commit comments

Comments
 (0)