Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759184AbaJaTTg (ORCPT ); Fri, 31 Oct 2014 15:19:36 -0400 Received: from mail-ig0-f202.google.com ([209.85.213.202]:33798 "EHLO mail-ig0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758965AbaJaTT0 (ORCPT ); Fri, 31 Oct 2014 15:19:26 -0400 From: Aditya Kali To: tj@kernel.org, lizefan@huawei.com, serge.hallyn@ubuntu.com, luto@amacapital.net, ebiederm@xmission.com, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, mingo@redhat.com Cc: containers@lists.linux-foundation.org, jnagal@google.com, Aditya Kali Subject: [PATCHv2 6/7] cgroup: cgroup namespace setns support Date: Fri, 31 Oct 2014 12:19:00 -0700 Message-Id: <1414783141-6947-7-git-send-email-adityakali@google.com> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1414783141-6947-1-git-send-email-adityakali@google.com> References: <1414783141-6947-1-git-send-email-adityakali@google.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- kernel/cgroup_namespace.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kernel/cgroup_namespace.c b/kernel/cgroup_namespace.c index 7e9bda0..0803575 100644 --- a/kernel/cgroup_namespace.c +++ b/kernel/cgroup_namespace.c @@ -86,8 +86,22 @@ err_out: static int cgroupns_install(struct nsproxy *nsproxy, void *ns) { - pr_info("setns not supported for cgroup namespace"); - return -EINVAL; + struct cgroup_namespace *cgroup_ns = ns; + + if (!ns_capable(current_user_ns(), CAP_SYS_ADMIN) || + !ns_capable(cgroup_ns->user_ns, CAP_SYS_ADMIN)) + return -EPERM; + + /* Prevent cgroup changes for this task. */ + threadgroup_lock(current); + + get_cgroup_ns(cgroup_ns); + put_cgroup_ns(nsproxy->cgroup_ns); + nsproxy->cgroup_ns = cgroup_ns; + + threadgroup_unlock(current); + + return 0; } static void *cgroupns_get(struct task_struct *task) -- 2.1.0.rc2.206.gedb03e5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/