]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
cgroupns: Close race between cgroup_post_fork and copy_cgroup_ns
authorEric W. Biederman <ebiederm@xmission.com>
Fri, 15 Jul 2016 11:35:51 +0000 (06:35 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 20 Aug 2016 16:10:58 +0000 (18:10 +0200)
commitf3d800d6752b023ce89fb4ab5b6e1d3b7f1a27f0
treeef6ffab0e78a1f0eb0a207021c28cf9939aa66f3
parentffdc59dda08cddf1b8402c33e7d1e9a75f0ea749
cgroupns: Close race between cgroup_post_fork and copy_cgroup_ns

commit eedd0f4cbf5f3b81e82649832091e1d9d53f0709 upstream.

In most code paths involving cgroup migration cgroup_threadgroup_rwsem
is taken.  There are two exceptions:

- remove_tasks_in_empty_cpuset calls cgroup_transfer_tasks
- vhost_attach_cgroups_work calls cgroup_attach_task_all

With cgroup_threadgroup_rwsem held it is guaranteed that cgroup_post_fork
and copy_cgroup_ns will reference the same css_set from the process calling
fork.

Without such an interlock there process after fork could reference one
css_set from it's new cgroup namespace and another css_set from
task->cgroups, which semantically is nonsensical.

Fixes: a79a908fd2b0 ("cgroup: introduce cgroup namespaces")
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/cgroup.c