teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0854-manager-limit-access-to-private-dbus-socket.patch

6f381c
From 004130ae74688eb321aadc05192bab69fe5cbcbf Mon Sep 17 00:00:00 2001
6f381c
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
6f381c
Date: Fri, 22 Jul 2022 11:45:12 +0200
6f381c
Subject: [PATCH] manager: limit access to private dbus socket
6f381c
6f381c
For the system manager, /run/systemd/private is publicly accessible, because
6f381c
/run/systemd is 0755, and /run/systemd/private is 0777. For the user manager,
6f381c
/run/user/<uid> is 0700, and /run/user/<uid>/systemd/private is 0777. This
6f381c
does not directly cause any security issue because we check the sender in
6f381c
bus_check_peercred (ucred.uid != 0 && ucred.uid != geteuid()).
6f381c
6f381c
But it makes sense to limit access to the socket to avoid wasting time in PID1.
6f381c
Somebody could send messages there that'd we'd reject anyway. It also makes
6f381c
things more explicit.
6f381c
6f381c
(cherry picked from commit df1cbd1adf26071aab41d96e054452a3d66103a4)
6f381c
6f381c
Resolves: #2119405
6f381c
---
6f381c
 src/core/dbus.c | 4 +++-
6f381c
 1 file changed, 3 insertions(+), 1 deletion(-)
6f381c
6f381c
diff --git a/src/core/dbus.c b/src/core/dbus.c
6f381c
index 66d838cdb4..ec6c52cb85 100644
6f381c
--- a/src/core/dbus.c
6f381c
+++ b/src/core/dbus.c
6f381c
@@ -42,6 +42,7 @@
6f381c
 #include "string-util.h"
6f381c
 #include "strv.h"
6f381c
 #include "strxcpyx.h"
6f381c
+#include "umask-util.h"
6f381c
 #include "user-util.h"
6f381c
 
6f381c
 #define CONNECTIONS_MAX 4096
6f381c
@@ -1019,7 +1020,8 @@ int bus_init_private(Manager *m) {
6f381c
         if (fd < 0)
6f381c
                 return log_error_errno(errno, "Failed to allocate private socket: %m");
6f381c
 
6f381c
-        r = bind(fd, &sa.sa, salen);
6f381c
+        RUN_WITH_UMASK(0077)
6f381c
+                r = bind(fd, &sa.sa, salen);
6f381c
         if (r < 0)
6f381c
                 return log_error_errno(errno, "Failed to bind private socket: %m");
6f381c