Commit 1d166527 authored by Ming Lei's avatar Ming Lei Committed by Jens Axboe

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: 71f28f31 ("ublk_drv: add io_uring based userspace block driver")
Reported-and-tested-by: default avatarBreno Leitao <leitao@debian.org>
Signed-off-by: default avatarMing Lei <ming.lei@redhat.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 8c68ae3b
...@@ -246,7 +246,7 @@ static int ublk_validate_params(const struct ublk_device *ub) ...@@ -246,7 +246,7 @@ static int ublk_validate_params(const struct ublk_device *ub)
if (ub->params.types & UBLK_PARAM_TYPE_BASIC) { if (ub->params.types & UBLK_PARAM_TYPE_BASIC) {
const struct ublk_param_basic *p = &ub->params.basic; const struct ublk_param_basic *p = &ub->params.basic;
if (p->logical_bs_shift > PAGE_SHIFT) if (p->logical_bs_shift > PAGE_SHIFT || p->logical_bs_shift < 9)
return -EINVAL; return -EINVAL;
if (p->logical_bs_shift > p->physical_bs_shift) if (p->logical_bs_shift > p->physical_bs_shift)
...@@ -1970,6 +1970,8 @@ static int ublk_ctrl_set_params(struct ublk_device *ub, ...@@ -1970,6 +1970,8 @@ static int ublk_ctrl_set_params(struct ublk_device *ub,
/* clear all we don't support yet */ /* clear all we don't support yet */
ub->params.types &= UBLK_PARAM_TYPE_ALL; ub->params.types &= UBLK_PARAM_TYPE_ALL;
ret = ublk_validate_params(ub); ret = ublk_validate_params(ub);
if (ret)
ub->params.types = 0;
} }
mutex_unlock(&ub->mutex); mutex_unlock(&ub->mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment