From: chenridong <chenridong@huawei.com>
To: "Michal Koutný" <mkoutny@suse.com>
Cc: <tj@kernel.org>, <lizefan.x@bytedance.com>, <hannes@cmpxchg.org>,
<longman@redhat.com>, <cgroups@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH -next 2/2] cgroup: Disallow delegatee to write all interfaces outsize of cgroup ns
Date: Tue, 13 Aug 2024 11:48:44 +0800 [thread overview]
Message-ID: <17f6eb65-e6c0-47be-b88a-e33819bbd66f@huawei.com> (raw)
In-Reply-To: <ex5gnhcoobbw74se4uchhqj2lsrcjx5bsh6m5lva2xmujv7uae@34vwukkwhkbc>
On 2024/8/13 0:57, Michal Koutný wrote:
> Hello.
>
> On Mon, Aug 12, 2024 at 07:37:46AM GMT, Chen Ridong <chenridong@huawei.com> wrote:
>> 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_ns1/pids.max // Permission denied
>> echo -pids > dlgt_grp_ns/cgroup.subtree_control // pids was unlimited now
>
> You could also have increased the ancestral limit (if there was any)
> echo max > dlgt_grp_ns/pids.max // similarly allowed
>
> If you're a root (or otherwise have sufficient permissions) and you can
> _see_ an ancestral cgroup, you can write to its attributes according to
> permissions. Thus the delegation works via cgroup ns (in)visibility but
> cgroup ns root is visible on both sides of the boundary hence the extra
> check.
>
> I can imagine that a container runtime process could enter the target
> cgroup ns while keeping visibility to the original cgroup ns and do some
> tuning on it before it drops any pointers to the original cgroup ns and
> exec's delegatee's workload. (But it's only my imagination to illustrate
> that this may be a breaking change.)
>
Yes, this is a change. However, the process within the container can
turn on subsystems , they can also turn off subsystems , which may not
only affect the host machine but may also affect other containers. I
believe this poses a danger.
> OTOH, I can see why this would be consistent with the migration rules
> that exist between sides of cgroup ns, so this could work if it was
> hidden behind (another) mount option like 'nsdelegate2' :-p
>
Hello, Michal, I am sorry I can not get your point.
Did you mean this issue should be fixed with another mount option
'nsdelegate2'? Or is the current patch acceptable?
>
>> @@ -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 != &init_cgroup_ns && ctx->ns->root_cset->dfl_cgrp == cgrp)
>> + ctx->ns != &init_cgroup_ns &&
>> + (!cgroup_is_descendant(cgrp, ctx->ns->root_cset->dfl_cgrp) ||
>> + (!(cft->flags & CFTYPE_NS_DELEGATABLE) &&
>> + ctx->ns->root_cset->dfl_cgrp == cgrp)))
>> return -EPERM;
>
> Could you please also update the comment above, to describe the boundary
> vs subtree delegation?
> Thanks,
> Michal
Sure.
Thanks
Ridong
next prev parent reply other threads:[~2024-08-13 3:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-12 7:37 [PATCH -next 0/2] Fixes about delegation Chen Ridong
2024-08-12 7:37 ` [PATCH -next 1/2] cgroup: update comment " Chen Ridong
2024-08-12 16:57 ` Michal Koutný
2024-08-12 7:37 ` [PATCH -next 2/2] cgroup: Disallow delegatee to write all interfaces outsize of cgroup ns Chen Ridong
2024-08-12 16:57 ` Michal Koutný
2024-08-13 3:48 ` chenridong [this message]
2024-08-13 19:02 ` Tejun Heo
2024-08-14 8:09 ` chenridong
2024-08-14 16:52 ` Tejun Heo
2024-08-15 0:50 ` chenridong
2024-08-13 1:35 ` Xiu Jianfeng
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=17f6eb65-e6c0-47be-b88a-e33819bbd66f@huawei.com \
--to=chenridong@huawei.com \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=longman@redhat.com \
--cc=mkoutny@suse.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