Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1479921pxf; Fri, 12 Mar 2021 10:24:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaO9tP56/yL/594zIO+Wnyk+MVQsj/pife8FVzKM5rjqjiAtjCo9rIuwJAFSKTQlxJmZ+F X-Received: by 2002:a17:906:f1d6:: with SMTP id gx22mr10081123ejb.59.1615573476277; Fri, 12 Mar 2021 10:24:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615573476; cv=none; d=google.com; s=arc-20160816; b=jOQIHfd74Bc8ZueJTfckMmo8yW0UhPlpLDYLfpBrR7n5nNEgvo6pQUKth96oO+/gWu 3u0IeJXxBpIHxsPNBx22kHUfuRDuFG0EUiFAyc1cG09kQI/GLdSOV3FtR+/mvBwOqsZn m2vH/REcBr+bENJUbQrn5cA8dGW+tpqoqrGV90sJNc1/jrFpXer1raYm1sdx09sKcPQg ChbUzmInd001lnXyA8F9jo0JJpoA+/rWlqP33v7Edg7ZwZMWEPplaOy/RcwEryNOyrhB 7sP6A/bqgc7L8E9zWl0ow/qAZdHavN6UGBxhkhlGJIgKRaX6k/zIAqjw/ctKQLVxoQfF MPdg== 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=zWqZl0pKVXffRKCiHw9hU/TANFbpUouva0IjCtU6rFs=; b=WiTnezcDA/QFMiWNqklnxPoYGpLXlWkKNS0xU0n5Eaie2eBL8T5Jmy0z/3EUi0SDAb +D1Dtw6nDJq9ImYZOGK7to3qlrAZLZKFsrMuBy0J7XH7PvP7DoHGwpE9CWlJ/lTkNdAg XpwxDfuZ5W9Tl2x5/MctbY8rheLTkhoLKgxrH0QDV7ZS+4G2QBbIvQG/ZJ8UMiMTHapG ZYsizdxV546BeHkTfv1IAVVIHD3aBDsP9GPtsp+yFT4iFVOLxOoK+Ap+2qfjmex0ObSb VL4xiILD/Vh9UtPS6xPNsPhiiIoI1AbPReIOkkaYvkl+STEnUjb6c/vToIRLxJ+mbZ2o nhqA== 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 38si4851758edr.200.2021.03.12.10.24.13; Fri, 12 Mar 2021 10:24:36 -0800 (PST) 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 S233114AbhCLSXS (ORCPT + 99 others); Fri, 12 Mar 2021 13:23:18 -0500 Received: from out02.mta.xmission.com ([166.70.13.232]:55486 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233116AbhCLSXJ (ORCPT ); Fri, 12 Mar 2021 13:23:09 -0500 Received: from in02.mta.xmission.com ([166.70.13.52]) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lKmRH-00HQQm-Fo; Fri, 12 Mar 2021 11:23:07 -0700 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=fess.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lKmRG-006GW6-3r; Fri, 12 Mar 2021 11:23:06 -0700 From: ebiederm@xmission.com (Eric W. Biederman) To: Qianli Zhao Cc: christian@brauner.io, axboe@kernel.dk, oleg@redhat.com, tglx@linutronix.de, pcc@google.com, linux-kernel@vger.kernel.org, zhaoqianli@xiaomi.com References: <1615519478-178620-1-git-send-email-zhaoqianligood@gmail.com> Date: Fri, 12 Mar 2021 12:23:11 -0600 In-Reply-To: <1615519478-178620-1-git-send-email-zhaoqianligood@gmail.com> (Qianli Zhao's message of "Fri, 12 Mar 2021 11:24:38 +0800") Message-ID: 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=1lKmRG-006GW6-3r;;;mid=;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/f1kXFGkxezBTJ1EPv0GbYNbbdaorH2Es= 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 sa03.xmission.com X-Spam-Level: X-Spam-Status: No, score=0.7 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,XMSubLong,XM_B_SpammyWords autolearn=disabled version=3.4.2 X-Spam-Virus: No 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.4995] * 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 * [sa03 1397; Body=1 Fuz1=1 Fuz2=1] * 0.2 XM_B_SpammyWords One or more commonly used spammy words X-Spam-DCC: XMission; sa03 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Qianli Zhao X-Spam-Relay-Country: X-Spam-Timing: total 513 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 3.4 (0.7%), b_tie_ro: 2.4 (0.5%), parse: 1.10 (0.2%), extract_message_metadata: 13 (2.6%), get_uri_detail_list: 2.7 (0.5%), tests_pri_-1000: 5 (1.1%), tests_pri_-950: 1.44 (0.3%), tests_pri_-900: 1.14 (0.2%), tests_pri_-90: 138 (26.9%), check_bayes: 136 (26.5%), b_tokenize: 11 (2.2%), b_tok_get_all: 8 (1.6%), b_comp_prob: 2.7 (0.5%), b_tok_touch_all: 111 (21.6%), b_finish: 0.72 (0.1%), tests_pri_0: 336 (65.5%), check_dkim_signature: 0.42 (0.1%), check_dkim_adsp: 2.5 (0.5%), poll_dns_idle: 1.07 (0.2%), tests_pri_10: 2.8 (0.5%), tests_pri_500: 7 (1.4%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH V2] exit: trigger panic when global init has exited X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Qianli Zhao writes: > From: Qianli Zhao > > When init sub-threads running on different CPUs exit at the same time, > zap_pid_ns_processe()->BUG() may be happened. > And every thread status is abnormal after exit(PF_EXITING set,task->mm=NULL etc), > which makes it difficult to parse coredump from fulldump normally. > In order to fix the above problem, when any one init has been set to SIGNAL_GROUP_EXIT, > trigger panic immediately, and prevent other init threads from continuing to exit. > > [ 24.705376] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00007f00 > [ 24.705382] CPU: 4 PID: 552 Comm: init Tainted: G S O 4.14.180-perf-g4483caa8ae80-dirty #1 > [ 24.705390] kernel BUG at include/linux/pid_namespace.h:98! > > PID: 552 CPU: 4 COMMAND: "init" > PID: 1 CPU: 7 COMMAND: "init" > core4 core7 > ... sys_exit_group() > do_group_exit() > - sig->flags = SIGNAL_GROUP_EXIT > - zap_other_threads() > do_exit() //PF_EXITING is set > ret_to_user() > do_notify_resume() > get_signal() > - signal_group_exit > - goto fatal; > do_group_exit() > do_exit() //PF_EXITING is set > - panic("Attempted to kill init! exitcode=0x%08x\n") > exit_notify() > find_alive_thread() //no alive sub-threads > zap_pid_ns_processes()//CONFIG_PID_NS is not set > BUG() > > Signed-off-by: Qianli Zhao The changelog is much better thank you. As Oleg pointer out we need to do something like the code below. diff --git a/kernel/exit.c b/kernel/exit.c index 04029e35e69a..bc676c06ef9a 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -785,15 +785,16 @@ void __noreturn do_exit(long code) sync_mm_rss(tsk->mm); acct_update_integrals(tsk); group_dead = atomic_dec_and_test(&tsk->signal->live); + /* + * If the global init has exited, panic immediately to get a + * useable coredump. + */ + if (unlikely(is_global_init(tsk) && + (group_dead || (tsk->signal->flags & SIGNAL_GROUP_EXIT)))) { + panic("Attempted to kill init! exitcode=0x%08x\n", + tsk->signal->group_exit_code ?: (int)code); + } if (group_dead) { - /* - * If the last thread of global init has exited, panic - * immediately to get a useable coredump. - */ - if (unlikely(is_global_init(tsk))) - panic("Attempted to kill init! exitcode=0x%08x\n", - tsk->signal->group_exit_code ?: (int)code); - #ifdef CONFIG_POSIX_TIMERS hrtimer_cancel(&tsk->signal->real_timer); exit_itimers(tsk->signal); There is still a race that could lead to the BUG in zap_pid_ns_processes. We still have a case where the last two threads of a process call pthread_exit (aka do_exit not do_group_exit in the kernel). Thread A Thread B do_exit() do_exit() exit_signals() tsk->flags |= PF_EXITING; group_dead = false; exit_signals() tsk->flags |= PF_EXITING; exit_notify() forget_original_parent find_child_reaper reaper = find_alive_thread() zap_pid_ns_processes() BUG() group_dead = true; if (is_global_init()) panic("Attemted to kill init"); As we are guaranteed to see the panic with my change above I suggest we augment it by simply removing the BUG in zap_pid_ns_processes. Or maybe not if there is a better way to write the panic code. I don't think having pid namespaces compiled out is a particularly common case. So whatever we can do to keep the code correct and reduce testing. Eric