提交 6ea7c5e7 编写于 作者: T Tetsuo Handa 提交者: Yongqiang Liu

cgroup: Add missing cpus_read_lock() to cgroup_attach_task_all()

stable inclusion
from stable-v4.19.280
commit 321488cfac7d0eb6d97de467015ff754f85813ff
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I6TI3Y
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=321488cfac7d0eb6d97de467015ff754f85813ff

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

commit 43626dad upstream.

syzbot is hitting percpu_rwsem_assert_held(&cpu_hotplug_lock) warning at
cpuset_attach() [1], for commit 4f7e7236 ("cgroup: Fix
threadgroup_rwsem <-> cpus_read_lock() deadlock") missed that
cpuset_attach() is also called from cgroup_attach_task_all().
Add cpus_read_lock() like what cgroup_procs_write_start() does.

Link: https://syzkaller.appspot.com/bug?extid=29d3a3b4d86c8136ad9e [1]
Reported-by: Nsyzbot <syzbot+29d3a3b4d86c8136ad9e@syzkaller.appspotmail.com>
Signed-off-by: NTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Fixes: 4f7e7236 ("cgroup: Fix threadgroup_rwsem <-> cpus_read_lock() deadlock")
Signed-off-by: NTejun Heo <tj@kernel.org>
Signed-off-by: NCai Xinchen <caixinchen1@huawei.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>

conflicts:
	kernel/cgroup/cgroup-internal.h
	kernel/cgroup/cgroup-v1.c
	kernel/cgroup/cgroup.c
Signed-off-by: NCai Xinchen <caixinchen1@huawei.com>
Reviewed-by: NWang Weiyang <wangweiyang2@huawei.com>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
上级 b48ceb10
......@@ -226,6 +226,8 @@ int cgroup_migrate(struct task_struct *leader, bool threadgroup,
int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader,
bool threadgroup);
void cgroup_attach_lock(void);
void cgroup_attach_unlock(void);
struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup)
__acquires(&cgroup_threadgroup_rwsem);
void cgroup_procs_write_finish(struct task_struct *task)
......
......@@ -55,7 +55,7 @@ int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
int retval = 0;
mutex_lock(&cgroup_mutex);
percpu_down_write(&cgroup_threadgroup_rwsem);
cgroup_attach_lock();
for_each_root(root) {
struct cgroup *from_cgrp;
......@@ -70,7 +70,7 @@ int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
if (retval)
break;
}
percpu_up_write(&cgroup_threadgroup_rwsem);
cgroup_attach_unlock();
mutex_unlock(&cgroup_mutex);
return retval;
......
......@@ -2236,7 +2236,7 @@ EXPORT_SYMBOL_GPL(task_cgroup_path);
* write-locking cgroup_threadgroup_rwsem. This allows ->attach() to assume that
* CPU hotplug is disabled on entry.
*/
static void cgroup_attach_lock(void)
void cgroup_attach_lock(void)
{
get_online_cpus();
percpu_down_write(&cgroup_threadgroup_rwsem);
......@@ -2246,7 +2246,7 @@ static void cgroup_attach_lock(void)
* cgroup_attach_unlock - Undo cgroup_attach_lock()
* @lock_threadgroup: whether to up_write cgroup_threadgroup_rwsem
*/
static void cgroup_attach_unlock(void)
void cgroup_attach_unlock(void)
{
percpu_up_write(&cgroup_threadgroup_rwsem);
put_online_cpus();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册