Skip to contentSkip to conversation

virtio-scsi: Fix num_queue input validation

PATCH Applied Fam Zheng 2 participants 2 messages Oct 31, 2014

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH v2 1/1 virtio-scsi: Fix num_queue input validation

We need to count the ctrlq and eventq, and also cleanup before returning. Besides, the format string should be unsigned.

The number could never be less than zero.

---
 hw/scsi/virtio-scsi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/scsi/virtio-scsi.c +5 -3
index 7d40ecc..fdcacfd 100644
@@ -804,10 +804,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 "), "
+    if (s->conf.num_queues == 0 ||
+            s->conf.num_queues > VIRTIO_PCI_QUEUE_MAX - 2) {
+        error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "
                          "must be a positive integer less than %d.",
-                   s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX);
+                   s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX - 2);
+        virtio_cleanup(vdev);
         return;
     }
     s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *));
Signature · 1 line
1.9.3
#1 lore raw
Quoted 21 lines · Fam Zheng

We need to count the ctrlq and eventq, and also cleanup before returning. Besides, the format string should be unsigned.

The number could never be less than zero.

---
 hw/scsi/virtio-scsi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/scsi/virtio-scsi.c +0 -2
index 7d40ecc..fdcacfd 100644
@@ -804,10 +804,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 "), "

hw/scsi/virtio-scsi.c void virtio_scsi_common_realize(DeviceState *dev, Error **errp, · line 815

Quoted 10 lines
hw/scsi/virtio-scsi.c +5 -1
+    if (s->conf.num_queues == 0 ||
+            s->conf.num_queues > VIRTIO_PCI_QUEUE_MAX - 2) {
+        error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "
                          "must be a positive integer less than %d.",
-                   s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX);
+                   s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX - 2);
+        virtio_cleanup(vdev);
         return;
     }
     s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *));

Thanks, applied.

Paolo