History

exec: make de_thread() killable

Change de_thread() to use KILLABLE rather than UNINTERRUPTIBLE while waiting for other threads. The only complication is that we should clear ->group_exit_task and ->notify_count before we return, and we should do this under tasklist_lock. -EAGAIN is used to match the initial signal_group_exit() check/return, it doesn't really matter. This fixes the (unlikely) race with coredump. de_thread() checks signal_group_exit() before it starts to kill the subthreads, but this can't help if another CLONE_VM (but non CLONE_THREAD) task starts the coredumping after de_thread() unlocks ->siglock. In this case the killed sub-thread can block in exit_mm() waiting for coredump_finish(), execing thread waits for that sub-thead, and the coredumping thread waits for execing thread. Deadlock.

Oleg Nesterov committed 14 years ago

Commit d5bbd431 parent b5356a11 file · +14 −2Browse files

Unified · Split

fs/exec.c+14−2
@@ -878,9 +878,11 @@ static int de_thread(struct task_struct *tsk) · 877 unmodified lines
878878 sig->notify_count--;
879879
880880 while (sig->notify_count) {
881− __set_current_state(TASK_UNINTERRUPTIBLE);
881+ __set_current_state(TASK_KILLABLE);
882882 spin_unlock_irq(lock);
883883 schedule();
884+ if (unlikely(__fatal_signal_pending(tsk)))
885+ goto killed;
884886 spin_lock_irq(lock);
885887 }
886888 spin_unlock_irq(lock);
@@ -898,9 +900,11 @@ static int de_thread(struct task_struct *tsk) · 11 unmodified lines
898900 write_lock_irq(&tasklist_lock);
899901 if (likely(leader->exit_state))
900902 break;
901− __set_current_state(TASK_UNINTERRUPTIBLE);
903+ __set_current_state(TASK_KILLABLE);
902904 write_unlock_irq(&tasklist_lock);
903905 schedule();
906+ if (unlikely(__fatal_signal_pending(tsk)))
907+ goto killed;
904908 }
905909
906910 /*
@@ -994,6 +998,14 @@ no_thread_group: · 87 unmodified lines
994998
995999 BUG_ON(!thread_group_leader(tsk));
9961000 return 0;
1001+
1002+killed:
1003+ /* protects against exit_notify() and __exit_signal() */
1004+ read_lock(&tasklist_lock);
1005+ sig->group_exit_task = NULL;
1006+ sig->notify_count = 0;
1007+ read_unlock(&tasklist_lock);
1008+ return -EAGAIN;
9971009 }
9981010
9991011 char *get_task_comm(char *buf, struct task_struct *tsk)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t