From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Florent Revest <revest@chromium.org>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
KP Singh <kpsingh@kernel.org>,
Brendan Jackman <jackmanb@google.com>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf-next] selftests/bpf: Fix the snprintf test
Date: Fri, 30 Apr 2021 10:46:07 -0700 [thread overview]
Message-ID: <CAEf4BzbXqSDL84j3Cb5WOCcghqN=C7eUEPKmw-h8bmN6EyyPwQ@mail.gmail.com> (raw)
In-Reply-To: <20210428152501.1024509-1-revest@chromium.org>
On Wed, Apr 28, 2021 at 8:25 AM Florent Revest <revest@chromium.org> wrote:
>
> 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>
> ---
Applied to bpf tree. Thanks.
> tools/testing/selftests/bpf/prog_tests/snprintf.c | 2 ++
> tools/testing/selftests/bpf/progs/test_snprintf.c | 5 +++++
> 2 files changed, 7 insertions(+)
>
> 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;
>
> diff --git a/tools/testing/selftests/bpf/progs/test_snprintf.c b/tools/testing/selftests/bpf/progs/test_snprintf.c
> index 951a0301c553..e35129bea0a0 100644
> --- a/tools/testing/selftests/bpf/progs/test_snprintf.c
> +++ b/tools/testing/selftests/bpf/progs/test_snprintf.c
> @@ -5,6 +5,8 @@
> #include <bpf/bpf_helpers.h>
> #include <bpf/bpf_tracing.h>
>
> +__u32 pid = 0;
> +
> char num_out[64] = {};
> long num_ret = 0;
>
> @@ -42,6 +44,9 @@ int handler(const void *ctx)
> static const char str1[] = "str1";
> static const char longstr[] = "longstr";
>
> + if ((int)bpf_get_current_pid_tgid() != pid)
> + return 0;
> +
> /* Integer types */
> num_ret = BPF_SNPRINTF(num_out, sizeof(num_out),
> "%d %u %x %li %llu %lX",
> --
> 2.31.1.498.g6c1eba8ee3d-goog
>
next prev parent reply other threads:[~2021-04-30 17:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-28 15:25 [PATCH bpf-next] selftests/bpf: Fix the snprintf test Florent Revest
2021-04-30 17:46 ` Andrii Nakryiko [this message]
2021-04-30 17:50 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAEf4BzbXqSDL84j3Cb5WOCcghqN=C7eUEPKmw-h8bmN6EyyPwQ@mail.gmail.com' \
--to=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jackmanb@google.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=revest@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).