dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0001-vmw_pvscsi-check-page-count-while-initialising-descr.patch

3a13dd
From: Prasad J Pandit <pjp@fedoraproject.org>
3a13dd
Date: Wed, 31 Aug 2016 12:19:29 +0530
3a13dd
Subject: [PATCH] vmw_pvscsi: check page count while initialising descriptor
3a13dd
 rings
3a13dd
3a13dd
Vmware Paravirtual SCSI emulation uses command descriptors to
3a13dd
process SCSI commands. These descriptors come with their ring
3a13dd
buffers. A guest could set the page count for these rings to
3a13dd
an arbitrary value, leading to infinite loop or OOB access.
3a13dd
Add check to avoid it.
3a13dd
3a13dd
Reported-by: Tom Victor <vv474172261@gmail.com>
3a13dd
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
3a13dd
Message-Id: <1472626169-12989-1-git-send-email-ppandit@redhat.com>
3a13dd
Cc: qemu-stable@nongnu.org
3a13dd
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
3a13dd
(cherry picked from commit 7f61f4690dd153be98900a2a508b88989e692753)
3a13dd
---
3a13dd
 hw/scsi/vmw_pvscsi.c | 19 +++++++++----------
3a13dd
 1 file changed, 9 insertions(+), 10 deletions(-)
3a13dd
3a13dd
diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c
3a13dd
index 5116f4a..4245c15 100644
3a13dd
--- a/hw/scsi/vmw_pvscsi.c
3a13dd
+++ b/hw/scsi/vmw_pvscsi.c
3a13dd
@@ -152,7 +152,7 @@ pvscsi_log2(uint32_t input)
3a13dd
     return log;
3a13dd
 }
3a13dd
 
3a13dd
-static int
3a13dd
+static void
3a13dd
 pvscsi_ring_init_data(PVSCSIRingInfo *m, PVSCSICmdDescSetupRings *ri)
3a13dd
 {
3a13dd
     int i;
3a13dd
@@ -160,10 +160,6 @@ pvscsi_ring_init_data(PVSCSIRingInfo *m, PVSCSICmdDescSetupRings *ri)
3a13dd
     uint32_t req_ring_size, cmp_ring_size;
3a13dd
     m->rs_pa = ri->ringsStatePPN << VMW_PAGE_SHIFT;
3a13dd
 
3a13dd
-    if ((ri->reqRingNumPages > PVSCSI_SETUP_RINGS_MAX_NUM_PAGES)
3a13dd
-        || (ri->cmpRingNumPages > PVSCSI_SETUP_RINGS_MAX_NUM_PAGES)) {
3a13dd
-        return -1;
3a13dd
-    }
3a13dd
     req_ring_size = ri->reqRingNumPages * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE;
3a13dd
     cmp_ring_size = ri->cmpRingNumPages * PVSCSI_MAX_NUM_CMP_ENTRIES_PER_PAGE;
3a13dd
     txr_len_log2 = pvscsi_log2(req_ring_size - 1);
3a13dd
@@ -195,8 +191,6 @@ pvscsi_ring_init_data(PVSCSIRingInfo *m, PVSCSICmdDescSetupRings *ri)
3a13dd
 
3a13dd
     /* Flush ring state page changes */
3a13dd
     smp_wmb();
3a13dd
-
3a13dd
-    return 0;
3a13dd
 }
3a13dd
 
3a13dd
 static int
3a13dd
@@ -746,7 +740,7 @@ pvscsi_dbg_dump_tx_rings_config(PVSCSICmdDescSetupRings *rc)
3a13dd
 
3a13dd
     trace_pvscsi_tx_rings_num_pages("Confirm Ring", rc->cmpRingNumPages);
3a13dd
     for (i = 0; i < rc->cmpRingNumPages; i++) {
3a13dd
-        trace_pvscsi_tx_rings_ppn("Confirm Ring", rc->reqRingPPNs[i]);
3a13dd
+        trace_pvscsi_tx_rings_ppn("Confirm Ring", rc->cmpRingPPNs[i]);
3a13dd
     }
3a13dd
 }
3a13dd
 
3a13dd
@@ -779,11 +773,16 @@ pvscsi_on_cmd_setup_rings(PVSCSIState *s)
3a13dd
 
3a13dd
     trace_pvscsi_on_cmd_arrived("PVSCSI_CMD_SETUP_RINGS");
3a13dd
 
3a13dd
-    pvscsi_dbg_dump_tx_rings_config(rc);
3a13dd
-    if (pvscsi_ring_init_data(&s->rings, rc) < 0) {
3a13dd
+    if (!rc->reqRingNumPages
3a13dd
+        || rc->reqRingNumPages > PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
3a13dd
+        || !rc->cmpRingNumPages
3a13dd
+        || rc->cmpRingNumPages > PVSCSI_SETUP_RINGS_MAX_NUM_PAGES) {
3a13dd
         return PVSCSI_COMMAND_PROCESSING_FAILED;
3a13dd
     }
3a13dd
 
3a13dd
+    pvscsi_dbg_dump_tx_rings_config(rc);
3a13dd
+    pvscsi_ring_init_data(&s->rings, rc);
3a13dd
+
3a13dd
     s->rings_info_valid = TRUE;
3a13dd
     return PVSCSI_COMMAND_PROCESSING_SUCCEEDED;
3a13dd
 }