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