From: Jens Axboe <axboe@kernel.dk>
To: stable@vger.kernel.org
Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org
Subject: [PATCH 6.18.y 10/14] io_uring/net: restore the cmsg buffer on recvmsg retry
Date: Sat, 5 Dec 2026 23:11:43 +0000 [thread overview]
Message-ID: <20261205231147.4095031-11-axboe@kernel.dk> (raw)
In-Reply-To: <20261205231147.4095031-1-axboe@kernel.dk>
From: Chris Mason <mason@kernel.org>
Commit 437e79d6a2a7aba81d56c11198576a72574e6d52 upstream.
A single-shot IORING_OP_RECVMSG that is retried after -EAGAIN can report
the control messages of the failed attempt, and hide those that came
with the data. On an AF_UNIX stream socket with SO_PASSCRED, the caller
gets SCM_CREDENTIALS with pid, uid and gid 0, and never sees the
descriptors that an SCM_RIGHTS message installed.
io_recvmsg() passes the msghdr that was set up at prep to each attempt,
so a failed ->recvmsg() has to leave msg_control and msg_controllen as
they were. recvmsg(2) doesn't depend on that, since it copies the user's
msghdr for each call. unix_stream_read_generic() calls scm_recv_unix()
whatever its result is, with a zeroed scm_cookie if the queue was empty,
and put_cmsg() advances the control buffer. ____sys_recvmsg() then
counts the reported length from where its call started, but the caller
reads from the head of its buffer:
msg_control = C, msg_controllen = 64
first attempt, the queue is empty
put_cmsg(SCM_CREDENTIALS {0, 0, 0}) at C
msg_control = C + 32, msg_controllen = 32
return -EAGAIN
second attempt
cmsg_ptr = C + 32
put_cmsg(SCM_CREDENTIALS of the sender) at C + 32
msg_control = C + 64, msg_controllen = 0
put_user(msg_control - cmsg_ptr = 32, &umsg->msg_controllen)
The fix used here is to save the control buffer before each attempt, and
to restore it if the attempt fails with -EAGAIN and will be retried.
The tradeoff: with MSG_WAITALL, a retry whose control buffer the failed
attempts had used up went on after a short receive until the data buffer
was full. It now completes short, as every recvmsg with a control buffer
does since commit 78d0d2063bab ("io_uring/net: disable partial retries
for recvmsg with cmsg").
Fixes: e54937963fa2 ("net: remove cmsg restriction from io_uring based send/recvmsg calls")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/net.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/io_uring/net.c b/io_uring/net.c
index 09ef15e0700e..476ae9b38b63 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1045,6 +1045,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
int ret, min_ret = 0;
bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
bool mshot_finished = true;
+ void __user *control;
+ size_t controllen;
int consumed = 0;
size_t len;
@@ -1082,6 +1084,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
kmsg->msg.msg_get_inq = 1;
kmsg->msg.msg_inq = -1;
+ control = kmsg->msg.msg_control_user;
+ controllen = kmsg->msg.msg_controllen;
if (req->flags & REQ_F_APOLL_MULTISHOT) {
ret = io_recvmsg_multishot(sock, sr, kmsg, flags,
&mshot_finished);
@@ -1106,6 +1110,12 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
if (ret < min_ret) {
if (ret == -EAGAIN && force_nonblock) {
+ /*
+ * Don't depend on the control buffer being untouched, a
+ * protocol may post a cmsg before it finds no data.
+ */
+ kmsg->msg.msg_control_user = control;
+ kmsg->msg.msg_controllen = controllen;
io_kbuf_recycle(req, sel.buf_list, issue_flags);
return IOU_RETRY;
}
--
2.55.0
next prev parent reply other threads:[~2026-12-05 23:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 01/14] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 02/14] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 03/14] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 04/14] io_uring/tctx: add separate lock for list of tctx's in ctx Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 05/14] io_uring: free the task context after a grace period Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 06/14] io_uring: free the ring " Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 07/14] io_uring/filetable: don't install O_PATH files Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 08/14] io_uring/cancel: always walk links under timeout_lock Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 09/14] io_uring/net: don't count the buffers of a send bundle Jens Axboe
2026-12-05 23:11 ` Jens Axboe [this message]
2026-12-05 23:11 ` [PATCH 6.18.y 11/14] io_uring: close poll activation race when enabling rings Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 12/14] io_uring/cancel: arm local work wakeups only for submitter Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 13/14] io_uring/zcrx: cache fallback availability in zcrx ctx Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 14/14] io_uring/zcrx: don't sync dma-bufs 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=20261205231147.4095031-11-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=gregkh@linuxfoundation.org \
--cc=io-uring@vger.kernel.org \
--cc=stable@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.