Xuan Zhuo
2022-Aug-17 11:04 UTC
[PATCH] virtio/virtio_pci_legacy: debug checking for queue size
Legacy virtio pci has no way to communicate a change in vq size to the hypervisor. If ring sizes don't match hypervisor will happily corrupt memory. We add a check to vring size before calling vp_legacy_set_queue_address(). Checking the memory range directly is a bit cumbersome. Signed-off-by: Xuan Zhuo <xuanzhuo at linux.alibaba.com> --- drivers/virtio/virtio_pci_legacy.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c index 2257f1b3d8ae..a1553abc45f9 100644 --- a/drivers/virtio/virtio_pci_legacy.c +++ b/drivers/virtio/virtio_pci_legacy.c @@ -146,6 +146,12 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, goto out_del_vq; } + /* Legacy virtio pci has no way to communicate a change in vq size to + * the hypervisor. If ring sizes don't match hypervisor will happily + * corrupt memory. + */ + BUG_ON(num != virtqueue_get_vring_size(vq)); + /* activate the queue */ vp_legacy_set_queue_address(&vp_dev->ldev, index, q_pfn); -- 2.31.0