From 4cdabb390dabaea2e2dc8c1114ec4d868f3db19c Mon Sep 17 00:00:00 2001 From: Zhiyuan Hou Date: Wed, 2 Dec 2020 16:31:06 +0800 Subject: [PATCH 2539/2944] bpf: tcp_bpf_recvmsg should return EAGAIN when nonblocking and no data fix #31874260 commit 27b31e68bc9fc25c519c7772fa23913687218d5f upstream. We return 0 in the case of a nonblocking socket that has no data available. However, this is incorrect and may confuse applications. After this patch we do the correct thing and return the error EAGAIN. Quoting return codes from recvmsg manpage, EAGAIN or EWOULDBLOCK The socket is marked nonblocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received. Fixes: 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: John Fastabend Acked-by: Song Liu Signed-off-by: Daniel Borkmann Signed-off-by: Zhiyuan Hou Acked-by: Dust Li --- kernel/bpf/sockmap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c index 2b762b2..d526ccf 100644 --- a/kernel/bpf/sockmap.c +++ b/kernel/bpf/sockmap.c @@ -1020,8 +1020,11 @@ static int bpf_tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, goto bytes_ready; } - if (err) + if (err) { copied = err; + } else { + copied = -EAGAIN; + } } release_sock(sk); -- 1.8.3.1