From ff5cdda3bafa9349c0399b61d0c05dd9d77e5add Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Tue, 4 Nov 2014 02:48:33 +0100 Subject: [PATCH 05/15] virtio-scsi: Report error if num_queues is 0 or too large Message-id: <1415069315-6921-2-git-send-email-famz@redhat.com> Patchwork-id: 62056 O-Subject: [RHEL-7.1 qemu-kvm-rhev PATCH v2 1/3] virtio-scsi: Report error if num_queues is 0 or too large Bugzilla: 1146826 RH-Acked-by: Michael S. Tsirkin RH-Acked-by: Markus Armbruster RH-Acked-by: Paolo Bonzini RH-Acked-by: Max Reitz No cmd vq surprises guest (Linux panics in virtscsi_probe), too many queues abort qemu (in the following virtio_add_queue). Signed-off-by: Fam Zheng Signed-off-by: Paolo Bonzini (cherry picked from commit c9f6552803d852d593dec9ef5bb39b7a61091963) Signed-off-by: Fam Zheng Signed-off-by: Miroslav Rezanina --- hw/scsi/virtio-scsi.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index e4276fc..7e41fda 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -699,6 +699,12 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp, virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI, sizeof(VirtIOSCSIConfig)); + if (s->conf.num_queues <= 0 || s->conf.num_queues > VIRTIO_PCI_QUEUE_MAX) { + error_setg(errp, "Invalid number of queues (= %" PRId32 "), " + "must be a positive integer less than %d.", + s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX); + return; + } s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *)); s->sense_size = VIRTIO_SCSI_SENSE_SIZE; s->cdb_size = VIRTIO_SCSI_CDB_SIZE; -- 1.8.3.1