Skip to content

Commit

Permalink
virtio: check VirtQueue Vring object is set
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Prasad J Pandit <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Reviewed-by: Cornelia Huck <[email protected]>
  • Loading branch information
Prasad J Pandit authored and mstsirkin committed Dec 1, 2017
1 parent 2fe45ec commit 758ead3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions hw/virtio/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 758ead3

Please sign in to comment.