]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
virtio: error out if guest exceeds virtqueue size qemu-xen-4.7.1
authorP J P <ppandit@redhat.com>
Mon, 25 Jul 2016 12:07:18 +0000 (17:37 +0530)
committerStefano Stabellini <sstabellini@kernel.org>
Wed, 27 Jul 2016 17:29:57 +0000 (10:29 -0700)
A broken or malicious guest can submit more requests than the virtqueue
size permits.

The guest can submit requests without bothering to wait for completion
and is therefore not bound by virtqueue size.  This requires reusing
vring descriptors in more than one request, which is incorrect but
possible.  Processing a request allocates a VirtQueueElement and
therefore causes unbounded memory allocation controlled by the guest.

Exit with an error if the guest provides more requests than the
virtqueue size permits.  This bounds memory allocation and makes the
buggy guest visible to the user.

upstream-commit-id: afd9096eb1882f23929f5b5c177898ed231bac66
Reported-by: Zhenhao Hong <zhenhaohong@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
hw/virtio/virtio.c

index d24f77551a2e0eb6a40216dc7a9d4b0c885f4f56..f8ac0fb53bedea5a1a5a0de4cd700ae24f1dfeb7 100644 (file)
@@ -483,6 +483,11 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
 
     max = vq->vring.num;
 
+    if (vq->inuse >= max) {
+        error_report("Virtqueue size exceeded");
+        exit(1);
+    }
+
     i = head = virtqueue_get_head(vq, vq->last_avail_idx++);
     if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_set_avail_event(vq, vq->last_avail_idx);