summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorWaiman Long <longman@redhat.com>2024-07-03 14:52:29 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-09-12 11:03:53 +0200
commit193f352631fd96f5a5f0090a4c7f861a7e7cdba9 (patch)
treec94a51cdb22be0ec6e7c2b58e555afda984b2349 /kernel
parent26cd726c321a68078e5c9d9ab30e7a97945adf64 (diff)
downloadlinux-193f352631fd96f5a5f0090a4c7f861a7e7cdba9.tar.gz
linux-193f352631fd96f5a5f0090a4c7f861a7e7cdba9.tar.bz2
linux-193f352631fd96f5a5f0090a4c7f861a7e7cdba9.zip
cgroup: Protect css->cgroup write under css_set_lock
[ Upstream commit 57b56d16800e8961278ecff0dc755d46c4575092 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/cgroup/cgroup.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 62a7a5075014..16ae86894121 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -1783,9 +1783,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]) {