]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
cgroup: Protect css->cgroup write under css_set_lock
authorWaiman Long <longman@redhat.com>
Wed, 3 Jul 2024 18:52:29 +0000 (14:52 -0400)
committerTejun Heo <tj@kernel.org>
Wed, 3 Jul 2024 18:59:06 +0000 (08:59 -1000)
The writing of css->cgroup associated with the cgroup root in
rebind_subsystems() is currently protected only by cgroup_mutex.
However, the reading of css->cgroup in both proc_cpuset_show() and
proc_cgroup_show() is protected just by css_set_lock. That makes the
readers susceptible to racing problems like data tearing or caching.
It is also a problem that can be reported by KCSAN.

This can be fixed by using READ_ONCE() and WRITE_ONCE() to access
css->cgroup. Alternatively, the writing of css->cgroup can be moved
under css_set_lock as well which is done by this patch.

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cgroup.c

index e32b6972c47840a8f6880964100b3356ab849f2a..278889170f94136d4d80e1020321c7a0b61a040b 100644 (file)
@@ -1839,9 +1839,9 @@ int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask)
                RCU_INIT_POINTER(scgrp->subsys[ssid], NULL);
                rcu_assign_pointer(dcgrp->subsys[ssid], css);
                ss->root = dst_root;
-               css->cgroup = dcgrp;
 
                spin_lock_irq(&css_set_lock);
+               css->cgroup = dcgrp;
                WARN_ON(!list_empty(&dcgrp->e_csets[ss->id]));
                list_for_each_entry_safe(cset, cset_pos, &scgrp->e_csets[ss->id],
                                         e_cset_node[ss->id]) {