CHROMIUM: remove Android's cgroup generic permissions checks

The implementation is utterly broken, resulting in all processes being
allows to move tasks between sets (as long as they have access to the
"tasks" attribute), and upstream is heading towards checking only
capability anyway, so let's get rid of this code.

BUG=b:31790445,chromium:647994
TEST=Boot android container, examine logcat

Change-Id: I2f780a5992c34e52a8f2d0b3557fc9d490da2779
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/394967
Reviewed-by: Ricky Zhou <rickyz@chromium.org>
Reviewed-by: John Stultz <john.stultz@linaro.org>
This commit is contained in:
Dmitry Torokhov 2016-10-06 15:53:38 -07:00 committed by John Stultz
parent 663cc53952
commit e78f134a78
6 changed files with 2 additions and 92 deletions

View file

@ -578,15 +578,6 @@ is completely unused; @cgrp->parent is still valid. (Note - can also
be called for a newly-created cgroup if an error occurs after this be called for a newly-created cgroup if an error occurs after this
subsystem's create() method has been called for the new cgroup). subsystem's create() method has been called for the new cgroup).
int allow_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
(cgroup_mutex held by caller)
Called prior to moving a task into a cgroup; if the subsystem
returns an error, this will abort the attach operation. Used
to extend the permission checks - if all subsystems in a cgroup
return 0, the attach will be allowed to proceed, even if the
default permission check (root or same user) fails.
int can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) int can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
(cgroup_mutex held by caller) (cgroup_mutex held by caller)

View file

@ -422,7 +422,6 @@ struct cgroup_subsys {
void (*css_reset)(struct cgroup_subsys_state *css); void (*css_reset)(struct cgroup_subsys_state *css);
void (*css_e_css_changed)(struct cgroup_subsys_state *css); void (*css_e_css_changed)(struct cgroup_subsys_state *css);
int (*allow_attach)(struct cgroup_taskset *tset);
int (*can_attach)(struct cgroup_taskset *tset); int (*can_attach)(struct cgroup_taskset *tset);
void (*cancel_attach)(struct cgroup_taskset *tset); void (*cancel_attach)(struct cgroup_taskset *tset);
void (*attach)(struct cgroup_taskset *tset); void (*attach)(struct cgroup_taskset *tset);

View file

@ -528,16 +528,6 @@ static inline void pr_cont_cgroup_path(struct cgroup *cgrp)
pr_cont_kernfs_path(cgrp->kn); pr_cont_kernfs_path(cgrp->kn);
} }
/*
* Default Android check for whether the current process is allowed to move a
* task across cgroups, either because CAP_SYS_NICE is set or because the uid
* of the calling process is the same as the moved task or because we are
* running as root.
* Returns 0 if this is allowed, or -EACCES otherwise.
*/
int subsys_cgroup_allow_attach(struct cgroup_taskset *tset);
#else /* !CONFIG_CGROUPS */ #else /* !CONFIG_CGROUPS */
struct cgroup_subsys_state; struct cgroup_subsys_state;
@ -562,10 +552,6 @@ static inline void cgroup_free(struct task_struct *p) {}
static inline int cgroup_init_early(void) { return 0; } static inline int cgroup_init_early(void) { return 0; }
static inline int cgroup_init(void) { return 0; } static inline int cgroup_init(void) { return 0; }
static inline int subsys_cgroup_allow_attach(void *tset)
{
return -EINVAL;
}
#endif /* !CONFIG_CGROUPS */ #endif /* !CONFIG_CGROUPS */
#endif /* _LINUX_CGROUP_H */ #endif /* _LINUX_CGROUP_H */

View file

@ -2663,45 +2663,6 @@ static int cgroup_attach_task(struct cgroup *dst_cgrp,
return ret; return ret;
} }
int subsys_cgroup_allow_attach(struct cgroup_taskset *tset)
{
const struct cred *cred = current_cred(), *tcred;
struct task_struct *task;
struct cgroup_subsys_state *css;
if (capable(CAP_SYS_NICE))
return 0;
cgroup_taskset_for_each(task, css, tset) {
tcred = __task_cred(task);
if (current != task && !uid_eq(cred->euid, tcred->uid) &&
!uid_eq(cred->euid, tcred->suid))
return -EACCES;
}
return 0;
}
static int cgroup_allow_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
{
struct cgroup_subsys_state *css;
int i;
int ret;
for_each_css(css, i, cgrp) {
if (css->ss->allow_attach) {
ret = css->ss->allow_attach(tset);
if (ret)
return ret;
} else {
return -EACCES;
}
}
return 0;
}
static int cgroup_procs_write_permission(struct task_struct *task, static int cgroup_procs_write_permission(struct task_struct *task,
struct cgroup *dst_cgrp, struct cgroup *dst_cgrp,
struct kernfs_open_file *of) struct kernfs_open_file *of)
@ -2716,24 +2677,8 @@ static int cgroup_procs_write_permission(struct task_struct *task,
*/ */
if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) && if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) &&
!uid_eq(cred->euid, tcred->uid) && !uid_eq(cred->euid, tcred->uid) &&
!uid_eq(cred->euid, tcred->suid)) { !uid_eq(cred->euid, tcred->suid))
/* ret = -EACCES;
* if the default permission check fails, give each
* cgroup a chance to extend the permission check
*/
struct cgroup_taskset tset = {
.src_csets = LIST_HEAD_INIT(tset.src_csets),
.dst_csets = LIST_HEAD_INIT(tset.dst_csets),
.csets = &tset.src_csets,
};
struct css_set *cset;
cset = task_css_set(task);
list_add(&cset->mg_node, &tset.src_csets);
ret = cgroup_allow_attach(dst_cgrp, &tset);
list_del(&tset.src_csets);
if (ret)
ret = -EACCES;
}
if (!ret && cgroup_on_dfl(dst_cgrp)) { if (!ret && cgroup_on_dfl(dst_cgrp)) {
struct super_block *sb = of->file->f_path.dentry->d_sb; struct super_block *sb = of->file->f_path.dentry->d_sb;

View file

@ -8935,7 +8935,6 @@ struct cgroup_subsys cpu_cgrp_subsys = {
.fork = cpu_cgroup_fork, .fork = cpu_cgroup_fork,
.can_attach = cpu_cgroup_can_attach, .can_attach = cpu_cgroup_can_attach,
.attach = cpu_cgroup_attach, .attach = cpu_cgroup_attach,
.allow_attach = subsys_cgroup_allow_attach,
.legacy_cftypes = cpu_files, .legacy_cftypes = cpu_files,
.early_init = 1, .early_init = 1,
}; };

View file

@ -4879,11 +4879,6 @@ static int mem_cgroup_can_attach(struct cgroup_taskset *tset)
return ret; return ret;
} }
static int mem_cgroup_allow_attach(struct cgroup_taskset *tset)
{
return subsys_cgroup_allow_attach(tset);
}
static void mem_cgroup_cancel_attach(struct cgroup_taskset *tset) static void mem_cgroup_cancel_attach(struct cgroup_taskset *tset)
{ {
if (mc.to) if (mc.to)
@ -5045,10 +5040,6 @@ static int mem_cgroup_can_attach(struct cgroup_taskset *tset)
{ {
return 0; return 0;
} }
static int mem_cgroup_allow_attach(struct cgroup_taskset *tset)
{
return 0;
}
static void mem_cgroup_cancel_attach(struct cgroup_taskset *tset) static void mem_cgroup_cancel_attach(struct cgroup_taskset *tset)
{ {
} }
@ -5232,7 +5223,6 @@ struct cgroup_subsys memory_cgrp_subsys = {
.can_attach = mem_cgroup_can_attach, .can_attach = mem_cgroup_can_attach,
.cancel_attach = mem_cgroup_cancel_attach, .cancel_attach = mem_cgroup_cancel_attach,
.attach = mem_cgroup_move_task, .attach = mem_cgroup_move_task,
.allow_attach = mem_cgroup_allow_attach,
.bind = mem_cgroup_bind, .bind = mem_cgroup_bind,
.dfl_cftypes = memory_files, .dfl_cftypes = memory_files,
.legacy_cftypes = mem_cgroup_legacy_files, .legacy_cftypes = mem_cgroup_legacy_files,