From 360f347fc876df3a256b33f27c88949effb148e1 Mon Sep 17 00:00:00 2001 From: Alban Crequy Date: Wed, 16 Jul 2014 14:34:35 +0100 Subject: [PATCH 1/3] config: add new limit: max_connections_per_systemd_unit dbus-daemon already has the following limits: - max_completed_connections: (default|system bus)=2048 (session bus)=100000 - max_connections_per_user: (default|system bus)=256 (session bus)=100000 So an user on the system bus cannot use all connections and prevent other users from connecting to the bus. But this per-user granularity does not allow to distinguish different services running as the same user. If one service starts to use all the available connections due to a bug, the other will not be able to connect. To fix this issue, this patch introduces a new configurable limit: - max_connections_per_systemd_unit: (default|system bus)=256 (session bus)=100000 It relies on systemd, so it is compiled only on HAVE_SYSTEMD. Configuration files with max_connections_per_systemd_unit will be rejected if dbus is compiled without HAVE_SYSTEMD. Note that not all processes are part of a system unit. max_connections_per_systemd_unit will not restrict connections from a process which is not part of a system unit. The default values are large enough to avoid impacting current systems but an administrator could restrict it more. v3: - change max_connections_per_cgroup to max_connections_per_systemd_unit https://bugs.freedesktop.org/show_bug.cgi?id=81469 --- bus/bus.c | 6 ++++++ bus/bus.h | 2 ++ bus/config-parser.c | 10 ++++++++++ bus/session.conf.in | 1 + doc/dbus-daemon.1.xml.in | 3 +++ 5 files changed, 22 insertions(+) diff --git a/bus/bus.c b/bus/bus.c index edce063..8bc2e42 100644 --- a/bus/bus.c +++ b/bus/bus.c @@ -1249,6 +1249,12 @@ bus_context_get_max_incomplete_connections (BusContext *context) } int +bus_context_get_max_connections_per_systemd_unit (BusContext *context) +{ + return context->limits.max_connections_per_systemd_unit; +} + +int bus_context_get_max_connections_per_user (BusContext *context) { return context->limits.max_connections_per_user; diff --git a/bus/bus.h b/bus/bus.h index 2c4cec3..1db42c1 100644 --- a/bus/bus.h +++ b/bus/bus.h @@ -56,6 +56,7 @@ typedef struct int auth_timeout; /**< How long to wait for an authentication to time out */ int max_completed_connections; /**< Max number of authorized connections */ int max_incomplete_connections; /**< Max number of incomplete connections */ + int max_connections_per_systemd_unit; /**< Max number of connections with the same systemd unit */ int max_connections_per_user; /**< Max number of connections auth'd as same user */ int max_connections_per_process; /**< Max number of connections per process */ int max_pending_activations; /**< Max number of pending activations for the entire bus */ @@ -109,6 +110,7 @@ int bus_context_get_activation_timeout (BusContext int bus_context_get_auth_timeout (BusContext *context); int bus_context_get_max_completed_connections (BusContext *context); int bus_context_get_max_incomplete_connections (BusContext *context); +int bus_context_get_max_connections_per_systemd_unit (BusContext *context); int bus_context_get_max_connections_per_user (BusContext *context); int bus_context_get_max_connections_per_process (BusContext *context); int bus_context_get_max_pending_activations (BusContext *context); diff --git a/bus/config-parser.c b/bus/config-parser.c index 781d857..54404aa 100644 --- a/bus/config-parser.c +++ b/bus/config-parser.c @@ -441,6 +441,7 @@ bus_config_parser_new (const DBusString *basedir, parser->limits.auth_timeout = 30000; /* 30 seconds */ parser->limits.max_incomplete_connections = 64; + parser->limits.max_connections_per_systemd_unit = 256; parser->limits.max_connections_per_user = 256; parser->limits.max_connections_per_process = 8; @@ -1921,6 +1922,14 @@ set_limit (BusConfigParser *parser, must_be_int = TRUE; parser->limits.max_incomplete_connections = value; } +#ifdef HAVE_SYSTEMD + else if (strcmp (name, "max_connections_per_systemd_unit") == 0) + { + must_be_positive = TRUE; + must_be_int = TRUE; + parser->limits.max_connections_per_systemd_unit = value; + } +#endif else if (strcmp (name, "max_connections_per_user") == 0) { must_be_positive = TRUE; @@ -3117,6 +3126,7 @@ limits_equal (const BusLimits *a, || a->auth_timeout == b->auth_timeout || a->max_completed_connections == b->max_completed_connections || a->max_incomplete_connections == b->max_incomplete_connections + || a->max_connections_per_systemd_unit == b->max_connections_per_systemd_unit || a->max_connections_per_user == b->max_connections_per_user || a->max_connections_per_process == b->max_connections_per_process || a->max_pending_activations == b->max_pending_activations diff --git a/bus/session.conf.in b/bus/session.conf.in index cd799f7..4638668 100644 --- a/bus/session.conf.in +++ b/bus/session.conf.in @@ -54,6 +54,7 @@ 240000 100000 10000 + 100000 100000 8 10000 diff --git a/doc/dbus-daemon.1.xml.in b/doc/dbus-daemon.1.xml.in index af8ba9f..e75f5db 100644 --- a/doc/dbus-daemon.1.xml.in +++ b/doc/dbus-daemon.1.xml.in @@ -531,6 +531,9 @@ Available limit names are: "max_completed_connections" : max number of authenticated connections "max_incomplete_connections" : max number of unauthenticated connections + "max_connections_per_systemd_unit" : max number of completed connections from + the same systemd unit + with the lowest hierarchy id "max_connections_per_user" : max number of completed connections from the same user "max_connections_per_process": max number of completed connections from -- 1.8.5.3