From patchwork Fri Feb 3 00:33:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 52234 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp558867wrn; Thu, 2 Feb 2023 16:37:12 -0800 (PST) X-Google-Smtp-Source: AK7set+tG7r970roe1yfBOH+nSOjsIK4z0m1JhQ//xfv4+Z2Lel1EUrwIdt0KXj+VduegLwAKETR X-Received: by 2002:a17:903:41ca:b0:196:6b7d:e6eb with SMTP id u10-20020a17090341ca00b001966b7de6ebmr9780020ple.59.1675384632574; Thu, 02 Feb 2023 16:37:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675384632; cv=none; d=google.com; s=arc-20160816; b=lit7PayUD7yFHXCQ3Gl0OdXYiEo+qW6eJMyRGKz1J9Y1D+tUOcJsUfShnCGPB6Shp6 mAo4lLwhxGRDAqekn6SsTO0oRwxbLFAy5WKQGkzT4v+gxpbXF/b76caMF8aSs9E32F+I Jqt/XGPTk2H/opuKZJv10Q7IRa7EI6DivgOf60XFaI9yGOgjt9yjFfw4B9OyU12X8tpo txOFw0FYiqPfuk+QW8IxkWt7HkArwfvM8NABpbMX8Mw6N6EYAC+/trB82MijBiwR4awD MIbgFDz/T/Yi5HdR/+I6PFr8Vi2sniJIY5YU+Oe8oWqwIDXGaMmTlhW9bKCzykjGyjcq RS1g== 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=gckCJgwrDWmh+2yXST9/kVftqSIFB2HBaiGP/gtc9u4=; b=EwM0FapEcIp3FpOIpuMsAu9Sqzaro+EbKQwg5EKinCMSziTVNCIt0Iuo5+s9IKaf82 kxcRvvV56Ie8RlmDUdXZMmWsGBUlyuG9gFI6+5tFST34AN3kuoPlo7n/OL7eANzGazVe ubWbwqSKg6lAix325fofqW8yXgHoiLhPbMyFejH+U/Fiekl2fM9eBMnY2LF769dv+GQU tjxfknDg+wgPkjuT4O761cVPf16kOvXNa+Z3uUPtsEomOEMZz10gacns6mMiKbk/WqeG RTkN7b7PIJKHbMx/Gx1+s3Is6ydu10qg2zxpW3uMjmJs9d2GyqGAvaDqCOGSqIfSsSfy VtiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qjkssc12; 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 b2-20020a170903228200b001944785f248si897022plh.84.2023.02.02.16.37.00; Thu, 02 Feb 2023 16:37:12 -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=qjkssc12; 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 S233090AbjBCAfg (ORCPT + 99 others); Thu, 2 Feb 2023 19:35:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232714AbjBCAf2 (ORCPT ); Thu, 2 Feb 2023 19:35:28 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47A2B64682; Thu, 2 Feb 2023 16:35:24 -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 D431E61D11; Fri, 3 Feb 2023 00:35:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C216BC433D2; Fri, 3 Feb 2023 00:35:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675384523; bh=gNpeNx44gA3Dz1NMaDk9iVn8+H0TL/VgfW5SQ5YlGbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qjkssc12B6Z7Jid7N0PlwYqWkcRej2GRbrk/JGUFYC4JYRa4PYiI9FJcmENCVu5zO YNVBCkCFntvNb7VCkeDOUtbJadIRNuy0tV7H/xRIK4tbtRkDZs8BlqTDuDFnaFslt2 HucE4jB3y+JyPeEtHifi/VIy5dqEMI4zR4yplR9KiwZmIOif7hIiaORmM8GZCgB8++ IxmFsADCiEsHkXrAL6v5rorsLr3TLJhg/As0WKtGqNartHy9GbigQX/a1rWE0p0ao1 +Gz0/+22cjlqnNiLbjVrgdeFd7aDJhLdI6lgyVRMJCJYYepBEEMCnLwUZzJpfEP0Ki 8kn77abxnAi5g== 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.14 v2 02/15] panic: unset panic_on_warn inside panic() Date: Thu, 2 Feb 2023 16:33:41 -0800 Message-Id: <20230203003354.85691-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230203003354.85691-1-ebiggers@kernel.org> References: <20230203003354.85691-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?1756768116688610950?= X-GMAIL-MSGID: =?utf-8?q?1756768116688610950?= 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 207ceac3a432e..bd7c3ea3bf1e6 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -139,6 +139,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 @@ -536,16 +546,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();