diff options
author | San Mehat <san@google.com> | 2011-10-09 02:19:16 +0100 |
---|---|---|
committer | Andy Green <andy.green@linaro.org> | 2011-10-09 02:19:16 +0100 |
commit | 81b3729ae9e4285c3e0239ea718f09c3451836fa (patch) | |
tree | 53f8cf555de53c4e6f63c86b9e37deb76501539e /kernel | |
parent | 524328d68118289e76bdff02edc922c8e523a9b3 (diff) |
cgroup: Add generic cgroup subsystem permission checks.
Rather than using explicit euid == 0 checks when trying to move
tasks into a cgroup via CFS, move permission checks into each
specific cgroup subsystem. If a subsystem does not specify a
'can_attach' handler, then we fall back to doing our checks the old way.
This way non-root processes can add arbitrary processes to
a cgroup if all the registered subsystems on that cgroup agree.
Also change explicit euid == 0 check to CAP_SYS_ADMIN
Signed-off-by: San Mehat <san@google.com>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/cgroup.c | 10 | ||||
-rw-r--r-- | kernel/cgroup_freezer.c | 8 | ||||
-rw-r--r-- | kernel/cpuset.c | 7 | ||||
-rw-r--r-- | kernel/sched.c | 9 |
4 files changed, 34 insertions, 0 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 1d2b6ceea95..e06035aa303 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -60,6 +60,7 @@ #include <linux/eventfd.h> #include <linux/poll.h> #include <linux/flex_array.h> /* used in cgroup_attach_proc */ +#include <linux/capability.h> #include <linux/atomic.h> @@ -1842,6 +1843,15 @@ int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk) failed_ss = ss; goto out; } + } else if (!capable(CAP_SYS_ADMIN)) { + const struct cred *cred = current_cred(), *tcred; + + /* No can_attach() - check perms generically */ + tcred = __task_cred(tsk); + if (cred->euid != tcred->uid && + cred->euid != tcred->suid) { + return -EACCES; + } } if (ss->can_attach_task) { retval = ss->can_attach_task(cgrp, tsk); diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c index e691818d7e4..6ebda1df9b7 100644 --- a/kernel/cgroup_freezer.c +++ b/kernel/cgroup_freezer.c @@ -164,6 +164,14 @@ static int freezer_can_attach(struct cgroup_subsys *ss, { struct freezer *freezer; + if ((current != task) && (!capable(CAP_SYS_ADMIN))) { + const struct cred *cred = current_cred(), *tcred; + + tcred = __task_cred(task); + if (cred->euid != tcred->uid && cred->euid != tcred->suid) + return -EPERM; + } + /* * Anything frozen can't move or be moved to/from. */ diff --git a/kernel/cpuset.c b/kernel/cpuset.c index 10131fdaff7..3b2305163da 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c @@ -1373,6 +1373,13 @@ static int cpuset_can_attach(struct cgroup_subsys *ss, struct cgroup *cont, { struct cpuset *cs = cgroup_cs(cont); + if ((current != task) && (!capable(CAP_SYS_ADMIN))) { + const struct cred *cred = current_cred(), *tcred; + + if (cred->euid != tcred->uid && cred->euid != tcred->suid) + return -EPERM; + } + if (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed)) return -ENOSPC; diff --git a/kernel/sched.c b/kernel/sched.c index d0f600c9484..279d2552dae 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -8967,6 +8967,15 @@ cpu_cgroup_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp) static int cpu_cgroup_can_attach_task(struct cgroup *cgrp, struct task_struct *tsk) { + if ((current != tsk) && (!capable(CAP_SYS_NICE))) { + const struct cred *cred = current_cred(), *tcred; + + tcred = __task_cred(tsk); + + if (cred->euid != tcred->uid && cred->euid != tcred->suid) + return -EPERM; + } + #ifdef CONFIG_RT_GROUP_SCHED if (!sched_rt_can_attach(cgroup_tg(cgrp), tsk)) return -EINVAL; |