* [PATCH 1/2] signal: fix/simplify .si_signo checks in dequeue_synchronous_signal()
@ 2026-11-29 14:34 Oleg Nesterov
2026-11-29 14:34 ` [PATCH 2/2] signal: explain the still_pending check " Oleg Nesterov
0 siblings, 1 reply; 2+ messages in thread
From: Oleg Nesterov @ 2026-11-29 14:34 UTC (permalink / raw)
To: Andrew Morton
Cc: Avi Weiss, Christian Brauner, Eric W . Biederman, linux-kernel
- Use SI_FROMKERNEL() instead of the open-coded check.
- Pre-calculate the unblocked synchronous signal "mask" to avoid
checking .si_signo twice.
- Use siginmask() instead of sigmask() to avoid shift UB if
.si_signo >= SIGRTMIN (on 32-bit, or on MIPS where _NSIG is 128).
This can only happen if a task sends a SI_FROMKERNEL RT signal to
itself and we could probably disallow this, but siginmask() makes
the code cleaner anyway.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/signal.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/kernel/signal.c b/kernel/signal.c
index dd770e68faee..482db380a498 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -676,21 +676,17 @@ static int dequeue_synchronous_signal(kernel_siginfo_t *info)
struct task_struct *tsk = current;
struct sigpending *pending = &tsk->pending;
struct sigqueue *q, *sync = NULL;
+ unsigned long mask;
- /*
- * Might a synchronous signal be in the queue?
- */
- if (!((pending->signal.sig[0] & ~tsk->blocked.sig[0]) & SYNCHRONOUS_MASK))
+ /* Might a synchronous signal be in the queue? */
+ mask = (pending->signal.sig[0] & ~tsk->blocked.sig[0]) & SYNCHRONOUS_MASK;
+ if (!mask)
return 0;
- /*
- * Return the first unblocked synchronous signal in the queue.
- */
+ /* Return the first synchronous signal in the queue. */
list_for_each_entry(q, &pending->list, list) {
- /* Synchronous signals have a positive si_code */
- if ((q->info.si_code > SI_USER) &&
- (sigmask(q->info.si_signo) & SYNCHRONOUS_MASK) &&
- !sigismember(&tsk->blocked, q->info.si_signo)) {
+ if (SI_FROMKERNEL(&q->info) &&
+ siginmask(q->info.si_signo, mask)) {
sync = q;
goto next;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] signal: explain the still_pending check in dequeue_synchronous_signal()
2026-11-29 14:34 [PATCH 1/2] signal: fix/simplify .si_signo checks in dequeue_synchronous_signal() Oleg Nesterov
@ 2026-11-29 14:34 ` Oleg Nesterov
0 siblings, 0 replies; 2+ messages in thread
From: Oleg Nesterov @ 2026-11-29 14:34 UTC (permalink / raw)
To: Andrew Morton
Cc: Avi Weiss, Christian Brauner, Eric W . Biederman, linux-kernel
The "still_pending" logic in dequeue_synchronous_signal() is actually
correct, but looks either unnecessary or incomplete: it is not clear how
we can find another siginfo with the same .si_signo < SIGRTMIN; and if
this is possible it is not clear why that siginfo can't be queued before
"sync".
Add a comment to explain both subtleties.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/signal.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/signal.c b/kernel/signal.c
index 482db380a498..e744bd146e80 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -695,6 +695,11 @@ static int dequeue_synchronous_signal(kernel_siginfo_t *info)
next:
/*
* Check if there is another siginfo for the same signal.
+ *
+ * sync->info.si_signo < SIGRTMIN, but posixtimer_queue_sigqueue()
+ * bypasses legacy_queue() and adds non-SI_FROMKERNEL SI_TIMER to
+ * the tail. It can't appear before SI_FROMKERNEL "sync" which had
+ * to pass legacy_queue() in __send_signal_locked().
*/
list_for_each_entry_continue(q, &pending->list, list) {
if (q->info.si_signo == sync->info.si_signo)
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 14:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 14:34 [PATCH 1/2] signal: fix/simplify .si_signo checks in dequeue_synchronous_signal() Oleg Nesterov
2026-11-29 14:34 ` [PATCH 2/2] signal: explain the still_pending check " Oleg Nesterov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox