Blame 0024-virtio-validate-config_len-on-load.patch

70114f
From 94998eaa5ef06ba17ad12976ac84801033a28582 Mon Sep 17 00:00:00 2001
70114f
From: "Michael S. Tsirkin" <mst@redhat.com>
70114f
Date: Mon, 28 Apr 2014 16:08:23 +0300
70114f
Subject: [PATCH] virtio: validate config_len on load
70114f
70114f
Malformed input can have config_len in migration stream
70114f
exceed the array size allocated on destination, the
70114f
result will be heap overflow.
70114f
70114f
To fix, that config_len matches on both sides.
70114f
70114f
CVE-2014-0182
70114f
70114f
Reported-by: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
70114f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
70114f
Signed-off-by: Juan Quintela <quintela@redhat.com>
70114f
70114f
--
70114f
70114f
v2: use %ix and %zx to print config_len values
70114f
Signed-off-by: Juan Quintela <quintela@redhat.com>
70114f
(cherry picked from commit a890a2f9137ac3cf5b607649e66a6f3a5512d8dc)
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 a70169a..7f4e7ec 100644
70114f
--- a/hw/virtio/virtio.c
70114f
+++ b/hw/virtio/virtio.c
70114f
@@ -898,6 +898,7 @@ int virtio_set_features(VirtIODevice *vdev, uint32_t val)
70114f
 int virtio_load(VirtIODevice *vdev, QEMUFile *f)
70114f
 {
70114f
     int i, ret;
70114f
+    int32_t config_len;
70114f
     uint32_t num;
70114f
     uint32_t features;
70114f
     uint32_t supported_features;
70114f
@@ -924,7 +925,12 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
70114f
                      features, supported_features);
70114f
         return -1;
70114f
     }
70114f
-    vdev->config_len = qemu_get_be32(f);
70114f
+    config_len = qemu_get_be32(f);
70114f
+    if (config_len != vdev->config_len) {
70114f
+        error_report("Unexpected config length 0x%x. Expected 0x%zx",
70114f
+                     config_len, vdev->config_len);
70114f
+        return -1;
70114f
+    }
70114f
     qemu_get_buffer(f, vdev->config, vdev->config_len);
70114f
 
70114f
     num = qemu_get_be32(f);