From patchwork Mon Jan 30 13:52:31 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: 13121259 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 1AF6BC54EED for ; Mon, 30 Jan 2023 14:24:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FB236B0072; Mon, 30 Jan 2023 09:24:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 884506B0073; Mon, 30 Jan 2023 09:24:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7258D6B0074; Mon, 30 Jan 2023 09:24:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 60DB66B0072 for ; Mon, 30 Jan 2023 09:24:27 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 33D3440AA8 for ; Mon, 30 Jan 2023 14:24:27 +0000 (UTC) X-FDA: 80411685774.11.76C263E Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf02.hostedemail.com (Postfix) with ESMTP id 172CB80002 for ; Mon, 30 Jan 2023 14:24:24 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=RATipVPU; spf=pass (imf02.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=1675088665; a=rsa-sha256; cv=none; b=IPIJ6rDqte4iUholpSU7TqWVHAnOwESERU6b1mbaX/mNVrUxhTU++0byP7wcjgFmBm071w WnqKM76Zs8ztPe0hSZNqAofE/i4UZMdMasiYd2uso4iuHmgdq594rOIACA2xJbTDiJcWKo pwoV3zA8szVWQQ6oKHQUtlbfErHK150= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=RATipVPU; spf=pass (imf02.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=1675088665; 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=eklLDj3vjqmi1JAEH9nmkvE8R8TFrc6yFvjm6e5rp04=; b=BezOWEpJnU3FxmB3wSj8twhO5HieMN7HK8LdhFkUkOVzG2p+vGuAWMi9PNEFVp9n3+p5Oy jx4i9Q5Y3/FShnT1eidSCC7TRdGMO2VAPippr36xJQQoN/m5GuVdZ/rPj/DDJrXxgN1SiZ NazVkV/FtJ9GVaU1m2Xl4KR8c6nUg/E= 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 C6133B80C9B; Mon, 30 Jan 2023 14:24:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 034D0C433D2; Mon, 30 Jan 2023 14:24:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675088662; bh=dtqc/EOYFfz1JjhCr5TcYloNnzsztJPyOnwqeEoboJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RATipVPURn1Q72NXxc9oKGSTgKqNw4Xa46pQ43x+64Rxv+Eo8pe06Y3EOhgZwHq9C aftDvj/nVHJ2fSUK1XLxfGMFwZTizIDMEh6wzq+Qch8/nXvlFGZbjJclRQY5y09Icy GtoiybI7Czm4qetruts1+alX1cXfd2CLgUCs+Ozc= 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 , Sasha Levin Subject: [PATCH 5.10 094/143] panic: Consolidate open-coded panic_on_warn checks Date: Mon, 30 Jan 2023 14:52:31 +0100 Message-Id: <20230130134310.753061249@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230130134306.862721518@linuxfoundation.org> References: <20230130134306.862721518@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 172CB80002 X-Rspamd-Server: rspam01 X-Stat-Signature: akjj3ns4hx1w4f46b6aws3g79qmsouyb X-HE-Tag: 1675088664-666309 X-HE-Meta: U2FsdGVkX19V4uEGdBJ6yboOpNXlpZIYK2iqRYfOQjPSkxZStog8bcO2ScsDTq4l3+LAB6kVaQKjl1GgqDF3xEbil1SHAiZSiA/zbhi0G6MhKOxKGXohoti+EuzKL+CMlyFUBrtV7ctWfPv8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epBhImFsO3W3CDj3r/rG9p+ZUMOhfhvy3iw3gxQStyBMFFPT7gHBx3LIPTDBig8mo6xteRu2qsIwoeOTyVJKZF6J6j7lsKJQGhnaX1jwAa6pogt4TdFFfNnFW3gxU0QInrACwOadJUs5F4BKdwXyYL/NVxKTEOQfLUvaLUhTV9jJbfGVgfKJy/YFWYdQalq5jzY9FIl5x3NMBHLVhbkXZc633eNXjykRCPUhK664V2hQAxgjBdPwj42Att6eyuVWvzG67RedX4BrwUNAjiD2IkMBRHao3dnKuw3w6+sTj2KpeFboDf6xSNAfp1Ufwp1RfjF5Oxm5gjxwm4ZF+DURLiPnAaHONhu2lQsZvFX220sBZp2FlU0+twhGTuTsfr0gh8lyKlRI6ObTfLUCON6KICIKgiExLo8GbsvSarQb49dpLRrkGch9JZGVyYdVzkzMvan6h0NmotEDT+NdKjdeEsRrrkFNFbnSrGa787C6kcbV8T4UesAVNlbk5zE+TxKoAmqEALJBbYCNAmTcXzlssFHKfBjEvp+c1z9PFpBRlgLO7Mgi89gBYgSiG0QoyIuKOEHrOaDIT0KPm4mh/N3zNh/XyGzafcX7pjSl4tYI9bO0xmxt7dFR5lGjUmtwooJiyEL17mvI1m+WHWOFzsk643utxSOtZ6TcOGuibHU15/NfSk76UQzbTh+L+zABRJ2M5zNYSxDdr1lnxdRbcjjy4+NKqFCGgMUijvCDPYelWJrMNirJX 0AMrs5v/ 8/cvF2F/KSv5xhsqK13L3EraUM6ekYBEmIlBhxVMXtHCKM4+0CVZBLdA5vR6LZTN2mqr0ICCuR9yuElKgBslbaEBY8bV5d0P2YGqQyc56rqzDz7IVIxEKNOTxaNeNWVXf/nXR+gCKeQufRGvwGqg5oZPNIvXXG/kHcFc6AcSU48arJizbKy/PyQ9LWrGvSW/1iBUi002vTU7lS+zoYT6P9jEcny+0lJy 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: Sasha Levin --- include/linux/kernel.h | 1 + kernel/kcsan/report.c | 4 ++-- kernel/panic.c | 9 +++++++-- kernel/sched/core.c | 3 +-- lib/ubsan.c | 3 +-- mm/kasan/report.c | 4 ++-- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 084d97070ed9..394f10fc29aa 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -320,6 +320,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); diff --git a/kernel/kcsan/report.c b/kernel/kcsan/report.c index d3bf87e6007c..069830f5a5d2 100644 --- a/kernel/kcsan/report.c +++ b/kernel/kcsan/report.c @@ -630,8 +630,8 @@ void kcsan_report(const volatile void *ptr, size_t size, int access_type, bool reported = value_change != KCSAN_VALUE_CHANGE_FALSE && print_report(value_change, type, &ai, other_info); - if (reported && panic_on_warn) - panic("panic_on_warn set ...\n"); + if (reported) + check_panic_on_warn("KCSAN"); release_report(&flags, other_info); } diff --git a/kernel/panic.c b/kernel/panic.c index 09f0802212c3..0da47888f72e 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -192,6 +192,12 @@ static void panic_print_sys_info(void) 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 @@ -630,8 +636,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint, if (regs) show_regs(regs); - if (panic_on_warn) - panic("panic_on_warn set ...\n"); + check_panic_on_warn("kernel"); if (!regs) dump_stack(); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a875bc59804e..1303a2607f1f 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4280,8 +4280,7 @@ static noinline void __schedule_bug(struct task_struct *prev) 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); diff --git a/lib/ubsan.c b/lib/ubsan.c index d81d107f64f4..ee14c46cac89 100644 --- a/lib/ubsan.c +++ b/lib/ubsan.c @@ -151,8 +151,7 @@ static void ubsan_epilogue(void) current->in_ubsan--; - if (panic_on_warn) - panic("panic_on_warn set ...\n"); + check_panic_on_warn("UBSAN"); } static void handle_overflow(struct overflow_data *data, void *lhs, diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 91714acea0d6..2f5e96ac4d00 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -95,8 +95,8 @@ static void end_report(unsigned long *flags) pr_err("==================================================================\n"); add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); 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"); kasan_enable_current(); }