5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pavel Begunkov asml.silence@gmail.com
commit 943ad0b62e3c21f324c4884caa6cb4a871bca05c upstream.
io_uring can asynchronously add a task_work while the task is getting freezed. TIF_NOTIFY_SIGNAL will prevent the task from sleeping in do_freezer_trap(), and since the get_signal()'s relock loop doesn't retry task_work, the task will spin there not being able to sleep until the freezing is cancelled / the task is killed / etc.
Run task_works in the freezer path. Keep the patch small and simple so it can be easily back ported, but we might need to do some cleaning after and look if there are other places with similar problems.
Cc: stable@vger.kernel.org Link: https://github.com/systemd/systemd/issues/33626 Fixes: 12db8b690010c ("entry: Add support for TIF_NOTIFY_SIGNAL") Reported-by: Julian Orth ju.orth@gmail.com Acked-by: Oleg Nesterov oleg@redhat.com Acked-by: Tejun Heo tj@kernel.org Signed-off-by: Pavel Begunkov asml.silence@gmail.com Link: https://lore.kernel.org/r/89ed3a52933370deaaf61a0a620a6ac91f1e754d.172063414... Signed-off-by: Jens Axboe axboe@kernel.dk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org --- include/linux/sched/signal.h | 6 ++++++ kernel/signal.c | 8 ++++++++ 2 files changed, 14 insertions(+)
--- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -348,6 +348,12 @@ extern void sigqueue_free(struct sigqueu extern int send_sigqueue(struct sigqueue *, struct pid *, enum pid_type); extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
+static inline void clear_notify_signal(void) +{ + clear_thread_flag(TIF_NOTIFY_SIGNAL); + smp_mb__after_atomic(); +} + static inline int restart_syscall(void) { set_tsk_thread_flag(current, TIF_SIGPENDING); --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2464,6 +2464,14 @@ static void do_freezer_trap(void) spin_unlock_irq(¤t->sighand->siglock); cgroup_enter_frozen(); freezable_schedule(); + + /* + * We could've been woken by task_work, run it to clear + * TIF_NOTIFY_SIGNAL. The caller will retry if necessary. + */ + clear_notify_signal(); + if (unlikely(READ_ONCE(current->task_works))) + task_work_run(); }
static int ptrace_signal(int signr, kernel_siginfo_t *info)