From patchwork Mon Jan 30 13:51:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 13121210 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 6EB4AC636D0 for ; Mon, 30 Jan 2023 14:17:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6C906B0072; Mon, 30 Jan 2023 09:17:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D1C856B0073; Mon, 30 Jan 2023 09:17:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBE4E6B0074; Mon, 30 Jan 2023 09:17:45 -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 A8B2A6B0072 for ; Mon, 30 Jan 2023 09:17:45 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5F850140A19 for ; Mon, 30 Jan 2023 14:17:45 +0000 (UTC) X-FDA: 80411668890.30.8332C59 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf01.hostedemail.com (Postfix) with ESMTP id 207E140015 for ; Mon, 30 Jan 2023 14:17:41 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=c2Dn+EtM; spf=pass (imf01.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=1675088262; 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=uyluDYmPAg9Fe3qpUBDneuVPmLqYruUbSAd4ixKVj0Q=; b=qPNQgpNKjBJT2XNOmKCl59XQppFtEcr2Grp0nsyECR3PeVOQcM9dL+b0izH3QfLuETivB9 fHF+51GaOd2P2DHc557UOBPiSbbBArpAAQJbEhBAvZg7+NDQMNNP9eekY1xO1TiY1+L+IG Ap0hXlxAovakUr5DfzxrEEav70sbadw= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=c2Dn+EtM; spf=pass (imf01.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=1675088262; a=rsa-sha256; cv=none; b=c6DIZRaqxV/UOpTyt/TZsTqscJ5nC/jG8QfhkZ5lt2TS0aiA5VIw59Zhu+Tk2/jsVHVgaZ X2IgRztDean3biCvpfLZk294NQXhukMQZMLH2XeCXyUQlu07EouqPErPmRyJepkdHlRqxM KYj7lAhfqZ/w93UgaZIJG7lpkHVnO/U= 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 9ECB9B811D3; Mon, 30 Jan 2023 14:17:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C96AC4339C; Mon, 30 Jan 2023 14:17:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675088259; bh=onhF2+w3JjQsp56jjrkrs3EPqyliI+JvH5PIMyQwmEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c2Dn+EtMk6YXIwy+PXCJHNGar/gjsLh4a+bA9eHy8zhv95gkLV2zvYsBIigGr9bwH egEfER/j18hdGXiP4dM3rqDiaEGlKliZqMJviJ119Pl69eAFFLWvgE1OoA40rOxBTV hkjl3iRFkeazSh75JaTUQU6ygnXNobrc3YUHobkE= 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.15 138/204] panic: Consolidate open-coded panic_on_warn checks Date: Mon, 30 Jan 2023 14:51:43 +0100 Message-Id: <20230130134322.600948088@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230130134316.327556078@linuxfoundation.org> References: <20230130134316.327556078@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Stat-Signature: w8qex11gedcmy6t5aq6sfxbw8ry4sog9 X-Rspam-User: X-Rspamd-Queue-Id: 207E140015 X-Rspamd-Server: rspam06 X-HE-Tag: 1675088261-308543 X-HE-Meta: U2FsdGVkX18eU2aHMfxgOHXOtioWjhiuszbX55IE8PTDD7H1A0R/V2ySFzL4NEs310lPDkXFgvwFSuF+2xIHjnj9u6YhgxoAyCqurmU95LnHhwSGD6Ob4pc8r76NBR6+94qc8XFJvOZpadOmQPLBd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xqs+1hkIARVna7e2m2ZUJr9HOiHIkHxsCABnuPwgKmORf2G54/oV+LgX02QV7CoPb6SGUkYwGWtsqYsERgSDGye61wmaldiVdyzIs+bf/rmL+yP2rluIqdxOwsgttAbkNd9Lf/+g/ncr7R9k69i0Kl72wmuJiWY8odz6ypTthK8jHhlIBAue9scNZuKDSlYEy42wnp/FcLiDNRN61j5rT0c+9RkxH5RSFppIvsjIBIy9bJanIXKu0Ft7rUdTd9alrYAip8LlXt4qDR6Cb5pThQ+uGEdwSfZfKMoDUGtVQ6oL9XJkjghXnSNhX1b5/Qno+kg4hVdAt6larBKFnBV7nw8m5hDDDTK/armbl9eBJu8rl4OuOJmzNVnLJy6JvO5Vry1ZHVjk8ztizMesfBHuFM+ubGwtnc5nTdkQn5IZI5ed8YDgM3MuejXaLpccpvrS60FVbPLrhz1f8BoLdCG/KZV9nbB1KoVbxLtPGkmoX42I9uIDqClZOPkBZJOuKOkw2DkYvw8mk0blDtSH+H2MRBwvV3CxTqq1zEzeOevk26UjUOBdGMzVDnrrREIpbv0vV2th7ZutjLsg5iSwBNLD/f7khf4v0Oj/yc94YD6BRDdX04yjPwW5ZDZaf9U8LjNBitmconZwZdNXdicYS9PnvSb7HtuHlWKSyMt+3WXv3eDRD2jvzatDEJBtNtxE8EcE14pykCcFtInwaS31Jetks7tgoao/6 GD/SchH8 WcXsXcWM8lCn5KgMZc5DEwIcVivO8C23BgwwNuxy1uzt9IwhpEhW3rtlIe8QwO0Rusmgmb9v6nnNzIIuZHlzYhoHe58LfPyY3ZvYo98dkxLF26rKUk070Tbc4ceIgi2Ezk0rittnUsAqghCj4J/AoYaBkOKeNcxLNi8MzPvaPOuKooxn6HNBFbbIWz7JOMoGOUAUTopo3sXrCrKasOhzzA3J3RuPQ3YE 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/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(-) diff --git a/include/linux/panic.h b/include/linux/panic.h index e71161da69c4..8eb5897c164f 100644 --- 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); diff --git a/kernel/kcsan/report.c b/kernel/kcsan/report.c index 21137929d428..b88d5d5f29e4 100644 --- a/kernel/kcsan/report.c +++ b/kernel/kcsan/report.c @@ -432,8 +432,7 @@ static void print_report(enum kcsan_value_change value_change, 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) diff --git a/kernel/panic.c b/kernel/panic.c index 0b560312878c..bf0324941e43 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -193,6 +193,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 @@ -628,8 +634,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 2bd5e235d078..c1458fa8beb3 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5560,8 +5560,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 36bd75e33426..60c7099857a0 100644 --- 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) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index bf17704b302f..887af873733b 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -117,8 +117,8 @@ static void end_report(unsigned long *flags, unsigned long addr) 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"); if (kasan_arg_fault == KASAN_ARG_FAULT_PANIC) panic("kasan.fault=panic set ...\n"); kasan_enable_current(); diff --git a/mm/kfence/report.c b/mm/kfence/report.c index 37e140e7f201..cbd9456359b9 100644 --- a/mm/kfence/report.c +++ b/mm/kfence/report.c @@ -267,8 +267,7 @@ void kfence_report_error(unsigned long address, bool is_write, struct pt_regs *r 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);