Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Fix test_vmlinux test to use bpf_probe_read_user()

The test is reading UAPI kernel structure from user-space. So it doesn't need
CO-RE relocations and has to use bpf_probe_read_user().

Fixes: acbd06206bbb ("selftests/bpf: Add vmlinux.h selftest exercising tracing of syscalls")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200818213356.2629020-6-andriin@fb.com

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
02f47faa 109cea5a

+9 -3
+9 -3
tools/testing/selftests/bpf/progs/test_vmlinux.c
··· 19 19 int handle__tp(struct trace_event_raw_sys_enter *args) 20 20 { 21 21 struct __kernel_timespec *ts; 22 + long tv_nsec; 22 23 23 24 if (args->id != __NR_nanosleep) 24 25 return 0; 25 26 26 27 ts = (void *)args->args[0]; 27 - if (BPF_CORE_READ(ts, tv_nsec) != MY_TV_NSEC) 28 + if (bpf_probe_read_user(&tv_nsec, sizeof(ts->tv_nsec), &ts->tv_nsec) || 29 + tv_nsec != MY_TV_NSEC) 28 30 return 0; 29 31 30 32 tp_called = true; ··· 37 35 int BPF_PROG(handle__raw_tp, struct pt_regs *regs, long id) 38 36 { 39 37 struct __kernel_timespec *ts; 38 + long tv_nsec; 40 39 41 40 if (id != __NR_nanosleep) 42 41 return 0; 43 42 44 43 ts = (void *)PT_REGS_PARM1_CORE(regs); 45 - if (BPF_CORE_READ(ts, tv_nsec) != MY_TV_NSEC) 44 + if (bpf_probe_read_user(&tv_nsec, sizeof(ts->tv_nsec), &ts->tv_nsec) || 45 + tv_nsec != MY_TV_NSEC) 46 46 return 0; 47 47 48 48 raw_tp_called = true; ··· 55 51 int BPF_PROG(handle__tp_btf, struct pt_regs *regs, long id) 56 52 { 57 53 struct __kernel_timespec *ts; 54 + long tv_nsec; 58 55 59 56 if (id != __NR_nanosleep) 60 57 return 0; 61 58 62 59 ts = (void *)PT_REGS_PARM1_CORE(regs); 63 - if (BPF_CORE_READ(ts, tv_nsec) != MY_TV_NSEC) 60 + if (bpf_probe_read_user(&tv_nsec, sizeof(ts->tv_nsec), &ts->tv_nsec) || 61 + tv_nsec != MY_TV_NSEC) 64 62 return 0; 65 63 66 64 tp_btf_called = true;