[PATCH 1/2] io_uring/net: restore msg_controllen on compat sendmsg retry
From: Hang Zhengyang
Date: Sat Dec 05 2026 - 05:49:11 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Hang Zhengyang <hang.zhengyang1010@xxxxxxxxx>
---
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