From patchwork Fri Feb 3 10:13:51 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: 13127366 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 B7B70C61DA4 for ; Fri, 3 Feb 2023 10:31:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57B706B0072; Fri, 3 Feb 2023 05:31:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 552376B0073; Fri, 3 Feb 2023 05:31:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F3CC6B0074; Fri, 3 Feb 2023 05:31:18 -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 2F8E16B0072 for ; Fri, 3 Feb 2023 05:31:18 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EB42B160791 for ; Fri, 3 Feb 2023 10:31:17 +0000 (UTC) X-FDA: 80425613394.03.F531BD0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 308F72001E for ; Fri, 3 Feb 2023 10:31:16 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=H7JXghOe; spf=pass (imf13.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 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=1675420276; 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=n06JNxPjI5ymotOPhoBg5x2sqSBbrn1ILvlu96Zr5uY=; b=Of+i+U+xPQGsz3c/GBJheIIBUAJXzwlxA3EVVvW88KTANdSpEVje7wormWcvXZc0BbWqWc 5uXM1JgZcQhdU8r6q0mw0dl4Q70HA5cqjCzpJ7xzXwhS/7Lo5x2fADzyZ6wXfvxI0Nv0Jh HxPtNCSwPGUK7Pd+WvQp70qlbD2LhnE= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=H7JXghOe; spf=pass (imf13.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 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=1675420276; a=rsa-sha256; cv=none; b=n2kSX3ZXuqe1fkOlaNK9Ho1uJlw0UOMB1M1GvH90tZ5c5NCNixAj95mLe8JTVrk1lJhSMD m/cAD8vVn02LzVin43n433wDrMbT4OZMrvpFrxGKHPx4Oe723duTL3IECqbNNoTpV8vVn3 /WTx3GZLtkTapRUMV6tOaXs4Rv/5sl0= 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 5786E61E93; Fri, 3 Feb 2023 10:31:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2602C433D2; Fri, 3 Feb 2023 10:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675420274; bh=Xb0MW+GNyNCzF9faksyNoS5mYfxnCjhE4VLAtJSAOiU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H7JXghOeBizdP1vnWs0gQ/pGFkj4A7o4JNFLBkNMOZbnOXPiSdHFKaO7nG+85eQ2x MX5WsybsVoVIHjcJQyPQO9FkbdmKhNcNdDYHVyap2jy7IZo1zi9MvPp+fiIdbQXuGx UG/JuymEYg/RVVhMDLBoDXPuNNcy/NE0wfavzlZQ= 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.4 126/134] panic: Consolidate open-coded panic_on_warn checks Date: Fri, 3 Feb 2023 11:13:51 +0100 Message-Id: <20230203101029.481281149@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230203101023.832083974@linuxfoundation.org> References: <20230203101023.832083974@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 308F72001E X-Stat-Signature: gc3657hbk8sjf1mty1j7yb69bxnnrywd X-HE-Tag: 1675420276-439694 X-HE-Meta: U2FsdGVkX19m2SkN4OjzXlPg7L6ao5uJW9YUlCEVS45q+rW80ekBJcUS0yn3ySIgom07jk/5RxasRbonUKZD1azQVaWQcXF9GgVYkHVlcNT7qUQQSriYn2vTz2zFXW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sYUAU8JgOG0/VIorCaeGTvwL3li4Zf+k6MU+KlgZ19FPG+ADxugE7ncLuBhY3g59KRUDpoMZQhm5GsjSjpd4aC8thlhCX5j5oiHY7zoM4hJ7MDlTHpM1xRXb28fUHeIBhwG2rw8DljfBUDV0K/1gzquBXS/c2u4nkDtGSPn5SWazm9j2KiWvICuOu9IM+mnl2FEKAwgy0oOYbfHeb86yYJi4HaFri9Nsv2CuIoLHfHKkRpfwEUskYUrbOtSwyhAVmbAwqxPKqFxfXJvXjUPA6PiYAVKyisP3l8y2m/GlWLtai1SDHtO0NkunB594wC4HL8ZEJrA7g9ygUEIWzb25pRs/INN5KwxpN9RZ+PJ041v8PqXLsnWmAJfVIf4gqFP0oNmW4IXvMPpzHm5WbN8FWmiuK/KVEHyOgUwLugWDhGsKJc9TMqahD3LUc7NJ8dq6CDXniKvNNBLITvjYHWE8vObHULFhgu6AxkrPl3jYnU/MHOgay3jdKAlNeeUEvk2Sq4ehyuAUdat1OsANPrhmqevM++domevAj5j8ciWLWKwElmliOV06on+s7z2QmXVFiDoCNj/HMyGKBG9hQTIbQ0lbJVKM1daGsJ0OUtPDJ6zUBIEZzxlyhCFszzkGnDAGXyo8llc/eOxXQHf5RWEQZ/kvDob7qtlkLm4jPvWZi9tB8SOdmc+CDveXpXF230P1X1mYCfdZuPuBKXem6bLENpTTtpUfa7cEck4XGVxwSmQopKJBUB/TIroUhzcxEPI dZMKSDOl Gw5RYXFy8Z8ykg9A6wEd2sQQjmNuq4KNOLJYzvhZiX3QT41uMDkfbpV4XiHUoj2sAzxw4GM1FnO8fJZtJ8GjHCzCopbNOO4b1uNgaW/GbLNJzatjO74uMBxzkH6PuOH5YkQ/cD+TL7Ruc/hsTfc0xGB5d/H4e/SEODvZ4riaP6ittjG36efS5I0JlMXAG5dTMRFBwMKER6pS8YJ/29klyMzlrCybQB+i 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/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 77c86a2236da..1fdb251947ed 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -321,6 +321,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 5e2b764ff5d5..7e4900eb25ac 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -156,6 +156,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 @@ -581,8 +587,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 06b686ef36e6..8ab239fd1c8d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3964,8 +3964,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 a05ff1922d49..4d87df96acc1 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -92,8 +92,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(); }