Skip to content

Commit 329f7db

Browse files
Oleg NesterovLinus Torvalds
authored andcommitted
[PATCH] fix de_thread() vs send_group_sigqueue() race
When non-leader thread does exec, de_thread calls release_task(leader) before calling exit_itimers(). If local timer interrupt happens in between, it can oops in send_group_sigqueue() while taking ->sighand->siglock == NULL. However, we can't change send_group_sigqueue() to check p->signal != NULL, because sys_timer_create() does get_task_struct() only in SIGEV_THREAD_ID case. So it is possible that this task_struct was already freed and we can't trust p->signal. This patch changes de_thread() so that leader released after exit_itimers() call. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Acked-by: Chris Wright <chrisw@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent a52e838 commit 329f7db

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎fs/exec.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ static inline int de_thread(struct task_struct *tsk)
590590
struct signal_struct *sig = tsk->signal;
591591
struct sighand_struct *newsighand, *oldsighand = tsk->sighand;
592592
spinlock_t *lock = &oldsighand->siglock;
593+
struct task_struct *leader = NULL;
593594
int count;
594595

595596
/*
@@ -665,7 +666,7 @@ static inline int de_thread(struct task_struct *tsk)
665666
* and to assume its PID:
666667
*/
667668
if (!thread_group_leader(current)) {
668-
struct task_struct *leader = current->group_leader, *parent;
669+
struct task_struct *parent;
669670
struct dentry *proc_dentry1, *proc_dentry2;
670671
unsigned long exit_state, ptrace;
671672

@@ -674,6 +675,7 @@ static inline int de_thread(struct task_struct *tsk)
674675
* It should already be zombie at this point, most
675676
* of the time.
676677
*/
678+
leader = current->group_leader;
677679
while (leader->exit_state != EXIT_ZOMBIE)
678680
yield();
679681

@@ -733,7 +735,6 @@ static inline int de_thread(struct task_struct *tsk)
733735
proc_pid_flush(proc_dentry2);
734736

735737
BUG_ON(exit_state != EXIT_ZOMBIE);
736-
release_task(leader);
737738
}
738739

739740
/*
@@ -743,8 +744,11 @@ static inline int de_thread(struct task_struct *tsk)
743744
sig->flags = 0;
744745

745746
no_thread_group:
746-
BUG_ON(atomic_read(&sig->count) != 1);
747747
exit_itimers(sig);
748+
if (leader)
749+
release_task(leader);
750+
751+
BUG_ON(atomic_read(&sig->count) != 1);
748752

749753
if (atomic_read(&oldsighand->count) == 1) {
750754
/*

0 commit comments

Comments
 (0)