We should check virtio_load return code
PATCH 1/1 We should check virtio_load return code
Otherwise we crash on error.
--- hw/virtio-balloon.c | 6 +++++- hw/virtio-blk.c | 7 ++++++- hw/virtio-net.c | 6 +++++- hw/virtio-scsi.c | 7 ++++++- hw/virtio-serial-bus.c | 6 +++++- 5 files changed, 27 insertions(+), 5 deletions(-)
hw/virtio-balloon.c +5 -1
@@ -211,11 +211,15 @@ static void virtio_balloon_save(QEMUFile *f, void *opaque)static int virtio_balloon_load (QEMUFile *f,void *opaque,int version_id) {VirtIOBalloon *s = opaque; +int ret;if (version_id !=1 )return -EINVAL ; -virtio_load (&s->vdev, f); + ret =virtio_load (&s->vdev, f); +if (ret) { +return ret; + } s->num_pages =qemu_get_be32 (f); s->actual =qemu_get_be32 (f);
hw/virtio-blk.c +6 -1
@@ -537,11 +537,16 @@ static void virtio_blk_save(QEMUFile *f, void *opaque)static int virtio_blk_load (QEMUFile *f,void *opaque,int version_id) {VirtIOBlock *s = opaque; +int ret;if (version_id !=2 )return -EINVAL ; -virtio_load (&s->vdev, f); + ret =virtio_load (&s->vdev, f); +if (ret) { +return ret; + } +while (qemu_get_sbyte (f)) {VirtIOBlockReq *req =virtio_blk_alloc_request (s);qemu_get_buffer (f, (unsigned char *)&req->elem,sizeof (req->elem));
hw/virtio-net.c +5 -1
@@ -891,11 +891,15 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) {VirtIONet *n = opaque;int i; +int ret;if (version_id <2 || version_id >VIRTIO_NET_VM_VERSION )return -EINVAL ; -virtio_load (&n->vdev, f); + ret =virtio_load (&n->vdev, f); +if (ret) { +return ret; + }qemu_get_buffer (f, n->mac,ETH_ALEN ); n->tx_waiting =qemu_get_be32 (f);
hw/virtio-scsi.c +6 -1
@@ -558,7 +558,12 @@ static void virtio_scsi_save(QEMUFile *f, void *opaque)static int virtio_scsi_load (QEMUFile *f,void *opaque,int version_id) {VirtIOSCSI *s = opaque; -virtio_load (&s->vdev, f); +int ret; + + ret =virtio_load (&s->vdev, f); +if (ret) { +return ret; + }return 0 ; }
hw/virtio-serial-bus.c +5 -1
@@ -590,13 +590,17 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)VirtIOSerialPort *port;uint32_t max_nr_ports, nr_active_ports, ports_map;unsigned int i; +int ret;if (version_id >3 ) {return -EINVAL ; }/* The virtio device */ -virtio_load (&s->vdev, f); + ret =virtio_load (&s->vdev, f); +if (ret) { +return ret; + }if (version_id <2 ) {return 0 ;
Signature · 1 line
1.7.6.5
Il 28/02/2012 14:31, Orit Wasserman ha scritto:
Quoted 107 lines
Otherwise we crash on error.
Signed-off-by Orit Wasserman <[email protected]>Signed-off-by Ulrich Obergfell <[email protected]>--- hw/virtio-balloon.c | 6 +++++- hw/virtio-blk.c | 7 ++++++- hw/virtio-net.c | 6 +++++- hw/virtio-scsi.c | 7 ++++++- hw/virtio-serial-bus.c | 6 +++++- 5 files changed, 27 insertions(+), 5 deletions(-)hw/virtio-balloon.c +5
-1@@ -211,11 +211,15 @@ static void virtio_balloon_save(QEMUFile *f, void *opaque)static int virtio_balloon_load (QEMUFile *f,void *opaque,int version_id) {VirtIOBalloon *s = opaque; +int ret;if (version_id !=1 )return -EINVAL ; -virtio_load (&s->vdev, f); + ret =virtio_load (&s->vdev, f); +if (ret) { +return ret; + } s->num_pages =qemu_get_be32 (f); s->actual =qemu_get_be32 (f);hw/virtio-blk.c +6
-1@@ -537,11 +537,16 @@ static void virtio_blk_save(QEMUFile *f, void *opaque)static int virtio_blk_load (QEMUFile *f,void *opaque,int version_id) {VirtIOBlock *s = opaque; +int ret;if (version_id !=2 )return -EINVAL ; -virtio_load (&s->vdev, f); + ret =virtio_load (&s->vdev, f); +if (ret) { +return ret; + } +while (qemu_get_sbyte (f)) {VirtIOBlockReq *req =virtio_blk_alloc_request (s);qemu_get_buffer (f, (unsigned char *)&req->elem,sizeof (req->elem));hw/virtio-net.c +5
-1@@ -891,11 +891,15 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) {VirtIONet *n = opaque;int i; +int ret;if (version_id <2 || version_id >VIRTIO_NET_VM_VERSION )return -EINVAL ; -virtio_load (&n->vdev, f); + ret =virtio_load (&n->vdev, f); +if (ret) { +return ret; + }qemu_get_buffer (f, n->mac,ETH_ALEN ); n->tx_waiting =qemu_get_be32 (f);hw/virtio-scsi.c +6
-1@@ -558,7 +558,12 @@ static void virtio_scsi_save(QEMUFile *f, void *opaque)static int virtio_scsi_load (QEMUFile *f,void *opaque,int version_id) {VirtIOSCSI *s = opaque; -virtio_load (&s->vdev, f); +int ret; + + ret =virtio_load (&s->vdev, f); +if (ret) { +return ret; + }return 0 ; }hw/virtio-serial-bus.c +1
-0@@ -590,13 +590,17 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)VirtIOSerialPort *port;uint32_t max_nr_ports, nr_active_ports, ports_map;unsigned int i; +int ret;if (version_id >3 ) {return -EINVAL ; }
hw/virtio-serial-bus.c static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id) · line 606
Quoted 10 lines
hw/virtio-serial-bus.c +4
-1/* The virtio device */ -virtio_load (&s->vdev, f); + ret =virtio_load (&s->vdev, f); +if (ret) { +return ret; + }if (version_id <2 ) {return 0 ;
Quoted 1 line · Orit Wasserman
Otherwise we crash on error.
A description on how to reproduce the crash would be nice.
Quoted 2 lines
Signed-off-by Orit Wasserman <[email protected]>Signed-off-by Ulrich Obergfell <[email protected]>
Amit
Quoted 4 lines · Amit Shah
Quoted 1 line · Orit Wasserman
Otherwise we crash on error.
A description on how to reproduce the crash would be nice.
Seconded. No bug fix is complete without instructions to reproduce.
[...]
Quoted 4 lines · Amit Shah
Quoted 1 line · Orit Wasserman
Otherwise we crash on error.
A description on how to reproduce the crash would be nice.
We changed the default of the command -device virtio-blk-pci,drive=...
from scsi=on to scsi=off for security reasons (disable SG_IO).
If you try to migrate from an older version (which had the default scsi=on) to a newer version (that has default scsi=off) we get the crash.
Orit
Quoted 7 lines
Quoted 3 lines
Signed-off-by Orit Wasserman <[email protected]>Signed-off-by Ulrich Obergfell <[email protected]>Acked-by Amit Shah <[email protected]>Amit
Il 01/03/2012 12:00, Orit Wasserman ha scritto:
Quoted 5 lines
Quoted 1 line
Quoted 1 line
A description on how to reproduce the crash would be nice.
We changed the default of the command -device virtio-blk-pci,drive=...
from scsi=on to scsi=off for security reasons (disableSG_IO).
If you try to migrate from an older version (which had the default scsi=on) to a newer version (that has default scsi=off) we get the crash.
Actually the default didn't change in QEMU. It's libvirt that changed the command-line with which it invokes QEMU.
This patch fixes the crash, I'll post one to fix migration later.
Paolo