thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
97168e
From d3602e5afa1e90c5e33625fc528db7f96195bada Mon Sep 17 00:00:00 2001
97168e
From: Jon Maloy <jmaloy@redhat.com>
97168e
Date: Mon, 7 Nov 2022 19:59:46 -0500
97168e
Subject: [PATCH 42/42] ui/vnc-clipboard: fix integer underflow in
97168e
 vnc_client_cut_text_ext
97168e
MIME-Version: 1.0
97168e
Content-Type: text/plain; charset=UTF-8
97168e
Content-Transfer-Encoding: 8bit
97168e
97168e
RH-Author: Jon Maloy <jmaloy@redhat.com>
97168e
RH-MergeRequest: 227: ui/vnc-clipboard: fix integer underflow in vnc_client_cut_text_ext
97168e
RH-Bugzilla: 2129760
97168e
RH-Acked-by: Mauro Matteo Cascella <None>
97168e
RH-Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
97168e
RH-Acked-by: Thomas Huth <thuth@redhat.com>
97168e
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
97168e
RH-Commit: [1/1] ac19a6c0777e308061bcb6d1de5cc9beaa105a3a (jmaloy/qemu-kvm)
97168e
97168e
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=2129760
97168e
CVE: CVE-2022-3165
97168e
Upstream: Merged
97168e
97168e
commit d307040b18bfcb1393b910f1bae753d5c12a4dc7
97168e
Author: Mauro Matteo Cascella <mcascell@redhat.com>
97168e
Date:   Sun Sep 25 22:45:11 2022 +0200
97168e
97168e
    ui/vnc-clipboard: fix integer underflow in vnc_client_cut_text_ext
97168e
97168e
    Extended ClientCutText messages start with a 4-byte header. If len < 4,
97168e
    an integer underflow occurs in vnc_client_cut_text_ext. The result is
97168e
    used to decompress data in a while loop in inflate_buffer, leading to
97168e
    CPU consumption and denial of service. Prevent this by checking dlen in
97168e
    protocol_client_msg.
97168e
97168e
    Fixes: CVE-2022-3165
97168e
    Fixes: 0bf41cab93e5 ("ui/vnc: clipboard support")
97168e
    Reported-by: TangPeng <tangpeng@qianxin.com>
97168e
    Signed-off-by: Mauro Matteo Cascella <mcascell@redhat.com>
97168e
    Message-Id: <20220925204511.1103214-1-mcascell@redhat.com>
97168e
    Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
97168e
97168e
(cherry picked from commit d307040b18bfcb1393b910f1bae753d5c12a4dc7)
97168e
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
97168e
---
97168e
 ui/vnc.c | 11 ++++++++---
97168e
 1 file changed, 8 insertions(+), 3 deletions(-)
97168e
97168e
diff --git a/ui/vnc.c b/ui/vnc.c
97168e
index af02522e84..a14b6861be 100644
97168e
--- a/ui/vnc.c
97168e
+++ b/ui/vnc.c
97168e
@@ -2442,8 +2442,8 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len)
97168e
         if (len == 1) {
97168e
             return 8;
97168e
         }
97168e
+        uint32_t dlen = abs(read_s32(data, 4));
97168e
         if (len == 8) {
97168e
-            uint32_t dlen = abs(read_s32(data, 4));
97168e
             if (dlen > (1 << 20)) {
97168e
                 error_report("vnc: client_cut_text msg payload has %u bytes"
97168e
                              " which exceeds our limit of 1MB.", dlen);
97168e
@@ -2456,8 +2456,13 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len)
97168e
         }
97168e
 
97168e
         if (read_s32(data, 4) < 0) {
97168e
-            vnc_client_cut_text_ext(vs, abs(read_s32(data, 4)),
97168e
-                                    read_u32(data, 8), data + 12);
97168e
+            if (dlen < 4) {
97168e
+                error_report("vnc: malformed payload (header less than 4 bytes)"
97168e
+                             " in extended clipboard pseudo-encoding.");
97168e
+                vnc_client_error(vs);
97168e
+                break;
97168e
+            }
97168e
+            vnc_client_cut_text_ext(vs, dlen, read_u32(data, 8), data + 12);
97168e
             break;
97168e
         }
97168e
         vnc_client_cut_text(vs, read_u32(data, 4), data + 8);
97168e
-- 
97168e
2.37.3
97168e