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: 51706 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52802wrn; Wed, 1 Feb 2023 21:30:27 -0800 (PST) X-Google-Smtp-Source: AK7set8dJJQ0tO4/+smlH/JVSZRBFnC5k3SIcGgiFcwo9ankNnybsJN2akM7yxK/KPhbsBVlqJ89 X-Received: by 2002:a17:902:f202:b0:194:3fa4:3f46 with SMTP id m2-20020a170902f20200b001943fa43f46mr4042102plc.29.1675315826885; Wed, 01 Feb 2023 21:30:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315826; cv=none; d=google.com; s=arc-20160816; b=c9SWt4vwY0mpNkM2mbIBvXRgvrv8nYIrvvgbXqxLKcziC5Ia3MDStogNbaCEli7I65 GqFx0a9l8BwQ1E7sY+lgTlz6Ye/hejgnlxyenz4tUcM6kAknlIVXDiKdZ2fHh3dHjdEU Zj+W9gvhe3gzLKwZNQxDQGDGmm4blosuEDvfKlHy0+uDJXTcSU5GzaNWPzIV8dDG+pDG mOTF/zegoqHMkELZSGlF8PfBVBO18kmciJCs7rePNR2MzTbuXAtyOHlEE786MiKU41eP rf5/v92Q+qlK/vS2uwkQ8lIyOOrrGsYcsmaHYWexjQHRrK4b1DkJD4Z1fXwNUA14qkRC SSvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Po7xxo2rOMSPri8SKf4EkdJBnmJkIyTqB8yrnEGgdek=; b=BrowGp3xgK/zQN2Rig9rj5Zr7U4BLQPlkRUQmwYig7NlV4+8fQ6MMtzaI1GZ4PduWi iyvzSZCdv2Hn/KvjuVtlFBpZL+Gm9Ig+g5z2nMOL7a06qj6pz38EB3sr6AN0jFiqCH7O uEO5JTtimWTXY1PRwFye4rSTCegY6ExqbuaOODZFQk3+UHDxUC1xy3JlRKq5rfUvUyqK 6gY9zgTYozhQaHFfhoWTkhNA3hYxiNC3XMsUxjxYcyXipiImMNOZ/983/URuc++Z9got GmRBteuVp9WmyBoYbI0SrvBq3u2W7eqiE2u9/0buCPj70bWgBr7s2Y6hkQs5NM31oT/h iQug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YmzlX08Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v11-20020a170902d68b00b00194afe281e7si20063884ply.429.2023.02.01.21.30.14; Wed, 01 Feb 2023 21:30:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YmzlX08Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230003AbjBBF2y (ORCPT + 99 others); Thu, 2 Feb 2023 00:28:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231926AbjBBF2V (ORCPT ); Thu, 2 Feb 2023 00:28:21 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC5BD193F3; Wed, 1 Feb 2023 21:28:09 -0800 (PST) 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 0A6CB61556; Thu, 2 Feb 2023 05:28:09 +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-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695968368324034?= X-GMAIL-MSGID: =?utf-8?q?1756695968368324034?= 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(); }