Skip to content

Commit 75c4021

Browse files
isilenceaxboe
authored andcommitted
io_uring: check register restriction afore quiesce
Move restriction checks of __io_uring_register() before quiesce, saves from waiting for requests in fail case and simplifies the code a bit. Also add array_index_nospec() for safety Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/88d7913c9280ee848fdb7b584eea37a465391cee.1618488258.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 38134ad commit 75c4021

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

fs/io_uring.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9738,6 +9738,14 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
97389738
if (percpu_ref_is_dying(&ctx->refs))
97399739
return -ENXIO;
97409740

9741+
if (ctx->restricted) {
9742+
if (opcode >= IORING_REGISTER_LAST)
9743+
return -EINVAL;
9744+
opcode = array_index_nospec(opcode, IORING_REGISTER_LAST);
9745+
if (!test_bit(opcode, ctx->restrictions.register_op))
9746+
return -EACCES;
9747+
}
9748+
97419749
if (io_register_op_must_quiesce(opcode)) {
97429750
percpu_ref_kill(&ctx->refs);
97439751

@@ -9766,18 +9774,6 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
97669774
}
97679775
}
97689776

9769-
if (ctx->restricted) {
9770-
if (opcode >= IORING_REGISTER_LAST) {
9771-
ret = -EINVAL;
9772-
goto out;
9773-
}
9774-
9775-
if (!test_bit(opcode, ctx->restrictions.register_op)) {
9776-
ret = -EACCES;
9777-
goto out;
9778-
}
9779-
}
9780-
97819777
switch (opcode) {
97829778
case IORING_REGISTER_BUFFERS:
97839779
ret = io_sqe_buffers_register(ctx, arg, nr_args);
@@ -9851,7 +9847,6 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
98519847
break;
98529848
}
98539849

9854-
out:
98559850
if (io_register_op_must_quiesce(opcode)) {
98569851
/* bring the ctx back to life */
98579852
percpu_ref_reinit(&ctx->refs);

0 commit comments

Comments
 (0)