public inbox for [email protected]
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
	Gabriel Krisman Bertazi <[email protected]>
Subject: [PATCH 1/5] io_uring: Fix leak of async data when connect prep fails
Date: Fri, 31 May 2024 17:12:07 -0400	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

move_addr_to_kernel can fail, like if the user provides a bad sockaddr
pointer. In this case where the failure happens on ->prep() we don't
have a chance to clean the request later, so handle it here.

Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
 io_uring/net.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/io_uring/net.c b/io_uring/net.c
index 0a48596429d9..c3377e70aeeb 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1657,6 +1657,7 @@ int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
 	struct io_connect *conn = io_kiocb_to_cmd(req, struct io_connect);
 	struct io_async_msghdr *io;
+	int ret;
 
 	if (sqe->len || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in)
 		return -EINVAL;
@@ -1669,7 +1670,10 @@ int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	if (unlikely(!io))
 		return -ENOMEM;
 
-	return move_addr_to_kernel(conn->addr, conn->addr_len, &io->addr);
+	ret = move_addr_to_kernel(conn->addr, conn->addr_len, &io->addr);
+	if (ret)
+		io_netmsg_recycle(req, 0);
+	return ret;
 }
 
 int io_connect(struct io_kiocb *req, unsigned int issue_flags)
-- 
2.44.0


  reply	other threads:[~2024-05-31 21:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31 21:12 [PATCH 0/5] io_uring: support IORING_OP_BIND and IORING_OP_LISTEN Gabriel Krisman Bertazi
2024-05-31 21:12 ` Gabriel Krisman Bertazi [this message]
2024-05-31 21:30   ` [PATCH 1/5] io_uring: Fix leak of async data when connect prep fails Jens Axboe
2024-05-31 23:01     ` Gabriel Krisman Bertazi
2024-05-31 23:07       ` Jens Axboe
2024-05-31 21:12 ` [PATCH 2/5] net: Split a __sys_bind helper for io_uring Gabriel Krisman Bertazi
2024-05-31 22:38   ` Jens Axboe
2024-05-31 21:12 ` [PATCH 3/5] net: Split a __sys_listen " Gabriel Krisman Bertazi
2024-05-31 22:38   ` Jens Axboe
2024-05-31 21:12 ` [PATCH 4/5] io_uring: Introduce IORING_OP_BIND Gabriel Krisman Bertazi
2024-05-31 22:30   ` Jens Axboe
2024-05-31 21:12 ` [PATCH 5/5] io_uring: Introduce IORING_OP_LISTEN Gabriel Krisman Bertazi
2024-05-31 22:31   ` 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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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