Skip to content

Commit 2c7269b

Browse files
qsnAlexei Starovoitov
authored andcommitted
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: 604326b ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: Sabrina Dubroca <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Jakub Sitnicki <[email protected]> Link: https://lore.kernel.org/bpf/26038a28c21fea5d04d4bd4744c5686d3f2e5504.1591784177.git.sd@queasysnail.net
1 parent 2c4779e commit 2c7269b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/ipv4/tcp_bpf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ static int tcp_bpf_wait_data(struct sock *sk, struct sk_psock *psock,
245245
DEFINE_WAIT_FUNC(wait, woken_wake_function);
246246
int ret = 0;
247247

248+
if (sk->sk_shutdown & RCV_SHUTDOWN)
249+
return 1;
250+
248251
if (!timeo)
249252
return ret;
250253

0 commit comments

Comments
 (0)