mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hang Zhengyang <hang.zhengyang1010@gmail.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Pavel Begunkov <asml.silence@gmail.com>,
	Keith Busch <kbusch@kernel.org>,
	Nicholas Carlini <nicholas@carlini.com>,
	io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH 1/2] io_uring/net: restore msg_controllen on compat sendmsg retry
Date: Sat,  5 Dec 2026 10:48:53 +0000	[thread overview]
Message-ID: <20261205104854.1207958-2-hang.zhengyang1010@gmail.com> (raw)
In-Reply-To: <20261205104854.1207958-1-hang.zhengyang1010@gmail.com>

On a compat ring, a retried IORING_OP_SENDMSG or IORING_OP_SENDMSG_ZC
with a control message can fail with -EINVAL.

The compat cmsg conversion in ____sys_sendmsg() replaces msg_controllen
with the native length, 24 instead of 16 for one SCM_RIGHTS fd. On a
retry, io_uring restores msg_control but not msg_controllen, so the
conversion runs past the end of the user's control buffer.

Save msg_controllen before each attempt and restore it after.

Fixes: cac9e4418f4c ("io_uring/net: save msghdr->msg_control for retries")
Fixes: 4fe82aedeb8a ("io_uring/net: restore msg_control on sendzc retry")
Cc: stable@vger.kernel.org
Signed-off-by: Hang Zhengyang <hang.zhengyang1010@gmail.com>
---
 io_uring/net.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/io_uring/net.c b/io_uring/net.c
index b0d508b772ce..0976e25b9d80 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -549,6 +549,7 @@ int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
 	struct io_async_msghdr *kmsg = req->async_data;
 	struct socket *sock;
 	unsigned flags;
+	size_t controllen;
 	int min_ret = 0;
 	int ret;
 
@@ -567,8 +568,11 @@ int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
 		min_ret = iov_iter_count(&kmsg->msg.msg_iter);
 
 	kmsg->msg.msg_control_user = sr->msg_control;
+	controllen = kmsg->msg.msg_controllen;
 
 	ret = __sys_sendmsg_sock(sock, &kmsg->msg, flags);
+	/* compat cmsg conversion changes it, restore it for a retry */
+	kmsg->msg.msg_controllen = controllen;
 
 	if (ret < min_ret) {
 		if (ret == -EAGAIN && (issue_flags & IO_URING_F_NONBLOCK))
@@ -1602,8 +1606,12 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags)
 		kmsg->msg.msg_flags = msg_flags;
 		ret = sock_sendmsg(sock, &kmsg->msg);
 	} else {
+		size_t controllen = kmsg->msg.msg_controllen;
+
 		kmsg->msg.msg_control_user = sr->msg_control;
 		ret = __sys_sendmsg_sock(sock, &kmsg->msg, msg_flags);
+		/* compat cmsg conversion changes it, restore it for a retry */
+		kmsg->msg.msg_controllen = controllen;
 	}
 
 	if (unlikely(ret < min_ret)) {
-- 
2.53.0


  reply	other threads:[~2026-12-05 10:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 10:48 [PATCH 0/2] io_uring: fix compat sendmsg retry and SQE_MIXED fdinfo Hang Zhengyang
2026-12-05 10:48 ` Hang Zhengyang [this message]
2026-12-05 10:48 ` [PATCH 2/2] io_uring/fdinfo: don't skip the SQE after a 128-byte one Hang Zhengyang
2026-12-05 14:04 ` [PATCH 0/2] io_uring: fix compat sendmsg retry and SQE_MIXED fdinfo 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=20261205104854.1207958-2-hang.zhengyang1010@gmail.com \
    --to=hang.zhengyang1010@gmail.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicholas@carlini.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®