Blame 0012-scsi-pvscsi-check-command-descriptor-ring-buffer-siz.patch

cf91b1
From: Prasad J Pandit <pjp@fedoraproject.org>
cf91b1
Date: Mon, 23 May 2016 16:18:05 +0530
cf91b1
Subject: [PATCH] scsi: pvscsi: check command descriptor ring buffer size
cf91b1
 (CVE-2016-4952)
cf91b1
cf91b1
Vmware Paravirtual SCSI emulation uses command descriptors to
cf91b1
process SCSI commands. These descriptors come with their ring
cf91b1
buffers. A guest could set the ring buffer size to an arbitrary
cf91b1
value leading to OOB access issue. Add check to avoid it.
cf91b1
cf91b1
Reported-by: Li Qiang <liqiang6-s@360.cn>
cf91b1
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
cf91b1
Cc: qemu-stable@nongnu.org
cf91b1
Message-Id: <1464000485-27041-1-git-send-email-ppandit@redhat.com>
cf91b1
Reviewed-by: Shmulik Ladkani <shmulik.ladkani@ravellosystems.com>
cf91b1
Reviewed-by: Dmitry Fleytman <dmitry@daynix.com>
cf91b1
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
cf91b1
(cherry picked from commit 3e831b40e015ba34dfb55ff11f767001839425ff)
cf91b1
---
cf91b1
 hw/scsi/vmw_pvscsi.c | 24 ++++++++++++++++++++----
cf91b1
 1 file changed, 20 insertions(+), 4 deletions(-)
cf91b1
cf91b1
diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c
cf91b1
index e690b4e..e1d6d06 100644
cf91b1
--- a/hw/scsi/vmw_pvscsi.c
cf91b1
+++ b/hw/scsi/vmw_pvscsi.c
cf91b1
@@ -153,7 +153,7 @@ pvscsi_log2(uint32_t input)
cf91b1
     return log;
cf91b1
 }
cf91b1
 
cf91b1
-static void
cf91b1
+static int
cf91b1
 pvscsi_ring_init_data(PVSCSIRingInfo *m, PVSCSICmdDescSetupRings *ri)
cf91b1
 {
cf91b1
     int i;
cf91b1
@@ -161,6 +161,10 @@ pvscsi_ring_init_data(PVSCSIRingInfo *m, PVSCSICmdDescSetupRings *ri)
cf91b1
     uint32_t req_ring_size, cmp_ring_size;
cf91b1
     m->rs_pa = ri->ringsStatePPN << VMW_PAGE_SHIFT;
cf91b1
 
cf91b1
+    if ((ri->reqRingNumPages > PVSCSI_SETUP_RINGS_MAX_NUM_PAGES)
cf91b1
+        || (ri->cmpRingNumPages > PVSCSI_SETUP_RINGS_MAX_NUM_PAGES)) {
cf91b1
+        return -1;
cf91b1
+    }
cf91b1
     req_ring_size = ri->reqRingNumPages * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE;
cf91b1
     cmp_ring_size = ri->cmpRingNumPages * PVSCSI_MAX_NUM_CMP_ENTRIES_PER_PAGE;
cf91b1
     txr_len_log2 = pvscsi_log2(req_ring_size - 1);
cf91b1
@@ -192,15 +196,20 @@ pvscsi_ring_init_data(PVSCSIRingInfo *m, PVSCSICmdDescSetupRings *ri)
cf91b1
 
cf91b1
     /* Flush ring state page changes */
cf91b1
     smp_wmb();
cf91b1
+
cf91b1
+    return 0;
cf91b1
 }
cf91b1
 
cf91b1
-static void
cf91b1
+static int
cf91b1
 pvscsi_ring_init_msg(PVSCSIRingInfo *m, PVSCSICmdDescSetupMsgRing *ri)
cf91b1
 {
cf91b1
     int i;
cf91b1
     uint32_t len_log2;
cf91b1
     uint32_t ring_size;
cf91b1
 
cf91b1
+    if (ri->numPages > PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES) {
cf91b1
+        return -1;
cf91b1
+    }
cf91b1
     ring_size = ri->numPages * PVSCSI_MAX_NUM_MSG_ENTRIES_PER_PAGE;
cf91b1
     len_log2 = pvscsi_log2(ring_size - 1);
cf91b1
 
cf91b1
@@ -220,6 +229,8 @@ pvscsi_ring_init_msg(PVSCSIRingInfo *m, PVSCSICmdDescSetupMsgRing *ri)
cf91b1
 
cf91b1
     /* Flush ring state page changes */
cf91b1
     smp_wmb();
cf91b1
+
cf91b1
+    return 0;
cf91b1
 }
cf91b1
 
cf91b1
 static void
cf91b1
@@ -770,7 +781,10 @@ pvscsi_on_cmd_setup_rings(PVSCSIState *s)
cf91b1
     trace_pvscsi_on_cmd_arrived("PVSCSI_CMD_SETUP_RINGS");
cf91b1
 
cf91b1
     pvscsi_dbg_dump_tx_rings_config(rc);
cf91b1
-    pvscsi_ring_init_data(&s->rings, rc);
cf91b1
+    if (pvscsi_ring_init_data(&s->rings, rc) < 0) {
cf91b1
+        return PVSCSI_COMMAND_PROCESSING_FAILED;
cf91b1
+    }
cf91b1
+
cf91b1
     s->rings_info_valid = TRUE;
cf91b1
     return PVSCSI_COMMAND_PROCESSING_SUCCEEDED;
cf91b1
 }
cf91b1
@@ -850,7 +864,9 @@ pvscsi_on_cmd_setup_msg_ring(PVSCSIState *s)
cf91b1
     }
cf91b1
 
cf91b1
     if (s->rings_info_valid) {
cf91b1
-        pvscsi_ring_init_msg(&s->rings, rc);
cf91b1
+        if (pvscsi_ring_init_msg(&s->rings, rc) < 0) {
cf91b1
+            return PVSCSI_COMMAND_PROCESSING_FAILED;
cf91b1
+        }
cf91b1
         s->msg_ring_info_valid = TRUE;
cf91b1
     }
cf91b1
     return sizeof(PVSCSICmdDescSetupMsgRing) / sizeof(uint32_t);