Skip to content

Commit 6d3971d

Browse files
braunerhtejun
authored andcommitted
cgroup: clarify cgroup_css_set_fork()
With recent fixes for the permission checking when moving a task into a cgroup using a file descriptor to a cgroup's cgroup.procs file and calling write() it seems a good idea to clarify CLONE_INTO_CGROUP permission checking with a comment. Cc: Tejun Heo <tj@kernel.org> Cc: <cgroups@vger.kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 05c7b7a commit 6d3971d

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

kernel/cgroup/cgroup.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6161,6 +6161,20 @@ static int cgroup_css_set_fork(struct kernel_clone_args *kargs)
61616161
if (ret)
61626162
goto err;
61636163

6164+
/*
6165+
* Spawning a task directly into a cgroup works by passing a file
6166+
* descriptor to the target cgroup directory. This can even be an O_PATH
6167+
* file descriptor. But it can never be a cgroup.procs file descriptor.
6168+
* This was done on purpose so spawning into a cgroup could be
6169+
* conceptualized as an atomic
6170+
*
6171+
* fd = openat(dfd_cgroup, "cgroup.procs", ...);
6172+
* write(fd, <child-pid>, ...);
6173+
*
6174+
* sequence, i.e. it's a shorthand for the caller opening and writing
6175+
* cgroup.procs of the cgroup indicated by @dfd_cgroup. This allows us
6176+
* to always use the caller's credentials.
6177+
*/
61646178
ret = cgroup_attach_permissions(cset->dfl_cgrp, dst_cgrp, sb,
61656179
!(kargs->flags & CLONE_THREAD),
61666180
current->nsproxy->cgroup_ns);

0 commit comments

Comments
 (0)