From patchwork Tue Jun 23 21:53:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 11621869 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E550390 for ; Tue, 23 Jun 2020 21:57:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6ACA2098B for ; Tue, 23 Jun 2020 21:57:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387872AbgFWV5z (ORCPT ); Tue, 23 Jun 2020 17:57:55 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:57396 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387455AbgFWV5y (ORCPT ); Tue, 23 Jun 2020 17:57:54 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out02.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jnqvR-0004Kz-EY; Tue, 23 Jun 2020 15:57:53 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1jnqvQ-00039X-No; Tue, 23 Jun 2020 15:57:53 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Cc: , Linus Torvalds , Oleg Nesterov , Jann Horn , Kees Cook , Bernd Edlinger References: <87pn9u6h8c.fsf@x220.int.ebiederm.org> <87r1u5laac.fsf@x220.int.ebiederm.org> Date: Tue, 23 Jun 2020 16:53:29 -0500 In-Reply-To: <87r1u5laac.fsf@x220.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 23 Jun 2020 16:52:43 -0500") Message-ID: <87lfkdla92.fsf_-_@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-XM-SPF: eid=1jnqvQ-00039X-No;;;mid=<87lfkdla92.fsf_-_@x220.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/1/vL+ah4gMSG5g2qvGjMYB9/S+zDHo+I= 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 sa08.xmission.com X-Spam-Level: X-Spam-Status: No, score=-0.2 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TooManySym_01 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.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa08 0; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: ; sa08 0; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ; X-Spam-Relay-Country: X-Spam-Timing: total 327 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 11 (3.3%), b_tie_ro: 9 (2.9%), parse: 0.71 (0.2%), extract_message_metadata: 9 (2.7%), get_uri_detail_list: 0.84 (0.3%), tests_pri_-1000: 12 (3.6%), tests_pri_-950: 1.28 (0.4%), tests_pri_-900: 1.09 (0.3%), tests_pri_-90: 110 (33.8%), check_bayes: 109 (33.2%), b_tokenize: 4.8 (1.5%), b_tok_get_all: 6 (1.8%), b_comp_prob: 1.58 (0.5%), b_tok_touch_all: 92 (28.2%), b_finish: 1.15 (0.4%), tests_pri_0: 171 (52.2%), check_dkim_signature: 0.70 (0.2%), check_dkim_adsp: 2.7 (0.8%), poll_dns_idle: 1.20 (0.4%), tests_pri_10: 2.2 (0.7%), tests_pri_500: 7 (2.0%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v2 1/6] signal: Pretty up the SIGNAL_GROUP_FLAGS X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Renumber the flags that go in sig->flags giving different groups of flags different hex digits. This is needed so that future additions of flags can be adjacent. Signed-off-by: "Eric W. Biederman" --- include/linux/sched/signal.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 0ee5e696c5d8..b4f36a11be5e 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -241,20 +241,22 @@ struct signal_struct { */ #define SIGNAL_STOP_STOPPED 0x00000001 /* job control stop in effect */ #define SIGNAL_STOP_CONTINUED 0x00000002 /* SIGCONT since WCONTINUED reap */ -#define SIGNAL_GROUP_EXIT 0x00000004 /* group exit in progress */ -#define SIGNAL_GROUP_COREDUMP 0x00000008 /* coredump in progress */ -/* - * Pending notifications to parent. - */ + +/* Pending notifications to parent. */ #define SIGNAL_CLD_STOPPED 0x00000010 #define SIGNAL_CLD_CONTINUED 0x00000020 #define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED) -#define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */ - #define SIGNAL_STOP_MASK (SIGNAL_CLD_MASK | SIGNAL_STOP_STOPPED | \ SIGNAL_STOP_CONTINUED) +/* Signal group actions. */ +#define SIGNAL_GROUP_EXIT 0x00000100 /* group exit in progress */ +#define SIGNAL_GROUP_COREDUMP 0x00000200 /* coredump in progress */ + +/* Flags applicable to the entire signal group. */ +#define SIGNAL_UNKILLABLE 0x00001000 /* for init: ignore fatal signals */ + static inline void signal_set_stop_flags(struct signal_struct *sig, unsigned int flags) { From patchwork Tue Jun 23 21:54:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 11621871 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6CC6160D for ; Tue, 23 Jun 2020 21:58:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C81320C09 for ; Tue, 23 Jun 2020 21:58:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388602AbgFWV6e (ORCPT ); Tue, 23 Jun 2020 17:58:34 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:57574 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387455AbgFWV6d (ORCPT ); Tue, 23 Jun 2020 17:58:33 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out02.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jnqw3-0004Nx-RL; Tue, 23 Jun 2020 15:58:31 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1jnqw3-0003FG-0o; Tue, 23 Jun 2020 15:58:31 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Cc: , Linus Torvalds , Oleg Nesterov , Jann Horn , Kees Cook , Bernd Edlinger References: <87pn9u6h8c.fsf@x220.int.ebiederm.org> <87r1u5laac.fsf@x220.int.ebiederm.org> Date: Tue, 23 Jun 2020 16:54:07 -0500 In-Reply-To: <87r1u5laac.fsf@x220.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 23 Jun 2020 16:52:43 -0500") Message-ID: <87ftalla80.fsf_-_@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-XM-SPF: eid=1jnqw3-0003FG-0o;;;mid=<87ftalla80.fsf_-_@x220.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX192WU5omqc6II6syhD9LEG1XUFeakeHPL4= 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=-0.2 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE 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.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 0; Body=1 Fuz1=1 Fuz2=1] X-Spam-DCC: ; sa07 0; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ; X-Spam-Relay-Country: X-Spam-Timing: total 427 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 9 (2.2%), b_tie_ro: 8 (1.9%), parse: 1.10 (0.3%), extract_message_metadata: 13 (3.0%), get_uri_detail_list: 1.92 (0.4%), tests_pri_-1000: 13 (3.1%), tests_pri_-950: 1.22 (0.3%), tests_pri_-900: 1.02 (0.2%), tests_pri_-90: 138 (32.3%), check_bayes: 136 (31.9%), b_tokenize: 6 (1.5%), b_tok_get_all: 6 (1.4%), b_comp_prob: 2.1 (0.5%), b_tok_touch_all: 118 (27.7%), b_finish: 0.95 (0.2%), tests_pri_0: 238 (55.8%), check_dkim_signature: 0.50 (0.1%), check_dkim_adsp: 2.1 (0.5%), poll_dns_idle: 0.46 (0.1%), tests_pri_10: 2.1 (0.5%), tests_pri_500: 7 (1.6%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v2 2/6] exec: Lock more defensively in exec X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When taking the task_list_lock in de_thread also take the siglock. This makes de_thread closer to fork the canonical place where these locks are taken. To complete the defensiveness always take siglock when clearing group_exit_task and notify_count. This gives now gives the guarantee that group_exit_task and notify_count are now always changed under siglock. As anything multi-threaded in exec is a rare and slow path I don't think we care if we take an extra lock in practice. The practical reason for doing this is to enable setting signal->flags along with group_exit_task so that the function signal_group_exit can be simplified. Signed-off-by: "Eric W. Biederman" --- fs/exec.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index e6e8a9a70327..33b5d9229c01 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1171,6 +1171,7 @@ static int de_thread(struct task_struct *tsk) for (;;) { cgroup_threadgroup_change_begin(tsk); write_lock_irq(&tasklist_lock); + spin_lock(lock); /* * Do this under tasklist_lock to ensure that * exit_notify() can't miss ->group_exit_task @@ -1179,6 +1180,7 @@ static int de_thread(struct task_struct *tsk) if (likely(leader->exit_state)) break; __set_current_state(TASK_KILLABLE); + spin_unlock(lock); write_unlock_irq(&tasklist_lock); cgroup_threadgroup_change_end(tsk); schedule(); @@ -1234,14 +1236,17 @@ static int de_thread(struct task_struct *tsk) */ if (unlikely(leader->ptrace)) __wake_up_parent(leader, leader->parent); + spin_unlock(lock); write_unlock_irq(&tasklist_lock); cgroup_threadgroup_change_end(tsk); release_task(leader); } + spin_lock_irq(lock); sig->group_exit_task = NULL; sig->notify_count = 0; + spin_unlock_irq(lock); no_thread_group: /* we have changed execution domain */ @@ -1252,10 +1257,12 @@ static int de_thread(struct task_struct *tsk) killed: /* protects against exit_notify() and __exit_signal() */ - read_lock(&tasklist_lock); + read_lock_irq(&tasklist_lock); + spin_lock(lock); sig->group_exit_task = NULL; sig->notify_count = 0; - read_unlock(&tasklist_lock); + spin_unlock(lock); + read_unlock_irq(&tasklist_lock); return -EAGAIN; } From patchwork Tue Jun 23 21:54:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 11621873 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B7B2F60D for ; Tue, 23 Jun 2020 21:59:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A851E208A9 for ; Tue, 23 Jun 2020 21:59:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388356AbgFWV7J (ORCPT ); Tue, 23 Jun 2020 17:59:09 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:42034 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387455AbgFWV7J (ORCPT ); Tue, 23 Jun 2020 17:59:09 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out01.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jnqwd-0002ux-QC; Tue, 23 Jun 2020 15:59:07 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1jnqwc-0000mu-Qc; Tue, 23 Jun 2020 15:59:07 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Cc: , Linus Torvalds , Oleg Nesterov , Jann Horn , Kees Cook , Bernd Edlinger References: <87pn9u6h8c.fsf@x220.int.ebiederm.org> <87r1u5laac.fsf@x220.int.ebiederm.org> Date: Tue, 23 Jun 2020 16:54:43 -0500 In-Reply-To: <87r1u5laac.fsf@x220.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 23 Jun 2020 16:52:43 -0500") Message-ID: <87a70tla70.fsf_-_@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-XM-SPF: eid=1jnqwc-0000mu-Qc;;;mid=<87a70tla70.fsf_-_@x220.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+kkhDUBissrPENOFQGDqoexIjbrQanp20= 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=-0.2 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TooManySym_01 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.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 0; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: ; sa07 0; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ; X-Spam-Relay-Country: X-Spam-Timing: total 540 ms - load_scoreonly_sql: 0.11 (0.0%), signal_user_changed: 215 (39.9%), b_tie_ro: 213 (39.5%), parse: 1.09 (0.2%), extract_message_metadata: 12 (2.2%), get_uri_detail_list: 1.34 (0.2%), tests_pri_-1000: 15 (2.8%), tests_pri_-950: 1.44 (0.3%), tests_pri_-900: 1.10 (0.2%), tests_pri_-90: 82 (15.2%), check_bayes: 81 (14.9%), b_tokenize: 7 (1.3%), b_tok_get_all: 6 (1.1%), b_comp_prob: 2.1 (0.4%), b_tok_touch_all: 62 (11.5%), b_finish: 0.96 (0.2%), tests_pri_0: 192 (35.5%), check_dkim_signature: 1.17 (0.2%), check_dkim_adsp: 2.9 (0.5%), poll_dns_idle: 0.53 (0.1%), tests_pri_10: 2.3 (0.4%), tests_pri_500: 14 (2.5%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v2 3/6] signal: Implement SIGNAL_GROUP_DETHREAD X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org To allow signal_group_exit to be simplfied so that it can only test signal->flags. Add a new flag SIGNAL_GROUP_DETHREAD, that is set and cleared where de_thread sets and clears group_exit_task today. Signed-off-by: "Eric W. Biederman" --- fs/exec.c | 3 +++ include/linux/sched/signal.h | 1 + 2 files changed, 4 insertions(+) diff --git a/fs/exec.c b/fs/exec.c index 33b5d9229c01..9c4c1ab8f715 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1145,6 +1145,7 @@ static int de_thread(struct task_struct *tsk) return -EAGAIN; } + sig->flags |= SIGNAL_GROUP_DETHREAD; sig->group_exit_task = tsk; sig->notify_count = zap_other_threads(tsk); if (!thread_group_leader(tsk)) @@ -1244,6 +1245,7 @@ static int de_thread(struct task_struct *tsk) } spin_lock_irq(lock); + sig->flags &= ~SIGNAL_GROUP_DETHREAD; sig->group_exit_task = NULL; sig->notify_count = 0; spin_unlock_irq(lock); @@ -1259,6 +1261,7 @@ static int de_thread(struct task_struct *tsk) /* protects against exit_notify() and __exit_signal() */ read_lock_irq(&tasklist_lock); spin_lock(lock); + sig->flags &= ~SIGNAL_GROUP_DETHREAD; sig->group_exit_task = NULL; sig->notify_count = 0; spin_unlock(lock); diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index b4f36a11be5e..5ff8697b21cd 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -253,6 +253,7 @@ struct signal_struct { /* Signal group actions. */ #define SIGNAL_GROUP_EXIT 0x00000100 /* group exit in progress */ #define SIGNAL_GROUP_COREDUMP 0x00000200 /* coredump in progress */ +#define SIGNAL_GROUP_DETHREAD 0x00000400 /* exec de_thread in progress */ /* Flags applicable to the entire signal group. */ #define SIGNAL_UNKILLABLE 0x00001000 /* for init: ignore fatal signals */ From patchwork Tue Jun 23 21:55:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 11621875 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83D9060D for ; Tue, 23 Jun 2020 21:59:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75A552078E for ; Tue, 23 Jun 2020 21:59:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388783AbgFWV7q (ORCPT ); Tue, 23 Jun 2020 17:59:46 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:51274 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387558AbgFWV7p (ORCPT ); Tue, 23 Jun 2020 17:59:45 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out03.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jnqxE-0004Hk-I8; Tue, 23 Jun 2020 15:59:44 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1jnqxD-0003OQ-N3; Tue, 23 Jun 2020 15:59:44 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Cc: , Linus Torvalds , Oleg Nesterov , Jann Horn , Kees Cook , Bernd Edlinger References: <87pn9u6h8c.fsf@x220.int.ebiederm.org> <87r1u5laac.fsf@x220.int.ebiederm.org> Date: Tue, 23 Jun 2020 16:55:20 -0500 In-Reply-To: <87r1u5laac.fsf@x220.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 23 Jun 2020 16:52:43 -0500") Message-ID: <874kr1la5z.fsf_-_@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-XM-SPF: eid=1jnqxD-0003OQ-N3;;;mid=<874kr1la5z.fsf_-_@x220.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+2UXPbTw30wEkfFjbQUHoFz2avs7xxoas= 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 sa06.xmission.com X-Spam-Level: X-Spam-Status: No, score=0.5 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01,XMSubLong 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 * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 0; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: ; sa06 0; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ; X-Spam-Relay-Country: X-Spam-Timing: total 334 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 10 (3.1%), b_tie_ro: 9 (2.7%), parse: 0.94 (0.3%), extract_message_metadata: 11 (3.3%), get_uri_detail_list: 1.27 (0.4%), tests_pri_-1000: 13 (3.8%), tests_pri_-950: 1.28 (0.4%), tests_pri_-900: 1.00 (0.3%), tests_pri_-90: 102 (30.7%), check_bayes: 101 (30.2%), b_tokenize: 6 (1.9%), b_tok_get_all: 6 (1.9%), b_comp_prob: 2.1 (0.6%), b_tok_touch_all: 82 (24.6%), b_finish: 0.96 (0.3%), tests_pri_0: 182 (54.5%), check_dkim_signature: 0.54 (0.2%), check_dkim_adsp: 2.7 (0.8%), poll_dns_idle: 0.78 (0.2%), tests_pri_10: 2.2 (0.6%), tests_pri_500: 7 (2.1%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v2 4/6] signal: In signal_group_exit remove the group_exit_task test X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org There are two places where signal_group_exit are set. In the fs/exec.c:de_thread() and in fs/coredump.c:zap_threads(). The coredump usage of group_exit_task was explicitly added[1] so that signal_group_exit() would return true during a coredump. When examining the coredump usage it turns out that SIGNAL_GROUP_COREDUMP is set in all of the same places as group_exit_task. So signal_group_exit can test SIGNAL_GROUP_COREDUMP and achieve the same results with respect to coredumps as testing group_exit_task. Similarly the exec code sets and clears SIGNAL_GROUP_DETHREAD in all of the places where group_exit_task is set and cleared. So test SIGNAL_GROUP_COREDUMP | SIGNAL_GROUP_DETHREAD instead of group_exit_task. Cc: Oleg Nesterov [1] 6cd8f0acae34 ("coredump: ensure that SIGKILL always kills the dumping thread") Signed-off-by: "Eric W. Biederman" --- include/linux/sched/signal.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 5ff8697b21cd..43822e2b63e6 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -268,8 +268,9 @@ static inline void signal_set_stop_flags(struct signal_struct *sig, /* If true, all threads except ->group_exit_task have pending SIGKILL */ static inline int signal_group_exit(const struct signal_struct *sig) { - return (sig->flags & SIGNAL_GROUP_EXIT) || - (sig->group_exit_task != NULL); + return (sig->flags & (SIGNAL_GROUP_EXIT | + SIGNAL_GROUP_COREDUMP | + SIGNAL_GROUP_DETHREAD)); } extern void flush_signals(struct task_struct *); From patchwork Tue Jun 23 21:55:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 11621877 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 75FF390 for ; Tue, 23 Jun 2020 22:00:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6799E207FF for ; Tue, 23 Jun 2020 22:00:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388927AbgFWWAR (ORCPT ); Tue, 23 Jun 2020 18:00:17 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:42486 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387558AbgFWWAQ (ORCPT ); Tue, 23 Jun 2020 18:00:16 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out01.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jnqxj-00032s-8r; Tue, 23 Jun 2020 16:00:15 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1jnqxi-0003Uu-CR; Tue, 23 Jun 2020 16:00:15 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Cc: , Linus Torvalds , Oleg Nesterov , Jann Horn , Kees Cook , Bernd Edlinger References: <87pn9u6h8c.fsf@x220.int.ebiederm.org> <87r1u5laac.fsf@x220.int.ebiederm.org> Date: Tue, 23 Jun 2020 16:55:51 -0500 In-Reply-To: <87r1u5laac.fsf@x220.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 23 Jun 2020 16:52:43 -0500") Message-ID: <87y2odjvko.fsf_-_@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-XM-SPF: eid=1jnqxi-0003Uu-CR;;;mid=<87y2odjvko.fsf_-_@x220.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18OOvS43z9gpnli31m0/YVpcSYNZcjVme4= 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=-0.2 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TooManySym_01 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.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 0; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: ; sa07 0; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ; X-Spam-Relay-Country: X-Spam-Timing: total 361 ms - load_scoreonly_sql: 0.06 (0.0%), signal_user_changed: 11 (3.2%), b_tie_ro: 10 (2.8%), parse: 1.74 (0.5%), extract_message_metadata: 13 (3.5%), get_uri_detail_list: 1.05 (0.3%), tests_pri_-1000: 17 (4.7%), tests_pri_-950: 2.2 (0.6%), tests_pri_-900: 1.58 (0.4%), tests_pri_-90: 140 (38.7%), check_bayes: 138 (38.2%), b_tokenize: 6 (1.7%), b_tok_get_all: 6 (1.6%), b_comp_prob: 2.2 (0.6%), b_tok_touch_all: 120 (33.2%), b_finish: 1.04 (0.3%), tests_pri_0: 160 (44.5%), check_dkim_signature: 0.51 (0.1%), check_dkim_adsp: 2.5 (0.7%), poll_dns_idle: 0.54 (0.1%), tests_pri_10: 2.7 (0.7%), tests_pri_500: 8 (2.1%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v2 5/6] coredump: Stop using group_exit_task X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Setting and clearing of group_exit_task in the coredump code was added to affect the outcome of signal_group_exit()[1]. The coredump code has not grown any other uses for setting group_exit_task since. Now that signal_group_exit() no longer tests group_exit_task stop setting and clearing it. [1] 6cd8f0acae34 ("coredump: ensure that SIGKILL always kills the dumping thread") Signed-off-by: "Eric W. Biederman" --- fs/coredump.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index 7237f07ff6be..37b71c72ab3a 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -369,7 +369,6 @@ static int zap_threads(struct task_struct *tsk, struct mm_struct *mm, spin_lock_irq(&tsk->sighand->siglock); if (!signal_group_exit(tsk->signal)) { mm->core_state = core_state; - tsk->signal->group_exit_task = tsk; nr = zap_process(tsk, exit_code, 0); clear_tsk_thread_flag(tsk, TIF_SIGPENDING); } @@ -481,7 +480,6 @@ static void coredump_finish(struct mm_struct *mm, bool core_dumped) spin_lock_irq(¤t->sighand->siglock); if (core_dumped && !__fatal_signal_pending(current)) current->signal->group_exit_code |= 0x80; - current->signal->group_exit_task = NULL; current->signal->flags = SIGNAL_GROUP_EXIT; spin_unlock_irq(¤t->sighand->siglock); From patchwork Tue Jun 23 21:56:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 11621881 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B87290 for ; Tue, 23 Jun 2020 22:00:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D62320675 for ; Tue, 23 Jun 2020 22:00:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388366AbgFWWAt (ORCPT ); Tue, 23 Jun 2020 18:00:49 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:58744 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388125AbgFWWAs (ORCPT ); Tue, 23 Jun 2020 18:00:48 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out02.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jnqyF-0004gJ-GE; Tue, 23 Jun 2020 16:00:47 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1jnqyE-00011w-IF; Tue, 23 Jun 2020 16:00:47 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Cc: , Linus Torvalds , Oleg Nesterov , Jann Horn , Kees Cook , Bernd Edlinger References: <87pn9u6h8c.fsf@x220.int.ebiederm.org> <87r1u5laac.fsf@x220.int.ebiederm.org> Date: Tue, 23 Jun 2020 16:56:23 -0500 In-Reply-To: <87r1u5laac.fsf@x220.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 23 Jun 2020 16:52:43 -0500") Message-ID: <87sgeljvjs.fsf_-_@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-XM-SPF: eid=1jnqyE-00011w-IF;;;mid=<87sgeljvjs.fsf_-_@x220.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1//9RpPvm0Ju/m/af9xHXdmD0J+69ybl0M= 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=0.5 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TooManySym_01,XMSubLong 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 * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 0; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: ; sa07 0; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ; X-Spam-Relay-Country: X-Spam-Timing: total 543 ms - load_scoreonly_sql: 0.10 (0.0%), signal_user_changed: 11 (2.1%), b_tie_ro: 10 (1.8%), parse: 1.15 (0.2%), extract_message_metadata: 19 (3.4%), get_uri_detail_list: 3.2 (0.6%), tests_pri_-1000: 24 (4.3%), tests_pri_-950: 1.34 (0.2%), tests_pri_-900: 1.12 (0.2%), tests_pri_-90: 159 (29.2%), check_bayes: 157 (28.9%), b_tokenize: 17 (3.1%), b_tok_get_all: 9 (1.6%), b_comp_prob: 4.3 (0.8%), b_tok_touch_all: 123 (22.6%), b_finish: 1.00 (0.2%), tests_pri_0: 313 (57.7%), check_dkim_signature: 0.82 (0.2%), check_dkim_adsp: 2.2 (0.4%), poll_dns_idle: 0.53 (0.1%), tests_pri_10: 2.2 (0.4%), tests_pri_500: 7 (1.3%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v2 6/6] exec: Rename group_exit_task group_exec_task and correct the Documentation X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Rename group_exit_task to group_exec_task to make it clear this field is only used during exec. Update the comments for the fields group_exec_task and notify_count as they are only used by exec. Notifications to the execing task aka group_exec_task happen at 0 and -1. Signed-off-by: "Eric W. Biederman" --- fs/exec.c | 8 ++++---- include/linux/sched/signal.h | 11 ++++------- kernel/exit.c | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 9c4c1ab8f715..c594af64acd2 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1146,7 +1146,7 @@ static int de_thread(struct task_struct *tsk) } sig->flags |= SIGNAL_GROUP_DETHREAD; - sig->group_exit_task = tsk; + sig->group_exec_task = tsk; sig->notify_count = zap_other_threads(tsk); if (!thread_group_leader(tsk)) sig->notify_count--; @@ -1175,7 +1175,7 @@ static int de_thread(struct task_struct *tsk) spin_lock(lock); /* * Do this under tasklist_lock to ensure that - * exit_notify() can't miss ->group_exit_task + * exit_notify() can't miss ->group_exec_task */ sig->notify_count = -1; if (likely(leader->exit_state)) @@ -1246,7 +1246,7 @@ static int de_thread(struct task_struct *tsk) spin_lock_irq(lock); sig->flags &= ~SIGNAL_GROUP_DETHREAD; - sig->group_exit_task = NULL; + sig->group_exec_task = NULL; sig->notify_count = 0; spin_unlock_irq(lock); @@ -1262,7 +1262,7 @@ static int de_thread(struct task_struct *tsk) read_lock_irq(&tasklist_lock); spin_lock(lock); sig->flags &= ~SIGNAL_GROUP_DETHREAD; - sig->group_exit_task = NULL; + sig->group_exec_task = NULL; sig->notify_count = 0; spin_unlock(lock); read_unlock_irq(&tasklist_lock); diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 43822e2b63e6..ad6b209b1363 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -98,13 +98,10 @@ struct signal_struct { /* thread group exit support */ int group_exit_code; - /* overloaded: - * - notify group_exit_task when ->count is equal to notify_count - * - everyone except group_exit_task is stopped during signal delivery - * of fatal signals, group_exit_task processes the signal. - */ + + /* exec support, notify group_exec_task when notify_count is 0 or -1 */ int notify_count; - struct task_struct *group_exit_task; + struct task_struct *group_exec_task; /* thread group stop support, overloads group_exit_code too */ int group_stop_count; @@ -265,7 +262,7 @@ static inline void signal_set_stop_flags(struct signal_struct *sig, sig->flags = (sig->flags & ~SIGNAL_STOP_MASK) | flags; } -/* If true, all threads except ->group_exit_task have pending SIGKILL */ +/* If true, all threads except ->group_exec_task have pending SIGKILL */ static inline int signal_group_exit(const struct signal_struct *sig) { return (sig->flags & (SIGNAL_GROUP_EXIT | diff --git a/kernel/exit.c b/kernel/exit.c index 727150f28103..4206d33b4904 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -115,7 +115,7 @@ static void __exit_signal(struct task_struct *tsk) * then notify it: */ if (sig->notify_count > 0 && !--sig->notify_count) - wake_up_process(sig->group_exit_task); + wake_up_process(sig->group_exec_task); if (tsk == sig->curr_target) sig->curr_target = next_thread(tsk); @@ -672,7 +672,7 @@ static void exit_notify(struct task_struct *tsk, int group_dead) /* mt-exec, de_thread() is waiting for group leader */ if (unlikely(tsk->signal->notify_count < 0)) - wake_up_process(tsk->signal->group_exit_task); + wake_up_process(tsk->signal->group_exec_task); write_unlock_irq(&tasklist_lock); list_for_each_entry_safe(p, n, &dead, ptrace_entry) {