FAILED: patch "[PATCH] signalfd: don't dequeue the forced fatal signals" failed to apply to 6.6-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 6.6-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.6.y
git checkout FETCH_HEAD
git cherry-pick -x d72e0fb3b00c6a1146bcfd7186ad9f6f609ba236
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From d72e0fb3b00c6a1146bcfd7186ad9f6f609ba236 Mon Sep 17 00:00:00 2001
From: Oleg Nesterov <[email protected]>
Date: Mon, 6 Apr 2026 15:37:32 +0200
Subject: [PATCH] signalfd: don't dequeue the forced fatal signals
These signals should act like SIGKILL, in that userspace must never dequeue them. But as Kusaram explains, io_uring-driven signalfd_read_iter() called from get_signal() -> task_work_run() paths can do this before get_signal() has a chance to dequeue such a signal and notice SA_IMMUTABLE.
Change signalfd_poll() and signalfd_dequeue() to add pending SA_IMMUTABLE signals to ctx->sigmask.
TODO: we should probably change force_sig_info_to_task(HANDLER_EXIT) to make fatal_signal_pending() true, or add a fatal_or_forced_signal_pending() helper. Then signalfd_dequeue() could just return -EINTR in this case. This also makes sense for get_signal(), which could prioritize a fatal signal sent by (say) force_sig_seccomp(force_coredump => true), just like it already prioritizes SIGKILL.
--- fs/signalfd.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
fs/signalfd.c +22 -6
@@ -48,17 +48,30 @@ static int signalfd_release(struct inode *inode, struct file *file)return 0 ; } +static void refine_sigmask (struct signalfd_ctx *ctx,sigset_t *sigmask) +{ +struct k_sigaction *k = current->sighand->action; +int n; + + *sigmask = ctx->sigmask; +for (n =1 ; n <= _NSIG; ++n, ++k) { +if (k->sa.sa_flags &SA_IMMUTABLE ) +sigaddset (sigmask, n); + } +} +static __poll_t signalfd_poll (struct file *file,poll_table *wait) {struct signalfd_ctx *ctx = file->private_data;__poll_t events =0 ; +sigset_t sigmask;poll_wait (file, ¤t->sighand->signalfd_wqh, wait);spin_lock_irq (¤t->sighand->siglock); -if (next_signal (¤t->pending, &ctx->sigmask) || -next_signal (¤t->signal->shared_pending, - &ctx->sigmask)) +refine_sigmask (ctx, &sigmask); +if (next_signal (¤t->pending, &sigmask) || +next_signal (¤t->signal->shared_pending, &sigmask)) events |=EPOLLIN ;spin_unlock_irq (¤t->sighand->siglock);
@@ -155,11 +168,13 @@ static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, kernel_siginfo_t *info int nonblock) {enum pid_type type; -ssize_t ret;DECLARE_WAITQUEUE (wait, current); +sigset_t sigmask; +ssize_t ret;spin_lock_irq (¤t->sighand->siglock); - ret =dequeue_signal (&ctx->sigmask, info, &type); +refine_sigmask (ctx, &sigmask); + ret =dequeue_signal (&sigmask, info, &type);switch (ret) {case 0 :if (!nonblock)
@@ -174,7 +189,7 @@ static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, kernel_siginfo_t *infoadd_wait_queue (¤t->sighand->signalfd_wqh, &wait);for (;;) {set_current_state (TASK_INTERRUPTIBLE ); - ret =dequeue_signal (&ctx->sigmask, info, &type); + ret =dequeue_signal (&sigmask, info, &type);if (ret !=0 )break ;if (signal_pending (current)) {
@@ -184,6 +199,7 @@ static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, kernel_siginfo_t *infospin_unlock_irq (¤t->sighand->siglock);schedule ();spin_lock_irq (¤t->sighand->siglock); +refine_sigmask (ctx, &sigmask); }spin_unlock_irq (¤t->sighand->siglock);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 signalfd: don't dequeue the forced fatal signals
From: Oleg Nesterov <[email protected]>
[ Upstream commit d72e0fb3b00c6a1146bcfd7186ad9f6f609ba236 ]
These signals should act like SIGKILL, in that userspace must never dequeue them. But as Kusaram explains, io_uring-driven signalfd_read_iter() called from get_signal() -> task_work_run() paths can do this before get_signal() has a chance to dequeue such a signal and notice SA_IMMUTABLE.
Change signalfd_poll() and signalfd_dequeue() to add pending SA_IMMUTABLE signals to ctx->sigmask.
TODO: we should probably change force_sig_info_to_task(HANDLER_EXIT) to make fatal_signal_pending() true, or add a fatal_or_forced_signal_pending() helper. Then signalfd_dequeue() could just return -EINTR in this case. This also makes sense for get_signal(), which could prioritize a fatal signal sent by (say) force_sig_seccomp(force_coredump => true), just like it already prioritizes SIGKILL.
--- fs/signalfd.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
fs/signalfd.c +22 -6
@@ -48,17 +48,30 @@ static int signalfd_release(struct inode *inode, struct file *file)return 0 ; } +static void refine_sigmask (struct signalfd_ctx *ctx,sigset_t *sigmask) +{ +struct k_sigaction *k = current->sighand->action; +int n; + + *sigmask = ctx->sigmask; +for (n =1 ; n <= _NSIG; ++n, ++k) { +if (k->sa.sa_flags &SA_IMMUTABLE ) +sigaddset (sigmask, n); + } +} +static __poll_t signalfd_poll (struct file *file,poll_table *wait) {struct signalfd_ctx *ctx = file->private_data;__poll_t events =0 ; +sigset_t sigmask;poll_wait (file, ¤t->sighand->signalfd_wqh, wait);spin_lock_irq (¤t->sighand->siglock); -if (next_signal (¤t->pending, &ctx->sigmask) || -next_signal (¤t->signal->shared_pending, - &ctx->sigmask)) +refine_sigmask (ctx, &sigmask); +if (next_signal (¤t->pending, &sigmask) || +next_signal (¤t->signal->shared_pending, &sigmask)) events |=EPOLLIN ;spin_unlock_irq (¤t->sighand->siglock);
@@ -156,11 +169,13 @@ static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, kernel_siginfo_t *info int nonblock) {enum pid_type type; -ssize_t ret;DECLARE_WAITQUEUE (wait, current); +sigset_t sigmask; +ssize_t ret;spin_lock_irq (¤t->sighand->siglock); - ret =dequeue_signal (current, &ctx->sigmask, info, &type); +refine_sigmask (ctx, &sigmask); + ret =dequeue_signal (current, &sigmask, info, &type);switch (ret) {case 0 :if (!nonblock)
@@ -175,7 +190,7 @@ static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, kernel_siginfo_t *infoadd_wait_queue (¤t->sighand->signalfd_wqh, &wait);for (;;) {set_current_state (TASK_INTERRUPTIBLE ); - ret =dequeue_signal (current, &ctx->sigmask, info, &type); + ret =dequeue_signal (current, &sigmask, info, &type);if (ret !=0 )break ;if (signal_pending (current)) {
@@ -185,6 +200,7 @@ static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, kernel_siginfo_t *infospin_unlock_irq (¤t->sighand->siglock);schedule ();spin_lock_irq (¤t->sighand->siglock); +refine_sigmask (ctx, &sigmask); }spin_unlock_irq (¤t->sighand->siglock);
Signature · 1 line
2.53.0