Skip to content

Commit f3b82bb

Browse files
Frederic Weisbeckergregkh
authored andcommitted
posix-timers: Target group sigqueue to current task only if not exiting
commit 63dffec upstream. A sigqueue belonging to a posix timer, which target is not a specific thread but a whole thread group, is preferrably targeted to the current task if it is part of that thread group. However nothing prevents a posix timer event from queueing such a sigqueue from a reaped yet running task. The interruptible code space between exit_notify() and the final call to schedule() is enough for posix_timer_fn() hrtimer to fire. If that happens while the current task is part of the thread group target, it is proposed to handle it but since its sighand pointer may have been cleared already, the sigqueue is dropped even if there are other tasks running within the group that could handle it. As a result posix timers with thread group wide target may miss signals when some of their threads are exiting. Fix this with verifying that the current task hasn't been through exit_notify() before proposing it as a preferred target so as to ensure that its sighand is still here and stable. complete_signal() might still reconsider the choice and find a better target within the group if current has passed retarget_shared_pending() already. Fixes: bcb7ee7 ("posix-timers: Prefer delivery of signals to the current thread") Reported-by: Anthony Mallet <[email protected]> Suggested-by: Oleg Nesterov <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Oleg Nesterov <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/all/[email protected] Closes: https://lore.kernel.org/all/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8a79914 commit f3b82bb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

kernel/signal.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,14 +1996,15 @@ int send_sigqueue(struct sigqueue *q, struct pid *pid, enum pid_type type)
19961996
* into t->pending).
19971997
*
19981998
* Where type is not PIDTYPE_PID, signals must be delivered to the
1999-
* process. In this case, prefer to deliver to current if it is in
2000-
* the same thread group as the target process, which avoids
2001-
* unnecessarily waking up a potentially idle task.
1999+
* process. In this case, prefer to deliver to current if it is in the
2000+
* same thread group as the target process and its sighand is stable,
2001+
* which avoids unnecessarily waking up a potentially idle task.
20022002
*/
20032003
t = pid_task(pid, type);
20042004
if (!t)
20052005
goto ret;
2006-
if (type != PIDTYPE_PID && same_thread_group(t, current))
2006+
if (type != PIDTYPE_PID &&
2007+
same_thread_group(t, current) && !current->exit_state)
20072008
t = current;
20082009
if (!likely(lock_task_sighand(t, &flags)))
20092010
goto ret;

0 commit comments

Comments
 (0)