Skip to content

Commit 1d16652

Browse files
Ming Leiaxboe
authored andcommitted
block: ublk: make sure that block size is set correctly
block size is one very key setting for block layer, and bad block size could panic kernel easily. Make sure that block size is set correctly. Meantime if ublk_validate_params() fails, clear ub->params so that disk is prevented from being added. Fixes: 71f28f3 ("ublk_drv: add io_uring based userspace block driver") Reported-and-tested-by: Breno Leitao <[email protected]> Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 8c68ae3 commit 1d16652

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/block/ublk_drv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static int ublk_validate_params(const struct ublk_device *ub)
246246
if (ub->params.types & UBLK_PARAM_TYPE_BASIC) {
247247
const struct ublk_param_basic *p = &ub->params.basic;
248248

249-
if (p->logical_bs_shift > PAGE_SHIFT)
249+
if (p->logical_bs_shift > PAGE_SHIFT || p->logical_bs_shift < 9)
250250
return -EINVAL;
251251

252252
if (p->logical_bs_shift > p->physical_bs_shift)
@@ -1970,6 +1970,8 @@ static int ublk_ctrl_set_params(struct ublk_device *ub,
19701970
/* clear all we don't support yet */
19711971
ub->params.types &= UBLK_PARAM_TYPE_ALL;
19721972
ret = ublk_validate_params(ub);
1973+
if (ret)
1974+
ub->params.types = 0;
19731975
}
19741976
mutex_unlock(&ub->mutex);
19751977

0 commit comments

Comments
 (0)