Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp471366pxv; Thu, 24 Jun 2021 12:03:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3XX45s1g592Bbf+s+34RkV3OyVO5GuOw+aa1t8SSWtbh4tYLrX/GcPkVKuDiHfd+5XjAY X-Received: by 2002:aa7:ccd4:: with SMTP id y20mr9300189edt.151.1624561383389; Thu, 24 Jun 2021 12:03:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624561383; cv=none; d=google.com; s=arc-20160816; b=ULNm5gqZlW0gToPwhsZ4h3WvOXPsrLluqKudVU6hEF1UY5RH+qCfzH57KzW7K6QqiL n4aqkNVm2axe8KJXqvjeIbZAuYPnpFqKa5vSkQrJbbSfocc92YHck4u9W2JyEgq930YJ /sdH6PgA3X2wnr6dBHhsLL/NhIRde6HOPwzqelpUwAS49Ic62XBuaJIXgFH5wkI01q7W G0VGSNN+aJHyXsZ3i7C3ZEf5zEw9YUdGQ5+UhbM9JwZia6rA+7LSy+0Wp45tugXt6zwY wKZNghVavb5wcngNveJAiZCwdNY7y6BGl8sp0L0Bt63m27YgwNh50Aceli7Ox2QNh2gn ZNjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:mime-version:user-agent:message-id :in-reply-to:date:references:cc:to:from; bh=/QTqJPelTYtuJ1GqxiNi10+hUfmIVhTVWN7tfoM1vfE=; b=KZWweDByNVzdyE5UiJ7h1rB3rhP3MKDsV/3YBsNjoq0Ulf/qQTOcpsn3odvYIxSjrR q5SI/ElAXsaChNujMVxJ5GphuyEJTc9xvb21sARhbFSJIwGyEYTb+9HTvjH+ARrVJJn4 WA7Fi/h1IhPJ9YVogLoTRRFYCaovYg0ofw+SDmJr0CQCN1D+563OoysRCf2E1IcS+BSE YmVRb7j101tdRjG8g1+CUjl1RJqbsAdlLjcTiWsr4sF16q1y5JaiVytYy4SyJzk86lYV lPzN5LG3zmNSzLex1ktCOib8MnKHZE+eIjmjniLYiH4Qx/ouv0K4NUqZt1xmWV3dwHve 0nqg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h10si1048841edb.192.2021.06.24.12.02.36; Thu, 24 Jun 2021 12:03:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232647AbhFXTDu (ORCPT + 99 others); Thu, 24 Jun 2021 15:03:50 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:36308 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232417AbhFXTDs (ORCPT ); Thu, 24 Jun 2021 15:03:48 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lwUbQ-0009Qk-PD; Thu, 24 Jun 2021 13:01:28 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95]:47150 helo=email.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lwUbP-003Rm9-NH; Thu, 24 Jun 2021 13:01:28 -0600 From: ebiederm@xmission.com (Eric W. Biederman) 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 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> Date: Thu, 24 Jun 2021 14:01:20 -0500 In-Reply-To: <875yy3850g.fsf_-_@disp2133> (Eric W. Biederman's message of "Thu, 24 Jun 2021 13:57:35 -0500") Message-ID: <87czsb6q9r.fsf_-_@disp2133> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1lwUbP-003Rm9-NH;;;mid=<87czsb6q9r.fsf_-_@disp2133>;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+PJXbb1itesHXgjxe+XHQIzMBZMGxsoRk= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on sa07.xmission.com X-Spam-Level: *** X-Spam-Status: No, score=3.0 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TooManySym_01,XMNoVowels,XMSubLong, XM_Body_Dirty_Words autolearn=disabled version=3.4.2 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * 1.0 XM_Body_Dirty_Words Contains a dirty word * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ***;Linus Torvalds X-Spam-Relay-Country: X-Spam-Timing: total 500 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 11 (2.2%), b_tie_ro: 9 (1.9%), parse: 1.49 (0.3%), extract_message_metadata: 18 (3.5%), get_uri_detail_list: 2.5 (0.5%), tests_pri_-1000: 23 (4.5%), tests_pri_-950: 1.91 (0.4%), tests_pri_-900: 1.46 (0.3%), tests_pri_-90: 117 (23.3%), check_bayes: 115 (23.0%), b_tokenize: 17 (3.4%), b_tok_get_all: 9 (1.7%), b_comp_prob: 3.5 (0.7%), b_tok_touch_all: 82 (16.3%), b_finish: 0.93 (0.2%), tests_pri_0: 315 (62.9%), check_dkim_signature: 0.58 (0.1%), check_dkim_adsp: 2.8 (0.6%), poll_dns_idle: 1.04 (0.2%), tests_pri_10: 2.0 (0.4%), tests_pri_500: 7 (1.3%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 4/9] signal: Factor start_group_exit out of complete_signal X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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