Skip to content

Commit 7e42863

Browse files
Yonghong Songanakryiko
authored andcommitted
selftests/bpf: Fix flaky test ptr_untrusted
Somehow recently I frequently hit the following test failure with either ./test_progs or ./test_progs-cpuv4: serial_test_ptr_untrusted:PASS:skel_open 0 nsec serial_test_ptr_untrusted:PASS:lsm_attach 0 nsec serial_test_ptr_untrusted:PASS:raw_tp_attach 0 nsec serial_test_ptr_untrusted:FAIL:cmp_tp_name unexpected cmp_tp_name: actual -115 != expected 0 #182 ptr_untrusted:FAIL Further investigation found the failure is due to bpf_probe_read_user_str() where reading user-level string attr->raw_tracepoint.name is not successfully, most likely due to the string itself still in disk and not populated into memory yet. One solution is do a printf() call of the string before doing bpf syscall which will force the raw_tracepoint.name into memory. But I think a more robust solution is to use bpf_copy_from_user() which is used in sleepable program and can tolerate page fault, and the fix here used the latter approach. Signed-off-by: Yonghong Song <yonghong.song@linux.dev> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20240204194452.2785936-1-yonghong.song@linux.dev
1 parent df9705e commit 7e42863

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
char tp_name[128];
88

9-
SEC("lsm/bpf")
9+
SEC("lsm.s/bpf")
1010
int BPF_PROG(lsm_run, int cmd, union bpf_attr *attr, unsigned int size)
1111
{
1212
switch (cmd) {
1313
case BPF_RAW_TRACEPOINT_OPEN:
14-
bpf_probe_read_user_str(tp_name, sizeof(tp_name) - 1,
15-
(void *)attr->raw_tracepoint.name);
14+
bpf_copy_from_user(tp_name, sizeof(tp_name) - 1,
15+
(void *)attr->raw_tracepoint.name);
1616
break;
1717
default:
1818
break;

0 commit comments

Comments
 (0)