io_uring: move io_uring_rsrc_update2 validation
authorDylan Yudaken <dylany@fb.com>
Tue, 12 Apr 2022 16:30:39 +0000 (09:30 -0700)
committerJens Axboe <axboe@kernel.dk>
Tue, 12 Apr 2022 16:46:54 +0000 (10:46 -0600)
Move validation to be more consistently straight after
copy_from_user. This is already done in io_register_rsrc_update and so
this removes that redundant check.

Signed-off-by: Dylan Yudaken <dylany@fb.com>
Link: https://lore.kernel.org/r/20220412163042.2788062-2-dylany@fb.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c

index 8a931eb8a3a62920d87be96cdc9780c820186e1f..58bfa71fe3b63cd6b74dbca8d6b3c90362194c25 100644 (file)
@@ -11398,8 +11398,6 @@ static int __io_register_rsrc_update(struct io_ring_ctx *ctx, unsigned type,
        __u32 tmp;
        int err;
 
-       if (up->resv)
-               return -EINVAL;
        if (check_add_overflow(up->offset, nr_args, &tmp))
                return -EOVERFLOW;
        err = io_rsrc_node_switch_start(ctx);
@@ -11425,6 +11423,8 @@ static int io_register_files_update(struct io_ring_ctx *ctx, void __user *arg,
        memset(&up, 0, sizeof(up));
        if (copy_from_user(&up, arg, sizeof(struct io_uring_rsrc_update)))
                return -EFAULT;
+       if (up.resv)
+               return -EINVAL;
        return __io_register_rsrc_update(ctx, IORING_RSRC_FILE, &up, nr_args);
 }