]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: tcp: Recv() should return 0 when the peer socket is closed
authorSabrina Dubroca <sd@queasysnail.net>
Wed, 10 Jun 2020 10:19:43 +0000 (12:19 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 12 Jun 2020 22:10:12 +0000 (15:10 -0700)
commit5713425586f1a72ee0281c1efa7a501b0e462ff4
tree8b85edb1c7f094125445f5cea4e5d574c0d783e7
parent7a105cad991e64d3e71f3cf9d734f2a0e5e75c84
bpf: tcp: Recv() should return 0 when the peer socket is closed

If the peer is closed, we will never get more data, so
tcp_bpf_wait_data will get stuck forever. In case we passed
MSG_DONTWAIT to recv(), we get EAGAIN but we should actually get
0.

>From man 2 recv:

    RETURN VALUE

    When a stream socket peer has performed an orderly shutdown, the
    return value will be 0 (the traditional "end-of-file" return).

This patch makes tcp_bpf_wait_data always return 1 when the peer
socket has been shutdown. Either we have data available, and it would
have returned 1 anyway, or there isn't, in which case we'll call
tcp_recvmsg which does the right thing in this situation.

Fixes: eaf66302e456 ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Jakub Sitnicki <jakub@cloudflare.com>
Link: https://lore.kernel.org/bpf/26038a28c21fea5d04d4bd4744c5686d3f2e5504.1591784177.git.sd@queasysnail.net
net/ipv4/tcp_bpf.c