[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 6/7] virtio: check VirtQueue Vring object is set
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 6/7] virtio: check VirtQueue Vring object is set |
Date: |
Fri, 1 Dec 2017 19:08:53 +0200 |
From: Prasad J Pandit <address@hidden>
A guest could attempt to use an uninitialised VirtQueue object
or unset Vring.align leading to a arithmetic exception. Add check
to avoid it.
Reported-by: Zhangboxian <address@hidden>
Signed-off-by: Prasad J Pandit <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Cornelia Huck <address@hidden>
---
hw/virtio/virtio.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 703e672..ad564b0 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -182,7 +182,7 @@ void virtio_queue_update_rings(VirtIODevice *vdev, int n)
{
VRing *vring = &vdev->vq[n].vring;
- if (!vring->desc) {
+ if (!vring->num || !vring->desc || !vring->align) {
/* not yet setup -> nothing to do */
return;
}
@@ -1414,6 +1414,9 @@ void virtio_config_modern_writel(VirtIODevice *vdev,
void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr)
{
+ if (!vdev->vq[n].vring.num) {
+ return;
+ }
vdev->vq[n].vring.desc = addr;
virtio_queue_update_rings(vdev, n);
}
@@ -1426,6 +1429,9 @@ hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n)
void virtio_queue_set_rings(VirtIODevice *vdev, int n, hwaddr desc,
hwaddr avail, hwaddr used)
{
+ if (!vdev->vq[n].vring.num) {
+ return;
+ }
vdev->vq[n].vring.desc = desc;
vdev->vq[n].vring.avail = avail;
vdev->vq[n].vring.used = used;
@@ -1494,8 +1500,10 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n,
int align)
*/
assert(k->has_variable_vring_alignment);
- vdev->vq[n].vring.align = align;
- virtio_queue_update_rings(vdev, n);
+ if (align) {
+ vdev->vq[n].vring.align = align;
+ virtio_queue_update_rings(vdev, n);
+ }
}
static bool virtio_queue_notify_aio_vq(VirtQueue *vq)
--
MST
- [Qemu-devel] [PULL 0/7] pc, pci, virtio: fixes for rc3, Michael S. Tsirkin, 2017/12/01
- [Qemu-devel] [PULL 1/7] i386/msi: Correct mask of destination ID in MSI address, Michael S. Tsirkin, 2017/12/01
- [Qemu-devel] [PULL 2/7] virtio: Add queue interface to restore avail index from vring used index, Michael S. Tsirkin, 2017/12/01
- [Qemu-devel] [PULL 3/7] vhost: restore avail index from vring used index on disconnection, Michael S. Tsirkin, 2017/12/01
- [Qemu-devel] [PULL 4/7] dump-guest-memory.py: fix No symbol "vmcoreinfo_find", Michael S. Tsirkin, 2017/12/01
- [Qemu-devel] [PULL 5/7] vhost: fix error check in vhost_verify_ring_mappings(), Michael S. Tsirkin, 2017/12/01
- [Qemu-devel] [PULL 6/7] virtio: check VirtQueue Vring object is set,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 7/7] pc: fix crash on attempted cpu unplug, Michael S. Tsirkin, 2017/12/01
- Re: [Qemu-devel] [PULL 0/7] pc, pci, virtio: fixes for rc3, Peter Maydell, 2017/12/01
- Re: [Qemu-devel] [PULL 0/7] pc, pci, virtio: fixes for rc3, Michael S. Tsirkin, 2017/12/02
- Re: [Qemu-devel] [PULL 0/7] pc, pci, virtio: fixes for rc3, Peter Maydell, 2017/12/04
- Re: [Qemu-devel] [PULL 0/7] pc, pci, virtio: fixes for rc3, Peter Maydell, 2017/12/04
- Re: [Qemu-devel] [PULL 0/7] pc, pci, virtio: fixes for rc3, Michael S. Tsirkin, 2017/12/04