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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 833B8C4332F for ; Sat, 24 Dec 2022 04:36:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231142AbiLXE3K (ORCPT ); Fri, 23 Dec 2022 23:29:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230160AbiLXE3D (ORCPT ); Fri, 23 Dec 2022 23:29:03 -0500 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0E6AB7D5 for ; Fri, 23 Dec 2022 20:29:01 -0800 (PST) Received: from in01.mta.xmission.com ([166.70.13.51]:38360) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1p8w9b-003u2d-Jt; Fri, 23 Dec 2022 21:28:59 -0700 Received: from ip68-110-29-46.om.om.cox.net ([68.110.29.46]:39140 helo=email.froward.int.ebiederm.org.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 1p8w9a-003BAt-9Q; Fri, 23 Dec 2022 21:28:59 -0700 From: "Eric W. Biederman" To: "Nicholas Piggin" Cc: , "Michael Ellerman" References: <20221004094401.708299-1-npiggin@gmail.com> Date: Fri, 23 Dec 2022 22:28:27 -0600 In-Reply-To: (Nicholas Piggin's message of "Tue, 20 Dec 2022 17:14:05 +1000") Message-ID: <874jtlo26s.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1p8w9a-003BAt-9Q;;;mid=<874jtlo26s.fsf@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.110.29.46;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1/zp9owaAJU/uCXstuqSpsBdgDyky8+sRU= X-SA-Exim-Connect-IP: 68.110.29.46 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH] exit: Detect and fix irq disabled state in oops 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 "Nicholas Piggin" writes: > On Tue Oct 4, 2022 at 7:44 PM AEST, Nicholas Piggin wrote: >> If a task oopses with irqs disabled, this can cause various cascading >> problems in the oops path such as sleep-from-invalid warnings, and >> potentially worse. >> >> Since commit 0258b5fd7c712 ("coredump: Limit coredumps to a single >> thread group"), the unconditional irq enable in coredump_task_exit() >> will "fix" the irq state to be enabled early in do_exit(), so currently >> this may not be triggerable, but that is coincidental and fragile. >> >> Detect and fix the irqs_disabled() condition in the oops path before >> calling do_exit(), similarly to the way in_atomic() is handled. >> >> Reported-by: Michael Ellerman >> Signed-off-by: Nicholas Piggin > > Hey Eric, did you have any thoughts on this? No strong thoughts. I agree that the unconditionally disabling then enabling irqs in coredump_task_exit will mean there is likely to be little change in real behavior. I also agree that is something fragile to depend upon so we making our assumptions explicit seems good. Acked-by: "Eric W. Biederman" > > Thanks, > Nick > >> --- >> kernel/exit.c | 6 ++++++ >> 1 file changed, 6 insertions(+) >> >> diff --git a/kernel/exit.c b/kernel/exit.c >> index 84021b24f79e..fa696765f694 100644 >> --- a/kernel/exit.c >> +++ b/kernel/exit.c >> @@ -738,6 +738,7 @@ void __noreturn do_exit(long code) >> struct task_struct *tsk = current; >> int group_dead; >> >> + WARN_ON(irqs_disabled()); >> WARN_ON(tsk->plug); >> >> kcov_task_exit(tsk); >> @@ -865,6 +866,11 @@ void __noreturn make_task_dead(int signr) >> if (unlikely(!tsk->pid)) >> panic("Attempted to kill the idle task!"); >> >> + if (unlikely(irqs_disabled())) { >> + pr_info("note: %s[%d] exited with irqs disabled\n", >> + current->comm, task_pid_nr(current)); >> + local_irq_enable(); >> + } >> if (unlikely(in_atomic())) { >> pr_info("note: %s[%d] exited with preempt_count %d\n", >> current->comm, task_pid_nr(current), >> -- >> 2.37.2