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