Skip to content

Commit 24f6008

Browse files
ebiedermhtejun
authored andcommitted
cgroup-v1: Require capabilities to set release_agent
The cgroup release_agent is called with call_usermodehelper. The function call_usermodehelper starts the release_agent with a full set fo capabilities. Therefore require capabilities when setting the release_agaent. Reported-by: Tabitha Sable <[email protected]> Tested-by: Tabitha Sable <[email protected]> Fixes: 81a6a5c ("Task Control Groups: automatic userspace notification of idle cgroups") Cc: [email protected] # v2.6.24+ Signed-off-by: "Eric W. Biederman" <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent c80d401 commit 24f6008

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

kernel/cgroup/cgroup-v1.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,14 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
549549

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

552+
/*
553+
* Release agent gets called with all capabilities,
554+
* require capabilities to set release agent.
555+
*/
556+
if ((of->file->f_cred->user_ns != &init_user_ns) ||
557+
!capable(CAP_SYS_ADMIN))
558+
return -EPERM;
559+
552560
cgrp = cgroup_kn_lock_live(of->kn, false);
553561
if (!cgrp)
554562
return -ENODEV;
@@ -954,6 +962,12 @@ int cgroup1_parse_param(struct fs_context *fc, struct fs_parameter *param)
954962
/* Specifying two release agents is forbidden */
955963
if (ctx->release_agent)
956964
return invalfc(fc, "release_agent respecified");
965+
/*
966+
* Release agent gets called with all capabilities,
967+
* require capabilities to set release agent.
968+
*/
969+
if ((fc->user_ns != &init_user_ns) || !capable(CAP_SYS_ADMIN))
970+
return invalfc(fc, "Setting release_agent not allowed");
957971
ctx->release_agent = param->string;
958972
param->string = NULL;
959973
break;

0 commit comments

Comments
 (0)