[PATCH v2] virtio-blk: Add validation for block size in config space

From: Xie Yongji
Date: Tue Jun 15 2021 - 06:48:35 EST


This ensures that we will not use an invalid block size
in config space (might come from an untrusted device).

Signed-off-by: Xie Yongji <xieyongji@xxxxxxxxxxxxx>
---
drivers/block/virtio_blk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index b9fa3ef5b57c..85ae3b27ea4b 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -827,7 +827,7 @@ static int virtblk_probe(struct virtio_device *vdev)
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_BLK_SIZE,
struct virtio_blk_config, blk_size,
&blk_size);
- if (!err)
+ if (!err && blk_size >= SECTOR_SIZE && blk_size <= PAGE_SIZE)
blk_queue_logical_block_size(q, blk_size);
else
blk_size = queue_logical_block_size(q);
--
2.11.0