Skip to contentSkip to conversation

virtio: validate config_len on load

PATCH Juan Quintela 1 participant 2 messages May 5, 2014 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 19 lines · Michael S. Tsirkin

Malformed input can have config_len in migration stream exceed the array size allocated on destination, the result will be heap overflow.

To fix, that config_len matches on both sides.

CVE-2014-0182

---
 hw/virtio/virtio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/virtio/virtio.c +0 -0
index 3bad71e..0d5d368 100644

hw/virtio/virtio.c int virtio_set_features(VirtIODevice *vdev, uint32_t val) · line 901

Quoted 4 lines
hw/virtio/virtio.c +1 -0
@@ -898,6 +898,7 @@ int virtio_set_features(VirtIODevice *vdev, uint32_t val)
 int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 {
     int i, ret;
+    int32_t config_len;

Has a warning.

/mnt/kvm/qemu/next/hw/virtio/virtio.c: In function ‘virtio_load’:
/mnt/kvm/qemu/next/hw/virtio/virtio.c:931:22: error: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘size_t’ [-Werror=format=]

                      config_len, vdev->config_len);
                      ^

changing config_len to size_t.

hw/virtio/virtio.c int virtio_load(VirtIODevice *vdev, QEMUFile *f) · line 930

Quoted 11 lines
hw/virtio/virtio.c +3 -1
     uint32_t num;
     uint32_t features;
     uint32_t supported_features;
@@ -924,7 +925,12 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
                      features, supported_features);
         return -1;
     }
-    vdev->config_len = qemu_get_be32(f);
+    config_len = qemu_get_be32(f);
+    if (config_len != vdev->config_len) {
+        error_report("Unexpected config length 0x%x. Expected 0x%x",

and this to:

s/%x/%zx/

Later, Juan.

Quoted 6 lines
hw/virtio/virtio.c +3 -0
+                     config_len, vdev->config_len);
+        return -1;
+    }
     qemu_get_buffer(f, vdev->config, vdev->config_len);
 
     num = qemu_get_be32(f);
#3 lore raw
Quoted 27 lines · Juan Quintela
Quoted 19 lines · Michael S. Tsirkin

Malformed input can have config_len in migration stream exceed the array size allocated on destination, the result will be heap overflow.

To fix, that config_len matches on both sides.

CVE-2014-0182

---
 hw/virtio/virtio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/virtio/virtio.c +0 -0
index 3bad71e..0d5d368 100644

hw/virtio/virtio.c int virtio_set_features(VirtIODevice *vdev, uint32_t val) · line 901

Quoted 4 lines
hw/virtio/virtio.c +1 -0
@@ -898,6 +898,7 @@ int virtio_set_features(VirtIODevice *vdev, uint32_t val)
 int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 {
     int i, ret;
+    int32_t config_len;

Has a warning.

Quoted 8 lines

/mnt/kvm/qemu/next/hw/virtio/virtio.c: In function ‘virtio_load’:
/mnt/kvm/qemu/next/hw/virtio/virtio.c:931:22: error: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘size_t’ [-Werror=format=]

                      config_len, vdev->config_len);
                      ^

changing config_len to size_t.

After discussing with michael, left it as int32_t

Quoted 15 lines

hw/virtio/virtio.c int virtio_load(VirtIODevice *vdev, QEMUFile *f) · line 930

Quoted 12 lines
hw/virtio/virtio.c +3 -1
     uint32_t num;
     uint32_t features;
     uint32_t supported_features;
@@ -924,7 +925,12 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
                      features, supported_features);
         return -1;
     }
-    vdev->config_len = qemu_get_be32(f);
+    config_len = qemu_get_be32(f);
+    if (config_len != vdev->config_len) {
+        error_report("Unexpected config length 0x%x. Expected 0x%x",

and this to:

Quoted 1 line

s/%x/%zx/

and use here "%ix .... %zx"

Later, Juan.

Quoted 9 lines

Later, Juan.

Quoted 6 lines
hw/virtio/virtio.c +3 -0
+                     config_len, vdev->config_len);
+        return -1;
+    }
     qemu_get_buffer(f, vdev->config, vdev->config_len);
 
     num = qemu_get_be32(f);