Skip to content

Commit fb3bbcf

Browse files
oleg-nesterovbrauner
authored andcommitted
exit: change the release_task() paths to call flush_sigqueue() lockless
A task can block a signal, accumulate up to RLIMIT_SIGPENDING sigqueues, and exit. In this case __exit_signal()->flush_sigqueue() called with irqs disabled can trigger a hard lockup, see https://lore.kernel.org/all/[email protected]/ Fortunately, after the recent posixtimer changes sys_timer_delete() paths no longer try to clear SIGQUEUE_PREALLOC and/or free tmr->sigq, and after the exiting task passes __exit_signal() lock_task_sighand() can't succeed and pid_task(tmr->it_pid) will return NULL. This means that after __exit_signal(tsk) nobody can play with tsk->pending or (if group_dead) with tsk->signal->shared_pending, so release_task() can safely call flush_sigqueue() after write_unlock_irq(&tasklist_lock). TODO: - we can probably shift posix_cpu_timers_exit() as well - do_sigaction() can hit the similar problem Signed-off-by: Oleg Nesterov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Frederic Weisbecker <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 2014c95 commit fb3bbcf

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

kernel/exit.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,20 +200,13 @@ static void __exit_signal(struct task_struct *tsk)
200200
__unhash_process(tsk, group_dead);
201201
write_sequnlock(&sig->stats_lock);
202202

203-
/*
204-
* Do this under ->siglock, we can race with another thread
205-
* doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
206-
*/
207-
flush_sigqueue(&tsk->pending);
208203
tsk->sighand = NULL;
209204
spin_unlock(&sighand->siglock);
210205

211206
__cleanup_sighand(sighand);
212207
clear_tsk_thread_flag(tsk, TIF_SIGPENDING);
213-
if (group_dead) {
214-
flush_sigqueue(&sig->shared_pending);
208+
if (group_dead)
215209
tty_kref_put(tty);
216-
}
217210
}
218211

219212
static void delayed_put_task_struct(struct rcu_head *rhp)
@@ -279,6 +272,16 @@ void release_task(struct task_struct *p)
279272
proc_flush_pid(thread_pid);
280273
put_pid(thread_pid);
281274
release_thread(p);
275+
/*
276+
* This task was already removed from the process/thread/pid lists
277+
* and lock_task_sighand(p) can't succeed. Nobody else can touch
278+
* ->pending or, if group dead, signal->shared_pending. We can call
279+
* flush_sigqueue() lockless.
280+
*/
281+
flush_sigqueue(&p->pending);
282+
if (thread_group_leader(p))
283+
flush_sigqueue(&p->signal->shared_pending);
284+
282285
put_task_struct_rcu_user(p);
283286

284287
p = leader;

0 commit comments

Comments
 (0)