From patchwork Thu Feb 2 04:42:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 51671 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp37486wrn; Wed, 1 Feb 2023 20:45:24 -0800 (PST) X-Google-Smtp-Source: AK7set9K9xCmytKHNKfz99+3i8XtuCADgJeqTY8ck2rC7XWypL1Oh/rUst6D5VX/TB2V4Ktkv3t/ X-Received: by 2002:a05:6a00:1c96:b0:593:893f:81d7 with SMTP id y22-20020a056a001c9600b00593893f81d7mr4029703pfw.16.1675313123923; Wed, 01 Feb 2023 20:45:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675313123; cv=none; d=google.com; s=arc-20160816; b=zZGrLx7kA3sqJqweNxBpYcY4yNetEEC/wIb+hhSJ9VPGBCbJZZCXYWnkUAew6xY3BJ 0L3o6knnSw6+tTGHt8IAAN2ukryBFxV1UJjYkjYnWVriRuBzu6XWwGZHx30OqjFS5jA1 WVGhzwXbDRdz8bw5NOXMHanBZeeTzcNpEFXq3Kcm70wKuMutQg0/0JMZa/A0HjvJU7M4 2yKR3dmFuLyqCc/7qVuwkDGHBnfrzuKy3sF6YNC5vjOWjgbhUuMUZh2H8sMqP0plJpQT SE1DIg8QW+JZB7s1n2neCtXcZFz4dbntzpETBOZGHqQT5mtkvxvIcNMHiD+R38xuJrtA i8aw== 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=eHNbL3QGejSDk0ZVsjo3MAQ17xDn3FHJFW2tEWABkTk=; b=zPo8M2TNwLWbYluhegSi0ssvpXhuOFn/dPUYIiYaCNBq1QUSm+CHX52x7YICJNl2qi B5hIuHjRZwnly3sRcCX3qyquG09O6Wly+zMU/gxuCrKLAt+Sun9wb/izDRmLxI+kMVtB HC3cjv8xOS/Gv5l+rNiiWrmxCn1JkNgacCoABIVNhOvYIARxpBth9Oskkkq98rGCD8z1 zE/4W0D4Ft4ikwGKiEvdCMldc01h/TdlUYNO1lyEjqyG51VhkGMYGgywbmnCO/OJEB+Q zusDIqq1RqKWXbJnXCPM4tVDLnqbV2cCJFUqHFReJopzq7HBz/57QFxc0/fFVOD4iDxd Ldmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YV6ouvdV; 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 201-20020a6215d2000000b005615ef4cfccsi21125789pfv.185.2023.02.01.20.45.08; Wed, 01 Feb 2023 20:45:23 -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=YV6ouvdV; 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 S231540AbjBBEoO (ORCPT + 99 others); Wed, 1 Feb 2023 23:44:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231485AbjBBEoF (ORCPT ); Wed, 1 Feb 2023 23:44:05 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BDB87C725; Wed, 1 Feb 2023 20:43:50 -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 3F5D4B8241A; Thu, 2 Feb 2023 04:43:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63371C433A1; Thu, 2 Feb 2023 04:43:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675313027; bh=FwUnERZE15TbKqhpyOVhsiv4XwkhT87iVqe38AaX1Pk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YV6ouvdV6PTKZoxGg1HEC9mBAcsuctU3hivQDWY9PWI3fP5qNSFvOaWTasl5nnb4n D84ATPVB9UOch3jvfEDYD9GbRqTP17aGOJy5u3aC0xZnsvp9WYDjzhEtK+QjMy8gSY rkJ9Gx0Bk9RG2kBX3jv/ejqIxdtLfsDaXe9kCjq3EHBiMAW0achIhlLZKPY2dqZvg7 UfXHXINVMbla+HPtP6ghY/MTghkAZ4CV7IorjFkp4vuak8VgU7HGWC799JEsOVvrH1 KMxocASJaw6zX2p9j3YLhJQSGZiLmCEx9ulRHiApojl26xXCBQgKhRdbOe6REEYRNd qENz8Z4aTvEJQ== 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 5.4 02/17] panic: unset panic_on_warn inside panic() Date: Wed, 1 Feb 2023 20:42:40 -0800 Message-Id: <20230202044255.128815-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202044255.128815-1-ebiggers@kernel.org> References: <20230202044255.128815-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1756693134262713312?= X-GMAIL-MSGID: =?utf-8?q?1756693134262713312?= 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 f470a038b05bd..5e2b764ff5d54 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -173,6 +173,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 @@ -571,16 +581,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();