bpf, tcp: correctly handle DONT_WAIT flags and timeo == 0
authorJohn Fastabend <john.fastabend@gmail.com>
Tue, 14 May 2019 04:42:03 +0000 (21:42 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 15 May 2019 23:36:13 +0000 (01:36 +0200)
The tcp_bpf_wait_data() routine needs to check timeo != 0 before
calling sk_wait_event() otherwise we may see unexpected stalls
on receiver.

Arika did all the leg work here I just formatted, posted and ran
a few tests.

Fixes: 604326b41a6fb ("bpf, sockmap: convert to generic sk_msg interface")
Reported-by: Arika Chen <eaglesora@gmail.com>
Suggested-by: Arika Chen <eaglesora@gmail.com>
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
net/ipv4/tcp_bpf.c

index 4a619c85daede6983ffbdeb0fa8a5a57e997b838..3d1e1540138440a0c0f6a65aabd888626ad0e384 100644 (file)
@@ -27,7 +27,10 @@ static int tcp_bpf_wait_data(struct sock *sk, struct sk_psock *psock,
                             int flags, long timeo, int *err)
 {
        DEFINE_WAIT_FUNC(wait, woken_wake_function);
-       int ret;
+       int ret = 0;
+
+       if (!timeo)
+               return ret;
 
        add_wait_queue(sk_sleep(sk), &wait);
        sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk);