FAILED: patch "[PATCH] signalfd: don't dequeue the forced fatal signals" failed to apply to 5.15-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 5.15-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-5.15.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 5.15.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/3 signal: Requeue signals in the appropriate queue
From: "Eric W. Biederman" <[email protected]>
[ Upstream commit 5768d8906bc23d512b1a736c1e198aa833a6daa4 ]
In the event that a tracer changes which signal needs to be delivered and that signal is currently blocked then the signal needs to be requeued for later delivery.
With the advent of CLONE_THREAD the kernel has 2 signal queues per task. The per process queue and the per task queue. Update the code so that if the signal is removed from the per process queue it is requeued on the per process queue. This is necessary to make it appear the signal was never dequeued.
The rr debugger reasonably believes that the state of the process from the last ptrace_stop it observed until PTRACE_EVENT_EXIT can be recreated by simply letting a process run. If a SIGKILL interrupts a ptrace_stop this is not true today.
So return signals to their original queue in ptrace_signal so that signals that are not delivered appear like they were never dequeued.
History Tree: https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.gi
Stable-dep-of: d72e0fb3b00c ("signalfd: don't dequeue the forced fatal signals")
--- fs/signalfd.c | 5 +++-- include/linux/sched/signal.h | 7 ++++--- kernel/signal.c | 21 ++++++++++++++------- 3 files changed, 21 insertions(+), 12 deletions(-)
fs/signalfd.c +3 -2
@@ -155,11 +155,12 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,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);spin_lock_irq (¤t->sighand->siglock); - ret =dequeue_signal (current, &ctx->sigmask, info); + ret =dequeue_signal (current, &ctx->sigmask, info, &type);switch (ret) {case 0 :if (!nonblock)
@@ -174,7 +175,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); + ret =dequeue_signal (current, &ctx->sigmask, info, &type);if (ret !=0 )break ;if (signal_pending (current)) {
include/linux/sched/signal.h +4 -3
@@ -274,17 +274,18 @@ static inline int signal_group_exit(const struct signal_struct *sig)extern void flush_signals (struct task_struct *);extern void ignore_signals (struct task_struct *);extern void flush_signal_handlers (struct task_struct *,int force_default); -extern int dequeue_signal (struct task_struct *task, -sigset_t *mask,kernel_siginfo_t *info); +extern int dequeue_signal (struct task_struct *task,sigset_t *mask, +kernel_siginfo_t *info,enum pid_type *type);static inline int kernel_dequeue_signal (void ) {struct task_struct *task = current;kernel_siginfo_t __info; +enum pid_type __type;int ret;spin_lock_irq (&task->sighand->siglock); - ret =dequeue_signal (task, &task->blocked, &__info); + ret =dequeue_signal (task, &task->blocked, &__info, &__type);spin_unlock_irq (&task->sighand->siglock);return ret;
kernel/signal.c +14 -7
@@ -626,7 +626,8 @@ static int __dequeue_signal(struct sigpending *pending, sigset_t *mask,* * All callers have to hold the siglock. */ -int dequeue_signal (struct task_struct *tsk,sigset_t *mask,kernel_siginfo_t *info) +int dequeue_signal (struct task_struct *tsk,sigset_t *mask, +kernel_siginfo_t *info,enum pid_type *type) {bool resched_timer = false;int signr;
@@ -634,8 +635,10 @@ int dequeue_signal(struct task_struct *tsk, sigset_t *mask, kernel_siginfo_t *in/* We only dequeue private signals from ourselves, we don't let * signalfd steal them */ + *type =PIDTYPE_PID ; signr =__dequeue_signal (&tsk->pending, mask, info, &resched_timer);if (!signr) { + *type =PIDTYPE_TGID ; signr =__dequeue_signal (&tsk->signal->shared_pending, mask, info, &resched_timer);#ifdef CONFIG_POSIX_TIMERS
@@ -2609,7 +2612,7 @@ static void do_freezer_trap(void)task_work_run (); } -static int ptrace_signal (int signr,kernel_siginfo_t *info) +static int ptrace_signal (int signr,kernel_siginfo_t *info,enum pid_type type) {/* * We do not check sig_kernel_stop(signr) but set this marker
@@ -2650,7 +2653,7 @@ static int ptrace_signal(int signr, kernel_siginfo_t *info)/* If the (new) signal is now blocked, requeue it. */ if (sigismember (¤t->blocked, signr)) { -send_signal (signr, info, current,PIDTYPE_PID ); +send_signal (signr, info, current, type); signr =0 ; }
@@ -2751,6 +2754,7 @@ bool get_signal(struct ksignal *ksig)for (;;) {struct k_sigaction *ka; +enum pid_type type;/* Has this task already been marked for death? */ if (signal_group_exit (signal)) {
@@ -2793,16 +2797,18 @@ bool get_signal(struct ksignal *ksig)* so that the instruction pointer in the signal stack * frame points to the faulting instruction. */ + type =PIDTYPE_PID ; signr =dequeue_synchronous_signal (&ksig->info);if (!signr) - signr =dequeue_signal (current, ¤t->blocked, &ksig->info); + signr =dequeue_signal (current, ¤t->blocked, + &ksig->info, &type);if (!signr)break ;/* will return 0 */ if (unlikely (current->ptrace) && (signr !=SIGKILL ) && !(sighand->action[signr -1 ].sa.sa_flags &SA_IMMUTABLE )) { - signr =ptrace_signal (signr, &ksig->info); + signr =ptrace_signal (signr, &ksig->info, type);if (!signr)continue ; }
@@ -3633,6 +3639,7 @@ static int do_sigtimedwait(const sigset_t *which, kernel_siginfo_t *info,ktime_t *to =NULL , timeout =KTIME_MAX ;struct task_struct *tsk = current;sigset_t mask = *which; +enum pid_type type;int sig, ret =0 ;if (ts) {
@@ -3649,7 +3656,7 @@ static int do_sigtimedwait(const sigset_t *which, kernel_siginfo_t *info,signotset (&mask);spin_lock_irq (&tsk->sighand->siglock); - sig =dequeue_signal (tsk, &mask, info); + sig =dequeue_signal (tsk, &mask, info, &type);if (!sig && timeout) {/* * None ready, temporarily unblock those we're interested
@@ -3668,7 +3675,7 @@ static int do_sigtimedwait(const sigset_t *which, kernel_siginfo_t *info,spin_lock_irq (&tsk->sighand->siglock);__set_task_blocked (tsk, &tsk->real_blocked);sigemptyset (&tsk->real_blocked); - sig =dequeue_signal (tsk, &mask, info); + sig =dequeue_signal (tsk, &mask, info, &type); }spin_unlock_irq (&tsk->sighand->siglock);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 signal: Remove task argument from dequeue_signal()
From: Thomas Gleixner <[email protected]>
[ Upstream commit a2b80ce87a87fc18c594e74d13031d5e347b69cb ]
The task pointer which is handed to dequeue_signal() is always current. The argument along with the first comment about signalfd in that function is confusing at best. Remove it and use current internally.
Update the stale comment for dequeue_signal() while at it.
Stable-dep-of: d72e0fb3b00c ("signalfd: don't dequeue the forced fatal signals")
--- fs/signalfd.c | 4 ++-- include/linux/sched/signal.h | 5 ++--- kernel/signal.c | 23 ++++++++++------------- 3 files changed, 14 insertions(+), 18 deletions(-)
fs/signalfd.c +2 -2
@@ -160,7 +160,7 @@ static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, kernel_siginfo_t *infoDECLARE_WAITQUEUE (wait, current);spin_lock_irq (¤t->sighand->siglock); - ret =dequeue_signal (current, &ctx->sigmask, info, &type); + ret =dequeue_signal (&ctx->sigmask, info, &type);switch (ret) {case 0 :if (!nonblock)
@@ -175,7 +175,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 (&ctx->sigmask, info, &type);if (ret !=0 )break ;if (signal_pending (current)) {
include/linux/sched/signal.h +2 -3
@@ -274,8 +274,7 @@ static inline int signal_group_exit(const struct signal_struct *sig)extern void flush_signals (struct task_struct *);extern void ignore_signals (struct task_struct *);extern void flush_signal_handlers (struct task_struct *,int force_default); -extern int dequeue_signal (struct task_struct *task,sigset_t *mask, -kernel_siginfo_t *info,enum pid_type *type); +extern int dequeue_signal (sigset_t *mask,kernel_siginfo_t *info,enum pid_type *type);static inline int kernel_dequeue_signal (void ) {
@@ -285,7 +284,7 @@ static inline int kernel_dequeue_signal(void)int ret;spin_lock_irq (&task->sighand->siglock); - ret =dequeue_signal (task, &task->blocked, &__info, &__type); + ret =dequeue_signal (&task->blocked, &__info, &__type);spin_unlock_irq (&task->sighand->siglock);return ret;
kernel/signal.c +10 -13
@@ -621,20 +621,18 @@ static int __dequeue_signal(struct sigpending *pending, sigset_t *mask, }/* -* Dequeue a signal and return the element to the caller, which is -* expected to free it. -* -* All callers have to hold the siglock. +* Try to dequeue a signal. If a deliverable signal is found fill in the +* caller provided siginfo and return the signal number. Otherwise return +* 0. */ -int dequeue_signal (struct task_struct *tsk,sigset_t *mask, -kernel_siginfo_t *info,enum pid_type *type) +int dequeue_signal (sigset_t *mask,kernel_siginfo_t *info,enum pid_type *type) { +struct task_struct *tsk = current;bool resched_timer = false;int signr; -/* We only dequeue private signals from ourselves, we don't let -* signalfd steal them -*/ +lockdep_assert_held (&tsk->sighand->siglock); + *type =PIDTYPE_PID ; signr =__dequeue_signal (&tsk->pending, mask, info, &resched_timer);if (!signr) {
@@ -2800,8 +2798,7 @@ bool get_signal(struct ksignal *ksig) type =PIDTYPE_PID ; signr =dequeue_synchronous_signal (&ksig->info);if (!signr) - signr =dequeue_signal (current, ¤t->blocked, - &ksig->info, &type); + signr =dequeue_signal (¤t->blocked, &ksig->info, &type);if (!signr)break ;/* will return 0 */
@@ -3656,7 +3653,7 @@ static int do_sigtimedwait(const sigset_t *which, kernel_siginfo_t *info,signotset (&mask);spin_lock_irq (&tsk->sighand->siglock); - sig =dequeue_signal (tsk, &mask, info, &type); + sig =dequeue_signal (&mask, info, &type);if (!sig && timeout) {/* * None ready, temporarily unblock those we're interested
@@ -3675,7 +3672,7 @@ static int do_sigtimedwait(const sigset_t *which, kernel_siginfo_t *info,spin_lock_irq (&tsk->sighand->siglock);__set_task_blocked (tsk, &tsk->real_blocked);sigemptyset (&tsk->real_blocked); - sig =dequeue_signal (tsk, &mask, info, &type); + sig =dequeue_signal (&mask, info, &type); }spin_unlock_irq (&tsk->sighand->siglock);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 signalfd: don't dequeue the forced fatal signals
In reply to Sasha LevinFrom: 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 (&ctx->sigmask, info, &type); +refine_sigmask (ctx, &sigmask); + ret =dequeue_signal (&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 (&ctx->sigmask, info, &type); + ret =dequeue_signal (&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