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