* [PATCH] virtio-blk: fix implicit overflow on virtio_max_dma_size
@ 2023-09-04 6:10 zhenwei pi
2023-10-19 9:43 ` PING: " zhenwei pi
0 siblings, 1 reply; 4+ messages in thread
From: zhenwei pi @ 2023-09-04 6:10 UTC (permalink / raw)
To: mst, jasowang, axboe; +Cc: xuanzhuo, virtualization, linux-kernel, zhenwei pi
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>
---
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 1fe011676d07..4a4b9bad551e 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -1313,6 +1313,7 @@ static int virtblk_probe(struct virtio_device *vdev)
u16 min_io_size;
u8 physical_block_exp, alignment_offset;
unsigned int queue_depth;
+ size_t max_dma_size;
if (!vdev->config->get) {
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. */
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
* segments. */
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* PING: [PATCH] virtio-blk: fix implicit overflow on virtio_max_dma_size
2023-09-04 6:10 [PATCH] virtio-blk: fix implicit overflow on virtio_max_dma_size zhenwei pi
@ 2023-10-19 9:43 ` zhenwei pi
2023-10-19 9:52 ` Michael S. Tsirkin
0 siblings, 1 reply; 4+ messages in thread
From: zhenwei pi @ 2023-10-19 9:43 UTC (permalink / raw)
To: mst; +Cc: jasowang, xuanzhuo, virtualization, axboe, linux-kernel
Hi Michael,
This seems to have been ignored as you suggested.
LINK: https://www.spinics.net/lists/linux-virtualization/msg63015.html
On 9/4/23 14:10, zhenwei pi wrote:
> 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>
> ---
> 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 1fe011676d07..4a4b9bad551e 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -1313,6 +1313,7 @@ static int virtblk_probe(struct virtio_device *vdev)
> u16 min_io_size;
> u8 physical_block_exp, alignment_offset;
> unsigned int queue_depth;
> + size_t max_dma_size;
>
> if (!vdev->config->get) {
> 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. */
> 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
> * segments. */
--
zhenwei pi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PING: [PATCH] virtio-blk: fix implicit overflow on virtio_max_dma_size
2023-10-19 9:43 ` PING: " zhenwei pi
@ 2023-10-19 9:52 ` Michael S. Tsirkin
2023-10-20 2:23 ` zhenwei pi
0 siblings, 1 reply; 4+ messages in thread
From: Michael S. Tsirkin @ 2023-10-19 9:52 UTC (permalink / raw)
To: zhenwei pi; +Cc: jasowang, xuanzhuo, virtualization, axboe, linux-kernel
On Thu, Oct 19, 2023 at 05:43:55PM +0800, zhenwei pi wrote:
> Hi Michael,
>
> This seems to have been ignored as you suggested.
>
> LINK: https://www.spinics.net/lists/linux-virtualization/msg63015.html
Pls Cc more widely then:
Paolo Bonzini <pbonzini@redhat.com> (reviewer:VIRTIO BLOCK AND SCSI DRIVERS)
Stefan Hajnoczi <stefanha@redhat.com> (reviewer:VIRTIO BLOCK AND SCSI DRIVERS)
Xuan Zhuo <xuanzhuo@linux.alibaba.com> (reviewer:VIRTIO CORE AND NET DRIVERS)
Jens Axboe <axboe@kernel.dk> (maintainer:BLOCK LAYER)
linux-block@vger.kernel.org (open list:BLOCK LAYER)
would all be good people to ask to review this.
> On 9/4/23 14:10, zhenwei pi wrote:
> > 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>
> > ---
> > 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 1fe011676d07..4a4b9bad551e 100644
> > --- a/drivers/block/virtio_blk.c
> > +++ b/drivers/block/virtio_blk.c
> > @@ -1313,6 +1313,7 @@ static int virtblk_probe(struct virtio_device *vdev)
> > u16 min_io_size;
> > u8 physical_block_exp, alignment_offset;
> > unsigned int queue_depth;
> > + size_t max_dma_size;
> > if (!vdev->config->get) {
> > 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. */
> > 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
> > * segments. */
>
> --
> zhenwei pi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Re: PING: [PATCH] virtio-blk: fix implicit overflow on virtio_max_dma_size
2023-10-19 9:52 ` Michael S. Tsirkin
@ 2023-10-20 2:23 ` zhenwei pi
0 siblings, 0 replies; 4+ messages in thread
From: zhenwei pi @ 2023-10-20 2:23 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: jasowang, xuanzhuo, virtualization, axboe, linux-kernel,
Paolo Bonzini, Stefan Hajnoczi, Xuan Zhuo, linux-block
Cc Paolo, Stefan, Xuan and linux-block.
On 10/19/23 17:52, Michael S. Tsirkin wrote:
> On Thu, Oct 19, 2023 at 05:43:55PM +0800, zhenwei pi wrote:
>> Hi Michael,
>>
>> This seems to have been ignored as you suggested.
>>
>> LINK: https://www.spinics.net/lists/linux-virtualization/msg63015.html
>
> Pls Cc more widely then:
>
> Paolo Bonzini <pbonzini@redhat.com> (reviewer:VIRTIO BLOCK AND SCSI DRIVERS)
> Stefan Hajnoczi <stefanha@redhat.com> (reviewer:VIRTIO BLOCK AND SCSI DRIVERS)
> Xuan Zhuo <xuanzhuo@linux.alibaba.com> (reviewer:VIRTIO CORE AND NET DRIVERS)
> Jens Axboe <axboe@kernel.dk> (maintainer:BLOCK LAYER)
> linux-block@vger.kernel.org (open list:BLOCK LAYER)
>
> would all be good people to ask to review this.
>
>
>> On 9/4/23 14:10, zhenwei pi wrote:
>>> 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>
>>> ---
>>> 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 1fe011676d07..4a4b9bad551e 100644
>>> --- a/drivers/block/virtio_blk.c
>>> +++ b/drivers/block/virtio_blk.c
>>> @@ -1313,6 +1313,7 @@ static int virtblk_probe(struct virtio_device *vdev)
>>> u16 min_io_size;
>>> u8 physical_block_exp, alignment_offset;
>>> unsigned int queue_depth;
>>> + size_t max_dma_size;
>>> if (!vdev->config->get) {
>>> 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. */
>>> 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
>>> * segments. */
>>
>> --
>> zhenwei pi
>
--
zhenwei pi
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-10-20 2:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-04 6:10 [PATCH] virtio-blk: fix implicit overflow on virtio_max_dma_size zhenwei pi
2023-10-19 9:43 ` PING: " zhenwei pi
2023-10-19 9:52 ` Michael S. Tsirkin
2023-10-20 2:23 ` zhenwei pi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).