mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aleksa Sarai <asarai@suse.de>
To: Tejun Heo <tj@kernel.org>, Li Zefan <lizefan@huawei.com>,
	Johannes Weiner <hannes@cmpxchg.org>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>,
	Aleksa Sarai <cyphar@cyphar.com>,
	cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
	dev@opencontainers.org, Aleksa Sarai <asarai@suse.de>
Subject: [PATCH v4 1/2] cgroup: make cgroup.procs permissions userns-aware
Date: Sat, 14 May 2016 13:19:59 +1000	[thread overview]
Message-ID: <1463196000-13900-2-git-send-email-asarai@suse.de> (raw)
In-Reply-To: <1463196000-13900-1-git-send-email-asarai@suse.de>

Instead of comparing the thread's euid to GLOBAL_ROOT_UID, use
capabilities to check the additional privileges required to migrate
processes between cgroups. In addition, add further permissions to
cgroup namespaces where:

* Both tasks are in the same cgroup namespace; and
* The current task has CAP_SYS_ADMIN in the target task's user namespace
  well as in the user namespace the cgroup namespace was created in.
  This essentially requires all of the namespaces to to be the same.

This allows for subtree management of processes in a cgroup namespace,
by a process that is in a user namespace.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
---
 kernel/cgroup.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 86cb5c6e8932..f1c798b69561 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -2841,6 +2841,8 @@ static int cgroup_procs_write_permission(struct task_struct *task,
 					 struct cgroup *dst_cgrp,
 					 struct kernfs_open_file *of)
 {
+	struct cgroup_namespace *ns = current->nsproxy->cgroup_ns;
+	struct cgroup_namespace *tns = task->nsproxy->cgroup_ns;
 	const struct cred *cred = current_cred();
 	const struct cred *tcred = get_task_cred(task);
 	int ret = 0;
@@ -2850,6 +2852,10 @@ static int cgroup_procs_write_permission(struct task_struct *task,
 	 * need to check permissions on one of them.
 	 */
 	if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
+	    !capable(CAP_SYS_ADMIN) &&
+	    !(ns == tns && ns_capable(tcred->user_ns, CAP_SYS_ADMIN) &&
+	      ns_capable(cred->user_ns, CAP_SYS_ADMIN) &&
+	      ns_capable(ns->user_ns, CAP_SYS_ADMIN)) &&
 	    !uid_eq(cred->euid, tcred->uid) &&
 	    !uid_eq(cred->euid, tcred->suid))
 		ret = -EACCES;
-- 
2.8.2

  reply	other threads:[~2016-05-14  3:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-14  3:19 [PATCH v4 0/2] cgroup: allow management of subtrees by new cgroup namespaces Aleksa Sarai
2016-05-14  3:19 ` Aleksa Sarai [this message]
2016-05-14  3:20 ` [PATCH v4 2/2] cgroup: implement subtree creation on copy_cgroup_ns() Aleksa Sarai
2016-05-20 14:48 ` [PATCH v4 0/2] cgroup: allow management of subtrees by new cgroup namespaces Aleksa Sarai
2016-05-20 15:22   ` Tejun Heo
2016-05-20 15:30     ` James Bottomley
2016-05-20 16:03       ` Tejun Heo
2016-05-20 16:09         ` James Bottomley
2016-05-20 16:17           ` Tejun Heo
2016-05-20 16:25             ` James Bottomley
2016-05-20 16:29               ` Aleksa Sarai
2016-05-20 16:53               ` Tejun Heo
2016-05-20 17:28                 ` James Bottomley
2016-05-20 17:49                   ` Tejun Heo
2016-05-28  5:12                     ` Aleksa Sarai
2016-05-31 18:18                       ` Tejun Heo
2016-05-20 17:33                 ` W. Trevor King
2016-05-20 17:33               ` Aditya Kali
2016-05-20 17:50                 ` James Bottomley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1463196000-13900-2-git-send-email-asarai@suse.de \
    --to=asarai@suse.de \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=cgroups@vger.kernel.org \
    --cc=cyphar@cyphar.com \
    --cc=dev@opencontainers.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®