Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f644f482 authored by Michal Koutný's avatar Michal Koutný Committed by Lee Jones
Browse files

UPSTREAM: cgroup-v1: Correct privileges check in release_agent writes

The idea is to check: a) the owning user_ns of cgroup_ns, b)
capabilities in init_user_ns.

The commit 24f600856418 ("cgroup-v1: Require capabilities to set
release_agent") got this wrong in the write handler of release_agent
since it checked user_ns of the opener (may be different from the owning
user_ns of cgroup_ns).
Secondly, to avoid possibly confused deputy, the capability of the
opener must be checked.

Bug: 254441685
Fixes: 24f600856418 ("cgroup-v1: Require capabilities to set release_agent")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/stable/20220216121142.GB30035@blackbody.suse.cz/


Signed-off-by: default avatarMichal Koutný <mkoutny@suse.com>
Reviewed-by: default avatarMasami Ichikawa(CIP) <masami.ichikawa@cybertrust.co.jp>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
(cherry picked from commit 467a726b754f474936980da793b4ff2ec3e382a7)
Signed-off-by: default avatarLee Jones <joneslee@google.com>
Change-Id: I486cd82ec93faca71107dcdc21de6f8aa422daf5
parent cb59d054
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -552,6 +552,7 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
					  char *buf, size_t nbytes, loff_t off)
{
	struct cgroup *cgrp;
	struct cgroup_file_ctx *ctx;

	BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);

@@ -559,8 +560,9 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
	 * Release agent gets called with all capabilities,
	 * require capabilities to set release agent.
	 */
	if ((of->file->f_cred->user_ns != &init_user_ns) ||
	    !capable(CAP_SYS_ADMIN))
	ctx = of->priv;
	if ((ctx->ns->user_ns != &init_user_ns) ||
	    !file_ns_capable(of->file, &init_user_ns, CAP_SYS_ADMIN))
		return -EPERM;

	cgrp = cgroup_kn_lock_live(of->kn, false);