Skip to content
Snippets Groups Projects
Commit 9fcc65d0 authored by Zhang Qiao's avatar Zhang Qiao Committed by Yongqiang Liu
Browse files

cpuset: Fix unsafe lock order between cpuset lock and cpuslock

stable inclusion
from linux-4.19.236
commit aa44002e7db25f333ddf412fb81e8db6c100841a
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5646A


CVE: NA

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

The backport commit 4eec5fe1c680a ("cgroup/cpuset: Fix a race
between cpuset_attach() and cpu hotplug") looks suspicious since
it comes before commit d74b27d6 ("cgroup/cpuset: Change
cpuset_rwsem and hotplug lock order") v5.4-rc1~176^2~30 when
the locking order was: cpuset lock, cpus lock.

Fix it with the correct locking order and reduce the cpus locking
range because only set_cpus_allowed_ptr() needs the protection of
cpus lock.

Fixes: 4eec5fe1c680a ("cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug")
Reported-by: default avatarMichal Koutný <mkoutny@suse.com>
Signed-off-by: default avatarZhang Qiao <zhangqiao22@huawei.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
parent 5d2ba004
Branches
Tags
No related merge requests found
...@@ -1530,9 +1530,13 @@ static void cpuset_attach(struct cgroup_taskset *tset) ...@@ -1530,9 +1530,13 @@ 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();
mutex_lock(&cpuset_mutex); mutex_lock(&cpuset_mutex);
/*
* It should hold cpus lock because a cpu offline event can
* cause set_cpus_allowed_ptr() failed.
*/
get_online_cpus();
/* prepare for attach */ /* prepare for attach */
if (cs == &top_cpuset) if (cs == &top_cpuset)
cpumask_copy(cpus_attach, cpu_possible_mask); cpumask_copy(cpus_attach, cpu_possible_mask);
...@@ -1551,6 +1555,7 @@ static void cpuset_attach(struct cgroup_taskset *tset) ...@@ -1551,6 +1555,7 @@ static void cpuset_attach(struct cgroup_taskset *tset)
cpuset_change_task_nodemask(task, &cpuset_attach_nodemask_to); cpuset_change_task_nodemask(task, &cpuset_attach_nodemask_to);
cpuset_update_task_spread_flag(cs, task); cpuset_update_task_spread_flag(cs, task);
} }
put_online_cpus();
/* /*
* Change mm for all threadgroup leaders. This is expensive and may * Change mm for all threadgroup leaders. This is expensive and may
...@@ -1586,7 +1591,6 @@ static void cpuset_attach(struct cgroup_taskset *tset) ...@@ -1586,7 +1591,6 @@ static void cpuset_attach(struct cgroup_taskset *tset)
wake_up(&cpuset_attach_wq); wake_up(&cpuset_attach_wq);
mutex_unlock(&cpuset_mutex); mutex_unlock(&cpuset_mutex);
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 */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment