ublk: santizize the arguments from userspace when adding a device block-6.16-20250619
authorRonnie Sahlberg <rsahlberg@whamcloud.com>
Thu, 19 Jun 2025 02:10:31 +0000 (12:10 +1000)
committerJens Axboe <axboe@kernel.dk>
Thu, 19 Jun 2025 13:53:24 +0000 (07:53 -0600)
Sanity check the values for queue depth and number of queues
we get from userspace when adding a device.

Signed-off-by: Ronnie Sahlberg <rsahlberg@whamcloud.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Fixes: 71f28f3136af ("ublk_drv: add io_uring based userspace block driver")
Fixes: 62fe99cef94a ("ublk: add read()/write() support for ublk char device")
Link: https://lore.kernel.org/r/20250619021031.181340-1-ronniesahlberg@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/ublk_drv.c

index c637ea010d3474d40a4bf465afa0017c17e8b30e..d36f44f5ee80162e6120238468c1efea1ea12e8d 100644 (file)
@@ -2825,6 +2825,9 @@ static int ublk_ctrl_add_dev(const struct ublksrv_ctrl_cmd *header)
        if (copy_from_user(&info, argp, sizeof(info)))
                return -EFAULT;
 
+       if (info.queue_depth > UBLK_MAX_QUEUE_DEPTH || info.nr_hw_queues > UBLK_MAX_NR_QUEUES)
+               return -EINVAL;
+
        if (capable(CAP_SYS_ADMIN))
                info.flags &= ~UBLK_F_UNPRIVILEGED_DEV;
        else if (!(info.flags & UBLK_F_UNPRIVILEGED_DEV))