From patchwork Fri Feb 3 10:12:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 13127345 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4182C636CC for ; Fri, 3 Feb 2023 10:16:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B7716B0072; Fri, 3 Feb 2023 05:16:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 169CF6B0073; Fri, 3 Feb 2023 05:16:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0310B6B0074; Fri, 3 Feb 2023 05:16:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EB8C86B0072 for ; Fri, 3 Feb 2023 05:16:48 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C8BC51A10E5 for ; Fri, 3 Feb 2023 10:16:48 +0000 (UTC) X-FDA: 80425576896.12.D9CE0E6 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id EF7601C0009 for ; Fri, 3 Feb 2023 10:16:46 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=1nPcQt5f; spf=pass (imf18.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675419407; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CPkCB3MnuIoX8ckhpCE/S/ALomLNl6p2lvtdVnu6MU8=; b=tE3kg+Mm4UAZNrlMhEbwbWzFROe7WOOPCtv/xtkMn1PXBiNYWyZaC3TT8fxLsEfUT2wsre h6OF6iBz3wH0aAAWSXt38/t8tEljSWmOJeaAo7WLaMCgk45sNRGFPSD4MJjRyyS5sXZp+p TprGSlfQAPvLT7lngxJM5b2ZBdB2tNQ= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=1nPcQt5f; spf=pass (imf18.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675419407; a=rsa-sha256; cv=none; b=D2gTYsGDeAJvGNfmOdt7f4xQvaoOUA3hgpE1ZpcN3QCj1NVcJjiurbeaw0SN/oUk1emlWE v0OmukgYA1/xIOklUNKW+j/ZG9xm4SvRCWuvPOs9ujdK9xow4qi71ZheFLXb4jYgfpHwrF b2bArIwYkX2TpXSU1w/5W6V1zyGefmo= 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 3174F61E92; Fri, 3 Feb 2023 10:16:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8ACEBC4339C; Fri, 3 Feb 2023 10:16:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675419399; bh=3emU3UY8p14orfXfoNLqUgWSkbCt+Y+PCzx989oGuGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1nPcQt5fjoRF/9726usp7zOayQOg7dAYCJ1GJt10lIlN0TC43zW3KClknkIc+AKY1 XuXMWSb4veZe314bx1CSXlXMXktWeAG1A8IPNk5DzPhyeLqrOgFnTI+xM02tI6XVsY rxIjaVElQqHqVw3a9l2QdnlR1ru1EU2/jlX3jPAI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Marco Elver , Dmitry Vyukov , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Vincenzo Frascino , Andrew Morton , David Gow , tangmeng , Jann Horn , Shuah Khan , Petr Mladek , "Paul E. McKenney" , Sebastian Andrzej Siewior , "Guilherme G. Piccoli" , Tiezhu Yang , kasan-dev@googlegroups.com, linux-mm@kvack.org, Luis Chamberlain , Kees Cook , Eric Biggers Subject: [PATCH 4.14 55/62] panic: Consolidate open-coded panic_on_warn checks Date: Fri, 3 Feb 2023 11:12:51 +0100 Message-Id: <20230203101015.317152114@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230203101012.959398849@linuxfoundation.org> References: <20230203101012.959398849@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EF7601C0009 X-Stat-Signature: c1i3a7x33rpzqkrhi6nd6oepnngrt13b X-HE-Tag: 1675419406-67364 X-HE-Meta: U2FsdGVkX19WKCgW60PhzseHh8pMq8IB0JEECvUFGlsug9hDXDBT+WtVw/Unhv8ZRAJLiAu3yRZ3GYqVaKDOERc438Pl6HCBpLmt07UczSJ7kitu1B5m8y8D5kuhC9x+LYA1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uUK/fG2eUxgH6rdp8ZvAxHVRq/BQ7BUmglapPbsooa4oT8Py/qGj+6xpIoDXDcgf8bejj+AQPu2UHBx7eBq7XpcUhfYB3UKtmxPRJdc5Y2xrZKKbt3ypZgYglHR+WYOWzIRnFzrpZDHnmzItwqRemOjAOJr1BSPVtEfDtqnrp+TH8G59Pd4gxZ8v5j4aUeJ65nvMtdhBUhW4yPAYBCY9lJprFw20EiYlIGWA7o9bnIZWUCZ+lXDw65JQssPTiPSt4Ou4u/CepkW5RGjDpxs9hSNMfMVVe3iTHHkUvP/XYbam3s11IW9Bf3rkhNs2WHZJWtVFBG6/+ol9E6APQCuJZQcjf5wBGCveS51c8p7SssRX/5PWCAzyhCiyr6WEe8b69QMJlZL58Asstm240zkU2aUJEwqCehTuLezyjtq9xVNVg69PkrHcU+FkiWqIkcyGr/rhxvuwDXmnBn/6THJVs3r3Y649adDGMKY6kh3hnPLRwRD8TVZUTzPNjrGDFDlvavXK0F7NcTvwlEXafOK+wFNDJIgL8MpqIMCWrShBQyMjroRyT8T/8ZxZ2uNJO84EbPBb7+LQPO4wLooDgcN4AXK8cM3Obaqfx9tGBDF+SI8aDuq1bVLuG7OBF5MMlH1q8xOVzXV597GeO9VVfDvZPo3NC1gaFODa530STlx++sBmiI4dGeAQDo0o//yVlxCdYz8YlmFdepWMLpqksZQbeL9moisWBveblAgGC4l3/kSuYOXzw FyYixRFc KvisyDgM+Op1c3NXZtmPESTEdjhvj2zuN9+hrZTOG+LkLugo9nQk8Rx77dwyAMWwzH6FCP/YtQ4oRs8/Mv/2Q5N5gczpnvHr0tS0Z6PTfPBglRGXLfPurxNXKO+UtIAT258yTZFvnfKVznR/7NO37aey3gCl8NsWGIT7dyVLC8JEEmcii8RyPbc0EcMbgGxJV2Jn1hkW0Yb0YFy0ZO7hp2PW9LkI9mCr X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Kees Cook commit 79cc1ba7badf9e7a12af99695a557e9ce27ee967 upstream. Several run-time checkers (KASAN, UBSAN, KFENCE, KCSAN, sched) roll their own warnings, and each check "panic_on_warn". Consolidate this into a single function so that future instrumentation can be added in a single location. Cc: Marco Elver Cc: Dmitry Vyukov Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Andrey Konovalov Cc: Vincenzo Frascino Cc: Andrew Morton Cc: David Gow Cc: tangmeng Cc: Jann Horn Cc: Shuah Khan Cc: Petr Mladek Cc: "Paul E. McKenney" Cc: Sebastian Andrzej Siewior Cc: "Guilherme G. Piccoli" Cc: Tiezhu Yang Cc: kasan-dev@googlegroups.com Cc: linux-mm@kvack.org Reviewed-by: Luis Chamberlain Signed-off-by: Kees Cook Reviewed-by: Marco Elver Reviewed-by: Andrey Konovalov Link: https://lore.kernel.org/r/20221117234328.594699-4-keescook@chromium.org Signed-off-by: Eric Biggers Signed-off-by: Greg Kroah-Hartman --- include/linux/kernel.h | 1 + kernel/panic.c | 9 +++++++-- kernel/sched/core.c | 3 +-- mm/kasan/report.c | 3 +-- 4 files changed, 10 insertions(+), 6 deletions(-) --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -293,6 +293,7 @@ extern long (*panic_blink)(int state); __printf(1, 2) void panic(const char *fmt, ...) __noreturn __cold; void nmi_panic(struct pt_regs *regs, const char *msg); +void check_panic_on_warn(const char *origin); extern void oops_enter(void); extern void oops_exit(void); void print_oops_end_marker(void); --- a/kernel/panic.c +++ b/kernel/panic.c @@ -122,6 +122,12 @@ void nmi_panic(struct pt_regs *regs, con } EXPORT_SYMBOL(nmi_panic); +void check_panic_on_warn(const char *origin) +{ + if (panic_on_warn) + panic("%s: panic_on_warn set ...\n", origin); +} + /** * panic - halt the system * @fmt: The text string to print @@ -546,8 +552,7 @@ void __warn(const char *file, int line, if (args) vprintk(args->fmt, args->args); - if (panic_on_warn) - panic("panic_on_warn set ...\n"); + check_panic_on_warn("kernel"); print_modules(); --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3185,8 +3185,7 @@ static noinline void __schedule_bug(stru print_ip_sym(preempt_disable_ip); pr_cont("\n"); } - if (panic_on_warn) - panic("scheduling while atomic\n"); + check_panic_on_warn("scheduling while atomic"); dump_stack(); add_taint(TAINT_WARN, LOCKDEP_STILL_OK); --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -172,8 +172,7 @@ static void kasan_end_report(unsigned lo pr_err("==================================================================\n"); add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); spin_unlock_irqrestore(&report_lock, *flags); - if (panic_on_warn) - panic("panic_on_warn set ...\n"); + check_panic_on_warn("KASAN"); kasan_enable_current(); }