From mboxrd@z Thu Jan 1 00:00:00 1970 From: ebiederm@xmission.com (Eric W. Biederman) Subject: [PATCH 4/9] signal: Factor start_group_exit out of complete_signal Date: Thu, 24 Jun 2021 14:01:20 -0500 Message-ID: <87czsb6q9r.fsf_-_@disp2133> References: <87sg1lwhvm.fsf@disp2133> <6e47eff8-d0a4-8390-1222-e975bfbf3a65@gmail.com> <924ec53c-2fd9-2e1c-bbb1-3fda49809be4@gmail.com> <87eed4v2dc.fsf@disp2133> <5929e116-fa61-b211-342a-c706dcb834ca@gmail.com> <87fsxjorgs.fsf@disp2133> <87a6njf0ia.fsf@disp2133> <87tulpbp19.fsf@disp2133> <87zgvgabw1.fsf@disp2133> <875yy3850g.fsf_-_@disp2133> Mime-Version: 1.0 Return-path: In-Reply-To: <875yy3850g.fsf_-_@disp2133> (Eric W. Biederman's message of "Thu, 24 Jun 2021 13:57:35 -0500") List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Linus Torvalds Cc: Al Viro , Michael Schmitz , linux-arch , Jens Axboe , Oleg Nesterov , Linux Kernel Mailing List , Richard Henderson , Ivan Kokshaysky , Matt Turner , alpha , Geert Uytterhoeven , linux-m68k , Arnd Bergmann , Ley Foon Tan , Tejun Heo , Kees Cook Signed-off-by: "Eric W. Biederman" --- include/linux/sched/signal.h | 2 ++ kernel/signal.c | 52 +++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 774be5d3ac3e..c007e55cb119 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -428,6 +428,8 @@ static inline void ptrace_signal_wake_up(struct task_struct *t, bool resume) signal_wake_up_state(t, resume ? __TASK_TRACED : 0); } +void start_group_exit(int exit_code); + void task_join_group_stop(struct task_struct *task); #ifdef TIF_RESTORE_SIGMASK diff --git a/kernel/signal.c b/kernel/signal.c index da37cc4515f2..c79c010ca5f3 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1027,6 +1027,42 @@ static inline bool wants_signal(int sig, struct task_struct *p) return task_curr(p) || !task_sigpending(p); } +static void start_group_exit_locked(struct signal_struct *signal, int exit_code) +{ + /* + * Start a group exit and wake everybody up. + * This way we don't have other threads + * running and doing things after a slower + * thread has the fatal signal pending. + */ + struct task_struct *t; + + signal->flags = SIGNAL_GROUP_EXIT; + signal->group_exit_code = exit_code; + signal->group_stop_count = 0; + __for_each_thread(signal, t) { + task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); + + /* Don't bother with already dead threads */ + if (t->exit_state) + continue; + sigaddset(&t->pending.signal, SIGKILL); + signal_wake_up(t, 1); + } +} + +void start_group_exit(int exit_code) +{ + if (!fatal_signal_pending(current)) { + struct sighand_struct *const sighand = current->sighand; + + spin_lock_irq(&sighand->siglock); + if (!fatal_signal_pending(current)) + start_group_exit_locked(current->signal, exit_code); + spin_unlock_irq(&sighand->siglock); + } +} + static void complete_signal(int sig, struct task_struct *p, enum pid_type type) { struct signal_struct *signal = p->signal; @@ -1076,21 +1112,7 @@ static void complete_signal(int sig, struct task_struct *p, enum pid_type type) * This signal will be fatal to the whole group. */ if (!sig_kernel_coredump(sig)) { - /* - * Start a group exit and wake everybody up. - * This way we don't have other threads - * running and doing things after a slower - * thread has the fatal signal pending. - */ - signal->flags = SIGNAL_GROUP_EXIT; - signal->group_exit_code = sig; - signal->group_stop_count = 0; - t = p; - do { - task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); - sigaddset(&t->pending.signal, SIGKILL); - signal_wake_up(t, 1); - } while_each_thread(p, t); + start_group_exit_locked(signal, sig); return; } } -- 2.20.1