From: "Masami Ichikawa" <masami256@gmail.com>
To: cip-dev@lists.cip-project.org
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
"Tabitha Sable" <tabitha.c.sable@gmail.com>,
stable@vger.kernel.org, "Tejun Heo" <tj@kernel.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Masami Ichikawa" <masami.ichikawa@cybertrust.co.jp>
Subject: [PATCH for 4.4.y-cip] cgroup-v1: Require capabilities to set release_agent
Date: Wed, 16 Feb 2022 08:40:37 +0900 [thread overview]
Message-ID: <20220215234036.19800-1-masami256@gmail.com> (raw)
From: "Eric W. Biederman" <ebiederm@xmission.com>
commit 24f6008564183aa120d07c03d9289519c2fe02af upstream.
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 <tabitha.c.sable@gmail.com>
Tested-by: Tabitha Sable <tabitha.c.sable@gmail.com>
Fixes: 81a6a5cdd2c5 ("Task Control Groups: automatic userspace notification of idle cgroups")
Cc: stable@vger.kernel.org # v2.6.24+
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
[mkoutny: Adjust for pre-fs_context, duplicate mount/remount check, drop log messages.]
Acked-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[masami: Backport patch from 4.9. Adjust to use current_user_ns() to get current user_ns.
Fix conflict in cgroup_release_agent_write().]
Reference: CVE-2022-0492
Signed-off-by: Masami Ichikawa(CIP) <masami.ichikawa@cybertrust.co.jp>
---
kernel/cgroup.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 1f5e7dcbfd40..af521a3da21c 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1786,6 +1786,13 @@ static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data)
pr_warn("option changes via remount are deprecated (pid=%d comm=%s)\n",
task_tgid_nr(current), current->comm);
+ /* See cgroup_mount release_agent handling */
+ if (opts.release_agent &&
+ ((current_user_ns() != &init_user_ns) || !capable(CAP_SYS_ADMIN))) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
+
added_mask = opts.subsys_mask & ~root->subsys_mask;
removed_mask = root->subsys_mask & ~opts.subsys_mask;
@@ -2135,6 +2142,16 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
goto out_unlock;
}
+ /*
+ * Release agent gets called with all capabilities,
+ * require capabilities to set release agent.
+ */
+ if (opts.release_agent &&
+ ((current_user_ns() != &init_user_ns) || !capable(CAP_SYS_ADMIN))) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
+
root = kzalloc(sizeof(*root), GFP_KERNEL);
if (!root) {
ret = -ENOMEM;
@@ -2839,6 +2856,14 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
+ /*
+ * 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))
+ return -EPERM;
+
cgrp = cgroup_kn_lock_live(of->kn);
if (!cgrp)
return -ENODEV;
--
2.35.1
next reply other threads:[~2022-02-15 23:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-15 23:40 Masami Ichikawa [this message]
2022-02-16 12:11 ` [PATCH for 4.4.y-cip] cgroup-v1: Require capabilities to set release_agent Michal Koutný
2022-02-17 2:17 ` Masami Ichikawa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220215234036.19800-1-masami256@gmail.com \
--to=masami256@gmail.com \
--cc=cip-dev@lists.cip-project.org \
--cc=ebiederm@xmission.com \
--cc=gregkh@linuxfoundation.org \
--cc=masami.ichikawa@cybertrust.co.jp \
--cc=mkoutny@suse.com \
--cc=stable@vger.kernel.org \
--cc=tabitha.c.sable@gmail.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox