login
Header Space

 
 

[PATCH 1/4] posix timers: fix sigqueue_free() vs __exit_signal() race

Previous thread: [RFC 2/2] x86: Enable rootmem allocator on X86_32 by Johannes Weiner on Saturday, May 3, 2008 - 11:25 am. (1 message)

Next thread: [PATCH 2/4] posix timers: sigqueue_free: don't free sigqueue if it is queued by Oleg Nesterov on Saturday, May 3, 2008 - 1:35 pm. (5 messages)
To: Andrew Morton <akpm@...>
Cc: Austin Clements <amdragon+kernelbugzilla@...>, Ingo Molnar <mingo@...>, john stultz <johnstul@...>, Linus Torvalds <torvalds@...>, Michael Kerrisk <mtk.manpages@...>, Roland McGrath <roland@...>, Thomas Gleixner <tglx@...>, <linux-kernel@...>
Date: Saturday, May 3, 2008 - 1:35 pm

__exit_signal() does flush_sigqueue(tsk-&gt;pending) outside of -&gt;siglock.
This can race with another thread doing sigqueue_free(), we can free
the same SIGQUEUE_PREALLOC sigqueue twice or corrupt the pending-&gt;list.

Note that even sys_exit_group() can trigger this race, not only
sys_timer_delete().

Move the callsite of flush_sigqueue(tsk-&gt;pending) under -&gt;siglock.

This patch doesn't touch flush_sigqueue(-&gt;shared_pending) below, it is
called when there are no other threads which can play with signals,
and sigqueue_free() can't be used outside of our thread group.

Signed-off-by: Oleg Nesterov &lt;oleg@tv-sign.ru&gt;

--- 25/kernel/exit.c~1_SF_EX_RACE	2008-03-20 18:25:11.000000000 +0300
+++ 25/kernel/exit.c	2008-05-03 18:21:34.000000000 +0400
@@ -125,6 +125,12 @@ static void __exit_signal(struct task_st
 
 	__unhash_process(tsk);
 
+	/*
+	 * Do this under -&gt;siglock, we can race with another thread
+	 * doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
+	 */
+	flush_sigqueue(&amp;tsk-&gt;pending);
+
 	tsk-&gt;signal = NULL;
 	tsk-&gt;sighand = NULL;
 	spin_unlock(&amp;sighand-&gt;siglock);
@@ -132,7 +138,6 @@ static void __exit_signal(struct task_st
 
 	__cleanup_sighand(sighand);
 	clear_tsk_thread_flag(tsk,TIF_SIGPENDING);
-	flush_sigqueue(&amp;tsk-&gt;pending);
 	if (sig) {
 		flush_sigqueue(&amp;sig-&gt;shared_pending);
 		taskstats_tgid_free(sig);
--- 25/kernel/signal.c~1_SF_EX_RACE	2008-05-03 17:47:01.000000000 +0400
+++ 25/kernel/signal.c	2008-05-03 18:27:03.000000000 +0400
@@ -1242,7 +1242,8 @@ void sigqueue_free(struct sigqueue *q)
 	/*
 	 * If the signal is still pending remove it from the
 	 * pending queue. We must hold -&gt;siglock while testing
-	 * q-&gt;list to serialize with collect_signal().
+	 * q-&gt;list to serialize with collect_signal() or with
+	 * __exit_signal()-&gt;flush_sigqueue().
 	 */
 	spin_lock_irqsave(lock, flags);
 	if (!list_empty(&amp;q-&gt;list))

--
To: Oleg Nesterov <oleg@...>
Cc: Andrew Morton <akpm@...>, Austin Clements <amdragon+kernelbugzilla@...>, Ingo Molnar <mingo@...>, john stultz <johnstul@...>, Linus Torvalds <torvalds@...>, Michael Kerrisk <mtk.manpages@...>, Thomas Gleixner <tglx@...>, <linux-kernel@...>
Date: Monday, May 5, 2008 - 10:29 pm

Signed-off-by: Roland McGrath &lt;roland@redhat.com&gt;
--
Previous thread: [RFC 2/2] x86: Enable rootmem allocator on X86_32 by Johannes Weiner on Saturday, May 3, 2008 - 11:25 am. (1 message)

Next thread: [PATCH 2/4] posix timers: sigqueue_free: don't free sigqueue if it is queued by Oleg Nesterov on Saturday, May 3, 2008 - 1:35 pm. (5 messages)
speck-geostationary