From: Martin KaFai Lau <kafai@fb.com>
To: Andrii Nakryiko <andriin@fb.com>
Cc: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>, <ast@fb.com>,
<daniel@iogearbox.net>, <andrii.nakryiko@gmail.com>,
<kernel-team@fb.com>
Subject: Re: [Potential Spoof] [PATCH bpf-next 1/3] selftests/bpf: fix race in tcp_rtt test
Date: Mon, 16 Mar 2020 22:27:15 -0700 [thread overview]
Message-ID: <20200317052715.xnof2rdecrmkep7v@kafai-mbp> (raw)
In-Reply-To: <20200314013932.4035712-1-andriin@fb.com>
On Fri, Mar 13, 2020 at 06:39:30PM -0700, Andrii Nakryiko wrote:
> Previous attempt to make tcp_rtt more robust introduced a new race, in which
> server_done might be set to true before server can actually accept any
> connection. Fix this by unconditionally waiting for accept(). Given socket is
> non-blocking, if there are any problems with client side, it should eventually
> close listening FD and let server thread exit with failure.
>
> Fixes: 4cd729fa022c ("selftests/bpf: Make tcp_rtt test more robust to failures")
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
> tools/testing/selftests/bpf/prog_tests/tcp_rtt.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c b/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
> index e08f6bb17700..e56b52ab41da 100644
> --- a/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
> +++ b/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
> @@ -226,7 +226,7 @@ static void *server_thread(void *arg)
> return ERR_PTR(err);
> }
>
> - while (!server_done) {
> + while (true) {
> client_fd = accept(fd, (struct sockaddr *)&addr, &len);
> if (client_fd == -1 && errno == EAGAIN) {
> usleep(50);
> @@ -272,7 +272,7 @@ void test_tcp_rtt(void)
> CHECK_FAIL(run_test(cgroup_fd, server_fd));
>
> server_done = true;
> - pthread_join(tid, &server_res);
> + CHECK_FAIL(pthread_join(tid, &server_res));
From looking at run_test(),
I suspect without accept and server_thread, this may also work:
listen(server_fd, 1);
run_test(cgroup_fd, server_fd);
close(server_fd);
This change lgtm since it is NONBLOCK. Ideally, may be it should
also be time limited by epoll or setsockopt(SO_RCVTIMEO) in the future.
Acked-by: Martin KaFai Lau <kafai@fb.com>
next prev parent reply other threads:[~2020-03-17 5:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-14 1:39 [PATCH bpf-next 1/3] selftests/bpf: fix race in tcp_rtt test Andrii Nakryiko
2020-03-14 1:39 ` [PATCH bpf-next 2/3] selftests/bpf: fix test_progs's parsing of test numbers Andrii Nakryiko
2020-03-17 5:28 ` Martin KaFai Lau
2020-03-14 1:39 ` [PATCH bpf-next 3/3] selftests/bpf: reset process and thread affinity after each test/sub-test Andrii Nakryiko
2020-03-17 5:35 ` [Potential Spoof] " Martin KaFai Lau
2020-03-17 5:39 ` Andrii Nakryiko
2020-03-17 5:27 ` Martin KaFai Lau [this message]
2020-03-17 18:58 ` [PATCH bpf-next 1/3] selftests/bpf: fix race in tcp_rtt test Daniel Borkmann
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=20200317052715.xnof2rdecrmkep7v@kafai-mbp \
--to=kafai@fb.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andriin@fb.com \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.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).