e2ec8a
From ac9c51b72213bcea3dc9cea330d4c5fce9c4470e Mon Sep 17 00:00:00 2001
e2ec8a
From: Riccardo Schirone <rschiron@redhat.com>
e2ec8a
Date: Mon, 4 Feb 2019 14:29:09 +0100
e2ec8a
Subject: [PATCH] Refuse dbus message paths longer than BUS_PATH_SIZE_MAX
e2ec8a
 limit.
e2ec8a
e2ec8a
Even though the dbus specification does not enforce any length limit on the
e2ec8a
path of a dbus message, having to analyze too long strings in PID1 may be
e2ec8a
time-consuming and it may have security impacts.
e2ec8a
e2ec8a
In any case, the limit is set so high that real-life applications should not
e2ec8a
have a problem with it.
e2ec8a
e2ec8a
(cherry-picked from commit 61397a60d98e368a5720b37e83f3169e3eb511c4)
e2ec8a
e2ec8a
Related: #1678641
e2ec8a
---
e2ec8a
 src/libsystemd/sd-bus/bus-internal.c | 2 +-
e2ec8a
 src/libsystemd/sd-bus/bus-internal.h | 4 ++++
e2ec8a
 2 files changed, 5 insertions(+), 1 deletion(-)
e2ec8a
e2ec8a
diff --git a/src/libsystemd/sd-bus/bus-internal.c b/src/libsystemd/sd-bus/bus-internal.c
e2ec8a
index 7bb653338d..35e0b668ee 100644
e2ec8a
--- a/src/libsystemd/sd-bus/bus-internal.c
e2ec8a
+++ b/src/libsystemd/sd-bus/bus-internal.c
e2ec8a
@@ -45,7 +45,7 @@ bool object_path_is_valid(const char *p) {
e2ec8a
         if (slash)
e2ec8a
                 return false;
e2ec8a
 
e2ec8a
-        return true;
e2ec8a
+        return (q - p) <= BUS_PATH_SIZE_MAX;
e2ec8a
 }
e2ec8a
 
e2ec8a
 char* object_path_startswith(const char *a, const char *b) {
e2ec8a
diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h
e2ec8a
index 2087ef8eeb..90e6028983 100644
e2ec8a
--- a/src/libsystemd/sd-bus/bus-internal.h
e2ec8a
+++ b/src/libsystemd/sd-bus/bus-internal.h
e2ec8a
@@ -333,6 +333,10 @@ struct sd_bus {
e2ec8a
 
e2ec8a
 #define BUS_MESSAGE_SIZE_MAX (128*1024*1024)
e2ec8a
 #define BUS_AUTH_SIZE_MAX (64*1024)
e2ec8a
+/* Note that the D-Bus specification states that bus paths shall have no size limit. We enforce here one
e2ec8a
+ * anyway, since truly unbounded strings are a security problem. The limit we pick is relatively large however,
e2ec8a
+ * to not clash unnecessarily with real-life applications. */
e2ec8a
+#define BUS_PATH_SIZE_MAX (64*1024)
e2ec8a
 
e2ec8a
 #define BUS_CONTAINER_DEPTH 128
e2ec8a