* [PATCH] cgroup-v1: Correct privileges check in release_agent writes
@ 2022-02-17 16:11 Michal Koutný
2022-02-18 1:06 ` Masami Ichikawa(CIP)
2022-02-22 18:13 ` Tejun Heo
0 siblings, 2 replies; 3+ messages in thread
From: Michal Koutný @ 2022-02-17 16:11 UTC (permalink / raw)
To: Eric W. Biederman
Cc: Masami Ichikawa, Tabitha Sable, Tejun Heo, Zefan Li,
Johannes Weiner, stable, cgroups, linux-kernel
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.
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: Michal Koutný <mkoutny@suse.com>
---
kernel/cgroup/cgroup-v1.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c
index 0e877dbcfeea..afc6c0e9c966 100644
--- a/kernel/cgroup/cgroup-v1.c
+++ b/kernel/cgroup/cgroup-v1.c
@@ -546,6 +546,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);
@@ -553,8 +554,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);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] cgroup-v1: Correct privileges check in release_agent writes
2022-02-17 16:11 [PATCH] cgroup-v1: Correct privileges check in release_agent writes Michal Koutný
@ 2022-02-18 1:06 ` Masami Ichikawa(CIP)
2022-02-22 18:13 ` Tejun Heo
1 sibling, 0 replies; 3+ messages in thread
From: Masami Ichikawa(CIP) @ 2022-02-18 1:06 UTC (permalink / raw)
To: Michal Koutný
Cc: Eric W. Biederman, Masami Ichikawa, Tabitha Sable, Tejun Heo,
Zefan Li, Johannes Weiner, stable, cgroups, linux-kernel
On Fri, Feb 18, 2022 at 1:11 AM Michal Koutný <mkoutny@suse.com> wrote:
>
> 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.
>
> 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: Michal Koutný <mkoutny@suse.com>
> ---
> kernel/cgroup/cgroup-v1.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c
> index 0e877dbcfeea..afc6c0e9c966 100644
> --- a/kernel/cgroup/cgroup-v1.c
> +++ b/kernel/cgroup/cgroup-v1.c
> @@ -546,6 +546,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);
>
> @@ -553,8 +554,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);
> --
> 2.34.1
Thank you. Looks good to me.
Reviewed-by: Masami Ichikawa(CIP) <masami.ichikawa@cybertrust.co.jp>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cgroup-v1: Correct privileges check in release_agent writes
2022-02-17 16:11 [PATCH] cgroup-v1: Correct privileges check in release_agent writes Michal Koutný
2022-02-18 1:06 ` Masami Ichikawa(CIP)
@ 2022-02-22 18:13 ` Tejun Heo
1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2022-02-22 18:13 UTC (permalink / raw)
To: Michal Koutný
Cc: Eric W. Biederman, Masami Ichikawa, Tabitha Sable, Zefan Li,
Johannes Weiner, stable, cgroups, linux-kernel
On Thu, Feb 17, 2022 at 05:11:28PM +0100, Michal Koutný wrote:
> 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.
>
> 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: Michal Koutný <mkoutny@suse.com>
Applied to cgroup/for-5.17-fixes.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-22 18:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-17 16:11 [PATCH] cgroup-v1: Correct privileges check in release_agent writes Michal Koutný
2022-02-18 1:06 ` Masami Ichikawa(CIP)
2022-02-22 18:13 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).