Commit 60187d27 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds
Browse files

sigqueue_free: fix the race with collect_signal()

Spotted by taoyue <> and Jeremy Katz <>.

collect_signal:				sigqueue_free:

						if (!list_empty(&q->list)) {
							// not taken
						q->flags &= ~SIGQUEUE_PREALLOC;

	__sigqueue_free(first);			__sigqueue_free(q);

Now, __sigqueue_free() is called twice on the same "struct sigqueue" with the
obviously bad implications.

In particular, this double free breaks the array_cache->avail logic, so the
same sigqueue could be "allocated" twice, and the bug can manifest itself via
the "impossible" BUG_ON(!SIGQUEUE_PREALLOC) in sigqueue_free/send_sigqueue.

Hopefully this can explain these mysterious bug-reports, see

Alexey Dobriyan reports this patch makes the difference for the testcase, but
nobody has an access to the application which opened the problems originally.

Also, this patch removes tasklist lock/unlock, ->siglock is enough.
Signed-off-by: default avatarOleg Nesterov <>
Cc: taoyue <>
Cc: Jeremy Katz <>
Cc: Sukadev Bhattiprolu <>
Cc: Alexey Dobriyan <>
Cc: Ingo Molnar <>
Cc: Thomas Gleixner <>
Cc: Roland McGrath <>
Cc: <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 99db67bc
......@@ -1300,20 +1300,19 @@ struct sigqueue *sigqueue_alloc(void)
void sigqueue_free(struct sigqueue *q)
unsigned long flags;
spinlock_t *lock = &current->sighand->siglock;
* If the signal is still pending remove it from the
* pending queue.
* pending queue. We must hold ->siglock while testing
* q->list to serialize with collect_signal().
if (unlikely(!list_empty(&q->list))) {
spinlock_t *lock = &current->sighand->siglock;
spin_lock_irqsave(lock, flags);
if (!list_empty(&q->list))
spin_unlock_irqrestore(lock, flags);
spin_lock_irqsave(lock, flags);
if (!list_empty(&q->list))
spin_unlock_irqrestore(lock, flags);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment