]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
config-loader-expat: Tell Expat not to defend against hash collisions
authorSimon McVittie <smcv@debian.org>
Fri, 21 Jul 2017 09:46:39 +0000 (10:46 +0100)
committerSimon McVittie <smcv@debian.org>
Fri, 28 Jul 2017 10:17:04 +0000 (11:17 +0100)
By default, Expat uses cryptographic-quality random numbers as a salt for
its hash algorithm, and since 2.2.1 it gets them from the getrandom
syscall on Linux. That syscall refuses to return any entropy until the
kernel's CSPRNG (random pool) has been initialized. Unfortunately, this
can take as long as 40 seconds on embedded devices with few entropy
sources, which is too long: if the system dbus-daemon blocks for that
length of time, important D-Bus clients like systemd and systemd-logind
time out and fail to connect to it.

We're parsing small configuration files here, and we trust them
completely, so we don't need to defend against hash collisions: nobody
is going to be crafting them to cause pathological performance.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101858
Tested-by: Christopher Hewitt <hewitt@ieee.org>
[smcv: Adjust build-system changes for 1.11.x]
Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
bus/config-loader-expat.c
configure.ac

index f59942e32d6f1ce7f6fcc8337cb6ff181e90065c..6cbd37eb1a44e3721c9e2b4496e8b4aefcfc6cc9 100644 (file)
@@ -203,6 +203,20 @@ bus_config_load (const DBusString      *file,
       goto failed;
     }
 
+  /* We do not need protection against hash collisions (CVE-2012-0876)
+   * because we are only parsing trusted XML; and if we let Expat block
+   * waiting for the CSPRNG to be initialized, as it does by default to
+   * defeat CVE-2012-0876, it can cause timeouts during early boot on
+   * entropy-starved embedded devices.
+   *
+   * TODO: When Expat gets a more explicit API for this than
+   * XML_SetHashSalt, check for that too, and use it preferentially.
+   * https://github.com/libexpat/libexpat/issues/91 */
+#if defined(HAVE_XML_SETHASHSALT)
+  /* Any nonzero number will do. https://xkcd.com/221/ */
+  XML_SetHashSalt (expat, 4);
+#endif
+
   if (!_dbus_string_get_dirname (file, &dirname))
     {
       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
index 9797035f324ecd872520fc1b5654298d5b58af73..05182d1f45048009042843ffd626cb7761ee8f93 100644 (file)
@@ -935,6 +935,14 @@ AC_SUBST(DBUS_PATH_OR_ABSTRACT)
 
 PKG_CHECK_MODULES([EXPAT], [expat])
 
+save_cflags="$CFLAGS"
+save_libs="$LIBS"
+CFLAGS="$CFLAGS $EXPAT_CFLAGS"
+LIBS="$LIBS $EXPAT_LIBS"
+AC_CHECK_FUNCS([XML_SetHashSalt])
+CFLAGS="$save_cflags"
+LIBS="$save_libs"
+
 # Thread lib detection
 AC_ARG_VAR([THREAD_LIBS])
 save_libs="$LIBS"