diff options
-rw-r--r-- | kernel/cgroup.c | 18 | ||||
-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, 33 insertions, 9 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index c9483d8f6140..f3d6f30c8cd1 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -58,6 +58,7 @@ #include <linux/vmalloc.h> /* TODO: replace with more sophisticated array */ #include <linux/eventfd.h> #include <linux/poll.h> +#include <linux/capability.h> #include <asm/atomic.h> @@ -1722,6 +1723,14 @@ 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; } } } @@ -1821,7 +1830,6 @@ EXPORT_SYMBOL_GPL(cgroup_attach_task_all); static int attach_task_by_pid(struct cgroup *cgrp, u64 pid) { struct task_struct *tsk; - const struct cred *cred = current_cred(), *tcred; int ret; if (pid) { @@ -1831,14 +1839,6 @@ static int attach_task_by_pid(struct cgroup *cgrp, u64 pid) rcu_read_unlock(); return -ESRCH; } - - tcred = __task_cred(tsk); - if (cred->euid && - cred->euid != tcred->uid && - cred->euid != tcred->suid) { - rcu_read_unlock(); - return -EACCES; - } get_task_struct(tsk); rcu_read_unlock(); } else { diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c index ce71ed53e88f..8e4c614d9553 100644 --- a/kernel/cgroup_freezer.c +++ b/kernel/cgroup_freezer.c @@ -172,6 +172,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 b23c0979bbe7..328f1e7ed782 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c @@ -1383,6 +1383,13 @@ static int cpuset_can_attach(struct cgroup_subsys *ss, struct cgroup *cont, int ret; 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 bbf29d6dbc5c..39e1666fb72d 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -8725,6 +8725,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; |