Blame 0017-vmsvga-move-fifo-sanity-checks-to-vmsvga_fifo_length.patch

cf91b1
From: Gerd Hoffmann <kraxel@redhat.com>
cf91b1
Date: Mon, 30 May 2016 09:09:18 +0200
cf91b1
Subject: [PATCH] vmsvga: move fifo sanity checks to vmsvga_fifo_length
cf91b1
MIME-Version: 1.0
cf91b1
Content-Type: text/plain; charset=UTF-8
cf91b1
Content-Transfer-Encoding: 8bit
cf91b1
cf91b1
Sanity checks are applied when the fifo is enabled by the guest
cf91b1
(SVGA_REG_CONFIG_DONE write).  Which doesn't help much if the guest
cf91b1
changes the fifo registers afterwards.  Move the checks to
cf91b1
vmsvga_fifo_length so they are done each time qemu is about to read
cf91b1
from the fifo.
cf91b1
cf91b1
Fixes: CVE-2016-4454
cf91b1
Cc: qemu-stable@nongnu.org
cf91b1
Cc: P J P <ppandit@redhat.com>
cf91b1
Reported-by: 李强 <liqiang6-s@360.cn>
cf91b1
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
cf91b1
Message-id: 1464592161-18348-2-git-send-email-kraxel@redhat.com
cf91b1
(cherry picked from commit 521360267876d3b6518b328051a2e56bca55bef8)
cf91b1
---
cf91b1
 hw/display/vmware_vga.c | 28 +++++++++++++++-------------
cf91b1
 1 file changed, 15 insertions(+), 13 deletions(-)
cf91b1
cf91b1
diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c
cf91b1
index 0c63fa8..63a7c05 100644
cf91b1
--- a/hw/display/vmware_vga.c
cf91b1
+++ b/hw/display/vmware_vga.c
cf91b1
@@ -555,6 +555,21 @@ static inline int vmsvga_fifo_length(struct vmsvga_state_s *s)
cf91b1
     if (!s->config || !s->enable) {
cf91b1
         return 0;
cf91b1
     }
cf91b1
+
cf91b1
+    /* Check range and alignment.  */
cf91b1
+    if ((CMD(min) | CMD(max) | CMD(next_cmd) | CMD(stop)) & 3) {
cf91b1
+        return 0;
cf91b1
+    }
cf91b1
+    if (CMD(min) < (uint8_t *) s->cmd->fifo - (uint8_t *) s->fifo) {
cf91b1
+        return 0;
cf91b1
+    }
cf91b1
+    if (CMD(max) > SVGA_FIFO_SIZE) {
cf91b1
+        return 0;
cf91b1
+    }
cf91b1
+    if (CMD(max) < CMD(min) + 10 * 1024) {
cf91b1
+        return 0;
cf91b1
+    }
cf91b1
+
cf91b1
     num = CMD(next_cmd) - CMD(stop);
cf91b1
     if (num < 0) {
cf91b1
         num += CMD(max) - CMD(min);
cf91b1
@@ -1005,19 +1020,6 @@ static void vmsvga_value_write(void *opaque, uint32_t address, uint32_t value)
cf91b1
     case SVGA_REG_CONFIG_DONE:
cf91b1
         if (value) {
cf91b1
             s->fifo = (uint32_t *) s->fifo_ptr;
cf91b1
-            /* Check range and alignment.  */
cf91b1
-            if ((CMD(min) | CMD(max) | CMD(next_cmd) | CMD(stop)) & 3) {
cf91b1
-                break;
cf91b1
-            }
cf91b1
-            if (CMD(min) < (uint8_t *) s->cmd->fifo - (uint8_t *) s->fifo) {
cf91b1
-                break;
cf91b1
-            }
cf91b1
-            if (CMD(max) > SVGA_FIFO_SIZE) {
cf91b1
-                break;
cf91b1
-            }
cf91b1
-            if (CMD(max) < CMD(min) + 10 * 1024) {
cf91b1
-                break;
cf91b1
-            }
cf91b1
             vga_dirty_log_stop(&s->vga);
cf91b1
         }
cf91b1
         s->config = !!value;