Linux io-uring development
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: Chris Mason <mason@kernel.org>, Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 01/10] io_uring/net: don't copy msg_name on a recvmsg retry
Date: Wed, 25 Nov 2026 11:43:10 -0700	[thread overview]
Message-ID: <20261125184439.58077-2-axboe@kernel.dk> (raw)
In-Reply-To: <20261125184439.58077-1-axboe@kernel.dk>

From: Chris Mason <mason@kernel.org>

IORING_OP_RECVMSG with MSG_WAITALL can write past the end of the user's
msg_name buffer, if a partial receive is retried and the source address
is longer than the buffer.

msg_namelen is an in/out field: move_addr_to_user() reads the size of
the buffer from it, and then stores the untruncated length of the
address there. So the size is valid for one call to ____sys_recvmsg()
only. But io_recvmsg() passes the same umsg and uaddr again when it
retries a partial receive, and nothing restores msg_namelen in between:

    msg_namelen = 16, AF_UNIX source address of 110 bytes

                 size read    bytes copied    msg_namelen stored
    receive 1    16           16              110
    receive 2    110          110             110

If the copy in the retry faults, the result of the request lacks the
data that the retry took off the socket. A retry that hits EOF has no
address, so it stores a msg_namelen of 0 while the buffer holds the
address. And an address that is longer than the one before it is
truncated to the length of the one before.

The fix used here is to copy the address out with the first part of the
data only, and to leave msg_name and msg_namelen alone in the retries.

The address is now that of the first part of the data and no longer that
of the last part. The two differ only if the source address changes
within one request: on an unconnected SOCK_SEQPACKET socket that
receives from several peers, or if an AF_UNIX peer binds between two
parts. A program that passes a msg_namelen smaller than its buffer got
the whole address from the second receive on, and now gets the truncated
address, as from recvmsg(2).

The retries also no longer reach audit_sockaddr(), so with an audit rule
for IORING_OP_RECVMSG the event of the retry that completes the request
can lack its SOCKADDR record. The event that keeps the record is that of
the first partial receive, which audit logs as failed with -EAGAIN.

Fixes: 7ba89d2af17a ("io_uring: ensure recv and recvmsg handle MSG_WAITALL correctly")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/net.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/io_uring/net.c b/io_uring/net.c
index 8afad1b2ddc0..f8d547c5e7d6 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1116,6 +1116,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
 		if (ret > 0 && io_net_retry(sock, flags) &&
 		    io_net_kbuf_can_retry(req, sel.buf_list, kmsg)) {
 			sr->done_io += ret;
+			/* msg_name and msg_namelen are filled in, leave them */
+			kmsg->uaddr = NULL;
 			return io_net_kbuf_recyle(req, sel.buf_list, kmsg, ret);
 		}
 		if (ret == -ERESTARTSYS)
-- 
2.55.0


  reply	other threads:[~2026-11-25 18:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
2026-11-25 18:43 ` Jens Axboe [this message]
2026-11-25 18:43 ` [PATCH 02/10] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
2026-11-25 18:43 ` [PATCH 03/10] io_uring: free the ring after a grace period Jens Axboe
2026-11-25 18:43 ` [PATCH 04/10] io_uring: free the ring from an RCU work Jens Axboe
2026-11-25 18:43 ` [PATCH 05/10] io_uring/filetable: don't install O_PATH files Jens Axboe
2026-11-25 18:43 ` [PATCH 06/10] io_uring/timeout: hold timeout_lock for the link splice Jens Axboe
2026-11-25 18:43 ` [PATCH 07/10] io_uring/cancel: always walk links under timeout_lock Jens Axboe
2026-11-25 18:43 ` [PATCH 08/10] io_uring/net: don't count the buffers of a send bundle Jens Axboe
2026-11-25 18:43 ` [PATCH 09/10] io_uring: drop cached task refs on ring release Jens Axboe
2026-11-25 18:43 ` [PATCH 10/10] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125184439.58077-2-axboe@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=mason@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox