]> git.hungrycats.org Git - linux/commitdiff
io_uring: check for valid register opcode earlier
authorJens Axboe <axboe@kernel.dk>
Fri, 23 Dec 2022 13:37:08 +0000 (06:37 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 Jan 2023 11:00:43 +0000 (12:00 +0100)
[ Upstream commit 343190841a1f22b96996d9f8cfab902a4d1bfd0e ]

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>
io_uring/io_uring.c

index b8a39be3bcb4c9f817d9bb97d7bbd13190cd180a..cfcf1d41552172c5c5e42eceb17f68e9ea4dd9e5 100644 (file)
@@ -3725,8 +3725,6 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
                return -EEXIST;
 
        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;
@@ -3882,6 +3880,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;