|
|
fc0419 |
From 0073e4f694d5a51bb72ff12a5e8364b6e752e094 Mon Sep 17 00:00:00 2001
|
|
|
fc0419 |
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
|
|
|
fc0419 |
Date: Mon, 26 Feb 2018 13:48:00 +0100
|
|
|
fc0419 |
Subject: [PATCH] Validate client cut text length
|
|
|
fc0419 |
MIME-Version: 1.0
|
|
|
fc0419 |
Content-Type: text/plain; charset=UTF-8
|
|
|
fc0419 |
Content-Transfer-Encoding: 8bit
|
|
|
fc0419 |
|
|
|
fc0419 |
Client-provided unsigned 32-bit cut text length is passed to various
|
|
|
fc0419 |
functions that expects argument of a different type.
|
|
|
fc0419 |
|
|
|
fc0419 |
E.g. "RFB 003.003\n\001\006\0\0\0\xff\xff\xff\xff" string sent to the
|
|
|
fc0419 |
RFB server leads to 4294967295 msg.cct.length value that in turn is
|
|
|
fc0419 |
interpreted as -1 by rfbReadExact() and thus uninitialized str buffer
|
|
|
fc0419 |
with potentially sensitive data is passed to subsequent functions.
|
|
|
fc0419 |
|
|
|
fc0419 |
This patch fixes it by checking for a maximal value that still can be
|
|
|
fc0419 |
processed correctly. It also corrects accepting length value of zero
|
|
|
fc0419 |
(malloc(0) is interpreted on differnet systems differently).
|
|
|
fc0419 |
|
|
|
fc0419 |
Whether a client can make the server allocate up to 2 GB and cause
|
|
|
fc0419 |
a denial of service on memory-tight systems is kept without answer.
|
|
|
fc0419 |
A possible solution would be adding an arbitrary memory limit that is
|
|
|
fc0419 |
deemed safe.
|
|
|
fc0419 |
|
|
|
fc0419 |
CVE-2018-7225
|
|
|
fc0419 |
<https://github.com/LibVNC/libvncserver/issues/218>
|
|
|
fc0419 |
|
|
|
fc0419 |
Signed-off-by: Petr Písař <ppisar@redhat.com>
|
|
|
fc0419 |
---
|
|
|
fc0419 |
libvncserver/rfbserver.c | 22 +++++++++++++++++++++-
|
|
|
fc0419 |
1 file changed, 21 insertions(+), 1 deletion(-)
|
|
|
fc0419 |
|
|
|
fc0419 |
diff --git a/libvncserver/rfbserver.c b/libvncserver/rfbserver.c
|
|
|
fc0419 |
index 116c488..a9561fc 100644
|
|
|
fc0419 |
--- a/libvncserver/rfbserver.c
|
|
|
fc0419 |
+++ b/libvncserver/rfbserver.c
|
|
|
fc0419 |
@@ -88,6 +88,12 @@
|
|
|
fc0419 |
#include <errno.h>
|
|
|
fc0419 |
/* strftime() */
|
|
|
fc0419 |
#include <time.h>
|
|
|
fc0419 |
+/* SIZE_MAX */
|
|
|
fc0419 |
+#include <stdint.h>
|
|
|
fc0419 |
+/* PRIu32 */
|
|
|
fc0419 |
+#include <inttypes.h>
|
|
|
fc0419 |
+/* INT_MAX */
|
|
|
fc0419 |
+#include <limits.h>
|
|
|
fc0419 |
|
|
|
fc0419 |
#ifdef LIBVNCSERVER_WITH_WEBSOCKETS
|
|
|
fc0419 |
#include "rfbssl.h"
|
|
|
fc0419 |
@@ -2575,7 +2581,21 @@ rfbProcessClientNormalMessage(rfbClientPtr cl)
|
|
|
fc0419 |
|
|
|
fc0419 |
msg.cct.length = Swap32IfLE(msg.cct.length);
|
|
|
fc0419 |
|
|
|
fc0419 |
- str = (char *)malloc(msg.cct.length);
|
|
|
fc0419 |
+ /* uint32_t input is passed to malloc()'s size_t argument,
|
|
|
fc0419 |
+ * to rfbReadExact()'s int argument, to rfbStatRecordMessageRcvd()'s int
|
|
|
fc0419 |
+ * argument increased of sz_rfbClientCutTextMsg, and to setXCutText()'s int
|
|
|
fc0419 |
+ * argument. Here we check that the value fits into all of them to
|
|
|
fc0419 |
+ * prevent from misinterpretation and thus from accessing uninitialized
|
|
|
fc0419 |
+ * memory. CVE-2018-7225 */
|
|
|
fc0419 |
+ if (msg.cct.length > SIZE_MAX || msg.cct.length > INT_MAX - sz_rfbClientCutTextMsg) {
|
|
|
fc0419 |
+ rfbLog("rfbClientCutText: too big cut text length requested: %" PRIu32 "\n",
|
|
|
fc0419 |
+ msg.cct.length);
|
|
|
fc0419 |
+ rfbCloseClient(cl);
|
|
|
fc0419 |
+ return;
|
|
|
fc0419 |
+ }
|
|
|
fc0419 |
+
|
|
|
fc0419 |
+ /* Allow zero-length client cut text. */
|
|
|
fc0419 |
+ str = (char *)malloc(msg.cct.length ? msg.cct.length : 1);
|
|
|
fc0419 |
if (str == NULL) {
|
|
|
fc0419 |
rfbLogPerror("rfbProcessClientNormalMessage: not enough memory");
|
|
|
fc0419 |
rfbCloseClient(cl);
|
|
|
fc0419 |
--
|
|
|
fc0419 |
2.13.6
|
|
|
fc0419 |
|