From patchwork Thu Feb 2 05:25:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 51694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52412wrn; Wed, 1 Feb 2023 21:29:27 -0800 (PST) X-Google-Smtp-Source: AK7set8j2rS6xgXQYJG52KmWX2QOKHRLGgKQI3BcoQYu7De6N2XGGISMshjF3ICvS3yw5gMeVLMd X-Received: by 2002:a05:6a20:8f06:b0:bc:ee95:dd3 with SMTP id b6-20020a056a208f0600b000bcee950dd3mr7164646pzk.54.1675315766884; Wed, 01 Feb 2023 21:29:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315766; cv=none; d=google.com; s=arc-20160816; b=xXounzxs6PDkiZY/C+7BpZHZHdRi5TVdMt3c4l1q1FjEoZZJziO26wPlsQZJ4MN2ka 3FxNBNbbNdHQPF66lwpNcDeqbfOMfsR2i0nTrfZ4FRIW6Lk3dQiS204ztCvyay77ekF0 0NNDuR2PEoT3HlWmT4m6pX+yR52bhpErVr7urS/NUbRa+Gfz5Q/28b6QU8YqwQDyDLav xs6sLLXwfEQqiinxEbkiyteYrSMUmCwRrT1nvbKtfJM65ydfW+sj2oz0ogiPWRTGeQC5 CV7ihdsZ90GWZMkEahc6cc2OZ4rxzqc9xYvORM6HXaZDFuWgQIHlk1yGZrjK+64P692x 1ThQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yGQysUV7bOtQpgi4S2oLylfvfEvDs0+YgiIDfzQ64lM=; b=RnaiI6su4g+xOK6OgSE+vOrXzdggz8mSNC/0uUFDKFzfaTVGg6Px1gR9IiyuDArskV mKtGSw64wT1IFOGiDFfdZXeTwgqVC4PEG2cD40xStbD+T3GoaH0/4euXi4X0KEPeMtPP jIQizv1j2XCPlGGAXXDvCRzGx96ygGQXo4tesuKmglJbupNY2t6JL9jfwgye0NWB0P+E xDINZ/yQQmkTmLGUrSFcvWvV6606BV9deu4tT4Z2z04H23Ol5cTcssdAuawAGQNzoVli JehDhsnU5m9R88FyY5axq0K/MOaw+IYcbdCPfthnWLhgVUyjLnFFs5tkakIAfw5IZ+t8 bwYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=plCbt4G0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u64-20020a638543000000b004cf574a78e1si20318940pgd.358.2023.02.01.21.29.11; Wed, 01 Feb 2023 21:29:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=plCbt4G0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231896AbjBBF2R (ORCPT + 99 others); Thu, 2 Feb 2023 00:28:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjBBF2H (ORCPT ); Thu, 2 Feb 2023 00:28:07 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F8CA1205A; Wed, 1 Feb 2023 21:28:05 -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 ams.source.kernel.org (Postfix) with ESMTPS id BBBD9B8247A; Thu, 2 Feb 2023 05:28:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE574C433A1; Thu, 2 Feb 2023 05:28:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315682; bh=DMz/MOCU306dak0OU7QypACmgBeBp7Zx+Xdx74bnwbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=plCbt4G0Ne1pvGa4coC/MeYJNMQOhsrWt60/rLLkXn4vSldpWk6Zjwsd3VhS8IjMy aKnKZNrJG2XnqyrucHG4fb7wIyIbKT/R7qmDdgILcsBreT3jl0Mj195qbfQ4TTGtqm GMXTC1Rz87bdA4bXo7ozclpJ1Nx+ViuUmexLQwwACh6mg9DuMUqoR0b5gGOyHCnOZ3 dK9KZsnhop+Bsqn5Tqh8yvXUcVsCPmjaaw5NIpvTzAJW9benVue/fcnOiGOMLLrIgI iV+tk66k7Jfr2UgLW/z5ocS5Q5wC6+NOeJqO2XGIMWuWL2/dgtodxsW2BirAWW0ksC LhRJT8u5iHuJQ== From: Eric Biggers To: stable@vger.kernel.org Cc: Harshit Mogalapalli , Kees Cook , SeongJae Park , Seth Jenkins , Jann Horn , "Eric W . Biederman" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Andrey Ryabinin , Baoquan He , Jonathan Corbet , Xuefeng Li , Tiezhu Yang , Marco Elver , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 02/16] panic: unset panic_on_warn inside panic() Date: Wed, 1 Feb 2023 21:25:50 -0800 Message-Id: <20230202052604.179184-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695905955686940?= X-GMAIL-MSGID: =?utf-8?q?1756695905955686940?= From: Tiezhu Yang commit 1a2383e8b84c0451fd9b1eec3b9aab16f30b597c upstream. In the current code, the following three places need to unset panic_on_warn before calling panic() to avoid recursive panics: kernel/kcsan/report.c: print_report() kernel/sched/core.c: __schedule_bug() mm/kfence/report.c: kfence_report_error() In order to avoid copy-pasting "panic_on_warn = 0" all over the places, it is better to move it inside panic() and then remove it from the other places. Link: https://lkml.kernel.org/r/1644324666-15947-4-git-send-email-yangtiezhu@loongson.cn Signed-off-by: Tiezhu Yang Reviewed-by: Marco Elver Cc: Andrey Ryabinin Cc: Baoquan He Cc: Jonathan Corbet Cc: Xuefeng Li Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Eric Biggers --- kernel/panic.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/kernel/panic.c b/kernel/panic.c index 8138a676fb7d1..a078d413042f2 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -142,6 +142,16 @@ void panic(const char *fmt, ...) int old_cpu, this_cpu; bool _crash_kexec_post_notifiers = crash_kexec_post_notifiers; + if (panic_on_warn) { + /* + * This thread may hit another WARN() in the panic path. + * Resetting this prevents additional WARN() from panicking the + * system on this thread. Other threads are blocked by the + * panic_mutex in panic(). + */ + panic_on_warn = 0; + } + /* * Disable local interrupts. This will prevent panic_smp_self_stop * from deadlocking the first cpu that invokes the panic, since @@ -530,16 +540,8 @@ void __warn(const char *file, int line, void *caller, unsigned taint, if (args) vprintk(args->fmt, args->args); - if (panic_on_warn) { - /* - * This thread may hit another WARN() in the panic path. - * Resetting this prevents additional WARN() from panicking the - * system on this thread. Other threads are blocked by the - * panic_mutex in panic(). - */ - panic_on_warn = 0; + if (panic_on_warn) panic("panic_on_warn set ...\n"); - } print_modules();