From patchwork Fri Feb 3 10:13:08 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: 13127359 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 0A18CC636CC for ; Fri, 3 Feb 2023 10:23:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4708B6B0072; Fri, 3 Feb 2023 05:23:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 421136B0073; Fri, 3 Feb 2023 05:23:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C1AE6B0074; Fri, 3 Feb 2023 05:23:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1CDF56B0072 for ; Fri, 3 Feb 2023 05:23:10 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C81DDAA3F6 for ; Fri, 3 Feb 2023 10:23:09 +0000 (UTC) X-FDA: 80425592898.06.C719868 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf11.hostedemail.com (Postfix) with ESMTP id C0A3740006 for ; Fri, 3 Feb 2023 10:23:07 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=KBHhxWWP; spf=pass (imf11.hostedemail.com: domain of gregkh@linuxfoundation.org designates 145.40.68.75 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=1675419788; 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=3WiNzHy+TzzAFPTu+Hq1aQhdGIS8zW+F8KgcJga/A+A=; b=nM0eca59SvCPeu96IiFBdGEbI3bIp8mWYE4h06vrZElPgYdGHD+5PfrwlljMI8Mnct7BZz qzVeN3nGGCa96OvEmIhMndKMbVvRu7kUZXmzPAjG/65sBYmLikmfRj1YA6wOItoNeyAViJ yLmFb6UYx+3OVue/5wXMJq3kAvymLNE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=KBHhxWWP; spf=pass (imf11.hostedemail.com: domain of gregkh@linuxfoundation.org designates 145.40.68.75 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=1675419788; a=rsa-sha256; cv=none; b=b6rWDadqdVAt22wgstmOU+tuoTYEgF452Gv+1flRi8lWka4OsN/hkiUvn4PuIFgVpx07Yc n4SqbkmsapKIuFIcO0lUaCR3LTV6KJ5CkihdmFwsfEK58GPg3XMKLa4I1sftg7GtS8cC7O 1Lk9nDbfj72VI0CtDA8atR7etGYxWSc= 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 50E23B82A6B; Fri, 3 Feb 2023 10:23:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7899FC433D2; Fri, 3 Feb 2023 10:23:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675419785; bh=FbUetLhw79WW3EuXs6rQ4Ut0dLEdVl38E2k3pLvcuxU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KBHhxWWPsxyIhrgmBBuAAdURU/MbHCAdsFA5l5HhCF9+QEX/07BEDDIrNpBenwXKp xlUc7H1HkpYbySfQM2o+qrmurMGLgVXhs5D8jiY3oJ0IfZiu/Pi5Dm5p2QTbc0pz0B m6o6IhLm/R98xUNr6lQhx2Y+f6i8o9VWHx7K6vbU= 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.19 74/80] panic: Consolidate open-coded panic_on_warn checks Date: Fri, 3 Feb 2023 11:13:08 +0100 Message-Id: <20230203101018.408088099@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230203101015.263854890@linuxfoundation.org> References: <20230203101015.263854890@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C0A3740006 X-Stat-Signature: hnhsxj33jref8fufbmuik5n9ck17pfq6 X-Rspam-User: X-HE-Tag: 1675419787-251589 X-HE-Meta: U2FsdGVkX19u9hqrVagCDjzozvHqxoD4MGX4/ZJpLtUhFYwoeSglfnrbj1OmSmEphV9ivBOGTxs4abgyyvBmJ4TsnvVjKe5euP6PkaE9JSh6uYhQAHMYwFYzkp5l8CnHFG7zSrdn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eqmqXIHw== 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 @@ -327,6 +327,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 @@ -125,6 +125,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 @@ -540,8 +546,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 @@ -3316,8 +3316,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 @@ -176,8 +176,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(); }