Refuse dbus message paths longer than BUS_PATH_SIZE_MAX limit.
authorRiccardo Schirone <rschiron@redhat.com>
Mon, 4 Feb 2019 13:29:09 +0000 (14:29 +0100)
committerLukas Nykryn <lnykryn@redhat.com>
Mon, 8 Apr 2019 11:43:16 +0000 (13:43 +0200)
Even though the dbus specification does not enforce any length limit on the
path of a dbus message, having to analyze too long strings in PID1 may be
time-consuming and it may have security impacts.

In any case, the limit is set so high that real-life applications should not
have a problem with it.

(cherry-picked from commit 61397a60d98e368a5720b37e83f3169e3eb511c4)

Related: #1678641

src/libsystemd/sd-bus/bus-internal.c
src/libsystemd/sd-bus/bus-internal.h

index 7bb653338dd46e021b72a8c883f57f054c40aeeb..35e0b668ee18a8f0e847a0a18525dd48685d5c5d 100644 (file)
@@ -45,7 +45,7 @@ bool object_path_is_valid(const char *p) {
         if (slash)
                 return false;
 
-        return true;
+        return (q - p) <= BUS_PATH_SIZE_MAX;
 }
 
 char* object_path_startswith(const char *a, const char *b) {
index 2087ef8eeb63dd1495d02b17c300dad08f200da1..90e60289833c84a2e1a9098bcb790132fecea1cf 100644 (file)
@@ -333,6 +333,10 @@ struct sd_bus {
 
 #define BUS_MESSAGE_SIZE_MAX (128*1024*1024)
 #define BUS_AUTH_SIZE_MAX (64*1024)
+/* Note that the D-Bus specification states that bus paths shall have no size limit. We enforce here one
+ * anyway, since truly unbounded strings are a security problem. The limit we pick is relatively large however,
+ * to not clash unnecessarily with real-life applications. */
+#define BUS_PATH_SIZE_MAX (64*1024)
 
 #define BUS_CONTAINER_DEPTH 128