Skip to content

Commit 57b56d1

Browse files
Waiman-Longhtejun
authored andcommitted
cgroup: Protect css->cgroup write under css_set_lock
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 <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 1be59c9 commit 57b56d1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/cgroup/cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,9 +1839,9 @@ int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask)
18391839
RCU_INIT_POINTER(scgrp->subsys[ssid], NULL);
18401840
rcu_assign_pointer(dcgrp->subsys[ssid], css);
18411841
ss->root = dst_root;
1842-
css->cgroup = dcgrp;
18431842

18441843
spin_lock_irq(&css_set_lock);
1844+
css->cgroup = dcgrp;
18451845
WARN_ON(!list_empty(&dcgrp->e_csets[ss->id]));
18461846
list_for_each_entry_safe(cset, cset_pos, &scgrp->e_csets[ss->id],
18471847
e_cset_node[ss->id]) {

0 commit comments

Comments
 (0)