Re: [PATCH v2] signal: respect the blocked mask in dequeue_synchronous_signal()

From: Eric W. Biederman

Date: Thu Oct 22 2026 - 16:21:43 EST


Oleg Nesterov <oleg@xxxxxxxxxx> writes:

> I was going to send another cleanup on top of this fix. Can't do this today,
> but let me explain... It is a bit ugly to check si_signo twice.

I can see where your proposed change is addressing that and it seems
reasonable.

> And afaics we have another problem. sys_rt_sigqueueinfo() allows to
> send a SI_FROMKERNEL RT signal to itself.

I don't see where your proposed code is addressing this.

>From 10,000 feet I think it is deliberate that we allow sending all
possible pending signals to ourselves. Some version of that is
necessary to restore a checkpoint of a process, if it has not
yet handled the signal at the point it is check-pointed.

You can look at CRIU if you need to see if this is behavior that
is being relied upon.

> In this case sigmask(q->info.si_signo) leads to UB on 32-bit.

I presume you are referring to a signal number that exceeds 32
being put into a 32bit mask. That does seem worth fixing.

Eric


> I'll recheck, write the changelog, and send something like below tomorrow.
> perhaps rt_sigmask() makes more sense than sigset_t...
>
> Oleg.
>
>
> From 6f7441ff08d7b88b96ac6787b40634e8c173003c Mon Sep 17 00:00:00 2001
> From: Oleg Nesterov <oleg@xxxxxxxxxx>
> Date: Thu, 22 Oct 2026 13:43:01 +0200
> Subject: [PATCH] signal: cleanup the .si_signo checks in dequeue_synchronous_signal()
>
> Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx>
> ---
> kernel/signal.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/signal.c b/kernel/signal.c
> index 7386b9552dc3..9cfd4d03cad4 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -676,21 +676,24 @@ 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;
> + sigset_t xxx;
>
> /*
> * Might a synchronous signal be in the queue?
> */
> - if (!((pending->signal.sig[0] & ~tsk->blocked.sig[0]) & SYNCHRONOUS_MASK))
> + mask = (pending->signal.sig[0] & ~tsk->blocked.sig[0]) & SYNCHRONOUS_MASK;
> + if (!mask)
> return 0;
>
> + siginitset(&xxx, mask);
> /*
> * 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) &&
> + sigismember(&xxx, q->info.si_signo)) {
> sync = q;
> goto next;
> }