FAILED: patch "[PATCH] cgroup-v1: Correct privileges check in release_agent writes" failed to apply to 4.19-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 4.19-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 467a726b754f474936980da793b4ff2ec3e382a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20Koutn=C3=BD?= <[email protected]>
Date: Thu, 17 Feb 2022 17:11:28 +0100
Subject: [PATCH] cgroup-v1: Correct privileges check in release_agent writes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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.
kernel/cgroup/cgroup-v1.c +4 -2
@@ -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);