From nobody Sun Feb 8 09:11:18 2026 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C41A413E40F; Mon, 12 Aug 2024 07:45:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723448741; cv=none; b=omK2uaXj8/LMP7zh4TExF6JlGQX96BPdO2x70e+KZYvNw+eB2c3xvLliLU4/2CKogMEPhbARs3oouPAb2Sw7KeEuzDOt47ukrYOBKgOmB0FbthqZTRpOG45l/O55YKZ2wH0Ixn4kxlkscodZ7EZE+tm0EX/O6CiRllmhHSEHL/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723448741; c=relaxed/simple; bh=TKcMFQSeCQZWv/nWYsGRVTZl4PK3WoyJ8xphSu+459U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=br0Lo5TAgq/kTLpW6G7Gpiw+Uo3IAIYB5fWmtnly16msKbq+NtSG7H0pnAAOqFUmL00n6+jZcpb21nOfBC4YkDI2IxBiowEIxm8jT3vUrx2oukCq+ORW2gqpKTuzOhwDFerzZ6MEifMOyxKPu1tIVmGpdVrZ1a0rltbWErxHelw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4Wj5zF64l1z1S7c8; Mon, 12 Aug 2024 15:40:41 +0800 (CST) Received: from kwepemd100013.china.huawei.com (unknown [7.221.188.163]) by mail.maildlp.com (Postfix) with ESMTPS id 6B3F21A016C; Mon, 12 Aug 2024 15:45:31 +0800 (CST) Received: from huawei.com (10.67.174.121) by kwepemd100013.china.huawei.com (7.221.188.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 12 Aug 2024 15:45:30 +0800 From: Chen Ridong To: , , , , CC: , Subject: [PATCH -next 1/2] cgroup: update comment about delegation Date: Mon, 12 Aug 2024 07:37:45 +0000 Message-ID: <20240812073746.3070616-2-chenridong@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240812073746.3070616-1-chenridong@huawei.com> References: <20240812073746.3070616-1-chenridong@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100013.china.huawei.com (7.221.188.163) Content-Type: text/plain; charset="utf-8" There are three interfaces that delegatee was not allowed to write. However, cgroup.threads was missed at some place, just add it. Signed-off-by: Chen Ridong --- Documentation/admin-guide/cgroup-v2.rst | 6 +++--- kernel/cgroup/cgroup.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-= guide/cgroup-v2.rst index f2d1ec7d6aba..513fd142293c 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -534,9 +534,9 @@ Because the resource control interface files in a given= directory control the distribution of the parent's resources, the delegatee shouldn't be allowed to write to them. For the first method, this is achieved by not granting access to these files. For the second, the -kernel rejects writes to all files other than "cgroup.procs" and -"cgroup.subtree_control" on a namespace root from inside the -namespace. +kernel rejects writes to all files other than "cgroup.procs", +"cgroup.threads" and "cgroup.subtree_control" on a namespace +root from inside the namespace. =20 The end results are equivalent for both delegation types. Once delegated, the user can build sub-hierarchy under the directory, diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index a3fa645f8433..8dbe00000fd4 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -4131,7 +4131,7 @@ static ssize_t cgroup_file_write(struct kernfs_open_f= ile *of, char *buf, * If namespaces are delegation boundaries, disallow writes to * files in an non-init namespace root from inside the namespace * except for the files explicitly marked delegatable - - * cgroup.procs and cgroup.subtree_control. + * cgroup.procs, cgroup.threads and cgroup.subtree_control. */ if ((cgrp->root->flags & CGRP_ROOT_NS_DELEGATE) && !(cft->flags & CFTYPE_NS_DELEGATABLE) && --=20 2.34.1 From nobody Sun Feb 8 09:11:18 2026 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AECF13E40F; Mon, 12 Aug 2024 07:45:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723448737; cv=none; b=Q2i1gI6el6eVWfBBl0CiNuqX6WKq3rEmwOfC5nstyAUtAE3JsL3sx/iLVaGRhQjlaKDngcwYXeaHyvAwwj1YWdHl6UdQPaBQS1XFORjYFsJ/B5arsyM4VEqm9u+/3iLF2lND5OwPv1K2dg8NPQZMOUWx4ZrUOAVVXSLJa6iP8wM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723448737; c=relaxed/simple; bh=WsrhgyVIDSbIDkdI/1g/lmrLmkheDEr9RdTZOc2jwJo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uOTz5ke07mOMQmYwV4uvqJl6kFf71QasIFekhxgV+Ojg0hjiOZHfMcf5Kh8B3pIES0pM6NM8GLX1e4YPK3qgW4H87AcaMaZedmc9PpNfFiyszcY1lLduakZyhEumxJ8Ypi+CQxgPTZeL/n5piUn82Cq611VM+jk2qm5b+QApSbU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Wj63L26hSzpTQL; Mon, 12 Aug 2024 15:44:14 +0800 (CST) Received: from kwepemd100013.china.huawei.com (unknown [7.221.188.163]) by mail.maildlp.com (Postfix) with ESMTPS id C7A771402E2; Mon, 12 Aug 2024 15:45:31 +0800 (CST) Received: from huawei.com (10.67.174.121) by kwepemd100013.china.huawei.com (7.221.188.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 12 Aug 2024 15:45:31 +0800 From: Chen Ridong To: , , , , CC: , Subject: [PATCH -next 2/2] cgroup: Disallow delegatee to write all interfaces outsize of cgroup ns Date: Mon, 12 Aug 2024 07:37:46 +0000 Message-ID: <20240812073746.3070616-3-chenridong@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240812073746.3070616-1-chenridong@huawei.com> References: <20240812073746.3070616-1-chenridong@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd100013.china.huawei.com (7.221.188.163) Content-Type: text/plain; charset="utf-8" The delegatee shouldn't be allowed to write to the resource control interface files. The kernel rejects writes to all files other than "cgroup.procs", "cgroup.threads" and "cgroup.subtree_control" on a namespace root from inside the namespace. However, delegatee can write "cgroup.subtree_control" outsize of the namespace, this can be reproduced by as follows: cd /sys/fs/cgroup echo '+pids' > cgroup.subtree_control mkdir dlgt_grp_ns echo '+pids' > dlgt_grp_ns/cgroup.subtree_control mkdir dlgt_grp_ns/dlgt_grp_ns1 echo $$ > dlgt_grp_ns/dlgt_grp_ns1/cgroup.procs echo 200 > dlgt_grp_ns/dlgt_grp_ns1/pids.max unshare -Cm /bin/bash echo max > dlgt_grp_ns/dlgt_grp_ns1/pids.max // Permission denied echo -pids > dlgt_grp_ns/cgroup.subtree_control // pids was unlimited now We set pids.max to 200 in the cgroup dlgt_grp_ns1, and we created a new cgroup namespace. The delegatee can't write to dlgt_grp_ns/dlgt_grp_ns1/pids.max. However, delegatee can write to dlgt_grp_ns/cgroup.subtree_control, which is outside of the cgroup namespace, and this invalided the pids limitation. Cgroup namespaces, as delegation boundaries, should disallow the delegatee to write all interfaces outside of the cgroup namespace. Fixes: 5136f6365ce3 ("cgroup: implement "nsdelegate" mount option") Signed-off-by: Chen Ridong --- kernel/cgroup/cgroup.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 8dbe00000fd4..1ef9413c02e3 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -4134,8 +4134,10 @@ static ssize_t cgroup_file_write(struct kernfs_open_= file *of, char *buf, * cgroup.procs, cgroup.threads and cgroup.subtree_control. */ if ((cgrp->root->flags & CGRP_ROOT_NS_DELEGATE) && - !(cft->flags & CFTYPE_NS_DELEGATABLE) && - ctx->ns !=3D &init_cgroup_ns && ctx->ns->root_cset->dfl_cgrp =3D=3D c= grp) + ctx->ns !=3D &init_cgroup_ns && + (!cgroup_is_descendant(cgrp, ctx->ns->root_cset->dfl_cgrp) || + (!(cft->flags & CFTYPE_NS_DELEGATABLE) && + ctx->ns->root_cset->dfl_cgrp =3D=3D cgrp))) return -EPERM; =20 if (cft->write) --=20 2.34.1