5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jens Axboe commit bdc350ddbcbe4788158019d4d8e8e9345cb16235 upstream. ____sys_sendmsg() and ____sys_recvmsg() turn O_NONBLOCK on the socket into MSG_DONTWAIT. That is right for the system calls, but io_uring uses __sys_sendmsg_sock() and __sys_recvmsg_sock() for a blocking attempt from io-wq as well, after the non-blocking attempts with MSG_DONTWAIT have failed. On an O_NONBLOCK socket that attempt can't block either and the request completes with -EAGAIN, unlike IORING_OP_SEND and RECV, which call sock_sendmsg() and sock_recvmsg() directly and don't look at O_NONBLOCK at all. Move the O_NONBLOCK handling to ___sys_sendmsg() and ___sys_recvmsg(), which the sendmsg, sendmmsg, recvmsg and recvmmsg system calls go through. The io_uring helpers then pass the flags the caller asked for. Cc: stable@vger.kernel.org Fixes: 0fa03c624d8f ("io_uring: add support for sendmsg()") Fixes: aa1fa28fc73e ("io_uring: add support for recvmsg()") Link: https://lore.kernel.org/io-uring/a5589b66-9a20-4b1c-a0f1-1b5b31af3667@app.fastmail.com/ Reported-by: Lukáš Lalinský Signed-off-by: Jens Axboe Signed-off-by: Dave Miller Signed-off-by: Greg Kroah-Hartman --- net/socket.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/net/socket.c +++ b/net/socket.c @@ -2361,8 +2361,6 @@ static int ____sys_sendmsg(struct socket } msg_sys->msg_flags = flags; - if (sock->file->f_flags & O_NONBLOCK) - msg_sys->msg_flags |= MSG_DONTWAIT; /* * If this is sendmmsg() and current destination address is same as * previously succeeded address, omit asking LSM's decision. @@ -2426,6 +2424,9 @@ static int ___sys_sendmsg(struct socket msg_sys->msg_name = &address; + if (sock->file->f_flags & O_NONBLOCK) + flags |= MSG_DONTWAIT; + err = sendmsg_copy_msghdr(msg_sys, msg, flags, &iov); if (err < 0) return err; @@ -2589,9 +2590,6 @@ static int ____sys_recvmsg(struct socket /* We assume all kernel code knows the size of sockaddr_storage */ msg_sys->msg_namelen = 0; - if (sock->file->f_flags & O_NONBLOCK) - flags |= MSG_DONTWAIT; - if (unlikely(nosec)) err = sock_recvmsg_nosec(sock, msg_sys, flags); else @@ -2633,6 +2631,9 @@ static int ___sys_recvmsg(struct socket struct sockaddr __user *uaddr; ssize_t err; + if (sock->file->f_flags & O_NONBLOCK) + flags |= MSG_DONTWAIT; + err = recvmsg_copy_msghdr(msg_sys, msg, flags, &uaddr, &iov); if (err < 0) return err;