cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
958e1b
From 3741ae811d3287e34779a307480dfb3e93dbb451 Mon Sep 17 00:00:00 2001
eb5a2f
From: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
958e1b
Date: Mon, 30 Jun 2014 09:49:51 +0200
eb5a2f
Subject: [PATCH] Allow mismatched virtio config-len
eb5a2f
eb5a2f
RH-Author: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
958e1b
Message-id: <1404121791-14438-2-git-send-email-dgilbert@redhat.com>
958e1b
Patchwork-id: 59405
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH 1/1] Allow mismatched virtio config-len
958e1b
Bugzilla: 1113009
eb5a2f
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
958e1b
RH-Acked-by: Juan Quintela <quintela@redhat.com>
958e1b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
eb5a2f
eb5a2f
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
eb5a2f
eb5a2f
Commit 'virtio: validate config_len on load' restricted config_len
eb5a2f
loaded from the wire to match the config_len that the device had.
eb5a2f
eb5a2f
Unfortunately, there are cases where this isn't true, the one
eb5a2f
we found it on was the wce addition in virtio-blk.
eb5a2f
eb5a2f
Allow mismatched config-lengths:
eb5a2f
   *) If the version on the wire is shorter then fine
eb5a2f
   *) If the version on the wire is longer, load what we have space
eb5a2f
      for and skip the rest.
eb5a2f
eb5a2f
(This is mst@redhat.com's rework of what I originally posted)
eb5a2f
eb5a2f
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
eb5a2f
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
(cherry picked from commit 2f5732e9648fcddc8759a8fd25c0b41a38352be6)
eb5a2f
---
eb5a2f
 hw/virtio/virtio.c | 16 +++++++++++-----
eb5a2f
 1 file changed, 11 insertions(+), 5 deletions(-)
eb5a2f
eb5a2f
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
eb5a2f
---
eb5a2f
 hw/virtio/virtio.c |   16 +++++++++++-----
eb5a2f
 1 files changed, 11 insertions(+), 5 deletions(-)
eb5a2f
eb5a2f
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
eb5a2f
index 44309c2..132b5af 100644
eb5a2f
--- a/hw/virtio/virtio.c
eb5a2f
+++ b/hw/virtio/virtio.c
eb5a2f
@@ -886,12 +886,18 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
eb5a2f
         return -1;
eb5a2f
     }
eb5a2f
     config_len = qemu_get_be32(f);
eb5a2f
-    if (config_len != vdev->config_len) {
eb5a2f
-        error_report("Unexpected config length 0x%x. Expected 0x%zx",
eb5a2f
-                     config_len, vdev->config_len);
eb5a2f
-        return -1;
eb5a2f
+
eb5a2f
+    /*
eb5a2f
+     * There are cases where the incoming config can be bigger or smaller
eb5a2f
+     * than what we have; so load what we have space for, and skip
eb5a2f
+     * any excess that's in the stream.
eb5a2f
+     */
eb5a2f
+    qemu_get_buffer(f, vdev->config, MIN(config_len, vdev->config_len));
eb5a2f
+
eb5a2f
+    while (config_len > vdev->config_len) {
eb5a2f
+        qemu_get_byte(f);
eb5a2f
+        config_len--;
eb5a2f
     }
eb5a2f
-    qemu_get_buffer(f, vdev->config, vdev->config_len);
eb5a2f
 
eb5a2f
     num = qemu_get_be32(f);
eb5a2f
 
eb5a2f
-- 
eb5a2f
1.7.1
eb5a2f