public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] signals: fix sigqueue_free() vs __exit_signal() race
@ 2008-05-17 15:14 Oleg Nesterov
  2008-05-20  6:33 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Oleg Nesterov @ 2008-05-17 15:14 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Roland McGrath, Thomas Gleixner, linux-kernel

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

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

Move the callsite of flush_sigqueue(tsk->pending) under ->siglock.

This patch doesn't touch flush_sigqueue(->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 <oleg@tv-sign.ru>
Acked-by: Roland McGrath <roland@redhat.com>

--- 25/kernel/exit.c~1_SQFREE_EXIT_RACE	2008-05-17 16:03:29.000000000 +0400
+++ 25/kernel/exit.c	2008-05-17 16:22:07.000000000 +0400
@@ -125,6 +125,12 @@ static void __exit_signal(struct task_st
 
 	__unhash_process(tsk);
 
+	/*
+	 * Do this under ->siglock, we can race with another thread
+	 * doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
+	 */
+	flush_sigqueue(&tsk->pending);
+
 	tsk->signal = NULL;
 	tsk->sighand = NULL;
 	spin_unlock(&sighand->siglock);
@@ -132,7 +138,6 @@ static void __exit_signal(struct task_st
 
 	__cleanup_sighand(sighand);
 	clear_tsk_thread_flag(tsk,TIF_SIGPENDING);
-	flush_sigqueue(&tsk->pending);
 	if (sig) {
 		flush_sigqueue(&sig->shared_pending);
 		taskstats_tgid_free(sig);
--- 25/kernel/signal.c~1_SQFREE_EXIT_RACE	2008-05-17 16:03:29.000000000 +0400
+++ 25/kernel/signal.c	2008-05-17 16:22:07.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 ->siglock while testing
-	 * q->list to serialize with collect_signal().
+	 * q->list to serialize with collect_signal() or with
+	 * __exit_signal()->flush_sigqueue().
 	 */
 	spin_lock_irqsave(lock, flags);
 	if (!list_empty(&q->list))


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/3] signals: fix sigqueue_free() vs __exit_signal() race
  2008-05-17 15:14 [PATCH 1/3] signals: fix sigqueue_free() vs __exit_signal() race Oleg Nesterov
@ 2008-05-20  6:33 ` Andrew Morton
  2008-05-20  9:17   ` Oleg Nesterov
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2008-05-20  6:33 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Roland McGrath, Thomas Gleixner, linux-kernel

On Sat, 17 May 2008 19:14:18 +0400 Oleg Nesterov <oleg@tv-sign.ru> wrote:

> __exit_signal() does flush_sigqueue(tsk->pending) outside of ->siglock.
> This can race with another thread doing sigqueue_free(), we can free
> the same SIGQUEUE_PREALLOC sigqueue twice or corrupt the pending->list.
> 
> Note that even sys_exit_group() can trigger this race, not only
> sys_timer_delete().
> 
> Move the callsite of flush_sigqueue(tsk->pending) under ->siglock.
> 
> This patch doesn't touch flush_sigqueue(->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.

afacit this is the only needed-in-2.6.26 patch from these two
three-patch series, yes?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/3] signals: fix sigqueue_free() vs __exit_signal() race
  2008-05-20  6:33 ` Andrew Morton
@ 2008-05-20  9:17   ` Oleg Nesterov
  0 siblings, 0 replies; 3+ messages in thread
From: Oleg Nesterov @ 2008-05-20  9:17 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Roland McGrath, Thomas Gleixner, linux-kernel

On 05/19, Andrew Morton wrote:
>
> On Sat, 17 May 2008 19:14:18 +0400 Oleg Nesterov <oleg@tv-sign.ru> wrote:
> 
> > __exit_signal() does flush_sigqueue(tsk->pending) outside of ->siglock.
> > This can race with another thread doing sigqueue_free(), we can free
> > the same SIGQUEUE_PREALLOC sigqueue twice or corrupt the pending->list.
> > 
> > Note that even sys_exit_group() can trigger this race, not only
> > sys_timer_delete().
> > 
> > Move the callsite of flush_sigqueue(tsk->pending) under ->siglock.
> > 
> > This patch doesn't touch flush_sigqueue(->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.
> 
> afacit this is the only needed-in-2.6.26 patch from these two
> three-patch series, yes?

Yes, other patches are not bugfixes.

Probably this fix is not "urgent" too, the race is very old and nobody
complained.

Oleg.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-05-20 10:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-17 15:14 [PATCH 1/3] signals: fix sigqueue_free() vs __exit_signal() race Oleg Nesterov
2008-05-20  6:33 ` Andrew Morton
2008-05-20  9:17   ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox