mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bradley Morgan <bradley.morgan@linux.dev>
To: oleg@redhat.com
Cc: akpm@linux-foundation.org, brauner@kernel.org,
	ebiederm@xmission.com, linux-kernel@vger.kernel.org,
	thnkslprpt@gmail.com
Subject: Re: [PATCH 1/2] signal: fix/simplify .si_signo checks in dequeue_synchronous_signal()
Date: Sun, 29 Nov 2026 22:15:00 +0000	[thread overview]
Message-ID: <1B900F51-11F7-4279-BEA1-35988038FA37@linux.dev> (raw)
In-Reply-To: <aww3-2LIfZqiIWMK@redhat.com>

On 29 November 2026 14:34:35 GMT, Oleg Nesterov <oleg@redhat.com> wrote:
>- 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. */

I may be stupid here, but why did you drop unblocked?

> 	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;
> 		}
>

--- Thanks!

      parent reply	other threads:[~2026-11-29 22:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 14:34 Oleg Nesterov
2026-11-29 14:34 ` [PATCH 2/2] signal: explain the still_pending check " Oleg Nesterov
2026-11-29 22:16   ` Bradley Morgan
2026-11-29 22:15 ` Bradley Morgan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1B900F51-11F7-4279-BEA1-35988038FA37@linux.dev \
    --to=bradley.morgan@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=thnkslprpt@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®