mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-04 08:08:54 +00:00
virtio-blk: fix implicit overflow on virtio_max_dma_size
[ Upstream commit fafb51a67f
]
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: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
a5a583fbb0
commit
d667fe301d
1 changed files with 3 additions and 1 deletions
|
@ -1313,6 +1313,7 @@ static int virtblk_probe(struct virtio_device *vdev)
|
||||||
u16 min_io_size;
|
u16 min_io_size;
|
||||||
u8 physical_block_exp, alignment_offset;
|
u8 physical_block_exp, alignment_offset;
|
||||||
unsigned int queue_depth;
|
unsigned int queue_depth;
|
||||||
|
size_t max_dma_size;
|
||||||
|
|
||||||
if (!vdev->config->get) {
|
if (!vdev->config->get) {
|
||||||
dev_err(&vdev->dev, "%s failure: config access disabled\n",
|
dev_err(&vdev->dev, "%s failure: config access disabled\n",
|
||||||
|
@ -1411,7 +1412,8 @@ static int virtblk_probe(struct virtio_device *vdev)
|
||||||
/* No real sector limit. */
|
/* No real sector limit. */
|
||||||
blk_queue_max_hw_sectors(q, UINT_MAX);
|
blk_queue_max_hw_sectors(q, UINT_MAX);
|
||||||
|
|
||||||
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
|
/* Host can optionally specify maximum segment size and number of
|
||||||
* segments. */
|
* segments. */
|
||||||
|
|
Loading…
Reference in a new issue