All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] virtio-blk: Add validation for block size in config space
@ 2021-06-15 10:48 Xie Yongji
  2021-06-15 15:27   ` Michael S. Tsirkin
  0 siblings, 1 reply; 4+ messages in thread
From: Xie Yongji @ 2021-06-15 10:48 UTC (permalink / raw)
  To: mst, jasowang, stefanha, axboe; +Cc: virtualization, linux-block, linux-kernel

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@bytedance.com>
---
 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


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

* Re: [PATCH v2] virtio-blk: Add validation for block size in config space
  2021-06-15 10:48 [PATCH v2] virtio-blk: Add validation for block size in config space Xie Yongji
@ 2021-06-15 15:27   ` Michael S. Tsirkin
  0 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2021-06-15 15:27 UTC (permalink / raw)
  To: Xie Yongji
  Cc: jasowang, stefanha, axboe, virtualization, linux-block, linux-kernel

On Tue, Jun 15, 2021 at 06:48:10PM +0800, Xie Yongji wrote:
> 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@bytedance.com>

I'd say if device presents an unreasonable value,
and we want to ignore that, then we should not
negotiate VIRTIO_BLK_F_BLK_SIZE so that host knows.

So maybe move the logic to validate_features.

> ---
>  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


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

* Re: [PATCH v2] virtio-blk: Add validation for block size in config space
@ 2021-06-15 15:27   ` Michael S. Tsirkin
  0 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2021-06-15 15:27 UTC (permalink / raw)
  To: Xie Yongji; +Cc: axboe, linux-kernel, virtualization, linux-block, stefanha

On Tue, Jun 15, 2021 at 06:48:10PM +0800, Xie Yongji wrote:
> 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@bytedance.com>

I'd say if device presents an unreasonable value,
and we want to ignore that, then we should not
negotiate VIRTIO_BLK_F_BLK_SIZE so that host knows.

So maybe move the logic to validate_features.

> ---
>  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

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: Re: [PATCH v2] virtio-blk: Add validation for block size in config space
  2021-06-15 15:27   ` Michael S. Tsirkin
  (?)
@ 2021-06-16  8:35   ` Yongji Xie
  -1 siblings, 0 replies; 4+ messages in thread
From: Yongji Xie @ 2021-06-16  8:35 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Jason Wang, Stefan Hajnoczi, Jens Axboe, virtualization,
	linux-block, linux-kernel

On Tue, Jun 15, 2021 at 11:27 PM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Tue, Jun 15, 2021 at 06:48:10PM +0800, Xie Yongji wrote:
> > 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@bytedance.com>
>
> I'd say if device presents an unreasonable value,
> and we want to ignore that, then we should not
> negotiate VIRTIO_BLK_F_BLK_SIZE so that host knows.
>
> So maybe move the logic to validate_features.
>

Looks good to me. Will do it in v3.

Thanks,
Yongji

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

end of thread, other threads:[~2021-06-16  8:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15 10:48 [PATCH v2] virtio-blk: Add validation for block size in config space Xie Yongji
2021-06-15 15:27 ` Michael S. Tsirkin
2021-06-15 15:27   ` Michael S. Tsirkin
2021-06-16  8:35   ` Yongji Xie

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.