All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 5.10.y] virtio-blk: fix implicit overflow on virtio_max_dma_size
@ 2026-11-20  1:14 Nobuhiro Iwamatsu
  2026-11-20 20:38 ` Sasha Levin
  0 siblings, 1 reply; 2+ messages in thread
From: Nobuhiro Iwamatsu @ 2026-11-20  1:14 UTC (permalink / raw)
  To: stable; +Cc: gregkh, sashal, zhenwei pi, Michael S . Tsirkin,
	Nobuhiro Iwamatsu

From: zhenwei pi <pizhenwei@bytedance.com>

commit fafb51a67fb883eb2dde352539df939a251851be upstream.

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>
Signed-off-by: Nobuhiro Iwamatsu (CIP) <nobuhiro.iwamatsu.x90@mail.toshiba>
---
 drivers/block/virtio_blk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index c87c6a4eb3b3..c048eeaf56dc 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -706,6 +706,7 @@ static int virtblk_probe(struct virtio_device *vdev)
 	u32 v, blk_size, max_size, sg_elems, opt_io_size;
 	u16 min_io_size;
 	u8 physical_block_exp, alignment_offset;
+	size_t max_dma_size;
 
 	if (!vdev->config->get) {
 		dev_err(&vdev->dev, "%s failure: config access disabled\n",
@@ -810,7 +811,8 @@ static int virtblk_probe(struct virtio_device *vdev)
 	/* No real sector limit. */
 	blk_queue_max_hw_sectors(q, -1U);
 
-	max_size = virtio_max_dma_size(vdev);
+	max_dma_size = virtio_max_dma_size(vdev);
+	max_size = max_dma_size > U32_MAX ? U32_MAX : max_dma_size;
 
 	/* Host can optionally specify maximum segment size and number of
 	 * segments. */
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-20 20:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  1:14 [PATCH 5.10.y] virtio-blk: fix implicit overflow on virtio_max_dma_size Nobuhiro Iwamatsu
2026-11-20 20:38 ` Sasha Levin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.