Blame SOURCES/libvncserver-0.9.11-Fix-CVE-2018-15127-Heap-out-of-bounds-write-in-rfbse.patch

e39311
From d9a832a2edbf95d664b07791f77a22ac3dfb95f5 Mon Sep 17 00:00:00 2001
e39311
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
e39311
Date: Thu, 10 Jan 2019 12:11:04 +0100
e39311
Subject: [PATCH] Fix CVE-2018-15127 (Heap out-of-bounds write in
e39311
 rfbserver.c:rfbProcessFileTransferReadBuffer())
e39311
MIME-Version: 1.0
e39311
Content-Type: text/plain; charset=UTF-8
e39311
Content-Transfer-Encoding: 8bit
e39311
e39311
This patch contains the following three upstream patches squashed
e39311
together and ported to 0.9.11 version:
e39311
e39311
    commit 502821828ed00b4a2c4bef90683d0fd88ce495de
e39311
    Author: Christian Beier <dontmind@freeshell.org>
e39311
    Date:   Sun Oct 21 20:21:30 2018 +0200
e39311
e39311
	LibVNCServer: fix heap out-of-bound write access
e39311
e39311
	Closes #243
e39311
e39311
    commit 15bb719c03cc70f14c36a843dcb16ed69b405707
e39311
    Author: Christian Beier <dontmind@freeshell.org>
e39311
    Date:   Sun Jan 6 15:13:56 2019 +0100
e39311
e39311
	Error out in rfbProcessFileTransferReadBuffer if length can not be allocated
e39311
e39311
	re #273
e39311
e39311
    commit 09e8fc02f59f16e2583b34fe1a270c238bd9ffec
e39311
    Author: Petr Písař <ppisar@redhat.com>
e39311
    Date:   Mon Jan 7 10:40:01 2019 +0100
e39311
e39311
	Limit lenght to INT_MAX bytes in rfbProcessFileTransferReadBuffer()
e39311
e39311
	This ammends 15bb719c03cc70f14c36a843dcb16ed69b405707 fix for a heap
e39311
	out-of-bound write access in rfbProcessFileTransferReadBuffer() when
e39311
	reading a transfered file content in a server. The former fix did not
e39311
	work on platforms with a 32-bit int type (expected by rfbReadExact()).
e39311
e39311
	CVE-2018-15127
e39311
	<https://github.com/LibVNC/libvncserver/issues/243>
e39311
	<https://github.com/LibVNC/libvncserver/issues/273>
e39311
e39311
Signed-off-by: Petr Písař <ppisar@redhat.com>
e39311
---
e39311
 libvncserver/rfbserver.c | 17 +++++++++++++++--
e39311
 1 file changed, 15 insertions(+), 2 deletions(-)
e39311
e39311
diff --git a/libvncserver/rfbserver.c b/libvncserver/rfbserver.c
e39311
index b50a7f4..1b4dd97 100644
e39311
--- a/libvncserver/rfbserver.c
e39311
+++ b/libvncserver/rfbserver.c
e39311
@@ -1471,11 +1471,24 @@ char *rfbProcessFileTransferReadBuffer(rfbClientPtr cl, uint32_t length)
e39311
     int   n=0;
e39311
 
e39311
     FILEXFER_ALLOWED_OR_CLOSE_AND_RETURN("", cl, NULL);
e39311
+
e39311
     /*
e39311
-    rfbLog("rfbProcessFileTransferReadBuffer(%dlen)\n", length);
e39311
+       We later alloc length+1, which might wrap around on 32-bit systems if length equals
e39311
+       0XFFFFFFFF, i.e. SIZE_MAX for 32-bit systems. On 64-bit systems, a length of 0XFFFFFFFF
e39311
+       will safely be allocated since this check will never trigger and malloc() can digest length+1
e39311
+       without problems as length is a uint32_t.
e39311
+       We also later pass length to rfbReadExact() that expects a signed int type and
e39311
+       that might wrap on platforms with a 32-bit int type if length is bigger
e39311
+       than 0X7FFFFFFF.
e39311
     */
e39311
+    if(length == SIZE_MAX || length > INT_MAX) {
e39311
+	rfbErr("rfbProcessFileTransferReadBuffer: too big file transfer length requested: %u", (unsigned int)length);
e39311
+	rfbCloseClient(cl);
e39311
+	return NULL;
e39311
+    }
e39311
+
e39311
     if (length>0) {
e39311
-        buffer=malloc(length+1);
e39311
+        buffer=malloc((size_t)length+1);
e39311
         if (buffer!=NULL) {
e39311
             if ((n = rfbReadExact(cl, (char *)buffer, length)) <= 0) {
e39311
                 if (n != 0)
e39311
-- 
e39311
2.17.2
e39311