linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Moyer <jmoyer@redhat.com>
To: axboe@kernel.dk
Cc: linux-fsdevel@vger.kernel.org, linux-aio@kvack.org,
	linux-block@vger.kernel.org
Subject: [patch] io_uring: don't allow duplicate registrations
Date: Wed, 16 Jan 2019 19:50:12 -0500	[thread overview]
Message-ID: <x497ef4hzuj.fsf@segfault.boston.devel.redhat.com> (raw)

Hi, Jens,

It looks to me like calling io_uring_register more than once (for either
IORING_REGISTER_BUFFERS or IORING_REGISTER_FILES) will leak the
references taken in previous calls.

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>

---

If this makes sense to you, feel free to just fold this into your
patches w/o any attribution.

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 3650e8b63a32..f0492b0e23a0 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1399,6 +1399,9 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
 	if (!nr_args)
 		return -EINVAL;
 
+	if (ctx->user_files)
+		return -EINVAL;
+
 	ctx->user_files = kcalloc(nr_args, sizeof(struct file *), GFP_KERNEL);
 	if (!ctx->user_files)
 		return -ENOMEM;
@@ -1580,6 +1583,9 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, void __user *arg,
 	if (!nr_args || nr_args > UIO_MAXIOV)
 		return -EINVAL;
 
+	if (ctx->user_bufs)
+		return -EINVAL;
+
 	ctx->user_bufs = kcalloc(nr_args, sizeof(struct io_mapped_ubuf),
 					GFP_KERNEL);
 	if (!ctx->user_bufs)

             reply	other threads:[~2019-01-17  0:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-17  0:50 Jeff Moyer [this message]
2019-01-17  1:23 ` [patch] io_uring: don't allow duplicate registrations Jens Axboe
2019-01-17  1:31   ` Jeff Moyer
2019-01-17  1:33     ` 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=x497ef4hzuj.fsf@segfault.boston.devel.redhat.com \
    --to=jmoyer@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=linux-aio@kvack.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@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;
as well as URLs for NNTP newsgroup(s).