lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzYFQhPKoDG7kq=_B5caL-0Af2duL_Uz5v3oVw=BKQ430w@mail.gmail.com>
Date:   Sun, 22 Sep 2019 14:03:54 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Stanislav Fomichev <sdf@...gle.com>
Cc:     Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
        "David S. Miller" <davem@...emloft.net>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>
Subject: Re: [PATCH bpf] selftests/bpf: test_progs: fix client/server race in tcp_rtt

On Sun, Sep 22, 2019 at 12:10 PM Stanislav Fomichev <sdf@...gle.com> wrote:
>
> This is the same problem I found earlier in test_sockopt_inherit:
> there is a race between server thread doing accept() and client
> thread doing connect(). Let's explicitly synchronize them via
> pthread conditional variable.
>
> Fixes: b55873984dab ("selftests/bpf: test BPF_SOCK_OPS_RTT_CB")
> Signed-off-by: Stanislav Fomichev <sdf@...gle.com>
> ---
>  tools/testing/selftests/bpf/prog_tests/tcp_rtt.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c b/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
> index fdc0b3614a9e..e64058906bcd 100644
> --- a/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
> +++ b/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
> @@ -203,6 +203,9 @@ static int start_server(void)
>         return fd;
>  }
>
> +static pthread_mutex_t server_started_mtx = PTHREAD_MUTEX_INITIALIZER;
> +static pthread_cond_t server_started = PTHREAD_COND_INITIALIZER;
> +
>  static void *server_thread(void *arg)
>  {
>         struct sockaddr_storage addr;
> @@ -215,6 +218,10 @@ static void *server_thread(void *arg)
>                 return NULL;
>         }
>
> +       pthread_mutex_lock(&server_started_mtx);
> +       pthread_cond_signal(&server_started);
> +       pthread_mutex_unlock(&server_started_mtx);
> +
>         client_fd = accept(fd, (struct sockaddr *)&addr, &len);
>         if (CHECK_FAIL(client_fd < 0)) {
>                 perror("Failed to accept client");
> @@ -248,7 +255,14 @@ void test_tcp_rtt(void)
>         if (CHECK_FAIL(server_fd < 0))
>                 goto close_cgroup_fd;
>
> -       pthread_create(&tid, NULL, server_thread, (void *)&server_fd);
> +       if (CHECK_FAIL(pthread_create(&tid, NULL, server_thread,
> +                                     (void *)&server_fd)))
> +               goto close_cgroup_fd;
> +
> +       pthread_mutex_lock(&server_started_mtx);
> +       pthread_cond_wait(&server_started, &server_started_mtx);
> +       pthread_mutex_unlock(&server_started_mtx);


If the server fails to listen, then we'll never get a signal, right?
Let's use timedwait instead to avoid test getting stuck forever in
such cases?


> +
>         CHECK_FAIL(run_test(cgroup_fd, server_fd));
>         close(server_fd);
>  close_cgroup_fd:
> --
> 2.23.0.351.gc4317032e6-goog
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ