|
|
eb6a6e |
From 8044880840bcde6f15a078e267cf163072ac1878 Mon Sep 17 00:00:00 2001
|
|
|
eb6a6e |
From: Benjamin Tissoires <benjamin.tissoires@gmail.com>
|
|
|
eb6a6e |
Date: Tue, 4 Apr 2017 19:12:53 +0200
|
|
|
eb6a6e |
Subject: [PATCH libICE 1/2] Use getentropy() if arc4random_buf() is not
|
|
|
eb6a6e |
available
|
|
|
eb6a6e |
|
|
|
eb6a6e |
This allows to fix CVE-2017-2626 on Linux platforms without pulling in
|
|
|
eb6a6e |
libbsd.
|
|
|
eb6a6e |
The libc getentropy() is available since glibc 2.25 but also on OpenBSD.
|
|
|
eb6a6e |
For Linux, we need at least a v3.17 kernel. If the recommended
|
|
|
eb6a6e |
arc4random_buf() function is not available, emulate it by first trying
|
|
|
eb6a6e |
to use getentropy() on a supported glibc and kernel. If the call fails,
|
|
|
eb6a6e |
fall back to the current (partly vulnerable) code.
|
|
|
eb6a6e |
|
|
|
eb6a6e |
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
|
|
|
eb6a6e |
Reviewed-by: Mark Kettenis <kettenis@openbsd.org>
|
|
|
eb6a6e |
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
|
|
|
eb6a6e |
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
|
|
|
eb6a6e |
---
|
|
|
eb6a6e |
configure.ac | 2 +-
|
|
|
eb6a6e |
src/iceauth.c | 65 ++++++++++++++++++++++++++++++++++++++++++-----------------
|
|
|
eb6a6e |
2 files changed, 47 insertions(+), 20 deletions(-)
|
|
|
eb6a6e |
|
|
|
eb6a6e |
diff --git a/configure.ac b/configure.ac
|
|
|
eb6a6e |
index 458882a..c971ab6 100644
|
|
|
eb6a6e |
--- a/configure.ac
|
|
|
eb6a6e |
+++ b/configure.ac
|
|
|
eb6a6e |
@@ -38,7 +38,7 @@ AC_DEFINE(ICE_t, 1, [Xtrans transport type])
|
|
|
eb6a6e |
|
|
|
eb6a6e |
# Checks for library functions.
|
|
|
eb6a6e |
AC_CHECK_LIB([bsd], [arc4random_buf])
|
|
|
eb6a6e |
-AC_CHECK_FUNCS([asprintf arc4random_buf])
|
|
|
eb6a6e |
+AC_CHECK_FUNCS([asprintf arc4random_buf getentropy])
|
|
|
eb6a6e |
|
|
|
eb6a6e |
# Allow checking code with lint, sparse, etc.
|
|
|
eb6a6e |
XORG_WITH_LINT
|
|
|
eb6a6e |
diff --git a/src/iceauth.c b/src/iceauth.c
|
|
|
eb6a6e |
index ef66626..9b77eac 100644
|
|
|
eb6a6e |
--- a/src/iceauth.c
|
|
|
eb6a6e |
+++ b/src/iceauth.c
|
|
|
eb6a6e |
@@ -42,31 +42,19 @@ Author: Ralph Mor, X Consortium
|
|
|
eb6a6e |
|
|
|
eb6a6e |
static int was_called_state;
|
|
|
eb6a6e |
|
|
|
eb6a6e |
-/*
|
|
|
eb6a6e |
- * MIT-MAGIC-COOKIE-1 is a sample authentication method implemented by
|
|
|
eb6a6e |
- * the SI. It is not part of standard ICElib.
|
|
|
eb6a6e |
- */
|
|
|
eb6a6e |
+#ifndef HAVE_ARC4RANDOM_BUF
|
|
|
eb6a6e |
|
|
|
eb6a6e |
-
|
|
|
eb6a6e |
-char *
|
|
|
eb6a6e |
-IceGenerateMagicCookie (
|
|
|
eb6a6e |
+static void
|
|
|
eb6a6e |
+emulate_getrandom_buf (
|
|
|
eb6a6e |
+ char *auth,
|
|
|
eb6a6e |
int len
|
|
|
eb6a6e |
)
|
|
|
eb6a6e |
{
|
|
|
eb6a6e |
- char *auth;
|
|
|
eb6a6e |
-#ifndef HAVE_ARC4RANDOM_BUF
|
|
|
eb6a6e |
long ldata[2];
|
|
|
eb6a6e |
int seed;
|
|
|
eb6a6e |
int value;
|
|
|
eb6a6e |
int i;
|
|
|
eb6a6e |
-#endif
|
|
|
eb6a6e |
|
|
|
eb6a6e |
- if ((auth = malloc (len + 1)) == NULL)
|
|
|
eb6a6e |
- return (NULL);
|
|
|
eb6a6e |
-
|
|
|
eb6a6e |
-#ifdef HAVE_ARC4RANDOM_BUF
|
|
|
eb6a6e |
- arc4random_buf(auth, len);
|
|
|
eb6a6e |
-#else
|
|
|
eb6a6e |
#ifdef ITIMER_REAL
|
|
|
eb6a6e |
{
|
|
|
eb6a6e |
struct timeval now;
|
|
|
eb6a6e |
@@ -74,13 +62,13 @@ IceGenerateMagicCookie (
|
|
|
eb6a6e |
ldata[0] = now.tv_sec;
|
|
|
eb6a6e |
ldata[1] = now.tv_usec;
|
|
|
eb6a6e |
}
|
|
|
eb6a6e |
-#else
|
|
|
eb6a6e |
+#else /* ITIMER_REAL */
|
|
|
eb6a6e |
{
|
|
|
eb6a6e |
long time ();
|
|
|
eb6a6e |
ldata[0] = time ((long *) 0);
|
|
|
eb6a6e |
ldata[1] = getpid ();
|
|
|
eb6a6e |
}
|
|
|
eb6a6e |
-#endif
|
|
|
eb6a6e |
+#endif /* ITIMER_REAL */
|
|
|
eb6a6e |
seed = (ldata[0]) + (ldata[1] << 16);
|
|
|
eb6a6e |
srand (seed);
|
|
|
eb6a6e |
for (i = 0; i < len; i++)
|
|
|
eb6a6e |
@@ -88,7 +76,46 @@ IceGenerateMagicCookie (
|
|
|
eb6a6e |
value = rand ();
|
|
|
eb6a6e |
auth[i] = value & 0xff;
|
|
|
eb6a6e |
}
|
|
|
eb6a6e |
-#endif
|
|
|
eb6a6e |
+}
|
|
|
eb6a6e |
+
|
|
|
eb6a6e |
+static void
|
|
|
eb6a6e |
+arc4random_buf (
|
|
|
eb6a6e |
+ char *auth,
|
|
|
eb6a6e |
+ int len
|
|
|
eb6a6e |
+)
|
|
|
eb6a6e |
+{
|
|
|
eb6a6e |
+ int ret;
|
|
|
eb6a6e |
+
|
|
|
eb6a6e |
+#if HAVE_GETENTROPY
|
|
|
eb6a6e |
+ /* weak emulation of arc4random through the entropy libc */
|
|
|
eb6a6e |
+ ret = getentropy (auth, len);
|
|
|
eb6a6e |
+ if (ret == 0)
|
|
|
eb6a6e |
+ return;
|
|
|
eb6a6e |
+#endif /* HAVE_GETENTROPY */
|
|
|
eb6a6e |
+
|
|
|
eb6a6e |
+ emulate_getrandom_buf (auth, len);
|
|
|
eb6a6e |
+}
|
|
|
eb6a6e |
+
|
|
|
eb6a6e |
+#endif /* !defined(HAVE_ARC4RANDOM_BUF) */
|
|
|
eb6a6e |
+
|
|
|
eb6a6e |
+/*
|
|
|
eb6a6e |
+ * MIT-MAGIC-COOKIE-1 is a sample authentication method implemented by
|
|
|
eb6a6e |
+ * the SI. It is not part of standard ICElib.
|
|
|
eb6a6e |
+ */
|
|
|
eb6a6e |
+
|
|
|
eb6a6e |
+
|
|
|
eb6a6e |
+char *
|
|
|
eb6a6e |
+IceGenerateMagicCookie (
|
|
|
eb6a6e |
+ int len
|
|
|
eb6a6e |
+)
|
|
|
eb6a6e |
+{
|
|
|
eb6a6e |
+ char *auth;
|
|
|
eb6a6e |
+
|
|
|
eb6a6e |
+ if ((auth = malloc (len + 1)) == NULL)
|
|
|
eb6a6e |
+ return (NULL);
|
|
|
eb6a6e |
+
|
|
|
eb6a6e |
+ arc4random_buf (auth, len);
|
|
|
eb6a6e |
+
|
|
|
eb6a6e |
auth[len] = '\0';
|
|
|
eb6a6e |
return (auth);
|
|
|
eb6a6e |
}
|
|
|
eb6a6e |
--
|
|
|
eb6a6e |
2.9.3
|
|
|
eb6a6e |
|