Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5567116ybl; Sun, 22 Dec 2019 08:57:42 -0800 (PST) X-Google-Smtp-Source: APXvYqxWL+ncle6T9iddGDIPDMWxbKv2uWAbYtG604CeN/WViOEAjxivOKY9v0cVax7u9WVvIlL9 X-Received: by 2002:a9d:ed5:: with SMTP id 79mr27860558otj.72.1577033862146; Sun, 22 Dec 2019 08:57:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577033862; cv=none; d=google.com; s=arc-20160816; b=uBy0WtwKdyN0YyumGxKQHziY+a153zsJFhGNnN2uon6xcQ6kU+b0m46HNeDOL24Lr4 TATLGW8X26h86yuiyb87wdZaSjGyB79p5icYsR3tDAFHaxwRrJglddBkhojod7FF6xws 00OUPbHbMQqIyYV0RbNT3ZWIqjFhzCladm0BYEMz8jpKwfAJt0mfueb9ihvrQ1Khiv9b 3DsrkPXo8Ng/p90vZg+WL6kIGqcsI5xh6imWWANLTBicBr9yjCZh7F1xDP6ako7G6ihp EP/i/gCdD/pVY8d6y6kmuP+gcxk8oOgPrt1UrSzSpZ9m4vLy1BNFj5OhSFLPxn5XXnGl a3bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=06pN6HgghAmlFzv4mGoZJtV/unZ4U/AcuUUi7m1Cz8Y=; b=avbXQmBwVtuHClYvCkpskzy4tpnuSZ5Viz/6HFSBEXuBCoDWHrk2uv/QmHPaOanRxM FNUW2jqHuSKYcrqL4hBPqEMmwuUkSmFsZaiA9soGJY0Z3h35wB5hc7JHG1BJfE36Dzi2 IdPVHH+wDho7VkgJWpKY8/ziRWr7d8F7sS++EPoPHNcEAydZfgC78Ch7B1j3GZ4TKl6C doYZ7Vs++npIlNxbESalRq7sYGpqyWFtV16PpXwBYjUm3T1Jfk1OeFzJdvDs39u4zJa9 +705QydnR9uPRV0EkqG2D+AuKDmQyM+ei2AkL2hj26cyqpzGn9okuTShFgZ/hKEEhEjt 4Tvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si8119618otr.102.2019.12.22.08.57.29; Sun, 22 Dec 2019 08:57:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726162AbfLVQ4o (ORCPT + 99 others); Sun, 22 Dec 2019 11:56:44 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:39808 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725919AbfLVQ4o (ORCPT ); Sun, 22 Dec 2019 11:56:44 -0500 Received: from [172.58.30.161] (helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ij4Wz-0007EQ-LL; Sun, 22 Dec 2019 16:56:38 +0000 From: Christian Brauner To: christian.brauner@ubuntu.com Cc: chenqiwu@xiaomi.com, kernel-team@android.com, linux-kernel@vger.kernel.org, mingo@kernel.org, oleg@redhat.com, peterz@infradead.org, prsood@codeaurora.org, qiwuchen55@gmail.com Subject: Applied patch "exit: panic before exit_mm() on global init exit" Date: Sun, 22 Dec 2019 17:56:11 +0100 Message-Id: <20191222165610.17637-1-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <1211FB6C-ECD6-4D4A-8353-4D103C1C5054@ubuntu.com> References: <1211FB6C-ECD6-4D4A-8353-4D103C1C5054@ubuntu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I've added the patch: exit: panic before exit_mm() on global init exit to https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/log/?h=fixes I've rewritten the commit message and fixed a typo in the comment. If noone objects this will be part of the threads-fixes pr early next week. Thanks! Christian From 43cf75d96409a20ef06b756877a2e72b10a026fc Mon Sep 17 00:00:00 2001 From: chenqiwu Date: Thu, 19 Dec 2019 14:29:53 +0800 Subject: [PATCH] exit: panic before exit_mm() on global init exit 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 --- kernel/exit.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index a46a50d67002..fc364272759d 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -517,10 +517,6 @@ static struct task_struct *find_child_reaper(struct task_struct *father, } 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); @@ -786,6 +782,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); -- 2.24.0