]> git.baikalelectronics.ru Git - kernel.git/commitdiff
io_uring: fix off-by-one in sync cancelation file check
authorJens Axboe <axboe@kernel.dk>
Tue, 23 Aug 2022 13:26:08 +0000 (07:26 -0600)
committerJens Axboe <axboe@kernel.dk>
Tue, 23 Aug 2022 13:26:08 +0000 (07:26 -0600)
The passed in index should be validated against the number of registered
files we have, it needs to be smaller than the index value to avoid going
one beyond the end.

Fixes: bd1ef2d85006 ("io_uring: add sync cancelation API through io_uring_register()")
Reported-by: Luo Likang <luolikang@nsfocus.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/cancel.c

index e4e1dc0325f0c8db54b858f8af678bdc43cf6c47..5fc5d3e80fcb3cd1fb53b10c02d22b70762627be 100644 (file)
@@ -218,7 +218,7 @@ static int __io_sync_cancel(struct io_uring_task *tctx,
            (cd->flags & IORING_ASYNC_CANCEL_FD_FIXED)) {
                unsigned long file_ptr;
 
-               if (unlikely(fd > ctx->nr_user_files))
+               if (unlikely(fd >= ctx->nr_user_files))
                        return -EBADF;
                fd = array_index_nospec(fd, ctx->nr_user_files);
                file_ptr = io_fixed_file_slot(&ctx->file_table, fd)->file_ptr;