FAILED: patch "[PATCH] posix-timers: Target group sigqueue to current task only if" failed to apply to 6.12-stable tree
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 63dffecfba3eddcf67a8f76d80e0c141f93d44a5
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2024120656-jelly-gore-aa4c@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 63dffecfba3eddcf67a8f76d80e0c141f93d44a5 Mon Sep 17 00:00:00 2001
From: Frederic Weisbecker <[email protected]>
Date: Sat, 23 Nov 2024 00:48:11 +0100
Subject: [PATCH] posix-timers: Target group sigqueue to current task only if
not exiting
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.
kernel/signal.c +4 -3
@@ -1959,14 +1959,15 @@ static void posixtimer_queue_sigqueue(struct sigqueue *q, struct task_struct *t,* * Where type is not PIDTYPE_PID, signals must be delivered to the * process. In this case, prefer to deliver to current if it is in -* the same thread group as the target process, which avoids -* unnecessarily waking up a potentially idle task. +* the same thread group as the target process and its sighand is +* stable, which avoids unnecessarily waking up a potentially idle task. */ static inline struct task_struct *posixtimer_get_target (struct k_itimer *tmr) {struct task_struct *t =pid_task (tmr->it_pid, tmr->it_pid_type); -if (t && tmr->it_pid_type !=PIDTYPE_PID &&same_thread_group (t, current)) +if (t && tmr->it_pid_type !=PIDTYPE_PID && +same_thread_group (t, current) && !current->exit_state) t = current;return t; }
Oleg Nesterov
Acked-byHi Greg,
Quoted 2 lines · On 12/06, [email protected] wrote:
The patch below does not apply to the 6.12-stable tree.
Please see the attached patch. For v6.12 and the previous versions.
Oleg.
From 3851a6b5b7183f377bcedc98ffaecff067236ce5 Mon Sep 17 00:00:00 2001
From: Frederic Weisbecker <[email protected]>
Date: Fri, 6 Dec 2024 13:59:12 +0100
Subject: [PATCH -stable] posix-timers: Target group sigqueue to current task
only if not exiting
From: Frederic Weisbecker <[email protected]>
commit 63dffecfba3eddcf67a8f76d80e0c141f93d44a5 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.
--- kernel/signal.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
kernel/signal.c +5 -4
@@ -1986,14 +1986,15 @@ int send_sigqueue(struct sigqueue *q, struct pid *pid, enum pid_type type)* into t->pending). * * Where type is not PIDTYPE_PID, signals must be delivered to the -* process. In this case, prefer to deliver to current if it is in -* the same thread group as the target process, which avoids -* unnecessarily waking up a potentially idle task. +* process. In this case, prefer to deliver to current if it is in the +* same thread group as the target process and its sighand is stable, +* which avoids unnecessarily waking up a potentially idle task. */ t =pid_task (pid, type);if (!t) goto ret; -if (type !=PIDTYPE_PID &&same_thread_group (t, current)) +if (type !=PIDTYPE_PID && +same_thread_group (t, current) && !current->exit_state) t = current;if (!likely (lock_task_sighand (t, &flags))) goto ret;
Signature · 1 line
2.25.1.362.g51ebf55
Greg KH
maintainerQuoted 7 lines · Oleg Nesterov
Hi Greg,
Quoted 2 lines · On 12/06, [email protected] wrote:
The patch below does not apply to the 6.12-stable tree.
Please see the attached patch. For v6.12 and the previous versions.
Thanks, now queued up.
greg k-h
Sasha Levin
maintainer[ Sasha's backport helper bot ]
Hi,
The upstream commit SHA1 provided is correct: 63dffecfba3eddcf67a8f76d80e0c141f93d44a5
WARNING: Author mismatch between patch and upstream commit:
Backport author: Oleg Nesterov <[email protected]> Commit author: Frederic Weisbecker <[email protected]>
Status in newer kernel trees:
6.12.y | Not found
Note: The patch differs from the upstream commit:
---
1: 63dffecfba3ed < -: ------------- posix-timers: Target group sigqueue to current task only if not exiting -: ------------- > 1: b5913c9a2e038 FAILED: patch "[PATCH] posix-timers: Target group sigqueue to current task only if" failed to apply to 6.12-stable tree
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-6.12.y | Success | Success |