Blame SOURCES/kvm-ui-cursor-fix-integer-overflow-in-cursor_alloc-CVE-2.patch

4841a6
From 87a318f0b8758f940a316831a77b6ebebca42b19 Mon Sep 17 00:00:00 2001
6443c2
From: Jon Maloy <jmaloy@redhat.com>
6443c2
Date: Wed, 4 May 2022 10:35:17 -0400
4841a6
Subject: [PATCH 3/3] ui/cursor: fix integer overflow in cursor_alloc
6443c2
 (CVE-2021-4206)
6443c2
MIME-Version: 1.0
6443c2
Content-Type: text/plain; charset=UTF-8
6443c2
Content-Transfer-Encoding: 8bit
6443c2
6443c2
RH-Author: Jon Maloy <jmaloy@redhat.com>
4841a6
RH-MergeRequest: 180: ui/cursor: fix integer overflow in cursor_alloc (CVE-2021-4206)
4841a6
RH-Commit: [1/1] 7ad711347bc6248dc5aefa45401ca74448dee5e5 (jmaloy/qemu-kvm)
4841a6
RH-Bugzilla: 2040734
4841a6
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
6443c2
RH-Acked-by: Mauro Matteo Cascella <None>
4841a6
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
6443c2
4841a6
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=2040734
6443c2
Upstream: Merged
6443c2
CVE: CVE-2021-4206
6443c2
6443c2
commit fa892e9abb728e76afcf27323ab29c57fb0fe7aa
6443c2
Author: Mauro Matteo Cascella <mcascell@redhat.com>
6443c2
Date:   Thu Apr 7 10:17:12 2022 +0200
6443c2
6443c2
    ui/cursor: fix integer overflow in cursor_alloc (CVE-2021-4206)
6443c2
6443c2
    Prevent potential integer overflow by limiting 'width' and 'height' to
6443c2
    512x512. Also change 'datasize' type to size_t. Refer to security
6443c2
    advisory https://starlabs.sg/advisories/22-4206/ for more information.
6443c2
6443c2
    Fixes: CVE-2021-4206
6443c2
    Signed-off-by: Mauro Matteo Cascella <mcascell@redhat.com>
6443c2
    Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
6443c2
    Message-Id: <20220407081712.345609-1-mcascell@redhat.com>
6443c2
    Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
6443c2
6443c2
(cherry picked from commit fa892e9abb728e76afcf27323ab29c57fb0fe7aa)
6443c2
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
6443c2
---
6443c2
 hw/display/qxl-render.c | 7 +++++++
6443c2
 hw/display/vmware_vga.c | 2 ++
6443c2
 ui/cursor.c             | 8 +++++++-
6443c2
 3 files changed, 16 insertions(+), 1 deletion(-)
6443c2
6443c2
diff --git a/hw/display/qxl-render.c b/hw/display/qxl-render.c
6443c2
index 237ed293ba..ca217004bf 100644
6443c2
--- a/hw/display/qxl-render.c
6443c2
+++ b/hw/display/qxl-render.c
6443c2
@@ -247,6 +247,13 @@ static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor,
6443c2
     size_t size;
6443c2
 
6443c2
     c = cursor_alloc(cursor->header.width, cursor->header.height);
6443c2
+
6443c2
+    if (!c) {
6443c2
+        qxl_set_guest_bug(qxl, "%s: cursor %ux%u alloc error", __func__,
6443c2
+                cursor->header.width, cursor->header.height);
6443c2
+        goto fail;
6443c2
+    }
6443c2
+
6443c2
     c->hot_x = cursor->header.hot_spot_x;
6443c2
     c->hot_y = cursor->header.hot_spot_y;
6443c2
     switch (cursor->header.type) {
6443c2
diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c
6443c2
index e2969a6c81..2b81d6122f 100644
6443c2
--- a/hw/display/vmware_vga.c
6443c2
+++ b/hw/display/vmware_vga.c
6443c2
@@ -509,6 +509,8 @@ static inline void vmsvga_cursor_define(struct vmsvga_state_s *s,
6443c2
     int i, pixels;
6443c2
 
6443c2
     qc = cursor_alloc(c->width, c->height);
6443c2
+    assert(qc != NULL);
6443c2
+
6443c2
     qc->hot_x = c->hot_x;
6443c2
     qc->hot_y = c->hot_y;
6443c2
     switch (c->bpp) {
6443c2
diff --git a/ui/cursor.c b/ui/cursor.c
6443c2
index 1d62ddd4d0..835f0802f9 100644
6443c2
--- a/ui/cursor.c
6443c2
+++ b/ui/cursor.c
6443c2
@@ -46,6 +46,8 @@ static QEMUCursor *cursor_parse_xpm(const char *xpm[])
6443c2
 
6443c2
     /* parse pixel data */
6443c2
     c = cursor_alloc(width, height);
6443c2
+    assert(c != NULL);
6443c2
+
6443c2
     for (pixel = 0, y = 0; y < height; y++, line++) {
6443c2
         for (x = 0; x < height; x++, pixel++) {
6443c2
             idx = xpm[line][x];
6443c2
@@ -91,7 +93,11 @@ QEMUCursor *cursor_builtin_left_ptr(void)
6443c2
 QEMUCursor *cursor_alloc(int width, int height)
6443c2
 {
6443c2
     QEMUCursor *c;
6443c2
-    int datasize = width * height * sizeof(uint32_t);
6443c2
+    size_t datasize = width * height * sizeof(uint32_t);
6443c2
+
6443c2
+    if (width > 512 || height > 512) {
6443c2
+        return NULL;
6443c2
+    }
6443c2
 
6443c2
     c = g_malloc0(sizeof(QEMUCursor) + datasize);
6443c2
     c->width  = width;
6443c2
-- 
4841a6
2.35.1
6443c2