Skip to content

Commit b4e0044

Browse files
Eddy0402torvalds
authored andcommitted
fork: fix copy_process(CLONE_PARENT) race with the exiting ->real_parent
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 <[email protected]> Acked-by: Oleg Nesterov <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 9dbc1c0 commit b4e0044

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

kernel/fork.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,14 +2167,9 @@ static __latent_entropy struct task_struct *copy_process(
21672167
/* ok, now we should be set up.. */
21682168
p->pid = pid_nr(pid);
21692169
if (clone_flags & CLONE_THREAD) {
2170-
p->exit_signal = -1;
21712170
p->group_leader = current->group_leader;
21722171
p->tgid = current->tgid;
21732172
} else {
2174-
if (clone_flags & CLONE_PARENT)
2175-
p->exit_signal = current->group_leader->exit_signal;
2176-
else
2177-
p->exit_signal = args->exit_signal;
21782173
p->group_leader = p;
21792174
p->tgid = p->pid;
21802175
}
@@ -2218,9 +2213,14 @@ static __latent_entropy struct task_struct *copy_process(
22182213
if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
22192214
p->real_parent = current->real_parent;
22202215
p->parent_exec_id = current->parent_exec_id;
2216+
if (clone_flags & CLONE_THREAD)
2217+
p->exit_signal = -1;
2218+
else
2219+
p->exit_signal = current->group_leader->exit_signal;
22212220
} else {
22222221
p->real_parent = current;
22232222
p->parent_exec_id = current->self_exec_id;
2223+
p->exit_signal = args->exit_signal;
22242224
}
22252225

22262226
klp_copy_process(p);

0 commit comments

Comments
 (0)