Skip to content

Commit beeae82

Browse files
pizhenweimstsirkin
authored andcommitted
virtio-blk: fix implicit overflow on virtio_max_dma_size
The following codes have an implicit conversion from size_t to u32: (u32)max_size = (size_t)virtio_max_dma_size(vdev); This may lead overflow, Ex (size_t)4G -> (u32)0. Once virtio_max_dma_size() has a larger size than U32_MAX, use U32_MAX instead. Signed-off-by: zhenwei pi <pizhenwei@bytedance.com> Message-Id: <20230904061045.510460-1-pizhenwei@bytedance.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 1fcc6ea commit beeae82

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/block/virtio_blk.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,7 @@ static int virtblk_probe(struct virtio_device *vdev)
13131313
u16 min_io_size;
13141314
u8 physical_block_exp, alignment_offset;
13151315
unsigned int queue_depth;
1316+
size_t max_dma_size;
13161317

13171318
if (!vdev->config->get) {
13181319
dev_err(&vdev->dev, "%s failure: config access disabled\n",
@@ -1411,7 +1412,8 @@ static int virtblk_probe(struct virtio_device *vdev)
14111412
/* No real sector limit. */
14121413
blk_queue_max_hw_sectors(q, UINT_MAX);
14131414

1414-
max_size = virtio_max_dma_size(vdev);
1415+
max_dma_size = virtio_max_dma_size(vdev);
1416+
max_size = max_dma_size > U32_MAX ? U32_MAX : max_dma_size;
14151417

14161418
/* Host can optionally specify maximum segment size and number of
14171419
* segments. */

0 commit comments

Comments
 (0)