diff options
author | 2021-04-28 17:25:01 +0200 | |
---|---|---|
committer | 2021-04-30 10:36:59 -0700 | |
commit | f80f88f0e2f2ef9cd805fad1bbf676b0ecd4b55c (patch) | |
tree | f29dea6f71982e58365e8f975437eed073925aa2 /tools/testing/selftests/bpf/prog_tests/snprintf.c | |
parent | net: dsa: ksz: ksz8863_smi_probe: set proper return value for ksz_switch_alloc() (diff) | |
download | linux-f80f88f0e2f2ef9cd805fad1bbf676b0ecd4b55c.tar.gz linux-f80f88f0e2f2ef9cd805fad1bbf676b0ecd4b55c.tar.bz2 linux-f80f88f0e2f2ef9cd805fad1bbf676b0ecd4b55c.zip |
selftests/bpf: Fix the snprintf test
The BPF program for the snprintf selftest runs on all syscall entries.
On busy multicore systems this can cause concurrency issues.
For example it was observed that sometimes the userspace part of the
test reads " 4 0000" instead of " 4 000" (extra '0' at the end)
which seems to happen just before snprintf on another core sets
end[-1] = '\0'.
This patch adds a pid filter to the test to ensure that no
bpf_snprintf() will write over the test's output buffers while the
userspace reads the values.
Fixes: c2e39c6bdc7e ("selftests/bpf: Add a series of tests for bpf_snprintf")
Reported-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Florent Revest <revest@chromium.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210428152501.1024509-1-revest@chromium.org
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/snprintf.c')
-rw-r--r-- | tools/testing/selftests/bpf/prog_tests/snprintf.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/snprintf.c b/tools/testing/selftests/bpf/prog_tests/snprintf.c index a958c22aec75..dffbcaa1ec98 100644 --- a/tools/testing/selftests/bpf/prog_tests/snprintf.c +++ b/tools/testing/selftests/bpf/prog_tests/snprintf.c @@ -43,6 +43,8 @@ void test_snprintf_positive(void) if (!ASSERT_OK_PTR(skel, "skel_open")) return; + skel->bss->pid = getpid(); + if (!ASSERT_OK(test_snprintf__attach(skel), "skel_attach")) goto cleanup; |