File kvm-qemu-preXX-validate-virtqueue.patch of Package kvm.853

EMBARGOED CVE-2011-2212 qemu-kvm: virtqueue: too-large indirect descriptor buffer overflow

It was found that virtio subsystem in qemu-kvm did not properly validate
virtqueue in and out requests from the guest. A privileged guest user could use
this flaw to cause buffer overflow, causing the guest to crash (denial of
service) or, possibly, resulting in the privileged guest user escalating their
privileges on the host.

--

virtqueue_pop (and less importantly, virtqueue_avail_bytes) do not limit
the size of an indirect descriptor entry, which allows a guest to
specify an arbitrarily-long descriptor chain, which will overflow the
fixed-size arrays in VirtQueueElement, leading to memory corruption.

>From 8e16077bfcd2d06a98aec8348cc171402ed75b51 Mon Sep 17 00:00:00 2001
From: Nelson Elhage <nelhage@ksplice.com>
Date: Thu, 19 May 2011 13:23:17 -0400
Subject: [PATCH] virtqueue: Sanity-check the length of indirect descriptors.

We were previously allowing arbitrarily-long descriptors, which could lead to a
buffer overflow in the qemu-kvm process.
---
 hw/virtio.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/hw/virtio.c b/hw/virtio.c
index 6e8814c..4935282 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -335,6 +335,11 @@ int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes)
             max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc);
             num_bufs = i = 0;
             desc_pa = vring_desc_addr(desc_pa, i);
+
+            if (max > VIRTQUEUE_MAX_SIZE) {
+                error_report("Too-large indirect descriptor");
+                exit(1);
+            }
         }
 
         do {
@@ -405,6 +410,11 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
         max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc);
         desc_pa = vring_desc_addr(desc_pa, i);
         i = 0;
+
+        if (max > VIRTQUEUE_MAX_SIZE) {
+            error_report("Too-large indirect descriptor");
+            exit(1);
+        }
     }
 
     /* Collect all the descriptors */
-- 
1.7.4.44.gf9e72