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 C8FE2C7EE2F for ; Sun, 26 Feb 2023 03:42:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbjBZDmN (ORCPT ); Sat, 25 Feb 2023 22:42:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229662AbjBZDmI (ORCPT ); Sat, 25 Feb 2023 22:42:08 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0D83126EE; Sat, 25 Feb 2023 19:42:01 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4F7B260BDC; Sun, 26 Feb 2023 03:42:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45F7FC433A0; Sun, 26 Feb 2023 03:41:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677382920; bh=gJQDl+6gt6pDDRZxyMcb9EXsji4noq6fNOEZsH36Rqk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P8/6XlBSy/X5CtB0sAtJlsssjweDiPX7qVS6FzCG4fbT18S4QKvd68F/ZlY6QQQKA mmEUnubpjoz0sDcBWXb61EAVECIFNuc4lFflsZIQ5WVDy0RkQBG25LEbgkdhCGOkkV RuNV0nE2sXDoBE/5vP9oQp0luaENNtMgjiJc14W8hhlFQiFxLVNlBdywktvi6posCe sScX7696SNklalOCs/3FI4wfHynHvz2lbgyclVikGtEGPJJnNpExyOchEmNQ6qcKL3 tal10wCr6oY8jdpwZ+rduRA8wx47sYER3MjHpqxgNKb4f67r7H0gQsKRaIMQTD0kz7 2YVm+Fej3LS1Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Nicholas Piggin , Michael Ellerman , Peter Zijlstra , "Eric W. Biederman" , Sasha Levin , keescook@chromium.org, akpm@linux-foundation.org, mcgrof@kernel.org, mark.rutland@arm.com, wangkefeng.wang@huawei.com, jannh@google.com, oleg@redhat.com, mingo@kernel.org Subject: [PATCH AUTOSEL 6.2 05/21] exit: Detect and fix irq disabled state in oops Date: Sat, 25 Feb 2023 22:41:34 -0500 Message-Id: <20230226034150.771411-5-sashal@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230226034150.771411-1-sashal@kernel.org> References: <20230226034150.771411-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicholas Piggin [ Upstream commit 001c28e57187570e4b5aa4492c7a957fb6d65d7b ] 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 Signed-off-by: Peter Zijlstra (Intel) Acked-by: "Eric W. Biederman" Link: https://lore.kernel.org/lkml/20221004094401.708299-1-npiggin@gmail.com/ Signed-off-by: Sasha Levin --- kernel/exit.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/exit.c b/kernel/exit.c index 15dc2ec80c467..bccfa4218356e 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -807,6 +807,8 @@ void __noreturn do_exit(long code) struct task_struct *tsk = current; int group_dead; + WARN_ON(irqs_disabled()); + synchronize_group_exit(tsk, code); WARN_ON(tsk->plug); @@ -938,6 +940,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.39.0