3a13ddd
From: Prasad J Pandit <pjp@fedoraproject.org>
3a13ddd
Date: Thu, 8 Sep 2016 18:15:54 +0530
3a13ddd
Subject: [PATCH] vmsvga: correct bitmap and pixmap size checks
3a13ddd
3a13ddd
When processing svga command DEFINE_CURSOR in vmsvga_fifo_run,
3a13ddd
the computed BITMAP and PIXMAP size are checked against the
3a13ddd
'cursor.mask[]' and 'cursor.image[]' array sizes in bytes.
3a13ddd
Correct these checks to avoid OOB memory access.
3a13ddd
3a13ddd
Reported-by: Qinghao Tang <luodalongde@gmail.com>
3a13ddd
Reported-by: Li Qiang <liqiang6-s@360.cn>
3a13ddd
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
3a13ddd
Message-id: 1473338754-15430-1-git-send-email-ppandit@redhat.com
3a13ddd
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
3a13ddd
(cherry picked from commit 167d97a3def77ee2dbf6e908b0ecbfe2103977db)
3a13ddd
---
3a13ddd
 hw/display/vmware_vga.c | 12 +++++++-----
3a13ddd
 1 file changed, 7 insertions(+), 5 deletions(-)
3a13ddd
3a13ddd
diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c
3a13ddd
index e51a05e..6599cf0 100644
3a13ddd
--- a/hw/display/vmware_vga.c
3a13ddd
+++ b/hw/display/vmware_vga.c
3a13ddd
@@ -676,11 +676,13 @@ static void vmsvga_fifo_run(struct vmsvga_state_s *s)
3a13ddd
             cursor.bpp = vmsvga_fifo_read(s);
3a13ddd
 
3a13ddd
             args = SVGA_BITMAP_SIZE(x, y) + SVGA_PIXMAP_SIZE(x, y, cursor.bpp);
3a13ddd
-            if (cursor.width > 256 ||
3a13ddd
-                cursor.height > 256 ||
3a13ddd
-                cursor.bpp > 32 ||
3a13ddd
-                SVGA_BITMAP_SIZE(x, y) > sizeof cursor.mask ||
3a13ddd
-                SVGA_PIXMAP_SIZE(x, y, cursor.bpp) > sizeof cursor.image) {
3a13ddd
+            if (cursor.width > 256
3a13ddd
+                || cursor.height > 256
3a13ddd
+                || cursor.bpp > 32
3a13ddd
+                || SVGA_BITMAP_SIZE(x, y)
3a13ddd
+                    > sizeof(cursor.mask) / sizeof(cursor.mask[0])
3a13ddd
+                || SVGA_PIXMAP_SIZE(x, y, cursor.bpp)
3a13ddd
+                    > sizeof(cursor.image) / sizeof(cursor.image[0])) {
3a13ddd
                     goto badcmd;
3a13ddd
             }
3a13ddd