]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: when in hybrid mode, chown() both the legacy and the unified hierarchy to...
authorLennart Poettering <lennart@poettering.net>
Tue, 28 Nov 2017 16:58:00 +0000 (17:58 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 5 Dec 2017 12:49:13 +0000 (13:49 +0100)
If user namespacing is used, let's make sure that the root user in the
container gets access to both /sys/fs/cgroup/systemd and
/sys/fs/cgroup/unified.

This matches similar logic in cg_set_access().

src/nspawn/nspawn-cgroup.c
src/nspawn/nspawn-cgroup.h
src/nspawn/nspawn.c

index 4b07b38163d7bb9d011923a290d9df9e3e4259a9..d51585a6524fb7394497cc03ff99d8dc39369e30 100644 (file)
@@ -57,7 +57,7 @@ static int chown_cgroup_path(const char *path, uid_t uid_shift) {
         return 0;
 }
 
-int chown_cgroup(pid_t pid, uid_t uid_shift) {
+int chown_cgroup(pid_t pid, CGroupUnified unified_requested, uid_t uid_shift) {
         _cleanup_free_ char *path = NULL, *fs = NULL;
         int r;
 
@@ -73,6 +73,19 @@ int chown_cgroup(pid_t pid, uid_t uid_shift) {
         if (r < 0)
                 return log_error_errno(r, "Failed to chown() cgroup %s: %m", fs);
 
+        if (unified_requested == CGROUP_UNIFIED_SYSTEMD) {
+                _cleanup_free_ char *lfs = NULL;
+                /* Always propagate access rights from unified to legacy controller */
+
+                r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path, NULL, &lfs);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to get file system path for container cgroup: %m");
+
+                r = chown_cgroup_path(lfs, uid_shift);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to chown() cgroup %s: %m", lfs);
+        }
+
         return 0;
 }
 
index e66a85484315bf6eda2b962146e793312304ff62..3855e5b4eaafc73a54433d725afb62cc5acb4caa 100644 (file)
@@ -25,6 +25,6 @@
 
 #include "cgroup-util.h"
 
-int chown_cgroup(pid_t pid, uid_t uid_shift);
+int chown_cgroup(pid_t pid, CGroupUnified unified_requested, uid_t uid_shift);
 int sync_cgroup(pid_t pid, CGroupUnified unified_requested, uid_t uid_shift);
 int create_subcgroup(pid_t pid, CGroupUnified unified_requested);
index dfe48bcf56a6e125ac01ff43c464e6542a92a4e6..ccf5418ceb67372714d11463dd5fc7dd8e81d948 100644 (file)
@@ -3619,7 +3619,7 @@ static int run(int master,
                         return r;
         }
 
-        r = chown_cgroup(*pid, arg_uid_shift);
+        r = chown_cgroup(*pid, arg_unified_cgroup_hierarchy, arg_uid_shift);
         if (r < 0)
                 return r;