All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] io_uring/net: fix netmsg_cache iovec leak on BIND and CONNECT
@ 2026-06-17  2:53 Yang Xiuwei
  2026-06-17  3:30 ` Yang Xiuwei
  0 siblings, 1 reply; 4+ messages in thread
From: Yang Xiuwei @ 2026-06-17  2:53 UTC (permalink / raw)
  To: axboe; +Cc: krisman, io-uring, Yang Xiuwei

BIND and CONNECT allocate struct io_async_msghdr from netmsg_cache via
io_msg_alloc_async(). When a prior SENDMSG left a heap-allocated iovec[]
in the cached header, REQ_F_NEED_CLEANUP is set. Neither opcode had a
cleanup handler, so io_clean_op() would kfree(async_data) without
freeing the iovec on prep failure or cancellation. io_bind() also
omitted io_req_msg_cleanup() on the issue success path,
unlike io_connect().

Add io_sendmsg_recvmsg_cleanup for both opcodes and recycle the async
header from io_bind() after issue, matching CONNECT.

Fixes: 7481fd93fa0a ("io_uring: Introduce IORING_OP_BIND")
Signed-off-by: Yang Xiuwei <yangxiuwei@kylinos.cn>
---
 io_uring/net.c   | 3 ++-
 io_uring/opdef.c | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/io_uring/net.c b/io_uring/net.c
index 8df15b639358..0382be472712 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1855,8 +1855,9 @@ int io_bind(struct io_kiocb *req, unsigned int issue_flags)
 	ret = __sys_bind_socket(sock, &io->addr, bind->addr_len);
 	if (ret < 0)
 		req_set_fail(req);
+	io_req_msg_cleanup(req, issue_flags);
 	io_req_set_res(req, ret, 0);
-	return 0;
+	return IOU_COMPLETE;
 }
 
 int io_listen_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
diff --git a/io_uring/opdef.c b/io_uring/opdef.c
index c3ef52b70811..3ee020701fc1 100644
--- a/io_uring/opdef.c
+++ b/io_uring/opdef.c
@@ -658,6 +658,9 @@ const struct io_cold_def io_cold_defs[] = {
 	},
 	[IORING_OP_CONNECT] = {
 		.name			= "CONNECT",
+#if defined(CONFIG_NET)
+		.cleanup		= io_sendmsg_recvmsg_cleanup,
+#endif
 	},
 	[IORING_OP_FALLOCATE] = {
 		.name			= "FALLOCATE",
@@ -816,6 +819,9 @@ const struct io_cold_def io_cold_defs[] = {
 	},
 	[IORING_OP_BIND] = {
 		.name			= "BIND",
+#if defined(CONFIG_NET)
+		.cleanup		= io_sendmsg_recvmsg_cleanup,
+#endif
 	},
 	[IORING_OP_LISTEN] = {
 		.name			= "LISTEN",
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-17 15:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-17  2:53 [PATCH] io_uring/net: fix netmsg_cache iovec leak on BIND and CONNECT Yang Xiuwei
2026-06-17  3:30 ` Yang Xiuwei
2026-06-17 15:07   ` Jens Axboe
2026-06-17 15:41     ` Gabriel Krisman Bertazi

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.