vhost-scsi and ivshmem fixes for Coverity issues
v2 cover vhost-scsi and ivshmem fixes for Coverity issues
The following fixes address NULL pointer dereferences spotted by Coverity.
v2:
* Dropped savevm.c popen(3) leak fix since Paolo has a better fix [eblake]
Stefan Hajnoczi (2):
vhost-scsi: fix k->set_guest_notifiers() NULL dereference
ivshmem: add missing error exit(2)
hw/misc/ivshmem.c | 1 + hw/scsi/vhost-scsi.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.1.4
PATCH v2 1/2 vhost-scsi: fix k->set_guest_notifiers() NULL dereference
Coverity picked up a copy-paste bug. In vhost_scsi_start() we check for !k->set_guest_notifiers and error out. The check probably got copied but instead of erroring we actually use the function pointer!
--- hw/scsi/vhost-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/vhost-scsi.c +1 -1
@@ -123,7 +123,7 @@ static void vhost_scsi_stop(VHostSCSI *s)VirtioBusClass *k =VIRTIO_BUS_GET_CLASS (qbus);int ret =0 ; -if (!k->set_guest_notifiers) { +if (k->set_guest_notifiers) { ret = k->set_guest_notifiers (qbus->parent, s->dev.nvqs, false);if (ret <0 ) {error_report ("vhost guest notifier cleanup failed: %d\n" , ret);
Signature · 1 line
1.8.1.4
Paolo Bonzini
AppliedRe: [Qemu-devel] [PATCH v2 1/2] vhost-scsi: fix k->set_guest_notifiers() NULL dereference
Il 03/06/2013 10:58, Stefan Hajnoczi ha scritto:
Quoted 3 lines
Coverity picked up a copy-paste bug. In
vhost_scsi_start()we check for !k->set_guest_notifiers and error out. The check probably got copied but instead of erroring we actually use the function pointer!
Exactly. :)
Applied to scsi branch, thanks.
Paolo
Quoted 22 lines
Cc Nicholas Bellinger <[email protected]>Cc Asias He <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/scsi/vhost-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/scsi/vhost-scsi.c +1
-1@@ -123,7 +123,7 @@ static void vhost_scsi_stop(VHostSCSI *s)VirtioBusClass *k =VIRTIO_BUS_GET_CLASS (qbus);int ret =0 ; -if (!k->set_guest_notifiers) { +if (k->set_guest_notifiers) { ret = k->set_guest_notifiers (qbus->parent, s->dev.nvqs, false);if (ret <0 ) {error_report ("vhost guest notifier cleanup failed: %d\n" , ret);
PATCH v2 2/2 ivshmem: add missing error exit(2)
In reply to Stefan HajnocziIf the user fails to specify 'chardev' or 'shm' then we cannot continue. Exit right away so that we don't invoke shm_open(3) with a NULL pointer.
It would be nice to replace exit(1) with error returns in the PCI device .init() function, but leave that for another patch since exit(1) is currently used elsewhere.
Spotted by Coverity.
--- hw/misc/ivshmem.c | 1 + 1 file changed, 1 insertion(+)
hw/misc/ivshmem.c +1 -0
@@ -735,6 +735,7 @@ static int pci_ivshmem_init(PCIDevice *dev)if (s->shmobj ==NULL ) {fprintf (stderr,"Must specify 'chardev' or 'shm' to ivshmem\n" ); +exit (1 ); }IVSHMEM_DPRINTF ("using shm_open (shm object = %s)\n" , s->shmobj);
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: add missing error exit(2)
Quoted 21 lines · Stefan Hajnoczi
If the user fails to specify 'chardev' or 'shm' then we cannot continue. Exit right away so that we don't invoke
shm_open(3)with a NULL pointer.It would be nice to replace exit(1) with error returns in the PCI device .init() function, but leave that for another patch since exit(1) is currently used elsewhere.
Spotted by Coverity.
Cc Cam Macdonell <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/misc/ivshmem.c | 1 + 1 file changed, 1 insertion(+)hw/misc/ivshmem.c +0
-0
hw/misc/ivshmem.c static int pci_ivshmem_init(PCIDevice *dev) · line 738
Quoted 4 lines
hw/misc/ivshmem.c +1
-0@@ -735,6 +735,7 @@ static int pci_ivshmem_init(PCIDevice *dev)if (s->shmobj ==NULL ) {fprintf (stderr,"Must specify 'chardev' or 'shm' to ivshmem\n" ); +exit (1 );
However, I prefer exit(EXIT_FAILURE) rather than exit(1), to make it a bit easier to grep for known failure exits. Libvirt has a syntax checker (taken from gnulib) that enforces such a style, if qemu would like to adopt that style.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: add missing error exit(2)
Quoted 29 lines · Eric Blake
Quoted 21 lines · Stefan Hajnoczi
If the user fails to specify 'chardev' or 'shm' then we cannot continue. Exit right away so that we don't invoke
shm_open(3)with a NULL pointer.It would be nice to replace exit(1) with error returns in the PCI device .init() function, but leave that for another patch since exit(1) is currently used elsewhere.
Spotted by Coverity.
Cc Cam Macdonell <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/misc/ivshmem.c | 1 + 1 file changed, 1 insertion(+)hw/misc/ivshmem.c +0
-0hw/misc/ivshmem.c static int pci_ivshmem_init(PCIDevice *dev) · line 738
Quoted 4 lines
hw/misc/ivshmem.c +1
-0@@ -735,6 +735,7 @@ static int pci_ivshmem_init(PCIDevice *dev)if (s->shmobj ==NULL ) {fprintf (stderr,"Must specify 'chardev' or 'shm' to ivshmem\n" ); +exit (1 );Reviewed-by Eric Blake <[email protected]>
Quoted 4 lines
However, I prefer
exit(EXIT_FAILURE)rather than exit(1), to make it a bit easier to grep for known failure exits. Libvirt has a syntax checker (taken from gnulib) that enforces such a style, if qemu would like to adopt that style.
I like EXIT_FAILURE too but the rest of the file inconsistently uses exit(1) and exit(-1). I decided exit(1) was the least evil but the longer term fix is to return instead of exiting.
Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: add missing error exit(2)
Am 03.06.2013 15:11, schrieb Stefan Hajnoczi:
Quoted 30 lines · Eric Blake
Quoted 29 lines · Stefan Hajnoczi
Quoted 21 lines
If the user fails to specify 'chardev' or 'shm' then we cannot continue. Exit right away so that we don't invoke
shm_open(3)with a NULL pointer.It would be nice to replace exit(1) with error returns in the PCI device .init() function, but leave that for another patch since exit(1) is currently used elsewhere.
Spotted by Coverity.
Cc Cam Macdonell <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/misc/ivshmem.c | 1 + 1 file changed, 1 insertion(+)hw/misc/ivshmem.c +0
-0hw/misc/ivshmem.c static int pci_ivshmem_init(PCIDevice *dev) · line 738
Quoted 4 lines
hw/misc/ivshmem.c +1
-0@@ -735,6 +735,7 @@ static int pci_ivshmem_init(PCIDevice *dev)if (s->shmobj ==NULL ) {fprintf (stderr,"Must specify 'chardev' or 'shm' to ivshmem\n" ); +exit (1 );Reviewed-by Eric Blake <[email protected]>
Quoted 8 lines
Quoted 4 lines
However, I prefer
exit(EXIT_FAILURE)rather than exit(1), to make it a bit easier to grep for known failure exits. Libvirt has a syntax checker (taken from gnulib) that enforces such a style, if qemu would like to adopt that style.I like
EXIT_FAILUREtoo but the rest of the file inconsistently uses exit(1) and exit(-1). I decided exit(1) was the least evil but the longer term fix is to return instead of exiting.
QOM realize would solve that, but similar to virtio the PCI qdev initfn actually does something (allocating the config region among others) so faces the same design questions of how to best inherit QOM methods as currently being discussed. Shouldn't hold up a bug fix like this one.
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: add missing error exit(2)
In reply to Stefan HajnocziQuoted 31 lines · Stefan Hajnoczi
If the user fails to specify 'chardev' or 'shm' then we cannot continue. Exit right away so that we don't invoke
shm_open(3)with a NULL pointer.It would be nice to replace exit(1) with error returns in the PCI device .init() function, but leave that for another patch since exit(1) is currently used elsewhere.
Spotted by Coverity.
Cc Cam Macdonell <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>--- hw/misc/ivshmem.c | 1 + 1 file changed, 1 insertion(+)hw/misc/ivshmem.c +1
-0@@ -735,6 +735,7 @@ static int pci_ivshmem_init(PCIDevice *dev)if (s->shmobj ==NULL ) {fprintf (stderr,"Must specify 'chardev' or 'shm' to ivshmem\n" ); +exit (1 ); }IVSHMEM_DPRINTF ("using shm_open (shm object = %s)\n" , s->shmobj);Signature · 1 line
1.8.1.4
Ping?
Michael Tokarev
AppliedRe: [Qemu-devel] [Qemu-trivial] [PATCH v2 2/2] ivshmem: add missing error exit(2)
Quoted 6 lines · Stefan Hajnoczi
Quoted 6 lines
hw/misc/ivshmem.c +0
-0@@ -735,6 +735,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
Quoted 8 lines
hw/misc/ivshmem.c static int pci_ivshmem_init(PCIDevice *dev) · line 741
Quoted 6 lines
hw/misc/ivshmem.c +1
-0if (s->shmobj ==NULL ) {fprintf (stderr,"Must specify 'chardev' or 'shm' to ivshmem\n" ); +exit (1 ); }IVSHMEM_DPRINTF ("using shm_open (shm object = %s)\n" , s->shmobj);Ping?
Ow. I missed it because part 1/2 were applied to scsi branch by Paolo and I marked whole thread as "done".
Applied this 2/2 now to the trivial patches tree.
Thank you!
/mjt