]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ublk: reject max_sectors smaller than PAGE_SECTORS in parameter validation
authorMing Lei <tom.leiming@gmail.com>
Sun, 10 May 2026 14:48:43 +0000 (22:48 +0800)
committerJens Axboe <axboe@kernel.dk>
Mon, 11 May 2026 13:44:20 +0000 (07:44 -0600)
blk_validate_limits() requires max_hw_sectors >= PAGE_SECTORS and fires
a WARN_ON_ONCE if this invariant is violated. ublk_validate_params()
only checked the upper bound of max_sectors against max_io_buf_bytes,
allowing userspace to pass small values (including zero) that trigger
the warning when blk_mq_alloc_disk() is called from
ublk_ctrl_start_dev().

Before 494ea040bcb5, ublk used blk_queue_max_hw_sectors() which silently
clamped small values up to PAGE_SECTORS. The conversion to passing
queue_limits directly to blk_mq_alloc_disk() lost that clamping and now
hits blk_validate_limits()'s WARN_ON_ONCE instead.

Validate that max_sectors is at least PAGE_SECTORS in
ublk_validate_params() so invalid values are rejected early with
-EINVAL instead of reaching the block layer.

Fixes: 494ea040bcb5 ("ublk: pass queue_limits to blk_mq_alloc_disk")
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Link: https://patch.msgid.link/20260510144843.769031-1-tom.leiming@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/ublk_drv.c

index 6d13f1481de053bb51189093265935e6d3880d63..6c041eaebdb9118017973bd89ca2f6405856487a 100644 (file)
@@ -920,6 +920,9 @@ static int ublk_validate_params(const struct ublk_device *ub)
                if (p->max_sectors > (ub->dev_info.max_io_buf_bytes >> 9))
                        return -EINVAL;
 
+               if (p->max_sectors < PAGE_SECTORS)
+                       return -EINVAL;
+
                if (ublk_dev_is_zoned(ub) && !p->chunk_sectors)
                        return -EINVAL;
        } else