From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DC7BC3F68F for ; Tue, 7 Jan 2020 21:10:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 212BD2080A for ; Tue, 7 Jan 2020 21:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578431412; bh=4rvA4xy7n8lOc1+1pyA6Xx8lub7A20J3l8e/G3/YzHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=D+g80m14GtSSTBe1Ogm7NLqRVjOKu8z/tmz9hO966AluONnWrqBWKPSg+4hbh8Tpr gLpoxd79RNq/PdsYMdj7+kzOlFf6AUfmLcC5uqHRwRcXycnEL4wMqUYuBie9nfbMTT 7PBVdhKPQ+mXqnOpa4kqOJ9aEmKUDZhx8fwYF3D4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729437AbgAGVKL (ORCPT ); Tue, 7 Jan 2020 16:10:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:36364 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729928AbgAGVKI (ORCPT ); Tue, 7 Jan 2020 16:10:08 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 737D920880; Tue, 7 Jan 2020 21:10:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578431407; bh=4rvA4xy7n8lOc1+1pyA6Xx8lub7A20J3l8e/G3/YzHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OJrwXGsXT9lmXklHBYzejsQKs99DHjkEGftWbOJwByGsFjIESjcBFnhgkf4Wj+cys xG65ezGWe1747Lo88+EBAo844gLgAxDunz86ax7VJNsL9OJReQlhatlxbbD+1rprPd 35YHHmkBLVhKPHVUBhIJk3HhWkbgNMUEMk0LxOiI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, chenqiwu , Christian Brauner , Oleg Nesterov Subject: [PATCH 4.14 44/74] exit: panic before exit_mm() on global init exit Date: Tue, 7 Jan 2020 21:55:09 +0100 Message-Id: <20200107205210.841380914@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200107205135.369001641@linuxfoundation.org> References: <20200107205135.369001641@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: chenqiwu commit 43cf75d96409a20ef06b756877a2e72b10a026fc upstream. Currently, when global init and all threads in its thread-group have exited we panic via: do_exit() -> exit_notify() -> forget_original_parent() -> find_child_reaper() This makes it hard to extract a useable coredump for global init from a kernel crashdump because by the time we panic exit_mm() will have already released global init's mm. This patch moves the panic futher up before exit_mm() is called. As was the case previously, we only panic when global init and all its threads in the thread-group have exited. Signed-off-by: chenqiwu Acked-by: Christian Brauner Acked-by: Oleg Nesterov [christian.brauner@ubuntu.com: fix typo, rewrite commit message] Link: https://lore.kernel.org/r/1576736993-10121-1-git-send-email-qiwuchen55@gmail.com Signed-off-by: Christian Brauner Signed-off-by: Greg Kroah-Hartman --- kernel/exit.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- a/kernel/exit.c +++ b/kernel/exit.c @@ -577,10 +577,6 @@ static struct task_struct *find_child_re } write_unlock_irq(&tasklist_lock); - if (unlikely(pid_ns == &init_pid_ns)) { - panic("Attempted to kill init! exitcode=0x%08x\n", - father->signal->group_exit_code ?: father->exit_code); - } list_for_each_entry_safe(p, n, dead, ptrace_entry) { list_del_init(&p->ptrace_entry); @@ -823,6 +819,14 @@ void __noreturn do_exit(long code) acct_update_integrals(tsk); group_dead = atomic_dec_and_test(&tsk->signal->live); 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);