From patchwork Thu Feb 2 05:26:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125310 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 2B317C61DA4 for ; Thu, 2 Feb 2023 05:28:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92DFE6B0071; Thu, 2 Feb 2023 00:28:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DD946B0072; Thu, 2 Feb 2023 00:28:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77EB36B0073; Thu, 2 Feb 2023 00:28:12 -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 6AF486B0071 for ; Thu, 2 Feb 2023 00:28:12 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3A7978018D for ; Thu, 2 Feb 2023 05:28:12 +0000 (UTC) X-FDA: 80421220824.16.738FDCA Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 900AD40003 for ; Thu, 2 Feb 2023 05:28:09 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YmzlX08Q; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of ebiggers@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=ebiggers@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675315689; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Po7xxo2rOMSPri8SKf4EkdJBnmJkIyTqB8yrnEGgdek=; b=NdF7cCaNBxxVonsCo1Xgdyd/B+9/2O/8Mk4+AWWoughBPyyFeOvPTMKw2OAtuVrP0qkSpa xI9epHPFALMHqXDGLG3qjsXhO31vqDIrtoE+aCSU4U8GaaMy+fgGX5WbBirDTQ5FLgcJ5T 570FbpmNe7oXDK+iVGddx9LKsY0gwCA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YmzlX08Q; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of ebiggers@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=ebiggers@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675315689; a=rsa-sha256; cv=none; b=6W6DNv1rT7WuXM2ro0xvmaRuJbnCB/eTAk+spzOWxQG5tbHwvAZS5IYBMUUvDFAVpDaLaz O7MMFpBeWP7EyQukPGutWwJYdkJbn147Nhw156kUehF2cL4fZQpQSzGiyeDv6jfNIUhS/d swNiJDNshNpc2shpQ0etilVxvYKydVo= 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 A06CA615E9; Thu, 2 Feb 2023 05:28:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A12FC43446; Thu, 2 Feb 2023 05:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315688; bh=5Ri/HkVcJ9rh8djKJRfkJzJeteQyLdBfCFzTyQfbWy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YmzlX08QXiBD4TUxauXkYmJsx2KoDJrKqQ5vkMfPTpQqzBuHooHeclBWk2qWvi2zv CnYShkItmuAlZSBTNCVB/OeFI4XYPnrt2rMyTy37/EWCtAeUh1zf9joZ+6ttla43yA j8WiddDXvTQ5hKnBu2E0J1BIUrELHdHye56o77dChXqkWCBkQCDDp3zml10RDZXpzJ 8d8vo6vBUvoh5/IqPq2JoF5AQ8ZZIZqLxa9KXVSTbVIlUHL68+D9ch9Is50phTs9x1 b71QBA3LzaJmGKtz+IKkUeslVcmjszmhFef3jpN8KoiSGypDQOH3HU9Ggg9wx5VWge P6A/Cihwd91EA== From: Eric Biggers To: stable@vger.kernel.org Cc: Harshit Mogalapalli , Kees Cook , SeongJae Park , Seth Jenkins , Jann Horn , "Eric W . Biederman" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, 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 , 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 Subject: [PATCH 4.19 12/16] panic: Consolidate open-coded panic_on_warn checks Date: Wed, 1 Feb 2023 21:26:00 -0800 Message-Id: <20230202052604.179184-13-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 900AD40003 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: oxb9wsjufk31zghc77jq8zo57b8pppi8 X-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g+iM3Oqi+wAqzHffeh43STWftGNXGdYvD/v1D1sFsa1JzW4dwDYjjXg59bgC9WgYswvEd0zvDNtk+U29ETSIVoQ7UBSkuFg09TuESL1s6sP3suDN5g== 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 --- include/linux/kernel.h | 1 + kernel/panic.c | 9 +++++++-- kernel/sched/core.c | 3 +-- mm/kasan/report.c | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 50733abbe548e..a28ec4c2f3f5a 100644 --- 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); diff --git a/kernel/panic.c b/kernel/panic.c index a078d413042f2..08b8adc55b2bf 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -125,6 +125,12 @@ void nmi_panic(struct pt_regs *regs, const char *msg) } 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, void *caller, unsigned taint, if (args) vprintk(args->fmt, args->args); - if (panic_on_warn) - panic("panic_on_warn set ...\n"); + check_panic_on_warn("kernel"); print_modules(); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a034642497718..46227cc48124d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3316,8 +3316,7 @@ static noinline void __schedule_bug(struct task_struct *prev) 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); diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 90fdb261a5e2d..29fd88ddddaeb 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -176,8 +176,8 @@ static void kasan_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(); }