From: John Fastabend Date: Mon, 29 Oct 2018 19:31:28 +0000 (-0700) Subject: bpf: tcp_bpf_recvmsg should return EAGAIN when nonblocking and no data X-Git-Tag: v4.20-rc1~37^2~3^2~3 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=27b31e68bc9fc25c519c7772fa23913687218d5f;p=linux-block.git bpf: tcp_bpf_recvmsg should return EAGAIN when nonblocking and no data 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 --- diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c index b7918d4caa30..3b45fe530f91 100644 --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -145,6 +145,7 @@ msg_bytes_ready: ret = err; goto out; } + copied = -EAGAIN; } ret = copied; out: