Skip to contentSkip to conversation

io_uring: don't allow duplicate registrations

PATCH In review Jeff Moyer 2 participants 4 messages Jan 17, 2019

Subsystems (2)
lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

PATCH 1/1 io_uring: don't allow duplicate registrations

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.

---

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

fs/io_uring.c +6 -0
index 3650e8b63a32..f0492b0e23a0 100644
@@ -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)

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in the body to [email protected]. For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>

maintainer
#1 lore raw
Quoted 5 lines · Jeff Moyer

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.

Oops, thanks for that. Let's make it -EBUSY though, everything ends up being -EINVAL and that sometimes makes it hard for an application to figure out wtf is going on.

I also added -EINVAL for unregister when not already setup.

Signature · 7 lines
Jens Axboe

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to [email protected].  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>
author
#2 lore raw
Quoted 10 lines · Jens Axboe
Quoted 5 lines · Jeff Moyer

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.

Oops, thanks for that. Let's make it -EBUSY though, everything ends up being -EINVAL and that sometimes makes it hard for an application to figure out wtf is going on.

Sounds good.

Quoted 1 line

I also added -EINVAL for unregister when not already setup.

Yep, I saw that.

-Jeff

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in the body to [email protected]. For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>

maintainer
#3 lore raw
Quoted 13 lines · Jeff Moyer
Quoted 10 lines · Jens Axboe
Quoted 5 lines · Jeff Moyer

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.

Oops, thanks for that. Let's make it -EBUSY though, everything ends up being -EINVAL and that sometimes makes it hard for an application to figure out wtf is going on.

Quoted 5 lines

Sounds good.

Quoted 1 line

I also added -EINVAL for unregister when not already setup.

Yep, I saw that.

Changed it to -ENXIO, that's more descriptive.

Signature · 7 lines
Jens Axboe

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to [email protected].  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>