Skip to content

Commit 467a726

Browse files
Werkovhtejun
authored andcommitted
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 24f6008 ("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. Fixes: 24f6008 ("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: Michal Koutný <mkoutny@suse.com> Reviewed-by: Masami Ichikawa(CIP) <masami.ichikawa@cybertrust.co.jp> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 6d3971d commit 467a726

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

kernel/cgroup/cgroup-v1.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,15 +546,17 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
546546
char *buf, size_t nbytes, loff_t off)
547547
{
548548
struct cgroup *cgrp;
549+
struct cgroup_file_ctx *ctx;
549550

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

552553
/*
553554
* Release agent gets called with all capabilities,
554555
* require capabilities to set release agent.
555556
*/
556-
if ((of->file->f_cred->user_ns != &init_user_ns) ||
557-
!capable(CAP_SYS_ADMIN))
557+
ctx = of->priv;
558+
if ((ctx->ns->user_ns != &init_user_ns) ||
559+
!file_ns_capable(of->file, &init_user_ns, CAP_SYS_ADMIN))
558560
return -EPERM;
559561

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

0 commit comments

Comments
 (0)