提交 f90dfed3 编写于 作者: Z Zhang Qiao 提交者: Zheng Zengkai

cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug

maillist inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I4TR86
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git/commit/?id=05c7b7a92cc87ff8d7fde189d0fade250697573c

--------------------------------

As previously discussed(https://lkml.org/lkml/2022/1/20/51),
cpuset_attach() is affected with similar cpu hotplug race,
as follow scenario:

     cpuset_attach()				cpu hotplug
    ---------------------------            ----------------------
    down_write(cpuset_rwsem)
    guarantee_online_cpus() // (load cpus_attach)
					sched_cpu_deactivate
					  set_cpu_active()
					  // will change cpu_active_mask
    set_cpus_allowed_ptr(cpus_attach)
      __set_cpus_allowed_ptr_locked()
       // (if the intersection of cpus_attach and
         cpu_active_mask is empty, will return -EINVAL)
    up_write(cpuset_rwsem)

To avoid races such as described above, protect cpuset_attach() call
with cpu_hotplug_lock.

Fixes: be367d09 ("cgroups: let ss->can_attach and ss->attach do whole threadgroups at a time")
Cc: stable@vger.kernel.org # v2.6.32+
Reported-by: NZhao Gongyi <zhaogongyi@huawei.com>
Signed-off-by: NZhang Qiao <zhangqiao22@huawei.com>
Acked-by: NWaiman Long <longman@redhat.com>
Reviewed-by: NMichal Koutný <mkoutny@suse.com>
Signed-off-by: NTejun Heo <tj@kernel.org>
Reviewed-by: NChen Hui <judy.chenhui@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 7ec2ec68
...@@ -2211,6 +2211,7 @@ static void cpuset_attach(struct cgroup_taskset *tset) ...@@ -2211,6 +2211,7 @@ static void cpuset_attach(struct cgroup_taskset *tset)
cgroup_taskset_first(tset, &css); cgroup_taskset_first(tset, &css);
cs = css_cs(css); cs = css_cs(css);
cpus_read_lock();
percpu_down_write(&cpuset_rwsem); percpu_down_write(&cpuset_rwsem);
/* prepare for attach */ /* prepare for attach */
...@@ -2266,6 +2267,7 @@ static void cpuset_attach(struct cgroup_taskset *tset) ...@@ -2266,6 +2267,7 @@ static void cpuset_attach(struct cgroup_taskset *tset)
wake_up(&cpuset_attach_wq); wake_up(&cpuset_attach_wq);
percpu_up_write(&cpuset_rwsem); percpu_up_write(&cpuset_rwsem);
cpus_read_unlock();
} }
/* The various types of files and directories in a cpuset file system */ /* The various types of files and directories in a cpuset file system */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册