From patchwork Thu Feb 2 05:43:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125344 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5D32C63797 for ; Thu, 2 Feb 2023 05:45:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230323AbjBBFp0 (ORCPT ); Thu, 2 Feb 2023 00:45:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230011AbjBBFpY (ORCPT ); Thu, 2 Feb 2023 00:45:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08B63301B2; Wed, 1 Feb 2023 21:45:22 -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 97FD06150C; Thu, 2 Feb 2023 05:45:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 955ECC4339B; Thu, 2 Feb 2023 05:45:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316721; bh=ZnNBhw1eTbB7Y3fUOl5z/Qym4o7iK9J4ZXmSuZHiggA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SYp/a5QDEpJi50N/toH4PxlZ+q/Wo3ZkkGTu704YRIZ5WYPZ64t992Gk892vP9pi0 7pWD8wLsMORaRIkGsR6ljIHe2NvUakqs3W3RMHa5Old4GblzC8MfhQ2wjpUeApK+Vq ZMwDBMby9P0nd+M1xQdx5VDkou/COXs1MgpEwCqQrSCG3VERdhyHNhsOl35XBGovdb JxnIhtS6NmuWIThf2URIdaogFtevZnN+1h0EyVGbfqv5z8EoOASzkWuGNckHy/pglx EajgrZe6jVKNkjIntPexP3l90vIW1qIjOvFgQKc8hu/NvUk8O/sfhnhhRSKxCKu/Fn SXZcZfz2SC5gA== 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, Iurii Zaikin , Peter Zijlstra , Greg Kroah-Hartman , Paul Turner , Andy Shevchenko , Sebastian Reichel , Tetsuo Handa , Petr Mladek , Sergey Senozhatsky , Qing Wang , Benjamin LaHaise , Al Viro , Jan Kara , Amir Goldstein , Stephen Kitt , Antti Palosaari , Arnd Bergmann , Benjamin Herrenschmidt , Clemens Ladisch , David Airlie , Jani Nikula , Joel Becker , Joonas Lahtinen , Joseph Qi , Julia Lawall , Lukas Middendorf , Mark Fasheh , Phillip Potter , Rodrigo Vivi , Douglas Gilbert , "James E . J . Bottomley" , Jani Nikula , John Ogness , "Martin K . Petersen" , "Rafael J. Wysocki" , Steven Rostedt , Suren Baghdasaryan , "Theodore Ts'o" , Xiaoming Ni , Luis Chamberlain , Andrew Morton , Linus Torvalds Subject: [PATCH 4.14 01/16] sysctl: add a new register_sysctl_init() interface Date: Wed, 1 Feb 2023 21:43:51 -0800 Message-Id: <20230202054406.221721-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Xiaoming Ni commit 3ddd9a808cee7284931312f2f3e854c9617f44b2 upstream. Patch series "sysctl: first set of kernel/sysctl cleanups", v2. Finally had time to respin the series of the work we had started last year on cleaning up the kernel/sysct.c kitchen sink. People keeps stuffing their sysctls in that file and this creates a maintenance burden. So this effort is aimed at placing sysctls where they actually belong. I'm going to split patches up into series as there is quite a bit of work. This first set adds register_sysctl_init() for uses of registerting a sysctl on the init path, adds const where missing to a few places, generalizes common values so to be more easy to share, and starts the move of a few kernel/sysctl.c out where they belong. The majority of rework on v2 in this first patch set is 0-day fixes. Eric Biederman's feedback is later addressed in subsequent patch sets. I'll only post the first two patch sets for now. We can address the rest once the first two patch sets get completely reviewed / Acked. This patch (of 9): The kernel/sysctl.c is a kitchen sink where everyone leaves their dirty dishes, this makes it very difficult to maintain. To help with this maintenance let's start by moving sysctls to places where they actually belong. The proc sysctl maintainers do not want to know what sysctl knobs you wish to add for your own piece of code, we just care about the core logic. Today though folks heavily rely on tables on kernel/sysctl.c so they can easily just extend this table with their needed sysctls. In order to help users move their sysctls out we need to provide a helper which can be used during code initialization. We special-case the initialization use of register_sysctl() since it *is* safe to fail, given all that sysctls do is provide a dynamic interface to query or modify at runtime an existing variable. So the use case of register_sysctl() on init should *not* stop if the sysctls don't end up getting registered. It would be counter productive to stop boot if a simple sysctl registration failed. Provide a helper for init then, and document the recommended init levels to use for callers of this routine. We will later use this in subsequent patches to start slimming down kernel/sysctl.c tables and moving sysctl registration to the code which actually needs these sysctls. [mcgrof@kernel.org: major commit log and documentation rephrasing also moved to fs/proc/proc_sysctl.c ] Link: https://lkml.kernel.org/r/20211123202347.818157-1-mcgrof@kernel.org Link: https://lkml.kernel.org/r/20211123202347.818157-2-mcgrof@kernel.org Signed-off-by: Xiaoming Ni Signed-off-by: Luis Chamberlain Reviewed-by: Kees Cook Cc: Iurii Zaikin Cc: "Eric W. Biederman" Cc: Peter Zijlstra Cc: Greg Kroah-Hartman Cc: Paul Turner Cc: Andy Shevchenko Cc: Sebastian Reichel Cc: Tetsuo Handa Cc: Petr Mladek Cc: Sergey Senozhatsky Cc: Qing Wang Cc: Benjamin LaHaise Cc: Al Viro Cc: Jan Kara Cc: Amir Goldstein Cc: Stephen Kitt Cc: Antti Palosaari Cc: Arnd Bergmann Cc: Benjamin Herrenschmidt Cc: Clemens Ladisch Cc: David Airlie Cc: Jani Nikula Cc: Joel Becker Cc: Joonas Lahtinen Cc: Joseph Qi Cc: Julia Lawall Cc: Lukas Middendorf Cc: Mark Fasheh Cc: Phillip Potter Cc: Rodrigo Vivi Cc: Douglas Gilbert Cc: James E.J. Bottomley Cc: Jani Nikula Cc: John Ogness Cc: Martin K. Petersen Cc: "Rafael J. Wysocki" Cc: Steven Rostedt (VMware) Cc: Suren Baghdasaryan Cc: "Theodore Ts'o" Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Eric Biggers --- fs/proc/proc_sysctl.c | 33 +++++++++++++++++++++++++++++++++ include/linux/sysctl.h | 3 +++ 2 files changed, 36 insertions(+) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 12bac452738df..f4b46f796901c 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "internal.h" static const struct dentry_operations proc_sys_dentry_operations; @@ -1370,6 +1371,38 @@ struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *tab } EXPORT_SYMBOL(register_sysctl); +/** + * __register_sysctl_init() - register sysctl table to path + * @path: path name for sysctl base + * @table: This is the sysctl table that needs to be registered to the path + * @table_name: The name of sysctl table, only used for log printing when + * registration fails + * + * The sysctl interface is used by userspace to query or modify at runtime + * a predefined value set on a variable. These variables however have default + * values pre-set. Code which depends on these variables will always work even + * if register_sysctl() fails. If register_sysctl() fails you'd just loose the + * ability to query or modify the sysctls dynamically at run time. Chances of + * register_sysctl() failing on init are extremely low, and so for both reasons + * this function does not return any error as it is used by initialization code. + * + * Context: Can only be called after your respective sysctl base path has been + * registered. So for instance, most base directories are registered early on + * init before init levels are processed through proc_sys_init() and + * sysctl_init(). + */ +void __init __register_sysctl_init(const char *path, struct ctl_table *table, + const char *table_name) +{ + struct ctl_table_header *hdr = register_sysctl(path, table); + + if (unlikely(!hdr)) { + pr_err("failed when register_sysctl %s to %s\n", table_name, path); + return; + } + kmemleak_not_leak(hdr); +} + static char *append_path(const char *path, char *pos, const char *name) { int namelen; diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index b769ecfcc3bd4..0a980aecc8f02 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -198,6 +198,9 @@ struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, void unregister_sysctl_table(struct ctl_table_header * table); extern int sysctl_init(void); +extern void __register_sysctl_init(const char *path, struct ctl_table *table, + const char *table_name); +#define register_sysctl_init(path, table) __register_sysctl_init(path, table, #table) extern struct ctl_table sysctl_mount_point[]; From patchwork Thu Feb 2 05:43:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125348 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83022C63797 for ; Thu, 2 Feb 2023 05:45:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231371AbjBBFpg (ORCPT ); Thu, 2 Feb 2023 00:45:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbjBBFp0 (ORCPT ); Thu, 2 Feb 2023 00:45:26 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05AC738B51; Wed, 1 Feb 2023 21:45:24 -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 ams.source.kernel.org (Postfix) with ESMTPS id 0D9F1B824B5; Thu, 2 Feb 2023 05:45:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34532C433A1; Thu, 2 Feb 2023 05:45:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316721; bh=gNpeNx44gA3Dz1NMaDk9iVn8+H0TL/VgfW5SQ5YlGbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OolubR8pKL/RnLJbpN5zSOftp0IqZka7ShfPX76E8roX4CCM3Rj6vFuuB83VXJyKr EvnbnG9IUyDeo8Y05Rl+imBdQpEWvwUm1gaXhbISZYFdJEXcFB0WLG0xA65N4OwLCP A6LluPHlXIVQAmLftwQ48uE3UkiLutIaWGRKL59nlErxNsY/izvZDSzH/ChNmy9o9Z 6S6LdsyfMxoJ6aDpDDHr6iT7nGgAnljQtkvx6TaE2B1HhMxIb1OgwGi2Mj+Pu5YiDF NE3qiXhkBix2lLR+yhiNSXjlIHJdALpMmeNULu6mNy+VD1q3GpbOVLjJF2NgSjR57D 2i6ysfC7LU/AA== 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, Andrey Ryabinin , Baoquan He , Jonathan Corbet , Xuefeng Li , Tiezhu Yang , Marco Elver , Andrew Morton , Linus Torvalds Subject: [PATCH 4.14 02/16] panic: unset panic_on_warn inside panic() Date: Wed, 1 Feb 2023 21:43:52 -0800 Message-Id: <20230202054406.221721-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Tiezhu Yang commit 1a2383e8b84c0451fd9b1eec3b9aab16f30b597c upstream. In the current code, the following three places need to unset panic_on_warn before calling panic() to avoid recursive panics: kernel/kcsan/report.c: print_report() kernel/sched/core.c: __schedule_bug() mm/kfence/report.c: kfence_report_error() In order to avoid copy-pasting "panic_on_warn = 0" all over the places, it is better to move it inside panic() and then remove it from the other places. Link: https://lkml.kernel.org/r/1644324666-15947-4-git-send-email-yangtiezhu@loongson.cn Signed-off-by: Tiezhu Yang Reviewed-by: Marco Elver Cc: Andrey Ryabinin Cc: Baoquan He Cc: Jonathan Corbet Cc: Xuefeng Li Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Eric Biggers --- kernel/panic.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/kernel/panic.c b/kernel/panic.c index 207ceac3a432e..bd7c3ea3bf1e6 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -139,6 +139,16 @@ void panic(const char *fmt, ...) int old_cpu, this_cpu; bool _crash_kexec_post_notifiers = crash_kexec_post_notifiers; + if (panic_on_warn) { + /* + * This thread may hit another WARN() in the panic path. + * Resetting this prevents additional WARN() from panicking the + * system on this thread. Other threads are blocked by the + * panic_mutex in panic(). + */ + panic_on_warn = 0; + } + /* * Disable local interrupts. This will prevent panic_smp_self_stop * from deadlocking the first cpu that invokes the panic, since @@ -536,16 +546,8 @@ void __warn(const char *file, int line, void *caller, unsigned taint, if (args) vprintk(args->fmt, args->args); - if (panic_on_warn) { - /* - * This thread may hit another WARN() in the panic path. - * Resetting this prevents additional WARN() from panicking the - * system on this thread. Other threads are blocked by the - * panic_mutex in panic(). - */ - panic_on_warn = 0; + if (panic_on_warn) panic("panic_on_warn set ...\n"); - } print_modules(); From patchwork Thu Feb 2 05:43:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125343 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78B73C05027 for ; Thu, 2 Feb 2023 05:45:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230116AbjBBFpZ (ORCPT ); Thu, 2 Feb 2023 00:45:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229988AbjBBFpY (ORCPT ); Thu, 2 Feb 2023 00:45:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79A053644C; Wed, 1 Feb 2023 21:45:23 -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 153C9615F2; Thu, 2 Feb 2023 05:45:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2E0CC433A4; Thu, 2 Feb 2023 05:45:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316722; bh=ZrJE/T7SLlHhvTiGljJycVNk4Ss4UF98+LFJwDCgDho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Opw6F21NCn/0eyL0JLjPetpv06wMS1xqhkHxD7snPBkviI/mJsQKP/Q+P2wQBCpG0 dn0srPB0+54tGOBE/Z1tHcNkwTLL6T4jhaKZtKpD+GBrVjNyMuflIOy9uhPsug+uUH 5EnlWsaC4jLiXXyBfCbriwDPR0nOMoJzWMghS1ryuMt+6rdsj+dz2ifZOA8UBqzhR1 YB5A2ybGDH+1Y7DPZoYtq0AFY9XjFBPU7y4VFYxpOxOzl3tOTGnmXCoRzGyw6zV8iN fcI4eosEEK80ZuEqgBwq6QZiVYJ0Lo2IuS5Ko6NLonxQypow2UbrfYw+Qg/zYCXXO2 mhnj3a9M2DG7g== 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, Andrey Ryabinin , Dmitry Vyukov , Ingo Molnar , Juri Lelli , Patricia Alfonso , Peter Zijlstra , Shuah Khan , Vincent Guittot , David Gow , Andrew Morton , Andrey Konovalov , Brendan Higgins , Linus Torvalds Subject: [PATCH 4.14 03/16] mm: kasan: do not panic if both panic_on_warn and kasan_multishot set Date: Wed, 1 Feb 2023 21:43:53 -0800 Message-Id: <20230202054406.221721-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: David Gow commit be4f1ae978ffe98cc95ec49ceb95386fb4474974 upstream. KASAN errors will currently trigger a panic when panic_on_warn is set. This renders kasan_multishot useless, as further KASAN errors won't be reported if the kernel has already paniced. By making kasan_multishot disable this behaviour for KASAN errors, we can still have the benefits of panic_on_warn for non-KASAN warnings, yet be able to use kasan_multishot. This is particularly important when running KASAN tests, which need to trigger multiple KASAN errors: previously these would panic the system if panic_on_warn was set, now they can run (and will panic the system should non-KASAN warnings show up). Signed-off-by: David Gow Signed-off-by: Andrew Morton Tested-by: Andrey Konovalov Reviewed-by: Andrey Konovalov Reviewed-by: Brendan Higgins Cc: Andrey Ryabinin Cc: Dmitry Vyukov Cc: Ingo Molnar Cc: Juri Lelli Cc: Patricia Alfonso Cc: Peter Zijlstra Cc: Shuah Khan Cc: Vincent Guittot Link: https://lkml.kernel.org/r/20200915035828.570483-6-davidgow@google.com Link: https://lkml.kernel.org/r/20200910070331.3358048-6-davidgow@google.com Signed-off-by: Linus Torvalds Signed-off-by: Eric Biggers --- mm/kasan/report.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 6bcfb01ba0386..5b421f8433488 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -172,7 +172,7 @@ 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) + if (panic_on_warn && !test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags)) panic("panic_on_warn set ...\n"); kasan_enable_current(); } From patchwork Thu Feb 2 05:43:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125349 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85CF8C64EC3 for ; Thu, 2 Feb 2023 05:45:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231520AbjBBFph (ORCPT ); Thu, 2 Feb 2023 00:45:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbjBBFpf (ORCPT ); Thu, 2 Feb 2023 00:45:35 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACC0F3F283; Wed, 1 Feb 2023 21:45:25 -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 ams.source.kernel.org (Postfix) with ESMTPS id 40091B824B6; Thu, 2 Feb 2023 05:45:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0FEDC4339C; Thu, 2 Feb 2023 05:45:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316722; bh=CPC3rnkJBI+2seUXRbQ6cBmh4fgZrX70sHReKY5rEZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oYyMXxn5zYzVzt2gJWJOLWY6litnWBqumdAoDbpX964Vdkh81Yci4EWv4Jec3JUMZ SZi3TLLWL3V6dpJqXBtzd94V/hbdMiIlr5lx/toRPuLFHz8Y//uM3E1RTb1Sd2bRHR s2gY6wz/NHuuaFdKRAJv7qsaBNscnXIYN9pWkXSz9/N1IDgjl0SxqjNArT8cQWBCZ3 cgPgZcgR9uH5bek27l2FHkqBsgxqsmKWN61gSaoLTrlcphhkYNbswDPeKD9ayla6Qi xVn7ABW9RKgyJb62ulGRXn/GY56aJim9mCd5Klr0kAtS+kALsRPbN3tH963w6NqYSE SyBzw089cudyA== 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 Subject: [PATCH 4.14 04/16] exit: Add and use make_task_dead. Date: Wed, 1 Feb 2023 21:43:54 -0800 Message-Id: <20230202054406.221721-5-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: "Eric W. Biederman" commit 0e25498f8cd43c1b5aa327f373dd094e9a006da7 upstream. There are two big uses of do_exit. The first is it's design use to be the guts of the exit(2) system call. The second use is to terminate a task after something catastrophic has happened like a NULL pointer in kernel code. Add a function make_task_dead that is initialy exactly the same as do_exit to cover the cases where do_exit is called to handle catastrophic failure. In time this can probably be reduced to just a light wrapper around do_task_dead. For now keep it exactly the same so that there will be no behavioral differences introducing this new concept. Replace all of the uses of do_exit that use it for catastraphic task cleanup with make_task_dead to make it clear what the code is doing. As part of this rename rewind_stack_do_exit rewind_stack_and_make_dead. Signed-off-by: "Eric W. Biederman" Signed-off-by: Eric Biggers --- arch/alpha/kernel/traps.c | 6 +++--- arch/alpha/mm/fault.c | 2 +- arch/arm/kernel/traps.c | 2 +- arch/arm/mm/fault.c | 2 +- arch/arm64/kernel/traps.c | 2 +- arch/arm64/mm/fault.c | 2 +- arch/h8300/kernel/traps.c | 2 +- arch/h8300/mm/fault.c | 2 +- arch/hexagon/kernel/traps.c | 2 +- arch/ia64/kernel/mca_drv.c | 2 +- arch/ia64/kernel/traps.c | 2 +- arch/ia64/mm/fault.c | 2 +- arch/m68k/kernel/traps.c | 2 +- arch/m68k/mm/fault.c | 2 +- arch/microblaze/kernel/exceptions.c | 4 ++-- arch/mips/kernel/traps.c | 2 +- arch/nios2/kernel/traps.c | 4 ++-- arch/openrisc/kernel/traps.c | 2 +- arch/parisc/kernel/traps.c | 2 +- arch/powerpc/kernel/traps.c | 2 +- arch/s390/kernel/dumpstack.c | 2 +- arch/s390/kernel/nmi.c | 2 +- arch/sh/kernel/traps.c | 2 +- arch/sparc/kernel/traps_32.c | 4 +--- arch/sparc/kernel/traps_64.c | 4 +--- arch/x86/entry/entry_32.S | 6 +++--- arch/x86/entry/entry_64.S | 6 +++--- arch/x86/kernel/dumpstack.c | 4 ++-- arch/xtensa/kernel/traps.c | 2 +- include/linux/sched/task.h | 1 + kernel/exit.c | 9 +++++++++ tools/objtool/check.c | 3 ++- 32 files changed, 50 insertions(+), 43 deletions(-) diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c index f43bd05dede26..6a45f392c6728 100644 --- a/arch/alpha/kernel/traps.c +++ b/arch/alpha/kernel/traps.c @@ -192,7 +192,7 @@ die_if_kernel(char * str, struct pt_regs *regs, long err, unsigned long *r9_15) local_irq_enable(); while (1); } - do_exit(SIGSEGV); + make_task_dead(SIGSEGV); } #ifndef CONFIG_MATHEMU @@ -609,7 +609,7 @@ do_entUna(void * va, unsigned long opcode, unsigned long reg, printk("Bad unaligned kernel access at %016lx: %p %lx %lu\n", pc, va, opcode, reg); - do_exit(SIGSEGV); + make_task_dead(SIGSEGV); got_exception: /* Ok, we caught the exception, but we don't want it. Is there @@ -664,7 +664,7 @@ do_entUna(void * va, unsigned long opcode, unsigned long reg, local_irq_enable(); while (1); } - do_exit(SIGSEGV); + make_task_dead(SIGSEGV); } /* diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c index e9392302c5dab..a85c1b18d0bc9 100644 --- a/arch/alpha/mm/fault.c +++ b/arch/alpha/mm/fault.c @@ -206,7 +206,7 @@ do_page_fault(unsigned long address, unsigned long mmcsr, printk(KERN_ALERT "Unable to handle kernel paging request at " "virtual address %016lx\n", address); die_if_kernel("Oops", regs, cause, (unsigned long*)regs - 16); - do_exit(SIGKILL); + make_task_dead(SIGKILL); /* We ran out of memory, or some other thing happened to us that made us unable to handle the page fault gracefully. */ diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index 7d81d4a1f5a9c..df7a92c5df6c5 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -342,7 +342,7 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr) if (panic_on_oops) panic("Fatal exception"); if (signr) - do_exit(signr); + make_task_dead(signr); } /* diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index 9bb446cc135d1..45e73596b524c 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -150,7 +150,7 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, show_pte(mm, addr); die("Oops", regs, fsr); bust_spinlocks(0); - do_exit(SIGKILL); + make_task_dead(SIGKILL); } /* diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index b30d23431fe11..ee19e6463e5a4 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -223,7 +223,7 @@ void die(const char *str, struct pt_regs *regs, int err) raw_spin_unlock_irqrestore(&die_lock, flags); if (ret != NOTIFY_STOP) - do_exit(SIGSEGV); + make_task_dead(SIGSEGV); } void arm64_notify_die(const char *str, struct pt_regs *regs, diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 617787e4081f1..d191b046d4c18 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -288,7 +288,7 @@ static void __do_kernel_fault(unsigned long addr, unsigned int esr, show_pte(addr); die("Oops", regs, esr); bust_spinlocks(0); - do_exit(SIGKILL); + make_task_dead(SIGKILL); } /* diff --git a/arch/h8300/kernel/traps.c b/arch/h8300/kernel/traps.c index e47a9e0dc278f..a284c126f07a6 100644 --- a/arch/h8300/kernel/traps.c +++ b/arch/h8300/kernel/traps.c @@ -110,7 +110,7 @@ void die(const char *str, struct pt_regs *fp, unsigned long err) dump(fp); spin_unlock_irq(&die_lock); - do_exit(SIGSEGV); + make_dead_task(SIGSEGV); } static int kstack_depth_to_print = 24; diff --git a/arch/h8300/mm/fault.c b/arch/h8300/mm/fault.c index fabffb83930af..a8d8fc63780e4 100644 --- a/arch/h8300/mm/fault.c +++ b/arch/h8300/mm/fault.c @@ -52,7 +52,7 @@ asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address, printk(" at virtual address %08lx\n", address); if (!user_mode(regs)) die("Oops", regs, error_code); - do_exit(SIGKILL); + make_dead_task(SIGKILL); return 1; } diff --git a/arch/hexagon/kernel/traps.c b/arch/hexagon/kernel/traps.c index 2942a9204a9aa..797608772f8a4 100644 --- a/arch/hexagon/kernel/traps.c +++ b/arch/hexagon/kernel/traps.c @@ -234,7 +234,7 @@ int die(const char *str, struct pt_regs *regs, long err) panic("Fatal exception"); oops_exit(); - do_exit(err); + make_dead_task(err); return 0; } diff --git a/arch/ia64/kernel/mca_drv.c b/arch/ia64/kernel/mca_drv.c index 3503d488e9b3f..7c9d63ef1cb28 100644 --- a/arch/ia64/kernel/mca_drv.c +++ b/arch/ia64/kernel/mca_drv.c @@ -176,7 +176,7 @@ mca_handler_bh(unsigned long paddr, void *iip, unsigned long ipsr) spin_unlock(&mca_bh_lock); /* This process is about to be killed itself */ - do_exit(SIGKILL); + make_task_dead(SIGKILL); } /** diff --git a/arch/ia64/kernel/traps.c b/arch/ia64/kernel/traps.c index 6d4e76a4267f1..2bab65c10d236 100644 --- a/arch/ia64/kernel/traps.c +++ b/arch/ia64/kernel/traps.c @@ -85,7 +85,7 @@ die (const char *str, struct pt_regs *regs, long err) if (panic_on_oops) panic("Fatal exception"); - do_exit(SIGSEGV); + make_task_dead(SIGSEGV); return 0; } diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c index dfdc152d6737b..23f23e051ee24 100644 --- a/arch/ia64/mm/fault.c +++ b/arch/ia64/mm/fault.c @@ -300,7 +300,7 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re regs = NULL; bust_spinlocks(0); if (regs) - do_exit(SIGKILL); + make_task_dead(SIGKILL); return; out_of_memory: diff --git a/arch/m68k/kernel/traps.c b/arch/m68k/kernel/traps.c index c1cc4e99aa945..5c72deb117a8e 100644 --- a/arch/m68k/kernel/traps.c +++ b/arch/m68k/kernel/traps.c @@ -1141,7 +1141,7 @@ void die_if_kernel (char *str, struct pt_regs *fp, int nr) pr_crit("%s: %08x\n", str, nr); show_registers(fp); add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); - do_exit(SIGSEGV); + make_task_dead(SIGSEGV); } asmlinkage void set_esp0(unsigned long ssp) diff --git a/arch/m68k/mm/fault.c b/arch/m68k/mm/fault.c index 127d7c1f2090c..4ef6057592f12 100644 --- a/arch/m68k/mm/fault.c +++ b/arch/m68k/mm/fault.c @@ -50,7 +50,7 @@ int send_fault_sig(struct pt_regs *regs) pr_alert("Unable to handle kernel access"); pr_cont(" at virtual address %p\n", siginfo.si_addr); die_if_kernel("Oops", regs, 0 /*error_code*/); - do_exit(SIGKILL); + make_task_dead(SIGKILL); } return 1; diff --git a/arch/microblaze/kernel/exceptions.c b/arch/microblaze/kernel/exceptions.c index e6f338d0496bb..3066d7fe484bd 100644 --- a/arch/microblaze/kernel/exceptions.c +++ b/arch/microblaze/kernel/exceptions.c @@ -44,10 +44,10 @@ void die(const char *str, struct pt_regs *fp, long err) pr_warn("Oops: %s, sig: %ld\n", str, err); show_regs(fp); spin_unlock_irq(&die_lock); - /* do_exit() should take care of panic'ing from an interrupt + /* make_task_dead() should take care of panic'ing from an interrupt * context so we don't handle it here */ - do_exit(err); + make_task_dead(err); } /* for user application debugging */ diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c index abbc64788008a..a8f166ff2762b 100644 --- a/arch/mips/kernel/traps.c +++ b/arch/mips/kernel/traps.c @@ -414,7 +414,7 @@ void __noreturn die(const char *str, struct pt_regs *regs) if (regs && kexec_should_crash(current)) crash_kexec(regs); - do_exit(sig); + make_task_dead(sig); } extern struct exception_table_entry __start___dbe_table[]; diff --git a/arch/nios2/kernel/traps.c b/arch/nios2/kernel/traps.c index 8184e7d6b3857..5dadd36d13ce3 100644 --- a/arch/nios2/kernel/traps.c +++ b/arch/nios2/kernel/traps.c @@ -43,10 +43,10 @@ void die(const char *str, struct pt_regs *regs, long err) show_regs(regs); spin_unlock_irq(&die_lock); /* - * do_exit() should take care of panic'ing from an interrupt + * make_task_dead() should take care of panic'ing from an interrupt * context so we don't handle it here */ - do_exit(err); + make_task_dead(err); } void _exception(int signo, struct pt_regs *regs, int code, unsigned long addr) diff --git a/arch/openrisc/kernel/traps.c b/arch/openrisc/kernel/traps.c index 0d44e8007ad6e..a8fb061f1c888 100644 --- a/arch/openrisc/kernel/traps.c +++ b/arch/openrisc/kernel/traps.c @@ -265,7 +265,7 @@ void die(const char *str, struct pt_regs *regs, long err) __asm__ __volatile__("l.nop 1"); do {} while (1); #endif - do_exit(SIGSEGV); + make_task_dead(SIGSEGV); } /* This is normally the 'Oops' routine */ diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c index 346456c43aa0b..36582e23f9b9d 100644 --- a/arch/parisc/kernel/traps.c +++ b/arch/parisc/kernel/traps.c @@ -290,7 +290,7 @@ void die_if_kernel(char *str, struct pt_regs *regs, long err) panic("Fatal exception"); oops_exit(); - do_exit(SIGSEGV); + make_task_dead(SIGSEGV); } /* gdb uses break 4,8 */ diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c index 05c1aabad01c6..a507a6874d420 100644 --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -211,7 +211,7 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, panic("Fatal exception in interrupt"); if (panic_on_oops) panic("Fatal exception"); - do_exit(signr); + make_task_dead(signr); } NOKPROBE_SYMBOL(oops_end); diff --git a/arch/s390/kernel/dumpstack.c b/arch/s390/kernel/dumpstack.c index 2aa545dca4d53..d9513a9f0db12 100644 --- a/arch/s390/kernel/dumpstack.c +++ b/arch/s390/kernel/dumpstack.c @@ -186,5 +186,5 @@ void die(struct pt_regs *regs, const char *str) if (panic_on_oops) panic("Fatal exception: panic_on_oops"); oops_exit(); - do_exit(SIGSEGV); + make_task_dead(SIGSEGV); } diff --git a/arch/s390/kernel/nmi.c b/arch/s390/kernel/nmi.c index 31d03a84126c5..5dca748d3815c 100644 --- a/arch/s390/kernel/nmi.c +++ b/arch/s390/kernel/nmi.c @@ -94,7 +94,7 @@ void s390_handle_mcck(void) "malfunction (code 0x%016lx).\n", mcck.mcck_code); printk(KERN_EMERG "mcck: task: %s, pid: %d.\n", current->comm, current->pid); - do_exit(SIGSEGV); + make_task_dead(SIGSEGV); } } EXPORT_SYMBOL_GPL(s390_handle_mcck); diff --git a/arch/sh/kernel/traps.c b/arch/sh/kernel/traps.c index 8b49cced663dc..5fafbef7849b1 100644 --- a/arch/sh/kernel/traps.c +++ b/arch/sh/kernel/traps.c @@ -57,7 +57,7 @@ void die(const char *str, struct pt_regs *regs, long err) if (panic_on_oops) panic("Fatal exception"); - do_exit(SIGSEGV); + make_task_dead(SIGSEGV); } void die_if_kernel(const char *str, struct pt_regs *regs, long err) diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c index b1ed763e47877..fb0576f3b1de0 100644 --- a/arch/sparc/kernel/traps_32.c +++ b/arch/sparc/kernel/traps_32.c @@ -86,9 +86,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs) } printk("Instruction DUMP:"); instruction_dump ((unsigned long *) regs->pc); - if(regs->psr & PSR_PS) - do_exit(SIGKILL); - do_exit(SIGSEGV); + make_task_dead((regs->psr & PSR_PS) ? SIGKILL : SIGSEGV); } void do_hw_interrupt(struct pt_regs *regs, unsigned long type) diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c index 6ab9b87dbca8c..cfc06eeeb4f35 100644 --- a/arch/sparc/kernel/traps_64.c +++ b/arch/sparc/kernel/traps_64.c @@ -2547,9 +2547,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs) } if (panic_on_oops) panic("Fatal exception"); - if (regs->tstate & TSTATE_PRIV) - do_exit(SIGKILL); - do_exit(SIGSEGV); + make_task_dead((regs->tstate & TSTATE_PRIV)? SIGKILL : SIGSEGV); } EXPORT_SYMBOL(die_if_kernel); diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S index dbcea4281c309..1fdedb2eaef35 100644 --- a/arch/x86/entry/entry_32.S +++ b/arch/x86/entry/entry_32.S @@ -1068,13 +1068,13 @@ ENTRY(async_page_fault) END(async_page_fault) #endif -ENTRY(rewind_stack_do_exit) +ENTRY(rewind_stack_and_make_dead) /* Prevent any naive code from trying to unwind to our caller. */ xorl %ebp, %ebp movl PER_CPU_VAR(cpu_current_top_of_stack), %esi leal -TOP_OF_KERNEL_STACK_PADDING-PTREGS_SIZE(%esi), %esp - call do_exit + call make_task_dead 1: jmp 1b -END(rewind_stack_do_exit) +END(rewind_stack_and_make_dead) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 637a23d404e95..b57f15b51ed52 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -1672,7 +1672,7 @@ ENTRY(ignore_sysret) sysret END(ignore_sysret) -ENTRY(rewind_stack_do_exit) +ENTRY(rewind_stack_and_make_dead) UNWIND_HINT_FUNC /* Prevent any naive code from trying to unwind to our caller. */ xorl %ebp, %ebp @@ -1681,5 +1681,5 @@ ENTRY(rewind_stack_do_exit) leaq -PTREGS_SIZE(%rax), %rsp UNWIND_HINT_REGS - call do_exit -END(rewind_stack_do_exit) + call make_task_dead +END(rewind_stack_and_make_dead) diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index 224de37821e4e..92585a755410b 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c @@ -271,7 +271,7 @@ unsigned long oops_begin(void) EXPORT_SYMBOL_GPL(oops_begin); NOKPROBE_SYMBOL(oops_begin); -void __noreturn rewind_stack_do_exit(int signr); +void __noreturn rewind_stack_and_make_dead(int signr); void oops_end(unsigned long flags, struct pt_regs *regs, int signr) { @@ -303,7 +303,7 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr) * reuse the task stack and that existing poisons are invalid. */ kasan_unpoison_task_stack(current); - rewind_stack_do_exit(signr); + rewind_stack_and_make_dead(signr); } NOKPROBE_SYMBOL(oops_end); diff --git a/arch/xtensa/kernel/traps.c b/arch/xtensa/kernel/traps.c index 2986bc88a18e7..09ba7436d1bd0 100644 --- a/arch/xtensa/kernel/traps.c +++ b/arch/xtensa/kernel/traps.c @@ -547,5 +547,5 @@ void die(const char * str, struct pt_regs * regs, long err) if (panic_on_oops) panic("Fatal exception"); - do_exit(err); + make_task_dead(err); } diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index c3d157a370734..3ef0986cf0ea3 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -36,6 +36,7 @@ extern int sched_fork(unsigned long clone_flags, struct task_struct *p); extern void sched_dead(struct task_struct *p); void __noreturn do_task_dead(void); +void __noreturn make_task_dead(int signr); extern void proc_caches_init(void); diff --git a/kernel/exit.c b/kernel/exit.c index 9e70577b818ab..1e778b88fa3fe 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -920,6 +920,15 @@ void __noreturn do_exit(long code) } EXPORT_SYMBOL_GPL(do_exit); +void __noreturn make_task_dead(int signr) +{ + /* + * Take the task off the cpu after something catastrophic has + * happened. + */ + do_exit(signr); +} + void complete_and_exit(struct completion *comp, long code) { if (comp) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 2c8e2dae17016..9048b02b54474 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -159,6 +159,7 @@ static int __dead_end_function(struct objtool_file *file, struct symbol *func, "panic", "do_exit", "do_task_dead", + "make_task_dead", "__module_put_and_exit", "complete_and_exit", "kvm_spurious_fault", @@ -166,7 +167,7 @@ static int __dead_end_function(struct objtool_file *file, struct symbol *func, "lbug_with_loc", "fortify_panic", "machine_real_restart", - "rewind_stack_do_exit", + "rewind_stack_and_make_dead" }; if (func->bind == STB_WEAK) From patchwork Thu Feb 2 05:43:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125345 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9C85C05027 for ; Thu, 2 Feb 2023 05:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230317AbjBBFp1 (ORCPT ); Thu, 2 Feb 2023 00:45:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229595AbjBBFpZ (ORCPT ); Thu, 2 Feb 2023 00:45:25 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7407135261; Wed, 1 Feb 2023 21:45:24 -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 ED3AE61783; Thu, 2 Feb 2023 05:45:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B92BC433EF; Thu, 2 Feb 2023 05:45:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316723; bh=Q1iK07+TfUGftVW45xfnQtsOGOOjDYaWhjdzlKJkRcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H5K2ZX8NDzqu0C7L9WC5+5iXCgFyof+VCgQu/94N7VwSnt8esGfz8PIgWaolj5NyQ S4jdv63roHDQWMR4UtfnMjpq1ynDtiown4KVBv8QzyG4h+Whj7Rws8wZjMa2Ry1IFT QK1i8+5gnKLWAcLlXA+uHpaEgugUsKwVzi/UBQ/H6SsHfQ1sf70shq8Bb2lamQTmh6 1oxFC54idfXed6qlIZJYBQ2ZT5/Eszmidm8SNdHWiU2zYaimgXrCcJUl9u8sedsKol L3u37LgDAHziYQwjS6A95F3qWmgeHxW6XwRNEvAGEUCycgQkPOfRSLjFOaGxkN4cq6 yEBvOjjMjeTKw== 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, kernel test robot Subject: [PATCH 4.14 05/16] objtool: Add a missing comma to avoid string concatenation Date: Wed, 1 Feb 2023 21:43:55 -0800 Message-Id: <20230202054406.221721-6-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: "Eric W. Biederman" commit 1fb466dff904e4a72282af336f2c355f011eec61 upstream. Recently the kbuild robot reported two new errors: >> lib/kunit/kunit-example-test.o: warning: objtool: .text.unlikely: unexpected end of section >> arch/x86/kernel/dumpstack.o: warning: objtool: oops_end() falls through to next function show_opcodes() I don't know why they did not occur in my test setup but after digging it I realized I had accidentally dropped a comma in tools/objtool/check.c when I renamed rewind_stack_do_exit to rewind_stack_and_make_dead. Add that comma back to fix objtool errors. Link: https://lkml.kernel.org/r/202112140949.Uq5sFKR1-lkp@intel.com Fixes: 0e25498f8cd4 ("exit: Add and use make_task_dead.") Reported-by: kernel test robot Signed-off-by: "Eric W. Biederman" Signed-off-by: Eric Biggers --- tools/objtool/check.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 9048b02b54474..e93c061654a79 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -167,7 +167,7 @@ static int __dead_end_function(struct objtool_file *file, struct symbol *func, "lbug_with_loc", "fortify_panic", "machine_real_restart", - "rewind_stack_and_make_dead" + "rewind_stack_and_make_dead", }; if (func->bind == STB_WEAK) From patchwork Thu Feb 2 05:43:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125346 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F03FC61DA4 for ; Thu, 2 Feb 2023 05:45:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230404AbjBBFp2 (ORCPT ); Thu, 2 Feb 2023 00:45:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbjBBFpZ (ORCPT ); Thu, 2 Feb 2023 00:45:25 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 063BE3B0EC; Wed, 1 Feb 2023 21:45:24 -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 69F5B6177C; Thu, 2 Feb 2023 05:45:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89BF3C4339B; Thu, 2 Feb 2023 05:45:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316723; bh=sg1KwdXv0FVnbAh1B0Mu7C1aCwLVKT+GZqGfNjJjHPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bHVTcuz0ufejEqPH8YQ3xCQIHYRS8ASbecuMe0myj5RXS+rzSqlIoTs/UYV4pK+Yn c71VaOaHKrxWWrxre1Z/TG0pUXs/NYisdCzWRGu/GUAYDcnpVKczoucKRKC4cJHipw Z8gliPQzg7QyReemptGzXYOUDcKrA9ZJleqiB5reGStnwhNwdiuT9ENVL2I0lgvl6C iMDdRFAkEuiabudBE1dznZmPG2ids1RbQXWGjtsWEHK+0S0nTfKaK0z/6xRCmUdelj rQEI9YPYEPlO4wqKbf05saJIZpUarYJnGfpRPogA2jZskP95QU80v4V4TCs3I30TbG 9n4mU9si+eo4g== 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, Nathan Chancellor Subject: [PATCH 4.14 06/16] hexagon: Fix function name in die() Date: Wed, 1 Feb 2023 21:43:56 -0800 Message-Id: <20230202054406.221721-7-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Nathan Chancellor commit 4f0712ccec09c071e221242a2db9a6779a55a949 upstream. When building ARCH=hexagon defconfig: arch/hexagon/kernel/traps.c:217:2: error: implicit declaration of function 'make_dead_task' [-Werror,-Wimplicit-function-declaration] make_dead_task(err); ^ The function's name is make_task_dead(), change it so there is no more build error. Fixes: 0e25498f8cd4 ("exit: Add and use make_task_dead.") Signed-off-by: Nathan Chancellor Link: https://lkml.kernel.org/r/20211227184851.2297759-2-nathan@kernel.org Signed-off-by: Eric W. Biederman Signed-off-by: Eric Biggers --- arch/hexagon/kernel/traps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/hexagon/kernel/traps.c b/arch/hexagon/kernel/traps.c index 797608772f8a4..65330343bdc33 100644 --- a/arch/hexagon/kernel/traps.c +++ b/arch/hexagon/kernel/traps.c @@ -234,7 +234,7 @@ int die(const char *str, struct pt_regs *regs, long err) panic("Fatal exception"); oops_exit(); - make_dead_task(err); + make_task_dead(err); return 0; } From patchwork Thu Feb 2 05:43:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125347 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE0E4C05027 for ; Thu, 2 Feb 2023 05:45:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231160AbjBBFpf (ORCPT ); Thu, 2 Feb 2023 00:45:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230204AbjBBFp0 (ORCPT ); Thu, 2 Feb 2023 00:45:26 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 064603D0B7; Wed, 1 Feb 2023 21:45:24 -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 79C26615F1; Thu, 2 Feb 2023 05:45:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 054DDC433A1; Thu, 2 Feb 2023 05:45:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316724; bh=w2+gKam0hgvqls1hiqaw8OhtqAs87LqFnf26zQZbz5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UUsrcEWMF5o5ZkejsYMVZIiZ8uPrD4RFgVBVKzBxoncH0JbFJZQ7/iPnW8IcWskpy vXV+ZxN4YcC7BUSYi+Wr5RaBxoOrG9dFIcKlTrkIfecGpokcS+ebR/SsurMFzZsLxS 4v3izFnEN+IKquzVnHI2Dk70Ct4hOWFKqZuU45bUEJoDMgBS5YIf2asyS4humC5rVW ZJZauNoXfjNdtv1k4gI7jraGZa3JbmwuqKb9uJqTTX8XAxc8LEFEjOzjfhJLofUnch HhT5DUwB8trtlg+6jpwdxaq0lVgdLoowYiOArl1PQ8QA5Uw9IEuSm+CS3P2QNvu9Tw CuqcgFbAq7Q8w== 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, Nathan Chancellor Subject: [PATCH 4.14 07/16] h8300: Fix build errors from do_exit() to make_task_dead() transition Date: Wed, 1 Feb 2023 21:43:57 -0800 Message-Id: <20230202054406.221721-8-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Nathan Chancellor commit ab4ababdf77ccc56c7301c751dff49c79709c51c upstream. When building ARCH=h8300 defconfig: arch/h8300/kernel/traps.c: In function 'die': arch/h8300/kernel/traps.c:109:2: error: implicit declaration of function 'make_dead_task' [-Werror=implicit-function-declaration] 109 | make_dead_task(SIGSEGV); | ^~~~~~~~~~~~~~ arch/h8300/mm/fault.c: In function 'do_page_fault': arch/h8300/mm/fault.c:54:2: error: implicit declaration of function 'make_dead_task' [-Werror=implicit-function-declaration] 54 | make_dead_task(SIGKILL); | ^~~~~~~~~~~~~~ The function's name is make_task_dead(), change it so there is no more build error. Additionally, include linux/sched/task.h in arch/h8300/kernel/traps.c to avoid the same error because do_exit()'s declaration is in kernel.h but make_task_dead()'s is in task.h, which is not included in traps.c. Fixes: 0e25498f8cd4 ("exit: Add and use make_task_dead.") Signed-off-by: Nathan Chancellor Link: https://lkml.kernel.org/r/20211227184851.2297759-3-nathan@kernel.org Signed-off-by: Eric W. Biederman Signed-off-by: Eric Biggers --- arch/h8300/kernel/traps.c | 3 ++- arch/h8300/mm/fault.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/h8300/kernel/traps.c b/arch/h8300/kernel/traps.c index a284c126f07a6..090adaee4b84c 100644 --- a/arch/h8300/kernel/traps.c +++ b/arch/h8300/kernel/traps.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -110,7 +111,7 @@ void die(const char *str, struct pt_regs *fp, unsigned long err) dump(fp); spin_unlock_irq(&die_lock); - make_dead_task(SIGSEGV); + make_task_dead(SIGSEGV); } static int kstack_depth_to_print = 24; diff --git a/arch/h8300/mm/fault.c b/arch/h8300/mm/fault.c index a8d8fc63780e4..573825c3cb708 100644 --- a/arch/h8300/mm/fault.c +++ b/arch/h8300/mm/fault.c @@ -52,7 +52,7 @@ asmlinkage int do_page_fault(struct pt_regs *regs, unsigned long address, printk(" at virtual address %08lx\n", address); if (!user_mode(regs)) die("Oops", regs, error_code); - make_dead_task(SIGKILL); + make_task_dead(SIGKILL); return 1; } From patchwork Thu Feb 2 05:43:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125350 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5377C636D7 for ; Thu, 2 Feb 2023 05:45:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231540AbjBBFpi (ORCPT ); Thu, 2 Feb 2023 00:45:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230169AbjBBFp1 (ORCPT ); Thu, 2 Feb 2023 00:45:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECBBE46098; Wed, 1 Feb 2023 21:45:25 -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 761A261780; Thu, 2 Feb 2023 05:45:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 750D5C433AC; Thu, 2 Feb 2023 05:45:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316724; bh=OEFRgj2r07VcIiioIVTwsasK/y5NxA97g2mUL0L6xKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XJ5wvGvox1K5BuwroHNiqcMrwLcPIzVwO+rnOgTrUt/jdsb4NJImjWH79lIvpjDpL IHEbbrQTT8B1zBRr06imQxTea6wD7FRjkNK5xR5DYDgJUx81G7RyOWlOad84So5FDd wEy1+uQAXwFQOzznT/iw8WKtNeiLqyO5pjPZjArmPuUbkfmSarurCTzj+9hUaxVEWT ZMGKCQyxCdB8R50G4sYRtZmSDEgECQ3IVOTKu/Wh2aAWYygg/2aGxOGqO9y4nRHtzx GoS1PXrp6KriIxfNdtsu5fN3Auz9VgDo7be9cnjm2PzkYLqz0c0hFE7k7GXY7Rf3n+ xTtJz4xKQXvFg== 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, Tony Luck , Randy Dunlap , Christoph Hellwig , Christoph Hellwig , Andrew Morton , Linus Torvalds Subject: [PATCH 4.14 08/16] ia64: make IA64_MCA_RECOVERY bool instead of tristate Date: Wed, 1 Feb 2023 21:43:58 -0800 Message-Id: <20230202054406.221721-9-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Randy Dunlap commit dbecf9b8b8ce580f4e11afed9d61e8aa294cddd2 upstream. In linux-next, IA64_MCA_RECOVERY uses the (new) function make_task_dead(), which is not exported for use by modules. Instead of exporting it for one user, convert IA64_MCA_RECOVERY to be a bool Kconfig symbol. In a config file from "kernel test robot " for a different problem, this linker error was exposed when CONFIG_IA64_MCA_RECOVERY=m. Fixes this build error: ERROR: modpost: "make_task_dead" [arch/ia64/kernel/mca_recovery.ko] undefined! Link: https://lkml.kernel.org/r/20220124213129.29306-1-rdunlap@infradead.org Fixes: 0e25498f8cd4 ("exit: Add and use make_task_dead.") Signed-off-by: Randy Dunlap Suggested-by: Christoph Hellwig Reviewed-by: Christoph Hellwig Reviewed-by: "Eric W. Biederman" Cc: Tony Luck Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Eric Biggers --- arch/ia64/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig index 1efc444f5fa1a..f8dac6bd17dd2 100644 --- a/arch/ia64/Kconfig +++ b/arch/ia64/Kconfig @@ -461,7 +461,7 @@ config ARCH_PROC_KCORE_TEXT depends on PROC_KCORE config IA64_MCA_RECOVERY - tristate "MCA recovery from errors other than TLB." + bool "MCA recovery from errors other than TLB." config PERFMON bool "Performance monitor support" From patchwork Thu Feb 2 05:43:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125354 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFD60C61DA4 for ; Thu, 2 Feb 2023 05:45:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231866AbjBBFpx (ORCPT ); Thu, 2 Feb 2023 00:45:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229616AbjBBFpf (ORCPT ); Thu, 2 Feb 2023 00:45:35 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E37D3864D; Wed, 1 Feb 2023 21:45:28 -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 ams.source.kernel.org (Postfix) with ESMTPS id ADF5DB8247A; Thu, 2 Feb 2023 05:45:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13A1DC4339E; Thu, 2 Feb 2023 05:45:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316725; bh=GM64I8LDi7cDnrLEl3psUaDr0dWAk6jElGhklKg21VU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MNKqe06FeFJBMmO7TN74mtI216jErllITCk24N/TTd0kuvsox2tnuhKkDgU41V2EX rvNjanEATfD1pb2B6CBXUG9EujfGHZe4+Zeh15GnP6FgYZVXTdXc0RQ774fD4/CtHJ SbVEmrQQJO/r2p3FR/VmAMdeH2zRob7jresEKwngci1U2ceQNrEZRo7ta40ffBTXpF 4NIvCcgVZYeLMMfQiXYqYLXyf74OYCPWUi1y7P68eicpjcC9q6j64bljea1/M3SfJw ifxZhoSbwieUjtPnBocWfBiPHOPKKMSuwzC0Kn603Qv8GNv2zS0lXSJWXJUphIq9XG ebG5ys8JPB6ug== 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, Luis Chamberlain Subject: [PATCH 4.14 09/16] exit: Put an upper limit on how often we can oops Date: Wed, 1 Feb 2023 21:43:59 -0800 Message-Id: <20230202054406.221721-10-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Jann Horn commit d4ccd54d28d3c8598e2354acc13e28c060961dbb upstream. Many Linux systems are configured to not panic on oops; but allowing an attacker to oops the system **really** often can make even bugs that look completely unexploitable exploitable (like NULL dereferences and such) if each crash elevates a refcount by one or a lock is taken in read mode, and this causes a counter to eventually overflow. The most interesting counters for this are 32 bits wide (like open-coded refcounts that don't use refcount_t). (The ldsem reader count on 32-bit platforms is just 16 bits, but probably nobody cares about 32-bit platforms that much nowadays.) So let's panic the system if the kernel is constantly oopsing. The speed of oopsing 2^32 times probably depends on several factors, like how long the stack trace is and which unwinder you're using; an empirically important one is whether your console is showing a graphical environment or a text console that oopses will be printed to. In a quick single-threaded benchmark, it looks like oopsing in a vfork() child with a very short stack trace only takes ~510 microseconds per run when a graphical console is active; but switching to a text console that oopses are printed to slows it down around 87x, to ~45 milliseconds per run. (Adding more threads makes this faster, but the actual oops printing happens under &die_lock on x86, so you can maybe speed this up by a factor of around 2 and then any further improvement gets eaten up by lock contention.) It looks like it would take around 8-12 days to overflow a 32-bit counter with repeated oopsing on a multi-core X86 system running a graphical environment; both me (in an X86 VM) and Seth (with a distro kernel on normal hardware in a standard configuration) got numbers in that ballpark. 12 days aren't *that* short on a desktop system, and you'd likely need much longer on a typical server system (assuming that people don't run graphical desktop environments on their servers), and this is a *very* noisy and violent approach to exploiting the kernel; and it also seems to take orders of magnitude longer on some machines, probably because stuff like EFI pstore will slow it down a ton if that's active. Signed-off-by: Jann Horn Link: https://lore.kernel.org/r/20221107201317.324457-1-jannh@google.com Reviewed-by: Luis Chamberlain Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20221117234328.594699-2-keescook@chromium.org Signed-off-by: Eric Biggers --- Documentation/sysctl/kernel.txt | 9 +++++++ kernel/exit.c | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt index 37b612a17c461..7b04c616c5901 100644 --- a/Documentation/sysctl/kernel.txt +++ b/Documentation/sysctl/kernel.txt @@ -48,6 +48,7 @@ show up in /proc/sys/kernel: - msgmnb - msgmni - nmi_watchdog +- oops_limit - osrelease - ostype - overflowgid @@ -515,6 +516,14 @@ scanned for a given scan. ============================================================== +oops_limit: + +Number of kernel oopses after which the kernel should panic when +``panic_on_oops`` is not set. Setting this to 0 or 1 has the same effect +as setting ``panic_on_oops=1``. + +============================================================== + osrelease, ostype & version: # cat osrelease diff --git a/kernel/exit.c b/kernel/exit.c index 1e778b88fa3fe..482bcaf158127 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -68,6 +68,33 @@ #include #include +/* + * The default value should be high enough to not crash a system that randomly + * crashes its kernel from time to time, but low enough to at least not permit + * overflowing 32-bit refcounts or the ldsem writer count. + */ +static unsigned int oops_limit = 10000; + +#ifdef CONFIG_SYSCTL +static struct ctl_table kern_exit_table[] = { + { + .procname = "oops_limit", + .data = &oops_limit, + .maxlen = sizeof(oops_limit), + .mode = 0644, + .proc_handler = proc_douintvec, + }, + { } +}; + +static __init int kernel_exit_sysctls_init(void) +{ + register_sysctl_init("kernel", kern_exit_table); + return 0; +} +late_initcall(kernel_exit_sysctls_init); +#endif + static void __unhash_process(struct task_struct *p, bool group_dead) { nr_threads--; @@ -922,10 +949,26 @@ EXPORT_SYMBOL_GPL(do_exit); void __noreturn make_task_dead(int signr) { + static atomic_t oops_count = ATOMIC_INIT(0); + /* * Take the task off the cpu after something catastrophic has * happened. */ + + /* + * Every time the system oopses, if the oops happens while a reference + * to an object was held, the reference leaks. + * If the oops doesn't also leak memory, repeated oopsing can cause + * reference counters to wrap around (if they're not using refcount_t). + * This means that repeated oopsing can make unexploitable-looking bugs + * exploitable through repeated oopsing. + * To make sure this can't happen, place an upper bound on how often the + * kernel may oops without panic(). + */ + if (atomic_inc_return(&oops_count) >= READ_ONCE(oops_limit)) + panic("Oopsed too often (kernel.oops_limit is %d)", oops_limit); + do_exit(signr); } From patchwork Thu Feb 2 05:44: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: 13125352 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9142C64EC3 for ; Thu, 2 Feb 2023 05:45:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231635AbjBBFpm (ORCPT ); Thu, 2 Feb 2023 00:45:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230375AbjBBFp1 (ORCPT ); Thu, 2 Feb 2023 00:45:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EBAE474E6; Wed, 1 Feb 2023 21:45:26 -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 0AC7A6150C; Thu, 2 Feb 2023 05:45:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82F4BC4339B; Thu, 2 Feb 2023 05:45:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316725; bh=NvHqmOgG2aAfs54Rnjd2jLih4AMjzsSDG6iFMQBllZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nDzeGMFnqc25P7VvHZgMcUsQM0iTsM9f/ufUyPfc0uUMhtmfNZP3GwR3IvcfAvyjk Imy4joa/KW4NWMuHkdgDnkJBzRVrd9493D900R9m2uMrX5OUUpya5uBaz9xNO0hS5a o2xtffj+BOud4aduCWunbfIcDET0aGIWjm/rA40ZGYvDvXmnUHxJh2ZkjdnEUgb99P 2zOuu4KniRLJhaKKdQX0rKKv5h+TpBFyNnEQObcY/6nohmDXzNMsE3BF1mbf54siaQ sGjLxGManBAZwfKvkHrn0ktr+dKz5KNc6VCJb67QNE1Bpa0Ka9MHIjSADLC2nZaI3C S2GdP0BstqGrQ== 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, Arnd Bergmann , Luis Chamberlain Subject: [PATCH 4.14 10/16] exit: Expose "oops_count" to sysfs Date: Wed, 1 Feb 2023 21:44:00 -0800 Message-Id: <20230202054406.221721-11-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Kees Cook commit 9db89b41117024f80b38b15954017fb293133364 upstream. Since Oops count is now tracked and is a fairly interesting signal, add the entry /sys/kernel/oops_count to expose it to userspace. Cc: "Eric W. Biederman" Cc: Jann Horn Cc: Arnd Bergmann Reviewed-by: Luis Chamberlain Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20221117234328.594699-3-keescook@chromium.org Signed-off-by: Eric Biggers --- .../ABI/testing/sysfs-kernel-oops_count | 6 +++++ kernel/exit.c | 22 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-kernel-oops_count diff --git a/Documentation/ABI/testing/sysfs-kernel-oops_count b/Documentation/ABI/testing/sysfs-kernel-oops_count new file mode 100644 index 0000000000000..156cca9dbc960 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-kernel-oops_count @@ -0,0 +1,6 @@ +What: /sys/kernel/oops_count +Date: November 2022 +KernelVersion: 6.2.0 +Contact: Linux Kernel Hardening List +Description: + Shows how many times the system has Oopsed since last boot. diff --git a/kernel/exit.c b/kernel/exit.c index 482bcaf158127..138b110bf83a1 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -62,6 +62,7 @@ #include #include #include +#include #include #include @@ -95,6 +96,25 @@ static __init int kernel_exit_sysctls_init(void) late_initcall(kernel_exit_sysctls_init); #endif +static atomic_t oops_count = ATOMIC_INIT(0); + +#ifdef CONFIG_SYSFS +static ssize_t oops_count_show(struct kobject *kobj, struct kobj_attribute *attr, + char *page) +{ + return sysfs_emit(page, "%d\n", atomic_read(&oops_count)); +} + +static struct kobj_attribute oops_count_attr = __ATTR_RO(oops_count); + +static __init int kernel_exit_sysfs_init(void) +{ + sysfs_add_file_to_group(kernel_kobj, &oops_count_attr.attr, NULL); + return 0; +} +late_initcall(kernel_exit_sysfs_init); +#endif + static void __unhash_process(struct task_struct *p, bool group_dead) { nr_threads--; @@ -949,8 +969,6 @@ EXPORT_SYMBOL_GPL(do_exit); void __noreturn make_task_dead(int signr) { - static atomic_t oops_count = ATOMIC_INIT(0); - /* * Take the task off the cpu after something catastrophic has * happened. From patchwork Thu Feb 2 05:44:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125351 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E642FC61DA4 for ; Thu, 2 Feb 2023 05:45:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231546AbjBBFpk (ORCPT ); Thu, 2 Feb 2023 00:45:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230508AbjBBFpf (ORCPT ); Thu, 2 Feb 2023 00:45:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24F6A37B46; Wed, 1 Feb 2023 21:45:27 -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 AB5BD61783; Thu, 2 Feb 2023 05:45:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04CC1C433D2; Thu, 2 Feb 2023 05:45:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316726; bh=gTyWdbMQBkC6bj2L7uRC+LIn00TYkfea/W2V8Ev9Cfw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SXBa8TdiOhzgbCB7WRvrT5ADcJIuaKB97mPE95Zc7EPVXvPq+wcLlbwa4s8opZRnP BRL8M7CLTUpwAKPtU3NuqTMjplzmn9RGqxVEb7RrGv7JsMT6DFngJgKVscCwITjxBi U2QbvmFVihP+Lh9okXkpQy4Zy675b+hLY85XKIuoBIsFHBrK/2rX0nAj+lbjTOWFHI TrGby2TffvqjR/RF6FDnMLvOmpPYXWn/Z/bgxoYeh5UnAhMOTXP+CAoqq3m0122cit 28Id6Z4mnSOzjct6pk3h2G2vKvR+nidq/zs6DuzuSzFJ+PLPW/NIOCXRW5CwQLlwGF /YCtWwuVD4TEQ== 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, Jonathan Corbet , Andrew Morton , Baolin Wang , "Jason A. Donenfeld" , Eric Biggers , Huang Ying , Arnd Bergmann , linux-doc@vger.kernel.org Subject: [PATCH 4.14 11/16] exit: Allow oops_limit to be disabled Date: Wed, 1 Feb 2023 21:44:01 -0800 Message-Id: <20230202054406.221721-12-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Kees Cook commit de92f65719cd672f4b48397540b9f9eff67eca40 upstream. In preparation for keeping oops_limit logic in sync with warn_limit, have oops_limit == 0 disable checking the Oops counter. Cc: Jann Horn Cc: Jonathan Corbet Cc: Andrew Morton Cc: Baolin Wang Cc: "Jason A. Donenfeld" Cc: Eric Biggers Cc: Huang Ying Cc: "Eric W. Biederman" Cc: Arnd Bergmann Cc: linux-doc@vger.kernel.org Signed-off-by: Kees Cook Signed-off-by: Eric Biggers --- Documentation/sysctl/kernel.txt | 5 +++-- kernel/exit.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt index 7b04c616c5901..b6124a4475fb7 100644 --- a/Documentation/sysctl/kernel.txt +++ b/Documentation/sysctl/kernel.txt @@ -519,8 +519,9 @@ scanned for a given scan. oops_limit: Number of kernel oopses after which the kernel should panic when -``panic_on_oops`` is not set. Setting this to 0 or 1 has the same effect -as setting ``panic_on_oops=1``. +``panic_on_oops`` is not set. Setting this to 0 disables checking +the count. Setting this to 1 has the same effect as setting +``panic_on_oops=1``. The default value is 10000. ============================================================== diff --git a/kernel/exit.c b/kernel/exit.c index 138b110bf83a1..73103e008a627 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -984,7 +984,7 @@ void __noreturn make_task_dead(int signr) * To make sure this can't happen, place an upper bound on how often the * kernel may oops without panic(). */ - if (atomic_inc_return(&oops_count) >= READ_ONCE(oops_limit)) + if (atomic_inc_return(&oops_count) >= READ_ONCE(oops_limit) && oops_limit) panic("Oopsed too often (kernel.oops_limit is %d)", oops_limit); do_exit(signr); From patchwork Thu Feb 2 05:44:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125353 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF042C05027 for ; Thu, 2 Feb 2023 05:45:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231814AbjBBFpv (ORCPT ); Thu, 2 Feb 2023 00:45:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231224AbjBBFpf (ORCPT ); Thu, 2 Feb 2023 00:45:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0BE13FF05; Wed, 1 Feb 2023 21:45:28 -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 470B061783; Thu, 2 Feb 2023 05:45:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A535AC433A0; Thu, 2 Feb 2023 05:45:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316727; bh=nycxOJDoQHR+udRNP1byUzzeXV+porSobyOm4mVZRs8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I2OnUMEdnaOUS/ra4zbq5GGVbVRb+XyCB1fJ7hk4rhzLwEHpAvcoAti960Bk6hpyh dAWXH/y2pj8LmIk6XBYfaGbKV1a2pHezCZ9970VlqPeNCUSLsRrfxBOe9khPcACSht ZgNXdXPLbN4W4uA5z1j202B7N+pnXSKDOkUDS6La9De9xN0HcEWazKEIq2+6Im6Nhm O12AlE98IL/raRJfl7l7AUBcKMfF5L5tc8oeQnQsCQX36Ae4aQyiJTl3Qe5A0pjKkc 84zpehdc1TQ/pKfDd0W+8rocxF7TLliQZMcQT32yJ6jtm+9f2ZUC7fpjMLEYrdwuBU XRfQS54t69TfA== 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.14 12/16] panic: Consolidate open-coded panic_on_warn checks Date: Wed, 1 Feb 2023 21:44:02 -0800 Message-Id: <20230202054406.221721-13-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org 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 22b9146655958..a4ac278d02d0a 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -293,6 +293,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 bd7c3ea3bf1e6..8e3460e985904 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -122,6 +122,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 @@ -546,8 +552,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 544a1cb66d90d..5dc66377864a9 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3185,8 +3185,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 5b421f8433488..4dc577d7e7494 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -172,8 +172,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(); } From patchwork Thu Feb 2 05:44:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125355 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FEC9C64EC4 for ; Thu, 2 Feb 2023 05:45:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231357AbjBBFpz (ORCPT ); Thu, 2 Feb 2023 00:45:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231359AbjBBFpg (ORCPT ); Thu, 2 Feb 2023 00:45:36 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A19B3A5BD; Wed, 1 Feb 2023 21:45:29 -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 123DF61780; Thu, 2 Feb 2023 05:45:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D80D1C433A4; Thu, 2 Feb 2023 05:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316728; bh=yLIP0xVEX1f7nCjSlc4iuL265LW+GAg4/ELnRAuM/P4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R/EbGpGvGclwb39Ju4FEQvnV+EtfYYWAhW6qRlr1m7pWlAI8g6bjYAqjQXM5NaO27 V1uT90cutSrnWa8Qjeh7f+L1vUz5TB+ishcQc3iI68yBVd6CDESHwc1MVUW80ZxFph 9x9Q4xmzQlKPLkfUB1ajHVIuDUN5biViAaRYVr8tq1aAZX5IT/TelIjdm8D+uROjt6 Fyidwt8XjmM8fVyi/SQj3ix9+ggBGYaCCrBvJKDzI3HDSQu8pHjevmY/aF1mlK7Acg nQSMPpOOb2hhlBFKvKwp02ob57Ox6wwMUKUY9c9JiufUcfWfCOENqwqHMvg5eH13/S bBpHLQoQ+NcOQ== 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, Jonathan Corbet , Andrew Morton , Baolin Wang , "Jason A. Donenfeld" , Eric Biggers , Huang Ying , Petr Mladek , tangmeng , "Guilherme G. Piccoli" , Tiezhu Yang , Sebastian Andrzej Siewior , linux-doc@vger.kernel.org, Luis Chamberlain Subject: [PATCH 4.14 13/16] panic: Introduce warn_limit Date: Wed, 1 Feb 2023 21:44:03 -0800 Message-Id: <20230202054406.221721-14-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Kees Cook commit 9fc9e278a5c0b708eeffaf47d6eb0c82aa74ed78 upstream. Like oops_limit, add warn_limit for limiting the number of warnings when panic_on_warn is not set. Cc: Jonathan Corbet Cc: Andrew Morton Cc: Baolin Wang Cc: "Jason A. Donenfeld" Cc: Eric Biggers Cc: Huang Ying Cc: Petr Mladek Cc: tangmeng Cc: "Guilherme G. Piccoli" Cc: Tiezhu Yang Cc: Sebastian Andrzej Siewior Cc: linux-doc@vger.kernel.org Reviewed-by: Luis Chamberlain Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20221117234328.594699-5-keescook@chromium.org Signed-off-by: Eric Biggers --- Documentation/sysctl/kernel.txt | 10 ++++++++++ kernel/panic.c | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt index b6124a4475fb7..fefffc8e6ac5c 100644 --- a/Documentation/sysctl/kernel.txt +++ b/Documentation/sysctl/kernel.txt @@ -94,6 +94,7 @@ show up in /proc/sys/kernel: - threads-max - unprivileged_bpf_disabled - unknown_nmi_panic +- warn_limit - watchdog - watchdog_thresh - version @@ -1072,6 +1073,15 @@ example. If a system hangs up, try pressing the NMI switch. ============================================================== +warn_limit: + +Number of kernel warnings after which the kernel should panic when +``panic_on_warn`` is not set. Setting this to 0 disables checking +the warning count. Setting this to 1 has the same effect as setting +``panic_on_warn=1``. The default value is 0. + +============================================================== + watchdog: This parameter can be used to disable or enable the soft lockup detector diff --git a/kernel/panic.c b/kernel/panic.c index 8e3460e985904..bfe6e4c5cd0e7 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -39,6 +39,7 @@ static int pause_on_oops_flag; static DEFINE_SPINLOCK(pause_on_oops_lock); bool crash_kexec_post_notifiers; int panic_on_warn __read_mostly; +static unsigned int warn_limit __read_mostly; int panic_timeout = CONFIG_PANIC_TIMEOUT; EXPORT_SYMBOL_GPL(panic_timeout); @@ -47,6 +48,26 @@ ATOMIC_NOTIFIER_HEAD(panic_notifier_list); EXPORT_SYMBOL(panic_notifier_list); +#ifdef CONFIG_SYSCTL +static struct ctl_table kern_panic_table[] = { + { + .procname = "warn_limit", + .data = &warn_limit, + .maxlen = sizeof(warn_limit), + .mode = 0644, + .proc_handler = proc_douintvec, + }, + { } +}; + +static __init int kernel_panic_sysctls_init(void) +{ + register_sysctl_init("kernel", kern_panic_table); + return 0; +} +late_initcall(kernel_panic_sysctls_init); +#endif + static long no_blink(int state) { return 0; @@ -124,8 +145,14 @@ EXPORT_SYMBOL(nmi_panic); void check_panic_on_warn(const char *origin) { + static atomic_t warn_count = ATOMIC_INIT(0); + if (panic_on_warn) panic("%s: panic_on_warn set ...\n", origin); + + if (atomic_inc_return(&warn_count) >= READ_ONCE(warn_limit) && warn_limit) + panic("%s: system warned too often (kernel.warn_limit is %d)", + origin, warn_limit); } /** From patchwork Thu Feb 2 05:44:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125356 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20334C64EC6 for ; Thu, 2 Feb 2023 05:45:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231971AbjBBFp5 (ORCPT ); Thu, 2 Feb 2023 00:45:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231362AbjBBFpg (ORCPT ); Thu, 2 Feb 2023 00:45:36 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB49367C8; Wed, 1 Feb 2023 21:45:30 -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 AA2386150C; Thu, 2 Feb 2023 05:45:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3EFFC4339C; Thu, 2 Feb 2023 05:45:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316729; bh=F6gV3Nc4RzN8pDwwOc0MdHuzOpEsbmsKn97m0ZuPXgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jSpq7SOBfpRoXmIqShON34N25+npPt4unzDb1I0Y0ttt/9ZnlLk9j2TmLOS7MX1zl lSM3LcfJYu8GWF0Aq2jUnghkeK7LgRSH26bvWOUvYIzd8Wh/5IfRfHNr+Jt04S7QPb N+waywK2l0WWl/mE/Hwcc7+3vGTfoLgbEFLHaeyK4SJqy0HO2bhq2C9VAGiVDT5kzf Vt3WFLWxQ0YDDlKEo6qNKr9sjgDIj5mBXRA0XNA3lnpOVOB50lUWzb9qybWvYtullC 0kzi5iJEmSpXGo9TsRRHhjLjhQGY9t3MgXVarD36UesS8KVC/8M2h+6dbWKpF4yc6j F332BZBH7N2fQ== 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, Petr Mladek , Andrew Morton , tangmeng , "Guilherme G. Piccoli" , Sebastian Andrzej Siewior , Tiezhu Yang , Luis Chamberlain Subject: [PATCH 4.14 14/16] panic: Expose "warn_count" to sysfs Date: Wed, 1 Feb 2023 21:44:04 -0800 Message-Id: <20230202054406.221721-15-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Kees Cook commit 8b05aa26336113c4cea25f1c333ee8cd4fc212a6 upstream. Since Warn count is now tracked and is a fairly interesting signal, add the entry /sys/kernel/warn_count to expose it to userspace. Cc: Petr Mladek Cc: Andrew Morton Cc: tangmeng Cc: "Guilherme G. Piccoli" Cc: Sebastian Andrzej Siewior Cc: Tiezhu Yang Reviewed-by: Luis Chamberlain Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20221117234328.594699-6-keescook@chromium.org Signed-off-by: Eric Biggers --- .../ABI/testing/sysfs-kernel-warn_count | 6 +++++ kernel/panic.c | 22 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-kernel-warn_count diff --git a/Documentation/ABI/testing/sysfs-kernel-warn_count b/Documentation/ABI/testing/sysfs-kernel-warn_count new file mode 100644 index 0000000000000..08f083d2fd51b --- /dev/null +++ b/Documentation/ABI/testing/sysfs-kernel-warn_count @@ -0,0 +1,6 @@ +What: /sys/kernel/oops_count +Date: November 2022 +KernelVersion: 6.2.0 +Contact: Linux Kernel Hardening List +Description: + Shows how many times the system has Warned since last boot. diff --git a/kernel/panic.c b/kernel/panic.c index bfe6e4c5cd0e7..8f7bf0a8cef1a 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -28,6 +28,7 @@ #include #include #include +#include #define PANIC_TIMER_STEP 100 #define PANIC_BLINK_SPD 18 @@ -68,6 +69,25 @@ static __init int kernel_panic_sysctls_init(void) late_initcall(kernel_panic_sysctls_init); #endif +static atomic_t warn_count = ATOMIC_INIT(0); + +#ifdef CONFIG_SYSFS +static ssize_t warn_count_show(struct kobject *kobj, struct kobj_attribute *attr, + char *page) +{ + return sysfs_emit(page, "%d\n", atomic_read(&warn_count)); +} + +static struct kobj_attribute warn_count_attr = __ATTR_RO(warn_count); + +static __init int kernel_panic_sysfs_init(void) +{ + sysfs_add_file_to_group(kernel_kobj, &warn_count_attr.attr, NULL); + return 0; +} +late_initcall(kernel_panic_sysfs_init); +#endif + static long no_blink(int state) { return 0; @@ -145,8 +165,6 @@ EXPORT_SYMBOL(nmi_panic); void check_panic_on_warn(const char *origin) { - static atomic_t warn_count = ATOMIC_INIT(0); - if (panic_on_warn) panic("%s: panic_on_warn set ...\n", origin); From patchwork Thu Feb 2 05:44:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125358 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EB6BC636D7 for ; Thu, 2 Feb 2023 05:46:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232005AbjBBFp7 (ORCPT ); Thu, 2 Feb 2023 00:45:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231382AbjBBFpg (ORCPT ); Thu, 2 Feb 2023 00:45:36 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A00C3FF35; Wed, 1 Feb 2023 21:45:30 -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 25CA2617D1; Thu, 2 Feb 2023 05:45:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47770C433A0; Thu, 2 Feb 2023 05:45:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316729; bh=jO10o07RAKyXXgWsy3XBxX0WTtST48LzT0RY2uOU2ZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BsoLp0vdb9wjgciaHX6Y6KE2Uj+lkFgMIid8x129U7wL3DM2HJSH6l0cHqIsXf3vn Ysq2h+bCUb0qBbA373Yf/iW2G60crG7hZHmbj3mtzjqAcEXd9MaInbhrMdFKqK1njB gGoLkO71Hl1GL5MYzAr9B8zuMdX7AxY7f3ttFi1eURTdh1XXAoTjwKEwgxWvcGRssX eGHsVg3cqoQSiuFDa1IktPRUNpAx1Ng6eFpTDtjIqEmy/BRTjjtOXmv9DJ8UAT3Rgt TZ81AK/ieHgr4yPT2SDo+j2nSoeNFQcAX1O/q9r3rfqOdNS8hcFHjha9ooRTD6Q1rC s75E6Jn6/kksw== 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, kernel test robot Subject: [PATCH 4.14 15/16] docs: Fix path paste-o for /sys/kernel/warn_count Date: Wed, 1 Feb 2023 21:44:05 -0800 Message-Id: <20230202054406.221721-16-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Kees Cook commit 00dd027f721e0458418f7750d8a5a664ed3e5994 upstream. Running "make htmldocs" shows that "/sys/kernel/oops_count" was duplicated. This should have been "warn_count": Warning: /sys/kernel/oops_count is defined 2 times: ./Documentation/ABI/testing/sysfs-kernel-warn_count:0 ./Documentation/ABI/testing/sysfs-kernel-oops_count:0 Fix the typo. Reported-by: kernel test robot Link: https://lore.kernel.org/linux-doc/202212110529.A3Qav8aR-lkp@intel.com Fixes: 8b05aa263361 ("panic: Expose "warn_count" to sysfs") Cc: linux-hardening@vger.kernel.org Signed-off-by: Kees Cook Signed-off-by: Eric Biggers --- Documentation/ABI/testing/sysfs-kernel-warn_count | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-kernel-warn_count b/Documentation/ABI/testing/sysfs-kernel-warn_count index 08f083d2fd51b..90a029813717d 100644 --- a/Documentation/ABI/testing/sysfs-kernel-warn_count +++ b/Documentation/ABI/testing/sysfs-kernel-warn_count @@ -1,4 +1,4 @@ -What: /sys/kernel/oops_count +What: /sys/kernel/warn_count Date: November 2022 KernelVersion: 6.2.0 Contact: Linux Kernel Hardening List From patchwork Thu Feb 2 05:44:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13125357 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ACCAC64EC7 for ; Thu, 2 Feb 2023 05:45:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231149AbjBBFp6 (ORCPT ); Thu, 2 Feb 2023 00:45:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231463AbjBBFpg (ORCPT ); Thu, 2 Feb 2023 00:45:36 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89A174DBEC; Wed, 1 Feb 2023 21:45:31 -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 CB67F61883; Thu, 2 Feb 2023 05:45:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7C01C4339E; Thu, 2 Feb 2023 05:45:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675316730; bh=PezzPrlLFd7Q51QZ1OXqNb3IL9FpXtGge3PpuUfRJNk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CoTtGhvsMHnMkgjeHZ+eFrE4S4bMahykAc9CQ03gcOQHNllnQhu9wWjiN+Y7aIjag gV3ut6lO9JgnQA2iY+0twwpoW+hQQJhZSGGNGhUjykgPyKfVic2X3HIEC/D1WOp6kS x3ajWJDjZgl3tPYlQ5LT8oiyg2bhFc/Mj4ZK9Pg/NjXZRWtOXulVeRdf8WygjoN6Ec vt98OkN9Fj88m2x7n+lOHh+Ymd68/b9IGzvrukYEc3nGqHeb3XJqMvS45M97PKe/pM JvHGSBQ9+ysPLiFrmvudjYD5uGX+lNxGbvHtlaaWzyV5MHuVpAf9VDZ5AEp0+aw4hv i+O196/ljCWlw== 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, Arnd Bergmann , Petr Mladek , Andrew Morton , Luis Chamberlain , Marco Elver , tangmeng , Sebastian Andrzej Siewior , Tiezhu Yang , Peter Zijlstra Subject: [PATCH 4.14 16/16] exit: Use READ_ONCE() for all oops/warn limit reads Date: Wed, 1 Feb 2023 21:44:06 -0800 Message-Id: <20230202054406.221721-17-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202054406.221721-1-ebiggers@kernel.org> References: <20230202054406.221721-1-ebiggers@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Kees Cook commit 7535b832c6399b5ebfc5b53af5c51dd915ee2538 upstream. Use a temporary variable to take full advantage of READ_ONCE() behavior. Without this, the report (and even the test) might be out of sync with the initial test. Reported-by: Peter Zijlstra Link: https://lore.kernel.org/lkml/Y5x7GXeluFmZ8E0E@hirez.programming.kicks-ass.net Fixes: 9fc9e278a5c0 ("panic: Introduce warn_limit") Fixes: d4ccd54d28d3 ("exit: Put an upper limit on how often we can oops") Cc: "Eric W. Biederman" Cc: Jann Horn Cc: Arnd Bergmann Cc: Petr Mladek Cc: Andrew Morton Cc: Luis Chamberlain Cc: Marco Elver Cc: tangmeng Cc: Sebastian Andrzej Siewior Cc: Tiezhu Yang Signed-off-by: Kees Cook Signed-off-by: Eric Biggers --- kernel/exit.c | 6 ++++-- kernel/panic.c | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index 73103e008a627..c0ff4461643d0 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -973,6 +973,7 @@ void __noreturn make_task_dead(int signr) * Take the task off the cpu after something catastrophic has * happened. */ + unsigned int limit; /* * Every time the system oopses, if the oops happens while a reference @@ -984,8 +985,9 @@ void __noreturn make_task_dead(int signr) * To make sure this can't happen, place an upper bound on how often the * kernel may oops without panic(). */ - if (atomic_inc_return(&oops_count) >= READ_ONCE(oops_limit) && oops_limit) - panic("Oopsed too often (kernel.oops_limit is %d)", oops_limit); + limit = READ_ONCE(oops_limit); + if (atomic_inc_return(&oops_count) >= limit && limit) + panic("Oopsed too often (kernel.oops_limit is %d)", limit); do_exit(signr); } diff --git a/kernel/panic.c b/kernel/panic.c index 8f7bf0a8cef1a..165fd747cebd0 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -165,12 +165,15 @@ EXPORT_SYMBOL(nmi_panic); void check_panic_on_warn(const char *origin) { + unsigned int limit; + if (panic_on_warn) panic("%s: panic_on_warn set ...\n", origin); - if (atomic_inc_return(&warn_count) >= READ_ONCE(warn_limit) && warn_limit) + limit = READ_ONCE(warn_limit); + if (atomic_inc_return(&warn_count) >= limit && limit) panic("%s: system warned too often (kernel.warn_limit is %d)", - origin, warn_limit); + origin, limit); } /**