Skip to content

Commit deee01a

Browse files
shunghsiyugregkh
authored andcommitted
selftests/bpf: Fix raw_tp null handling test
Commit b2fc4b1, backport of upstream commit 838a10b ("bpf: Augment raw_tp arguments with PTR_MAYBE_NULL"), was missing the changes to tools/testing/selftests/bpf/progs/raw_tp_null.c, and cause the test to fail with the following error (see link below for the complete log) Error: #205 raw_tp_null libbpf: prog 'test_raw_tp_null': BPF program load failed: Permission denied libbpf: prog 'test_raw_tp_null': -- BEGIN PROG LOAD LOG -- 0: R1=ctx() R10=fp0 ; int BPF_PROG(test_raw_tp_null, struct sk_buff *skb) @ raw_tp_null.c:13 0: (79) r6 = *(u64 *)(r1 +0) func 'bpf_testmod_test_raw_tp_null' arg0 has btf_id 2081 type STRUCT 'sk_buff' 1: R1=ctx() R6_w=trusted_ptr_or_null_sk_buff(id=1) ; struct task_struct *task = bpf_get_current_task_btf(); @ raw_tp_null.c:15 1: (85) call bpf_get_current_task_btf#158 ; R0_w=trusted_ptr_task_struct() ; if (task->pid != tid) @ raw_tp_null.c:17 2: (61) r1 = *(u32 *)(r0 +1416) ; R0_w=trusted_ptr_task_struct() R1_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) 3: (18) r2 = 0xffffa3bb801c6000 ; R2_w=map_value(map=raw_tp_n.bss,ks=4,vs=8) 5: (61) r2 = *(u32 *)(r2 +0) ; R2_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) 6: (5e) if w1 != w2 goto pc+11 ; R1_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) R2_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) ; i = i + skb->mark + 1; @ raw_tp_null.c:20 7: (61) r2 = *(u32 *)(r6 +164) R6 invalid mem access 'trusted_ptr_or_null_' processed 7 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0 -- END PROG LOAD LOG -- libbpf: prog 'test_raw_tp_null': failed to load: -13 libbpf: failed to load object 'raw_tp_null' libbpf: failed to load BPF skeleton 'raw_tp_null': -13 test_raw_tp_null:FAIL:raw_tp_null__open_and_load unexpected error: -13 Bring the missing changes in to fix the test failure. Link: https://github.com/shunghsiyu/libbpf/actions/runs/14522396622/job/40766998873 Fixes: b2fc4b1 ("bpf: Augment raw_tp arguments with PTR_MAYBE_NULL") Signed-off-by: Shung-Hsi Yu <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e2a9f73 commit deee01a

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <vmlinux.h>
55
#include <bpf/bpf_tracing.h>
6+
#include "bpf_misc.h"
67

78
char _license[] SEC("license") = "GPL";
89

@@ -17,16 +18,14 @@ int BPF_PROG(test_raw_tp_null, struct sk_buff *skb)
1718
if (task->pid != tid)
1819
return 0;
1920

20-
i = i + skb->mark + 1;
21-
/* The compiler may move the NULL check before this deref, which causes
22-
* the load to fail as deref of scalar. Prevent that by using a barrier.
21+
/* If dead code elimination kicks in, the increment +=2 will be
22+
* removed. For raw_tp programs attaching to tracepoints in kernel
23+
* modules, we mark input arguments as PTR_MAYBE_NULL, so branch
24+
* prediction should never kick in.
2325
*/
24-
barrier();
25-
/* If dead code elimination kicks in, the increment below will
26-
* be removed. For raw_tp programs, we mark input arguments as
27-
* PTR_MAYBE_NULL, so branch prediction should never kick in.
28-
*/
29-
if (!skb)
30-
i += 2;
26+
asm volatile ("%[i] += 1; if %[ctx] != 0 goto +1; %[i] += 2;"
27+
: [i]"+r"(i)
28+
: [ctx]"r"(skb)
29+
: "memory");
3130
return 0;
3231
}

0 commit comments

Comments
 (0)