peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0006-virtio-out-of-bounds-buffer-write-on-invalid-state-l.patch

70114f
From 23f0db5c309893195025bc75402f3f9e1b4de743 Mon Sep 17 00:00:00 2001
70114f
From: "Michael S. Tsirkin" <mst@redhat.com>
70114f
Date: Thu, 3 Apr 2014 19:51:14 +0300
70114f
Subject: [PATCH] virtio: out-of-bounds buffer write on invalid state load
70114f
70114f
CVE-2013-4151 QEMU 1.0 out-of-bounds buffer write in
70114f
virtio_load@hw/virtio/virtio.c
70114f
70114f
So we have this code since way back when:
70114f
70114f
    num = qemu_get_be32(f);
70114f
70114f
    for (i = 0; i < num; i++) {
70114f
        vdev->vq[i].vring.num = qemu_get_be32(f);
70114f
70114f
array of vqs has size VIRTIO_PCI_QUEUE_MAX, so
70114f
on invalid input this will write beyond end of buffer.
70114f
70114f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
70114f
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
70114f
Signed-off-by: Juan Quintela <quintela@redhat.com>
70114f
(cherry picked from commit cc45995294b92d95319b4782750a3580cabdbc0c)
70114f
---
70114f
 hw/virtio/virtio.c | 8 +++++++-
70114f
 1 file changed, 7 insertions(+), 1 deletion(-)
70114f
70114f
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
70114f
index aeabf3a..05f05e7 100644
70114f
--- a/hw/virtio/virtio.c
70114f
+++ b/hw/virtio/virtio.c
70114f
@@ -891,7 +891,8 @@ int virtio_set_features(VirtIODevice *vdev, uint32_t val)
70114f
 
70114f
 int virtio_load(VirtIODevice *vdev, QEMUFile *f)
70114f
 {
70114f
-    int num, i, ret;
70114f
+    int i, ret;
70114f
+    uint32_t num;
70114f
     uint32_t features;
70114f
     uint32_t supported_features;
70114f
     BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
70114f
@@ -919,6 +920,11 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
70114f
 
70114f
     num = qemu_get_be32(f);
70114f
 
70114f
+    if (num > VIRTIO_PCI_QUEUE_MAX) {
70114f
+        error_report("Invalid number of PCI queues: 0x%x", num);
70114f
+        return -1;
70114f
+    }
70114f
+
70114f
     for (i = 0; i < num; i++) {
70114f
         vdev->vq[i].vring.num = qemu_get_be32(f);
70114f
         if (k->has_variable_vring_alignment) {