]> git.proxmox.com Git - mirror_qemu.git/blobdiff - hw/virtio/virtio.c
Merge remote-tracking branch 'mst/tags/for_anthony' into staging
[mirror_qemu.git] / hw / virtio / virtio.c
index 706bdf4c465726ffeef0951f5c4d143314ddb0f9..f03c45dff56f6ca3a71d5e71f361309ec2297329 100644 (file)
@@ -673,10 +673,16 @@ hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n)
 
 void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)
 {
-    if (num <= VIRTQUEUE_MAX_SIZE) {
-        vdev->vq[n].vring.num = num;
-        virtqueue_init(&vdev->vq[n]);
+    /* Don't allow guest to flip queue between existent and
+     * nonexistent states, or to set it to an invalid size.
+     */
+    if (!!num != !!vdev->vq[n].vring.num ||
+        num > VIRTQUEUE_MAX_SIZE ||
+        num < 0) {
+        return;
     }
+    vdev->vq[n].vring.num = num;
+    virtqueue_init(&vdev->vq[n]);
 }
 
 int virtio_queue_get_num(VirtIODevice *vdev, int n)