virtio: validate config_len on load
Quoted 19 lines · Michael S. Tsirkin
Malformed input can have
config_lenin migration stream exceed the array size allocated on destination, the result will be heap overflow.To fix, that
config_lenmatches on both sides.CVE-2014-0182
Reported-by "Dr. David Alan Gilbert" <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/virtio/virtio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)hw/virtio/virtio.c +0
-0
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
-1uint32_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);
Quoted 27 lines · Juan Quintela
Quoted 19 lines · Michael S. Tsirkin
Malformed input can have
config_lenin migration stream exceed the array size allocated on destination, the result will be heap overflow.To fix, that
config_lenmatches on both sides.CVE-2014-0182
Reported-by "Dr. David Alan Gilbert" <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/virtio/virtio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)hw/virtio/virtio.c +0
-0hw/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_lentosize_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
-1uint32_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);