dryang / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
923a60
From c043ae5b2ef2e1e437bf738bbf522799c6213230 Mon Sep 17 00:00:00 2001
923a60
From: Krzysztof Nowicki <krzysztof.a.nowicki+github@gmail.com>
923a60
Date: Thu, 30 Nov 2017 11:59:29 +0100
923a60
Subject: [PATCH] Fix SELinux labels in cgroup filesystem root directory
923a60
 (#7496)
923a60
923a60
When using SELinux with legacy cgroups the tmpfs on /sys/fs/cgroup is by
923a60
default labelled as tmpfs_t. This label is also inherited by the "cpu"
923a60
and "cpuacct" symbolic links. Unfortunately the policy expects them to
923a60
be labelled as cgroup_t, which is used for all the actual cgroup
923a60
filesystems. Failure to do so results in a stream of denials.
923a60
923a60
This state cannot be fixed reliably when the cgroup filesystem structure
923a60
is set-up as the SELinux policy is not yet loaded at this
923a60
moment. It also cannot be fixed later as the root of the cgroup
923a60
filesystem is remounted read-only. In order to fix it the root of the
923a60
cgroup filesystem needs to be temporary remounted read-write, relabelled
923a60
and remounted back read-only.
923a60
923a60
(cherry picked from commit 8739f23e3c26bbf8b0296421578e56daa63cbf4b)
923a60
---
923a60
 src/core/mount-setup.c | 10 +++++++++-
923a60
 1 file changed, 9 insertions(+), 1 deletion(-)
923a60
923a60
diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c
923a60
index 521545e5ce..7a2cae4a39 100644
923a60
--- a/src/core/mount-setup.c
923a60
+++ b/src/core/mount-setup.c
923a60
@@ -363,14 +363,22 @@ int mount_setup(bool loaded_policy) {
923a60
                 usec_t before_relabel, after_relabel;
923a60
                 char timespan[FORMAT_TIMESPAN_MAX];
923a60
 
923a60
+                mkdir_label("/run/systemd/policy-relabelling", 0755);
923a60
                 before_relabel = now(CLOCK_MONOTONIC);
923a60
 
923a60
                 nftw("/dev", nftw_cb, 64, FTW_MOUNT|FTW_PHYS|FTW_ACTIONRETVAL);
923a60
                 nftw("/run", nftw_cb, 64, FTW_MOUNT|FTW_PHYS|FTW_ACTIONRETVAL);
923a60
 
923a60
+                /* Temporarily remount the root cgroup filesystem to give it a proper label. */
923a60
+                (void) mount(NULL, "/sys/fs/cgroup", NULL, MS_REMOUNT, NULL);
923a60
+                label_fix("/sys/fs/cgroup", false, false);
923a60
+                nftw("/sys/fs/cgroup", nftw_cb, 64, FTW_MOUNT|FTW_PHYS|FTW_ACTIONRETVAL);
923a60
+                (void) mount(NULL, "/sys/fs/cgroup", NULL, MS_REMOUNT|MS_RDONLY, NULL);
923a60
+
923a60
                 after_relabel = now(CLOCK_MONOTONIC);
923a60
 
923a60
-                log_info("Relabelled /dev and /run in %s.",
923a60
+                mkdir_label("/run/systemd/policy-relabelled", 0755);
923a60
+                log_info("Relabelled /dev, /run and /sys/fs/cgroup in %s.",
923a60
                          format_timespan(timespan, sizeof(timespan), after_relabel - before_relabel, 0));
923a60
         }
923a60
 #endif