Skip to content

Commit

Permalink
[PATCH] Fix fs/exec.c:788 (de_thread()) BUG_ON
Browse files Browse the repository at this point in the history
It turns out that the BUG_ON() in fs/exec.c: de_thread() is unreliable
and can trigger due to the test itself being racy.

de_thread() does
 	while (atomic_read(&sig->count) > count) {
	}
	.....
	.....
	BUG_ON(!thread_group_empty(current));

but release_task does
	write_lock_irq(&tasklist_lock)
	__exit_signal
		(this is where atomic_dec(&sig->count) is run)
	__exit_sighand
	__unhash_process
		takes write lock on tasklist_lock
		remove itself out of PIDTYPE_TGID list
	write_unlock_irq(&tasklist_lock)

so there's a clear (although small) window between the
atomic_dec(&sig->count) and the actual PIDTYPE_TGID unhashing of the
thread.

And actually there is no need for all threads to have exited at this
point, so we simply kill the BUG_ON.

Big thanks to Marc Lehmann who provided the test-case.

Fixes Bug 5170 (http://bugme.osdl.org/show_bug.cgi?id=5170)

Signed-off-by: Alexander Nyberg <alexn@telia.com>
Cc: Roland McGrath <roland@redhat.com>
Cc: Andrew Morton <akpm@osdl.org>
Cc: Ingo Molnar <mingo@elte.hu>
Acked-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Alexander Nyberg authored and Linus Torvalds committed Sep 14, 2005
1 parent 32a3658 commit fb085cf
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,8 @@ static inline int de_thread(struct task_struct *tsk)
}

/*
* Now there are really no other threads at all,
* so it's safe to stop telling them to kill themselves.
* There may be one thread left which is just exiting,
* but it's safe to stop telling the group to kill themselves.
*/
sig->flags = 0;

Expand Down Expand Up @@ -785,7 +785,6 @@ static inline int de_thread(struct task_struct *tsk)
kmem_cache_free(sighand_cachep, oldsighand);
}

BUG_ON(!thread_group_empty(current));
BUG_ON(!thread_group_leader(current));
return 0;
}
Expand Down

0 comments on commit fb085cf

Please sign in to comment.