summary refs log tree commit diff
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorAditya Kali <adityakali@google.com>2016-01-29 02:54:07 -0600
committerTejun Heo <tj@kernel.org>2016-02-16 13:04:58 -0500
commita0530e087e648263f81a81d62ca020f66b54bcb0 (patch)
tree64b8708f51ebfb707a0f825c397315837c86394b /kernel/cgroup.c
parenta79a908fd2b080977b45bf103184b81c9d11ad07 (diff)
downloadlinux-a0530e087e648263f81a81d62ca020f66b54bcb0.tar.gz
cgroup: cgroup namespace setns support
setns on a cgroup namespace is allowed only if
task has CAP_SYS_ADMIN in its current user-namespace and
over the user-namespace associated with target cgroupns.
No implicit cgroup changes happen with attaching to another
cgroupns. It is expected that the somone moves the attaching
process under the target cgroupns-root.

Signed-off-by: Aditya Kali <adityakali@google.com>
Signed-off-by: Serge E. Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index b001c5d36bec..b086a461be23 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -6057,10 +6057,23 @@ static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns)
 	return container_of(ns, struct cgroup_namespace, ns);
 }
 
-static int cgroupns_install(struct nsproxy *nsproxy, void *ns)
+static int cgroupns_install(struct nsproxy *nsproxy, struct ns_common *ns)
 {
-	pr_info("setns not supported for cgroup namespace");
-	return -EINVAL;
+	struct cgroup_namespace *cgroup_ns = to_cg_ns(ns);
+
+	if (!ns_capable(current_user_ns(), CAP_SYS_ADMIN) ||
+	    !ns_capable(cgroup_ns->user_ns, CAP_SYS_ADMIN))
+		return -EPERM;
+
+	/* Don't need to do anything if we are attaching to our own cgroupns. */
+	if (cgroup_ns == nsproxy->cgroup_ns)
+		return 0;
+
+	get_cgroup_ns(cgroup_ns);
+	put_cgroup_ns(nsproxy->cgroup_ns);
+	nsproxy->cgroup_ns = cgroup_ns;
+
+	return 0;
 }
 
 static struct ns_common *cgroupns_get(struct task_struct *task)