Skip to content

Commit

Permalink
io_uring: check for valid register opcode earlier
Browse files Browse the repository at this point in the history
[ Upstream commit 3431908 ]

We only check the register opcode value inside the restricted ring
section, move it into the main io_uring_register() function instead
and check it up front.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
axboe authored and gregkh committed Jan 12, 2023
1 parent 4df413d commit f9309dc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions io_uring/io_uring.c
Expand Up @@ -10895,8 +10895,6 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
return -ENXIO;

if (ctx->restricted) {
if (opcode >= IORING_REGISTER_LAST)
return -EINVAL;
opcode = array_index_nospec(opcode, IORING_REGISTER_LAST);
if (!test_bit(opcode, ctx->restrictions.register_op))
return -EACCES;
Expand Down Expand Up @@ -11028,6 +11026,9 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,
long ret = -EBADF;
struct fd f;

if (opcode >= IORING_REGISTER_LAST)
return -EINVAL;

f = fdget(fd);
if (!f.file)
return -EBADF;
Expand Down

0 comments on commit f9309dc

Please sign in to comment.