From: Eddy Wu itseddy0402@gmail.com
stable inclusion from linux-4.19.156 commit b177d2d915cea2d0a590f0034a20299dd1ee3ef2
--------------------------------
commit b4e00444cab4c3f3fec876dc0cccc8cbb0d1a948 upstream.
current->group_leader->exit_signal may change during copy_process() if current->real_parent exits.
Move the assignment inside tasklist_lock to avoid the race.
Signed-off-by: Eddy Wu eddy_wu@trendmicro.com Acked-by: Oleg Nesterov oleg@redhat.com Signed-off-by: Linus Torvalds torvalds@linux-foundation.org Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: Yang Yingliang yangyingliang@huawei.com Signed-off-by: Cheng Jian cj.chengjian@huawei.com --- kernel/fork.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c index 68b0fd51302e..dc059179fd18 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2026,14 +2026,9 @@ static __latent_entropy struct task_struct *copy_process( /* ok, now we should be set up.. */ p->pid = pid_nr(pid); if (clone_flags & CLONE_THREAD) { - p->exit_signal = -1; p->group_leader = current->group_leader; p->tgid = current->tgid; } else { - if (clone_flags & CLONE_PARENT) - p->exit_signal = current->group_leader->exit_signal; - else - p->exit_signal = (clone_flags & CSIGNAL); p->group_leader = p; p->tgid = p->pid; } @@ -2079,10 +2074,15 @@ static __latent_entropy struct task_struct *copy_process( p->real_parent = current->real_parent; p->parent_exec_id = current->parent_exec_id; p->parent_exec_id_u64 = current->parent_exec_id_u64; + if (clone_flags & CLONE_THREAD) + p->exit_signal = -1; + else + p->exit_signal = current->group_leader->exit_signal; } else { p->real_parent = current; p->parent_exec_id = current->self_exec_id; p->parent_exec_id_u64 = current->self_exec_id_u64; + p->exit_signal = (clone_flags & CSIGNAL); }
klp_copy_process(p);