From patchwork Sun Jan 22 15:04:43 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: 13111498 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 50384C54E94 for ; Sun, 22 Jan 2023 15:27:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9474E6B0072; Sun, 22 Jan 2023 10:27:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D03C6B0073; Sun, 22 Jan 2023 10:27:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 770F76B0074; Sun, 22 Jan 2023 10:27:02 -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 63EC36B0072 for ; Sun, 22 Jan 2023 10:27:02 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3888D8074A for ; Sun, 22 Jan 2023 15:27:02 +0000 (UTC) X-FDA: 80382813084.02.72CA5D2 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf17.hostedemail.com (Postfix) with ESMTP id 46FA940004 for ; Sun, 22 Jan 2023 15:26:59 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=PiVNOgoQ; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf17.hostedemail.com: domain of gregkh@linuxfoundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674401219; 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=5svZGXzpRpEeF1fzdip1Pbs9ol6JvBAXG3U9qbuqc6w=; b=OnFiAz0+mJk8esYSrXt+Gb5qrXSUcLzPoD0mCT3+JEpyg8cVboZVC5KPPsUr/kVMdJM6gH 28Q7e6rfaDjsmOHC4Alh/Al2+Q340O7+yB5wtG6LfDpIt49Im3eKMIzateDbY6ZyT8tkiR CSzQMWujc9YNwUfXAvj25iM7E4uAjYk= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=PiVNOgoQ; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf17.hostedemail.com: domain of gregkh@linuxfoundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674401219; a=rsa-sha256; cv=none; b=BpiAPOe0mYPnJxC1OHioicfGfXXFf46U2mNKlg9G6Lv8ovMRQc7ap4lZmNtSzfevG+ggMV Ja9MmCgQ3K5Nvmgtz73Hm3zrC1YuY1FRys9fip93uH62m6pPEaVJaWbj6EeE+HqIibLcE8 27IvMllbiVwST/gwHSspNSP1q4vQjRs= 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 CFAE0B80B1D; Sun, 22 Jan 2023 15:26:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09FFDC433D2; Sun, 22 Jan 2023 15:26:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1674401216; bh=11CZXW0Y8V6fCu4Lsv8FaoLlw3NHkqlgRT1xk2vmROk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PiVNOgoQsrOyTiT4gnp2zhJiVuZ5WdsWgAE3+Rre36yJXsJQGeXonn398pq00etx5 XFU1dIX9X83hlF/XIH/xGUi6TnB1ITRwMDeReWq3+bkPE5Ebr9LPTP7N/uBsKinDmp 3RWcarIkWwr4qzAjuqRihalOzaankItsrRTZUFLY= 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 Subject: [PATCH 6.1 154/193] panic: Consolidate open-coded panic_on_warn checks Date: Sun, 22 Jan 2023 16:04:43 +0100 Message-Id: <20230122150253.432742379@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230122150246.321043584@linuxfoundation.org> References: <20230122150246.321043584@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 46FA940004 X-Stat-Signature: ng4fyt6miabwnwi1o59k1btqy8z7hpi8 X-HE-Tag: 1674401219-127264 X-HE-Meta: U2FsdGVkX1/T69sDgxXxhgiEFWzQx/gtjq7HgcSvp5wWn2guj8xwRFMHIx66ovoHd2gCZ5ynWoyLBvuJczCs6lZrx/c+mGkY3nkgYt/KvVe9ur3UCZNxRBCfxUkaCchAovXURnOn1vdy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QWN4ppaijjyTJ6ZtJQMxyZD2VjMdxKNfrloIRwcMBmPa8swNnzndKD3n85CFoDFdHCJ6APLj6lUethxjHUZ2+RtdDwllFTcp3x5OcyFNGYHfGGSQwb/D7MJz0aHzbIEokofgwdLRWSmfwqeUP/DbsZndttOq4V9qu9pNiFCBSjsR7ViGmfW5DvGb6zVRN0gvy3pKS3UKtqGYRcoTc8/NkSGZxIgw1aVMNJbMaoLgtDDqVBXTEvFd7VY2nX3EnT8k2g5+8O5anE+FU11+qf9UdEKutj1AM7dIGzi6A/U3/WD4luQ97DOOxq2ppFqTwRSsiNoGH47yiVzMF2HPU7hpyalf9/gfeeZFujQNQIuR7mAH/I/+yqnSpTlCxaIXBIW7dMMRUBlrA60D9AY2fCfYTEMvwndBYspDc8heeXwS+qCCDJpMz7hzKbcltFQzuMkDgDQ6ACOq05Lyc9FLGVv1cCMMXBXbq2lRVrFM/vl7DkROtj3wi+DpijXvsMSjb5+cT+FcV9anKl1ea8z3oSI34dytGk7azUgPSYk5qq35zV9pR5dJnfDlrT0vkDhYbJK8dMM7DWvuIDgy9ERlQMlySFMl33jk8U2OqdotgNB1ucbi3hTRpoVT9NSdNt9cwk82oveHGtxfrQFZYc5guE+7ieKjPKt78Ozzw16a4fbkIWacsg1yKYhzTTuTGvBmXMTQzwBbPt+bw+k7sI7s98gxVNtGbIzXk6wVZ/r5GRI/wMbhYWDt+IkM0Up20J4 FwU8P5AJ 59kuhLuzY8TPvL73XPdnDhvRohD3QAzCkiqHQLrGI1XpmEtvISpVniHUBMLb8ZYetfbgFvE28P3b9Wq8Gt06NjKA0eD1DtEzPZjwHOGbfC39+i6TzsvKF0v7Jofl6pD646tpr6YS6/05G7wsgvlcwUFStNhXy0xLNgvHUXQennKPipIG0Meb2/+J3uy3awTw54X1xX2DLzpGzE4cMu4HvA== 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: Greg Kroah-Hartman --- include/linux/panic.h | 1 + kernel/kcsan/report.c | 3 +-- kernel/panic.c | 9 +++++++-- kernel/sched/core.c | 3 +-- lib/ubsan.c | 3 +-- mm/kasan/report.c | 4 ++-- mm/kfence/report.c | 3 +-- 7 files changed, 14 insertions(+), 12 deletions(-) --- a/include/linux/panic.h +++ b/include/linux/panic.h @@ -11,6 +11,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); extern bool oops_may_print(void); --- a/kernel/kcsan/report.c +++ b/kernel/kcsan/report.c @@ -492,8 +492,7 @@ static void print_report(enum kcsan_valu dump_stack_print_info(KERN_DEFAULT); pr_err("==================================================================\n"); - if (panic_on_warn) - panic("panic_on_warn set ...\n"); + check_panic_on_warn("KCSAN"); } static void release_report(unsigned long *flags, struct other_info *other_info) --- a/kernel/panic.c +++ b/kernel/panic.c @@ -201,6 +201,12 @@ static void panic_print_sys_info(bool co ftrace_dump(DUMP_ALL); } +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 @@ -619,8 +625,7 @@ void __warn(const char *file, int line, if (regs) show_regs(regs); - if (panic_on_warn) - panic("panic_on_warn set ...\n"); + check_panic_on_warn("kernel"); if (!regs) dump_stack(); --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5778,8 +5778,7 @@ static noinline void __schedule_bug(stru pr_err("Preemption disabled at:"); print_ip_sym(KERN_ERR, preempt_disable_ip); } - 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/lib/ubsan.c +++ b/lib/ubsan.c @@ -154,8 +154,7 @@ static void ubsan_epilogue(void) current->in_ubsan--; - if (panic_on_warn) - panic("panic_on_warn set ...\n"); + check_panic_on_warn("UBSAN"); } void __ubsan_handle_divrem_overflow(void *_data, void *lhs, void *rhs) --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -164,8 +164,8 @@ static void end_report(unsigned long *fl (unsigned long)addr); pr_err("==================================================================\n"); spin_unlock_irqrestore(&report_lock, *flags); - if (panic_on_warn && !test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags)) - panic("panic_on_warn set ...\n"); + if (!test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags)) + check_panic_on_warn("KASAN"); if (kasan_arg_fault == KASAN_ARG_FAULT_PANIC) panic("kasan.fault=panic set ...\n"); add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); --- a/mm/kfence/report.c +++ b/mm/kfence/report.c @@ -273,8 +273,7 @@ void kfence_report_error(unsigned long a lockdep_on(); - if (panic_on_warn) - panic("panic_on_warn set ...\n"); + check_panic_on_warn("KFENCE"); /* We encountered a memory safety error, taint the kernel! */ add_taint(TAINT_BAD_PAGE, LOCKDEP_STILL_OK);