summaryrefslogtreecommitdiff
path: root/bus
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2022-02-21 16:00:42 +0000
committerSimon McVittie <smcv@collabora.com>2022-02-22 19:26:58 +0000
commit2efb462466d628d47d7f80c5a8e864a62b6154cc (patch)
treecf7760cd93aaadf3e6bc73933ca57a60b06d9c8d /bus
parentc42bb64457c3b31e561ad9885c618e051af1171a (diff)
downloaddbus-2efb462466d628d47d7f80c5a8e864a62b6154cc.tar.gz
dbus-daemon-launch-helper: Reset Linux OOM score adjustment here
Previously, we were relying on the system bus being able to reset its OOM score adjustment after it forks, but before it execs the dbus-daemon-launch-helper. However, it can't actually do that (leading to dbus#378), because the system bus typically starts as root, uses its root privileges to adjust resource limits, and then drops privileges to the `@DBUS_USER@`, typically `dbus` or `messagebus`. This leaves the pseudo-files in /proc for its process parameters owned by root, and the `@DBUS_USER@` is not allowed to open them for writing. The dbus-daemon-launch-helper is setuid root, so it can certainly alter its OOM score adjustment before exec'ing the actual activated service. We need to do this before dropping privileges, because after dropping privileges we would be unable to write to this process parameter. This is a non-async-signal-safe context, so we can safely log errors here, unlike the fork-and-exec code paths. Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/378 Signed-off-by: Simon McVittie <smcv@collabora.com>
Diffstat (limited to 'bus')
-rw-r--r--bus/activation-helper.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/bus/activation-helper.c b/bus/activation-helper.c
index 8172b6cf..8a4fd732 100644
--- a/bus/activation-helper.c
+++ b/bus/activation-helper.c
@@ -32,6 +32,7 @@
#include "activation-helper.h"
#include "activation-exit-codes.h"
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -43,6 +44,7 @@
#include <dbus/dbus-misc.h>
#include <dbus/dbus-shell.h>
#include <dbus/dbus-marshal-validate.h>
+#include <dbus/dbus-sysdeps-unix.h>
static BusDesktopFile *
desktop_file_for_name (BusConfigParser *parser,
@@ -337,11 +339,17 @@ exec_for_correct_user (char *exec, char *user, DBusError *error)
char **argv;
int argc;
dbus_bool_t retval;
+ const char *error_str = NULL;
argc = 0;
retval = TRUE;
argv = NULL;
+ /* Resetting the OOM score adjustment is best-effort, so we don't
+ * treat a failure to do so as fatal. */
+ if (!_dbus_reset_oom_score_adj (&error_str))
+ _dbus_warn ("%s: %s", error_str, strerror (errno));
+
if (!switch_user (user, error))
return FALSE;