projects/linux·commit f95d39d1

do_wait: fix the theoretical race with stop/trace/cont

f95d39d1 · Oleg Nesterov <[email protected]> · 2009-06-17 16:27:42 -07:00

do_wait:

	current->state = TASK_INTERRUPTIBLE;

	read_lock(&tasklist_lock);
	... search for the task to reap ...

In theory, the ->state changing can leak into the critical section.  Since
the child can change its status under read_lock(tasklist) in parallel
(finish_stop/ptrace_stop), we can miss the wakeup if __wake_up_parent()
sees us in TASK_RUNNING state.  Add the barrier.

Also, use __set_current_state() to set TASK_RUNNING.

Signed-off-by: Oleg Nesterov <[email protected]>
Cc: Ingo Molnar <[email protected]>
Acked-by: Roland McGrath <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
Commit
f95d39d10fe7d47336e65172f52bf64e0096f983
Parents
a3f6dfb7

Changes

1 files changed · +2 −2

FileStatusAddDelContent
kernel/exit.cmodified+2−2View file

kernel/exit.c

View file
diff --git a/kernel/exit.c b/kernel/exit.c
index dd83c84..7ef355d 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1581,7 +1581,7 @@ repeat:
(!wo->wo_pid || hlist_empty(&wo->wo_pid->tasks[wo->wo_type])))
goto notask;
- current->state = TASK_INTERRUPTIBLE;
+ set_current_state(TASK_INTERRUPTIBLE);
read_lock(&tasklist_lock);
tsk = current;
do {
@@ -1608,7 +1608,7 @@ notask:
}
}
end:
- current->state = TASK_RUNNING;
+ __set_current_state(TASK_RUNNING);
remove_wait_queue(&current->signal->wait_chldexit,&wait);
if (wo->wo_info) {
struct siginfo __user *infop = wo->wo_info;