Blame SOURCES/kvm-virtio-out-of-bounds-buffer-write-on-invalid-state-l.patch

958e1b
From 9dfb93fc21a678858e95e604339d95829f405724 Mon Sep 17 00:00:00 2001
eb5a2f
From: Michael S. Tsirkin <mst@redhat.com>
958e1b
Date: Wed, 14 May 2014 08:31:53 +0200
958e1b
Subject: [PATCH 12/31] virtio: out-of-bounds buffer write on invalid state load
eb5a2f
eb5a2f
RH-Author: Michael S. Tsirkin <mst@redhat.com>
958e1b
Message-id: <1400056285-6688-4-git-send-email-mst@redhat.com>
958e1b
Patchwork-id: 58858
958e1b
O-Subject: [PATCH qemu-kvm RHEL7.1] virtio: out-of-bounds buffer write on invalid state load
958e1b
Bugzilla: 1095695
eb5a2f
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
eb5a2f
RH-Acked-by: Juan Quintela <quintela@redhat.com>
eb5a2f
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
eb5a2f
eb5a2f
CVE-2013-4151 QEMU 1.0 out-of-bounds buffer write in
eb5a2f
virtio_load@hw/virtio/virtio.c
eb5a2f
eb5a2f
So we have this code since way back when:
eb5a2f
eb5a2f
    num = qemu_get_be32(f);
eb5a2f
eb5a2f
    for (i = 0; i < num; i++) {
eb5a2f
        vdev->vq[i].vring.num = qemu_get_be32(f);
eb5a2f
eb5a2f
array of vqs has size VIRTIO_PCI_QUEUE_MAX, so
eb5a2f
on invalid input this will write beyond end of buffer.
eb5a2f
eb5a2f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
eb5a2f
Signed-off-by: Juan Quintela <quintela@redhat.com>
eb5a2f
(cherry picked from commit cc45995294b92d95319b4782750a3580cabdbc0c)
eb5a2f
eb5a2f
Tested: lightly on developer's box
958e1b
Brew build: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=7452039
958e1b
Bugzilla: 1095695
eb5a2f
---
eb5a2f
 hw/virtio/virtio.c | 8 +++++++-
eb5a2f
 1 file changed, 7 insertions(+), 1 deletion(-)
eb5a2f
eb5a2f
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
eb5a2f
---
eb5a2f
 hw/virtio/virtio.c |    8 +++++++-
eb5a2f
 1 files changed, 7 insertions(+), 1 deletions(-)
eb5a2f
eb5a2f
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
eb5a2f
index b5bb0b6..070d64e 100644
eb5a2f
--- a/hw/virtio/virtio.c
eb5a2f
+++ b/hw/virtio/virtio.c
eb5a2f
@@ -851,7 +851,8 @@ int virtio_set_features(VirtIODevice *vdev, uint32_t val)
eb5a2f
 
eb5a2f
 int virtio_load(VirtIODevice *vdev, QEMUFile *f)
eb5a2f
 {
eb5a2f
-    int num, i, ret;
eb5a2f
+    int i, ret;
eb5a2f
+    uint32_t num;
eb5a2f
     uint32_t features;
eb5a2f
     uint32_t supported_features;
eb5a2f
     BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
eb5a2f
@@ -879,6 +880,11 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
eb5a2f
 
eb5a2f
     num = qemu_get_be32(f);
eb5a2f
 
eb5a2f
+    if (num > VIRTIO_PCI_QUEUE_MAX) {
eb5a2f
+        error_report("Invalid number of PCI queues: 0x%x", num);
eb5a2f
+        return -1;
eb5a2f
+    }
eb5a2f
+
eb5a2f
     for (i = 0; i < num; i++) {
eb5a2f
         vdev->vq[i].vring.num = qemu_get_be32(f);
eb5a2f
         vdev->vq[i].pa = qemu_get_be64(f);
eb5a2f
-- 
eb5a2f
1.7.1
eb5a2f