From patchwork Thu Feb 2 05:25:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 51696 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52512wrn; Wed, 1 Feb 2023 21:29:44 -0800 (PST) X-Google-Smtp-Source: AK7set8incKzrPcvVVUlpVv5S3R8uNdhgziobPPeK3lyhW+DafWjkr5Nk9aDvoZkaZsYoFFhTcP2 X-Received: by 2002:a17:903:2451:b0:196:4643:e1eb with SMTP id l17-20020a170903245100b001964643e1ebmr7190471pls.36.1675315784454; Wed, 01 Feb 2023 21:29:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315784; cv=none; d=google.com; s=arc-20160816; b=em3FADxFSLEc8DL4XgOT8tGryvwtR8ztKYFhAyQWONdnv6IlIiQvbIWAT5+H7rsTqN sdl8xex0jaiGlKWxAV2E1zmr6fxzB+cezK+OiYu8KP3oDfh0QjtRBwoDE0Ivoqx6c1oJ pMmCkFJUvpA15NaC8jUra8FAHAP+rZvRy6v03Gni1WY5XAcs+3XcZNL6xO/Eq45pcUF6 XxLGKF4sQp0eiBC8BUZUrRFLbKE+nEYCMub/+WMgopLtUxlV8LuYDtlWVlJcik4TklZy Bf0rA8lwRQXlMq9r9g7dQ4uOYHd8hVxbtVnYxJeedeRL1UBs0KwKDRQADOrOlYAKYqP1 IqHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=X71Vi0NCg+SNaLUsYQNo4IUi2WX8Xjhl2p463m0zgQw=; b=whorNEHEzGsFB0FO7esQzoSCkylY0qLMmo0AJeEGPEomZU1DRjAHJKfaTrbc454mGb FZFKE2Ww5vu+/rmVe4g1tF4ci8msq0Tv4d+j20CNs/jj9U+PqqBnzVLypr1QnTBv/Lgv L+7RTiItZMb9Hazlhp0F8bb14DzH7nqB76o5fza5DWib55GxNh83ng85jGbMjiHCBwIk j+YBAhmWJ4+utU4WHu+PkRQD5JhbVt/8AGWGubT1J7USciy/GPWQIjDJ8Wwb/VjLOR+Y Yj68aFqjN2Q3nzIZfIf/s8VB47OtxVmLFCas/43xnvwk6+y1ijZ4mCqheGvMP/NzDikS owiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MmjsxqV4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x7-20020a1709029a4700b001963f6a1b41si20408867plv.37.2023.02.01.21.29.28; Wed, 01 Feb 2023 21:29:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MmjsxqV4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231932AbjBBF2V (ORCPT + 99 others); Thu, 2 Feb 2023 00:28:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231744AbjBBF2H (ORCPT ); Thu, 2 Feb 2023 00:28:07 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1422CA1D; Wed, 1 Feb 2023 21:28:04 -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 2C776B824B2; Thu, 2 Feb 2023 05:28:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5974BC4339C; Thu, 2 Feb 2023 05:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315681; bh=OH/dOk5Gf673apnyAgJwouhC08eKKKT868bTFMniw+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MmjsxqV49tF6T7r6g7BkUkiH53k2SQHPlCXeeI2UVR+GH2l6V4KLwoF8jsthhwFgT DUVWHHVEC57/XF9Li9b3AQjpoVXFlyFlkgHkgko2OhILyfkdZl8kGQonJaqFZn2FJT Prx3QAfJ2JmpLjjMwYId6FEs0w5nf3PnaeaeT+tU6piNQB609NZAktCE9QGRbWhoC1 ktfRd0dCCT6rAArHr6SklVeZ/UDrV265Vto7aOGBwyCVqbFxNiAurUWx2Dz2SgfvWm tL0Yxsnp/aCMEUK8sHqBCz4/JQe451w6RjOasDVNT4GaBVa/WakyMFr+MwzeDd2gHD g3qUPBCW/OeZw== 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.19 01/16] sysctl: add a new register_sysctl_init() interface Date: Wed, 1 Feb 2023 21:25:49 -0800 Message-Id: <20230202052604.179184-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695924235362430?= X-GMAIL-MSGID: =?utf-8?q?1756695924235362430?= 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 c95f32b83a942..7c62a526506c1 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; @@ -1376,6 +1377,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:25:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 51694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52412wrn; Wed, 1 Feb 2023 21:29:27 -0800 (PST) X-Google-Smtp-Source: AK7set8j2rS6xgXQYJG52KmWX2QOKHRLGgKQI3BcoQYu7De6N2XGGISMshjF3ICvS3yw5gMeVLMd X-Received: by 2002:a05:6a20:8f06:b0:bc:ee95:dd3 with SMTP id b6-20020a056a208f0600b000bcee950dd3mr7164646pzk.54.1675315766884; Wed, 01 Feb 2023 21:29:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315766; cv=none; d=google.com; s=arc-20160816; b=xXounzxs6PDkiZY/C+7BpZHZHdRi5TVdMt3c4l1q1FjEoZZJziO26wPlsQZJ4MN2ka 3FxNBNbbNdHQPF66lwpNcDeqbfOMfsR2i0nTrfZ4FRIW6Lk3dQiS204ztCvyay77ekF0 0NNDuR2PEoT3HlWmT4m6pX+yR52bhpErVr7urS/NUbRa+Gfz5Q/28b6QU8YqwQDyDLav xs6sLLXwfEQqiinxEbkiyteYrSMUmCwRrT1nvbKtfJM65ydfW+sj2oz0ogiPWRTGeQC5 CV7ihdsZ90GWZMkEahc6cc2OZ4rxzqc9xYvORM6HXaZDFuWgQIHlk1yGZrjK+64P692x 1ThQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yGQysUV7bOtQpgi4S2oLylfvfEvDs0+YgiIDfzQ64lM=; b=RnaiI6su4g+xOK6OgSE+vOrXzdggz8mSNC/0uUFDKFzfaTVGg6Px1gR9IiyuDArskV mKtGSw64wT1IFOGiDFfdZXeTwgqVC4PEG2cD40xStbD+T3GoaH0/4euXi4X0KEPeMtPP jIQizv1j2XCPlGGAXXDvCRzGx96ygGQXo4tesuKmglJbupNY2t6JL9jfwgye0NWB0P+E xDINZ/yQQmkTmLGUrSFcvWvV6606BV9deu4tT4Z2z04H23Ol5cTcssdAuawAGQNzoVli JehDhsnU5m9R88FyY5axq0K/MOaw+IYcbdCPfthnWLhgVUyjLnFFs5tkakIAfw5IZ+t8 bwYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=plCbt4G0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u64-20020a638543000000b004cf574a78e1si20318940pgd.358.2023.02.01.21.29.11; Wed, 01 Feb 2023 21:29:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=plCbt4G0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231896AbjBBF2R (ORCPT + 99 others); Thu, 2 Feb 2023 00:28:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjBBF2H (ORCPT ); Thu, 2 Feb 2023 00:28:07 -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 0F8CA1205A; Wed, 1 Feb 2023 21:28:05 -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 BBBD9B8247A; Thu, 2 Feb 2023 05:28:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE574C433A1; Thu, 2 Feb 2023 05:28:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315682; bh=DMz/MOCU306dak0OU7QypACmgBeBp7Zx+Xdx74bnwbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=plCbt4G0Ne1pvGa4coC/MeYJNMQOhsrWt60/rLLkXn4vSldpWk6Zjwsd3VhS8IjMy aKnKZNrJG2XnqyrucHG4fb7wIyIbKT/R7qmDdgILcsBreT3jl0Mj195qbfQ4TTGtqm GMXTC1Rz87bdA4bXo7ozclpJ1Nx+ViuUmexLQwwACh6mg9DuMUqoR0b5gGOyHCnOZ3 dK9KZsnhop+Bsqn5Tqh8yvXUcVsCPmjaaw5NIpvTzAJW9benVue/fcnOiGOMLLrIgI iV+tk66k7Jfr2UgLW/z5ocS5Q5wC6+NOeJqO2XGIMWuWL2/dgtodxsW2BirAWW0ksC LhRJT8u5iHuJQ== 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.19 02/16] panic: unset panic_on_warn inside panic() Date: Wed, 1 Feb 2023 21:25:50 -0800 Message-Id: <20230202052604.179184-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695905955686940?= X-GMAIL-MSGID: =?utf-8?q?1756695905955686940?= 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 8138a676fb7d1..a078d413042f2 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -142,6 +142,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 @@ -530,16 +540,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:25: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: 51699 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52642wrn; Wed, 1 Feb 2023 21:30:05 -0800 (PST) X-Google-Smtp-Source: AK7set/HaQyWj240MJXJCKS3BswuJHLOVfg6q9p3oJo8KEd0BMb0kZuTEeQanGFoIHaMLgpyQydv X-Received: by 2002:a17:903:18b:b0:198:b3df:c753 with SMTP id z11-20020a170903018b00b00198b3dfc753mr4913263plg.45.1675315805333; Wed, 01 Feb 2023 21:30:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315805; cv=none; d=google.com; s=arc-20160816; b=Fv8eKHz7TB20RgJ3j/cPAFPqvL6fCZlHkC/DKi1AGOmLZgQmzjkDq9Hplv0NUxnhQN kR7cLtNhgmyiHX8LPke6BcAHeHSdvlKdoSMlFkRQ6YgFljWmjWaQl8AtoCWktIQzFvg4 2FUWBYXquC9T458eg1pkZcl9DrwbuYdwY61S428BTMYS7UB7ibx/48+TAI921o1JxBej l0CksjrFsP7s+ODRCv+6JQNqDv51gXOxpklR3jaePoiGYEqSm44kclnLMWi541zQ/5+Y V4Xw95eOaG50ZUWtJ7KUXFP1hTHUXMtPvfczByKaPiVHRAmkrKeeyXVQQDb+l46djv/t 4JWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FDvFLkFM7eKqAsAAnTAZPELfzYmV6p/rezuo0e2X/oU=; b=JFBdeWjPegAWHQ5ktFXL+7/OqxMYAjpL4KALNCa7DIo8z4XQxDjtTDV1VnjwsYmWQu zHol1hB0q7kEfnAICa94xUpKQ5/fpmHgD9zA0nwT7er2SX4FgQ0p9c8Xy0BHqz7zuXD/ oy3tdJkjuU1sfTOZjqUh2UMXaZ1ZmGvM9H2jWHhSJR8iz7ch0Hvnzo0NsWvgyXyrkWxn bxAivuOqQArdbM/wY+4vJhug+wrG3iAdp9SIjeXWd/Gu+M8xVleUMO7orOy0kUSeY4NO jEZLAuMYU655stj/DBjV2d6SMhdg1MgEvfe0nmSmwmkfFsANDeDl8ZD4R8alyKq5CUSR BOLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MJTRJ6Iy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q17-20020a17090311d100b0019484efdff8si24888685plh.483.2023.02.01.21.29.42; Wed, 01 Feb 2023 21:30:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MJTRJ6Iy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231996AbjBBF2b (ORCPT + 99 others); Thu, 2 Feb 2023 00:28:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230046AbjBBF2L (ORCPT ); Thu, 2 Feb 2023 00:28:11 -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 BBDD014E9A; Wed, 1 Feb 2023 21:28:06 -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 A8052B824B4; Thu, 2 Feb 2023 05:28:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 992F2C433EF; Thu, 2 Feb 2023 05:28:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315683; bh=fdhiGzoneKEwa2llZBhl60Z7qg58b1f/mZA06RgXQb4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MJTRJ6Iye1+rASmz7WEQpD9Mtnb9tTfYNgHKg8HEzp85eWtQTP4cwjB29dmwfQaV2 EsIviZvfTDdjlURyza8Z1vM0U4CC/mpLNgEEbvm+7rbC2Ez5S+lcFEThq5zB9g4sdJ cGWwt91hoSoAfcidcrhBVkUoUwXagtICA/3dz7Hnofc6AOOr9Qs05YV/7K32Ih74NY vZT7qfigTHP6IZ6TJEtK3+2oih2Ue0UX6aHcqdXDladFy0ytL2hbZMyfY4gpTTc6pQ VsCmuLeouWF8b4spML9Q/N4m97jqXFypQNOe1ic2xgdG5Hq36Gp84ic7NcbeuSuV+E EJ7Meiv7JRqZw== 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.19 03/16] mm: kasan: do not panic if both panic_on_warn and kasan_multishot set Date: Wed, 1 Feb 2023 21:25:51 -0800 Message-Id: <20230202052604.179184-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695946269732963?= X-GMAIL-MSGID: =?utf-8?q?1756695946269732963?= 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 5c169aa688fde..90fdb261a5e2d 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -176,7 +176,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:25: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: 51698 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52570wrn; Wed, 1 Feb 2023 21:29:54 -0800 (PST) X-Google-Smtp-Source: AK7set/GpiEdawZpLEmAAuxmjNwYoJY1lv4LjsGT5mnRxuRPROqeRhiFbdescG6yjsRtHahTwgPQ X-Received: by 2002:a17:90b:380a:b0:22c:18a:60b0 with SMTP id mq10-20020a17090b380a00b0022c018a60b0mr5243986pjb.26.1675315793706; Wed, 01 Feb 2023 21:29:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315793; cv=none; d=google.com; s=arc-20160816; b=YCP0XEKxkMLTypqqCvkEFI/Db2/feIaZw9IBXT5iN0DJHenKN4oIMX3SCZjdHDQr8V RZOLQRfU8sj8sfPwQKgqNZZOrD1/k79IrEh4kfGir3l7or/NnU6sPPdz0lKyftueJdnA pVE+2hQnltfxrtQJoplZrD02g1XW1ZEiM/EfEPne5LpeK6U5TFNxqmead8EcHlxUypdp 5jFlEkxG605eVWBXxET2GdgXoV3MDqp128AQkmc1Nd3R9tb1MeKboaIW2wnUAAWAiuge KlxNC/XA05GAlWDrnytJEib6dTUrpB+dF4Ue19kXEdpxQYWI9pTZ3kU7JES/+/1CXunf ++Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zEUkLNQvHx3mQgxaqigzWMuDjLMfUoG18QpSK4zLLP8=; b=r8xp80QXa3gUYrt7iwj1nAjn+IjT5eOKDBE74tYxlKjTqNY3FR/72WL2O1GhVzREOz 4F9Gr6yReBBy3BQxfoXU8fv3gZhZx08mguupLWQDFmHACdT3LBeZyFY+NCR1K8C+qUHH 5aGE554/s1MAujgE3/cPVRApnu3OABPhUK4YQvlj/Cau9DJnQl4ftCyWZ+SB4o6qn89Q HZBBMK7lppk7W/PfHsgudeF36QYBwPBNbEDmeAyvrDjFs/CWYJg/XqRSp09XtrgGmD4F 56SsXIC6BFUDrgmPupNRPLGgN0Ih7IvBO8A1VqvrhZXtxbsCZWtr2j2tOFSm3sIDZWJZ sWIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jkDv4l9S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u184-20020a6379c1000000b004d21c99e5c7si21608777pgc.28.2023.02.01.21.29.37; Wed, 01 Feb 2023 21:29:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jkDv4l9S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232007AbjBBF2e (ORCPT + 99 others); Thu, 2 Feb 2023 00:28:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231862AbjBBF2N (ORCPT ); Thu, 2 Feb 2023 00:28:13 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBFAF1557C; Wed, 1 Feb 2023 21:28:06 -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 07378B824B7; Thu, 2 Feb 2023 05:28:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6759AC4339B; Thu, 2 Feb 2023 05:28:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315683; bh=N56y6SWdsfeHL5R4n3qzUNZ62oUZLKsmqIM8Hb632Tk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jkDv4l9S/21h8ShBPp+UKeXwY2P8iB5XnB/8ViY/NeD0bWtz54Pm1OwLVWSJmQtld wK6GekTw1/Z7s0GAM5ZO0n4vMLNOuYGEWlxllAyyqQB2uG4P4uw54bODbTqwhBWHC4 hKTkOrWQ9iN23nJMxa732nY5yh2x4ft9xGBt/rEQ19T+NrY0180LyTBYobrt8msQEb Lye9PgpdK6UercZFKVE1PVrezyuVFoqDNUIweK0t81xM+iRfEatxAfg21X0p8u0Z8R kbEWt0nbrFFYWS7sfqCku9tyN5EQG3tJCA/s20ZeSlIWPvd5ToX6TsBaOsdKl4qQ4O tZFUqMUI5/CTQ== 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.19 04/16] exit: Add and use make_task_dead. Date: Wed, 1 Feb 2023 21:25:52 -0800 Message-Id: <20230202052604.179184-5-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695933599022397?= X-GMAIL-MSGID: =?utf-8?q?1756695933599022397?= 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/nds32/kernel/traps.c | 8 ++++---- 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/riscv/kernel/traps.c | 2 +- arch/riscv/mm/fault.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 ++- 35 files changed, 56 insertions(+), 49 deletions(-) diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c index bc9627698796e..22f5c27b96b7c 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 @@ -577,7 +577,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 @@ -632,7 +632,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 188fc9256baf1..6ce67b05412ec 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 d49fafd2b865f..02a4aea52fb05 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -344,7 +344,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 a9ee0d9dc740a..8457384139cb8 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -149,7 +149,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 965595fe68045..20f896b27a447 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -224,7 +224,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); } static bool show_unhandled_signals_ratelimited(void) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index b046006a387ff..0d2be8eb87ec8 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -268,7 +268,7 @@ static void die_kernel_fault(const char *msg, unsigned long addr, show_pte(addr); die("Oops", regs, esr); bust_spinlocks(0); - do_exit(SIGKILL); + make_task_dead(SIGKILL); } static void __do_kernel_fault(unsigned long addr, unsigned int esr, 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 91ee04842c22c..ac8154992f3eb 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 06419a95af309..05885ad68cccd 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 c6f4932073a18..32c2877b3c0ad 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 a9d55ad8d67be..0b072af7e20d8 100644 --- a/arch/ia64/mm/fault.c +++ b/arch/ia64/mm/fault.c @@ -302,7 +302,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 b2fd000b92857..9b70a7f5e7058 100644 --- a/arch/m68k/kernel/traps.c +++ b/arch/m68k/kernel/traps.c @@ -1139,7 +1139,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 9b6163c05a754..fc3aea6dcaa77 100644 --- a/arch/m68k/mm/fault.c +++ b/arch/m68k/mm/fault.c @@ -48,7 +48,7 @@ int send_fault_sig(struct pt_regs *regs) pr_alert("Unable to handle kernel access"); pr_cont(" at virtual address %p\n", 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 eafff21fcb0e6..182402db6b043 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 0ca4185cc5e38..01c85d37c47ab 100644 --- a/arch/mips/kernel/traps.c +++ b/arch/mips/kernel/traps.c @@ -412,7 +412,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/nds32/kernel/traps.c b/arch/nds32/kernel/traps.c index 1496aab489988..a811f286bc85c 100644 --- a/arch/nds32/kernel/traps.c +++ b/arch/nds32/kernel/traps.c @@ -183,7 +183,7 @@ void die(const char *str, struct pt_regs *regs, int err) bust_spinlocks(0); spin_unlock_irq(&die_lock); - do_exit(SIGSEGV); + make_task_dead(SIGSEGV); } EXPORT_SYMBOL(die); @@ -286,7 +286,7 @@ void unhandled_interruption(struct pt_regs *regs) pr_emerg("unhandled_interruption\n"); show_regs(regs); if (!user_mode(regs)) - do_exit(SIGKILL); + make_task_dead(SIGKILL); force_sig(SIGKILL, current); } @@ -297,7 +297,7 @@ void unhandled_exceptions(unsigned long entry, unsigned long addr, addr, type); show_regs(regs); if (!user_mode(regs)) - do_exit(SIGKILL); + make_task_dead(SIGKILL); force_sig(SIGKILL, current); } @@ -324,7 +324,7 @@ void do_revinsn(struct pt_regs *regs) pr_emerg("Reserved Instruction\n"); show_regs(regs); if (!user_mode(regs)) - do_exit(SIGILL); + make_task_dead(SIGILL); force_sig(SIGILL, current); } diff --git a/arch/nios2/kernel/traps.c b/arch/nios2/kernel/traps.c index 3bc3cd22b750e..dc6c270a355b6 100644 --- a/arch/nios2/kernel/traps.c +++ b/arch/nios2/kernel/traps.c @@ -37,10 +37,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 d8981cbb852a5..dfa3db1bccef4 100644 --- a/arch/openrisc/kernel/traps.c +++ b/arch/openrisc/kernel/traps.c @@ -224,7 +224,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 d7a66d8525091..5d9cf726e4ecd 100644 --- a/arch/parisc/kernel/traps.c +++ b/arch/parisc/kernel/traps.c @@ -265,7 +265,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 2379c4bf3979e..63c751ce130a5 100644 --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -251,7 +251,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/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index 7c65750508f25..9b736e616131d 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -64,7 +64,7 @@ void die(struct pt_regs *regs, const char *str) if (panic_on_oops) panic("Fatal exception"); if (ret != NOTIFY_STOP) - do_exit(SIGSEGV); + make_task_dead(SIGSEGV); } void do_trap(struct pt_regs *regs, int signo, int code, diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c index 523dbfbac03dd..7b5f110f8191a 100644 --- a/arch/riscv/mm/fault.c +++ b/arch/riscv/mm/fault.c @@ -200,7 +200,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs) (addr < PAGE_SIZE) ? "NULL pointer dereference" : "paging request", addr); die(regs, "Oops"); - do_exit(SIGKILL); + make_task_dead(SIGKILL); /* * We ran out of memory, call the OOM killer, and return the userspace diff --git a/arch/s390/kernel/dumpstack.c b/arch/s390/kernel/dumpstack.c index 5b23c4f6e50cd..7b21019096f44 100644 --- a/arch/s390/kernel/dumpstack.c +++ b/arch/s390/kernel/dumpstack.c @@ -187,5 +187,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 8c867b43c8ebc..471a965ae75a4 100644 --- a/arch/s390/kernel/nmi.c +++ b/arch/s390/kernel/nmi.c @@ -179,7 +179,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 bcdfc6168dd58..ec7fcfbad06c0 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 86879c28910b7..1a338784a37c8 100644 --- a/arch/sparc/kernel/traps_64.c +++ b/arch/sparc/kernel/traps_64.c @@ -2565,9 +2565,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 78b308f2f2ea6..e6c258bf95116 100644 --- a/arch/x86/entry/entry_32.S +++ b/arch/x86/entry/entry_32.S @@ -1500,13 +1500,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 3f418aedef8d7..1ebb70694d721 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -1762,7 +1762,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 @@ -1771,5 +1771,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 2b5886401e5f4..2b17a5cec0997 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c @@ -326,7 +326,7 @@ unsigned long oops_begin(void) } 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) { @@ -361,7 +361,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 86507fa7c2d7c..2ae5c505894bd 100644 --- a/arch/xtensa/kernel/traps.c +++ b/arch/xtensa/kernel/traps.c @@ -542,5 +542,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 91401309b1aa2..0ee9aab3e3091 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 908e7a33e1fcb..2147bbc2c7c32 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -922,6 +922,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 c0ab27368a345..0477190557107 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", @@ -167,7 +168,7 @@ static int __dead_end_function(struct objtool_file *file, struct symbol *func, "fortify_panic", "usercopy_abort", "machine_real_restart", - "rewind_stack_do_exit", + "rewind_stack_and_make_dead" }; if (func->bind == STB_WEAK) From patchwork Thu Feb 2 05:25: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: 51692 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52383wrn; Wed, 1 Feb 2023 21:29:23 -0800 (PST) X-Google-Smtp-Source: AK7set+zqaKba8D4MPUYF3nlRwZrgoBOCEnz5NyXh4p+ddk9dXf6D8DlcAzcyFyJCeAk/KbJZKLb X-Received: by 2002:a05:6a20:6d1f:b0:be:a27a:d5ba with SMTP id fv31-20020a056a206d1f00b000bea27ad5bamr5265573pzb.0.1675315763034; Wed, 01 Feb 2023 21:29:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315763; cv=none; d=google.com; s=arc-20160816; b=j/qP+fNff3q5mvszCrzWUnuYWQOQVaC+t9tQEKNvF+/vSupQ2iR4prSkWT1XxfJOpZ trDyX+BVjpM9WPXXxue5DFdrnmqY0ZLDCPIxjEACD6Aoi5hcp51L23xA6oMsJWCzR1cV 1hwBBcXA2NZGqgxsDynvhytmISkm+zJkiZ+2X0uIW4G5967i/BrMnO8D4tRFDq/JAYTn MQwcCSRO1ccN8okckETa/GyeI8s+28esVDyc42Kj1lWnQWarFqRYLN17oBUp8j0oGxL2 PuVh2pB9ajErKuNegaHQcuPKLBNUcpuKM+gw+/qxINk9QYn5ItK7K/LAVHu5K/RJr+eh qyVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HlUVjx7MR2AUpsiMIzOTaaN47kyIq56+aONYYZRR9bA=; b=lEa+p1zK6DWFNIIQUD8yDjtZnss2wv2Inf1E5+bIrma95iOZUQ5S/2+vbTlIEL+CMS YZJHlgwFPai05sMrMbuwbW1rlsU28yQvdL7aRZ6SVyrzOQ6cgnIs3lG1r2Qkga77XZOp DLO+hM17mijHKSPNN6BGi57dlgjmlR6mWoe5uprA3iWRWl+owgpk+zyCdWOvIre/of7M IJtgxUL4OVafw6MbO/CveSXhdp0gvsR4RGkm49Z72mdj68eCQxswE+f+XxGFErv/DiJA rXXoQkoNo+cJSdhMn8s8MREFR+VrHwQv1gTo5nzvLXAjE4T8EKFC8BBa1WjVGjIBwgQt tT+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UQn4mn6A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q78-20020a632a51000000b00462a6f64703si22406597pgq.376.2023.02.01.21.29.08; Wed, 01 Feb 2023 21:29:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UQn4mn6A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229471AbjBBF2J (ORCPT + 99 others); Thu, 2 Feb 2023 00:28:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229881AbjBBF2G (ORCPT ); Thu, 2 Feb 2023 00:28:06 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 271E012853; Wed, 1 Feb 2023 21:28:05 -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 B6660615EB; Thu, 2 Feb 2023 05:28:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5DDAC4339E; Thu, 2 Feb 2023 05:28:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315684; bh=gMkaknhHOUOvbO7ZN04Mon7pIpUm85+6r8AS4b1iOcM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UQn4mn6AUuux27TwN86ZHCGRMsE4Avlp8emzHlKJfzi/PWA8QGO4QmcO4GJhVU6wq SyeOXX1m455EyEVmPKWBHZ1IngGrNKvmFxxXNiJpx9nTJM9O8AcQlJKQbsR2MDphUI OmPVAhSDbZeCuwAmi2iDHbyg/5EhL+a33IcvIalidpUxw7f3AbNfVH4yHZjeb9aISV N2tt8Lg87gvK1PQdT74/I1qNFbfhFTDKK2w4YYC7ZAoE03sidSL02nXUngfTb2xRDq csUhEbdoUIxgM6VYCYzDn+8STskKX7IMSGNP9eWLSB4Bf15X2UO/2k3kJ/SNrFljWK z4julWHZYzllw== 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.19 05/16] objtool: Add a missing comma to avoid string concatenation Date: Wed, 1 Feb 2023 21:25:53 -0800 Message-Id: <20230202052604.179184-6-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695901572797454?= X-GMAIL-MSGID: =?utf-8?q?1756695901572797454?= 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 0477190557107..55f3e7fa1c5d0 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -168,7 +168,7 @@ static int __dead_end_function(struct objtool_file *file, struct symbol *func, "fortify_panic", "usercopy_abort", "machine_real_restart", - "rewind_stack_and_make_dead" + "rewind_stack_and_make_dead", }; if (func->bind == STB_WEAK) From patchwork Thu Feb 2 05:25: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: 51695 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52509wrn; Wed, 1 Feb 2023 21:29:44 -0800 (PST) X-Google-Smtp-Source: AK7set9S0eilDIvRQx6BuLO4d0tgI6xB1GADQsKMDEjl6JSzOq6E6qAvD5jvhPQhvWXUPlcNqRns X-Received: by 2002:a17:90b:1e4c:b0:22c:b1c5:ae87 with SMTP id pi12-20020a17090b1e4c00b0022cb1c5ae87mr5117838pjb.45.1675315783853; Wed, 01 Feb 2023 21:29:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315783; cv=none; d=google.com; s=arc-20160816; b=IB30hvGsShMZ20+dJEalhyqOgEgR0khvR/vOM4kgAKf7LXYCLg33R9ERC0fKhLnuJB vjaC24wZjgwjydLvfDlUnZ43C1+H9a9vwB2xCk0qOgIUvXdxQP+LtDfUq2nKLKPqCqLL uMkQ/X3S6nLKifmgCIxyXBsy/Nefm3417uqgNVSbDLjB7GH9zNKle+u5ILpTGn9N+fiv KAvCaiFFWKBsu47BS4xiYaGbIc1xK8XqCMsBUOHkD4I6xVbBKLyIcbZG6D9resJ0zqnX VbcZpSluL8roT1gmlW3KO8TfNPJ5pavEwQdCi0s4fMHwXmyygGa/sC9RPjpw4Z1zIM2F Y2Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8+ADFGHMcabOBH3L6OGi9UfMrAG9e/PX2cVIEpAoIHc=; b=n/qdSobHab0U+kH8mU9VsJsvAN9S/uYWLSYvgTNOPfkli7gIvTxnCZ5It73caWJEiM KPiYQQ7oGOOgAxeSU112Cqxh2z3nHucD9fZ3ql9eQSeFadTYlHJnwaGZZ5eQuuMuBV1r /Fc+XemjJ7IjEDNUJ30FofjpP0fm304vPzBeDNpGQ84UXP/yg/RCiyauwoTjh5GRW5bA +LCIGO7yALhiDDYrRGcAd47J0Lp8nxqT9AUIOWX0wLEjX875CmPMZClT2h1g/5J+zcyz 70LNi2TyWT4BNU1swes77gZQtVI0s8UZGch5wEIrtkQ7bmE2Gyf20XXQFHfVkMTrU+s8 i37g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=njD3bw7T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r4-20020a17090a690400b00218ac70fdefsi3414902pjj.183.2023.02.01.21.29.28; Wed, 01 Feb 2023 21:29:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=njD3bw7T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231971AbjBBF20 (ORCPT + 99 others); Thu, 2 Feb 2023 00:28:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231806AbjBBF2H (ORCPT ); Thu, 2 Feb 2023 00:28:07 -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 BBD1012853; Wed, 1 Feb 2023 21:28:05 -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 34C1061556; Thu, 2 Feb 2023 05:28:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 500D1C433A0; Thu, 2 Feb 2023 05:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315684; bh=rqPPFhpa75We+EsAx/7l1nnJIy+HSyNoMGUNdepG8jQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=njD3bw7TCFNV7X0q/6GjVbiqiYa7RBgPL/F9xnPpJ7gJaAWw/JE2KYxZrQsLdK2Ih Ci0EnKHhVAj5aUkC7D4RKKVgWieZ755DaSx4CpCCnFrrlhs5iOyrtaB4lGHHqpdNNk L73UyyjuNOPAo58/kfsH/Qjo7rTH4AsZ2rNFYiy/QpBJr0MIDdgM8T9B5gCJJcA5ZP Sf1ShcDSAKyCk572pJCcuj4r4c4ms3m8CKOUuRW+Uj/+FglJIslE+stXL6J4FMijYW ijfC1wlq430XFDpoosIKtXC8qLwZI74HU7yESbdfqQ9xjl3NdwQgAspPBfqScsuMsF 1Jh+UOI2cgmeg== 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.19 06/16] hexagon: Fix function name in die() Date: Wed, 1 Feb 2023 21:25:54 -0800 Message-Id: <20230202052604.179184-7-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695923362699961?= X-GMAIL-MSGID: =?utf-8?q?1756695923362699961?= 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 ac8154992f3eb..34a74f73f1690 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:25: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: 51693 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52389wrn; Wed, 1 Feb 2023 21:29:24 -0800 (PST) X-Google-Smtp-Source: AK7set8qOl9CWk48MBwXBzSoaSr+x1Mi4wwSrsp0DmZhPbssehbGQPWrB1aFCqODyhhWZ7/1NdSu X-Received: by 2002:a05:6a20:699b:b0:b6:3e6e:af94 with SMTP id t27-20020a056a20699b00b000b63e6eaf94mr6558666pzk.32.1675315763837; Wed, 01 Feb 2023 21:29:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315763; cv=none; d=google.com; s=arc-20160816; b=GNDPnscTn+jAmgseZdTPvV+nFPzJ1oLZLKaHLmZwRF8ySy5TuaIg7VOJCybp8uo0G5 UQMFtcQG34bmJjT6CJs4wAIt4jfBozdrDqnZhgRnky68AZ+X3KyknPiK1l1vOXoUa4t3 hNhJ581h/+FggJBFYF2JZSXYQ+YIED1QXGI+J9c0GKF22iDVa4ev1yq5wxzvzKblTv6F y+lTIoDPbl9WPeyV7tWX2biJHyn1bNsVNJhfDZNFrmUE29qMwwlyDBZSjhNMZQfGKTyn Lyg0qPsz5Yqgc95PYydVSiBH0PSuyJs+SArqYkgqSjOlMdPIFrCv9rZHm6eabwDBKxF0 VuIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0+ip4U/OqP5VNuiYiDuTDXWGm7K8l7d7AlcU1RpRoOI=; b=BiRknd9s4hD26Bi22pbExcwRw6kocdhPvQwq/WU0oz3WbIBdlaVWa0NeKbdYrIz+d6 LPAmv4ALbgoxmHZ2mWPeIczTLI/hfyaodaQLE9TxXb+fJYo79vb4V3yKfSkHK4xu2UH8 MtAbKl4AhUK/EolqxmKvmyc4d4bfFvyLqlbwUrrEcrLYVMMhqzXXvUraLExPTlY0pxRC XAboRS4eQAUvJI3bX6tknOi27vOMwURsB8v/3jG27KXrYEuRF5hTzDoKUpi+ON57AJsB 6L90nVlqzZpFePzFy8rxiiM4uo2S4fLwfK+Ikqz28d2o2qvMYjOIC2LMEZKWMWTLo8nq 5JNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bAr2FIfC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s197-20020a6377ce000000b004da8bc91307si21071422pgc.749.2023.02.01.21.29.08; Wed, 01 Feb 2023 21:29:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bAr2FIfC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230508AbjBBF2N (ORCPT + 99 others); Thu, 2 Feb 2023 00:28:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231679AbjBBF2H (ORCPT ); Thu, 2 Feb 2023 00:28:07 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1F291449C; Wed, 1 Feb 2023 21:28:05 -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 3FAEF615E9; Thu, 2 Feb 2023 05:28:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF024C4339C; Thu, 2 Feb 2023 05:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315685; bh=w2+gKam0hgvqls1hiqaw8OhtqAs87LqFnf26zQZbz5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bAr2FIfCLyzidKouTHr6RULNPnaA6klX1WwsIRPzSvd8r3RyE0PwXvCwH5qTRPOr2 h0gG/sCiynmjC6+JDp7Q8rXdffRovgf3vyPOxzO35TlaYz+o4GXc1fE9G/wVuusjEJ /dmk4ELX0FjZ1v0jMO9iSMClmOmPE9LB6NHU1uaXZlqv1JLzPIb6gQ02xdKfAKEkbc k/R4AZ3bZNokcV1voRi0mRlKK2iw3rstFbeDjvgWYiteqtfXWKdwBct4cannhNchRw x1d+cJZlI/ybnC3EkGDeKWOtPZPVExZZDoXLolZNRQHU4iHR/31I3X9BwH9H4dwx5V bF6759vbqO5dg== 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.19 07/16] h8300: Fix build errors from do_exit() to make_task_dead() transition Date: Wed, 1 Feb 2023 21:25:55 -0800 Message-Id: <20230202052604.179184-8-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695902256765955?= X-GMAIL-MSGID: =?utf-8?q?1756695902256765955?= 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:25: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: 51697 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52551wrn; Wed, 1 Feb 2023 21:29:50 -0800 (PST) X-Google-Smtp-Source: AK7set9clTjzEGKVMQ4ipnicgS5WGjrGr/gnoYXtsWQ6SA7l+XFZkv/Aai0w2AJoZEB7C3sjnL02 X-Received: by 2002:a62:1dc2:0:b0:592:4502:fb0 with SMTP id d185-20020a621dc2000000b0059245020fb0mr4663252pfd.0.1675315789809; Wed, 01 Feb 2023 21:29:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315789; cv=none; d=google.com; s=arc-20160816; b=SrPnnjgLtYYsN1XgboT0qt0jFn2fSq4y19NGmCrIc2bM4Mig1/rBjlIzLQQVbDHBs6 u8Hdxe5Cmi01pnN1ZN91ZjsrCXwNCjM5Xd/2bMq86nAD1WsA7isXniZGCEdMp4NRXUlo VJUa1wluSQAm8NT6eaWaZHpCDHlPYbQxLgUOes+Q6lmyyqCkOfJO9yGkUHKz2vPhdXfw Y6jH1Mor7GwCSqmcpTb3LfhRs38Un7MkIE+uVeETTFGx+1YIImmPItItOvTy5Uzbq6LB zcaYMrzTTyskhpa+n/EDUWo9oyV2dZ8zBwELe6ABtwxNc77uTVCIKLQt9lOfCXlJHDHj W1Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oY4hJ2XXlDh+V2Pw4IhQbxyFjcLSOTzVLsfV7CARGpY=; b=V9tCeg+tKT27gDtjQI5lRADwLUr65fInUP74W87mqIZGz+fSM2Yt2BB91Pb4qwD+vO kgdh1qJPqAaEJxlN5cINEdCxvRMC4fiGkE1LJBkspz1tQJpiA9cXHzBuKVWsETpJSPqC jySQyzFG6D0dBVzsfnarA4uzBVSF5lfeJ87yvx8iqPAhidOCCBcea6Qcdnvj0Aq3mBMb zzfLI17IXQ/+ahfG/6nmnqOadNWctp21OP3APRZbiXX3mreqQeMVeVGCI7B3VxMSAsHv E0Rjzip+AyM6rJooKOXXB768phwJ94wO2WrsTYAT/jbZzkboRgruLeHrjuZAhL/NQVx1 ZrVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WcdfRrlS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y8-20020aa79ae8000000b0058e09be04d8si20929525pfp.340.2023.02.01.21.29.30; Wed, 01 Feb 2023 21:29:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WcdfRrlS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231624AbjBBF2p (ORCPT + 99 others); Thu, 2 Feb 2023 00:28:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231357AbjBBF2T (ORCPT ); Thu, 2 Feb 2023 00:28:19 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D886818155; Wed, 1 Feb 2023 21:28:08 -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 EE551B824B6; Thu, 2 Feb 2023 05:28:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3ABCDC433D2; Thu, 2 Feb 2023 05:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315685; bh=XvMp8OxqN686wYYBuokqdDG9zEqwVzaClZ28PNpdlgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WcdfRrlSbdKncAZuzC0qEsWO7IHkpVyImUDNOAEdGOchVIlLlmNKSE+oj6ZWrJefp zvnOgiZ72xZ4gdgv8oU2lmpoXBl/U4kSTbqI8EtCri8Dqe7HTp8KJObPIXTCVnjm9U UqaUbs7ToyHXGlaSX/vpVPvFd45djSpHA3WlSxlQZw9wH/VBZF6Hn0ubVGP4cWiGlG ymWXSqUUN/Q4rPol4AuWicm3BibmjufLLIo5/7DiJ5ln4yJpzMS7KzJEg3fBKdI58o J5YMdq+bLudQfPpWlL1MzDEcdF6j32njIzOdJRf73Y3FMhqsnmgl1ZHAU38aWi/q5d dn+w/t7nSG/9w== 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.19 08/16] ia64: make IA64_MCA_RECOVERY bool instead of tristate Date: Wed, 1 Feb 2023 21:25:56 -0800 Message-Id: <20230202052604.179184-9-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695929216419400?= X-GMAIL-MSGID: =?utf-8?q?1756695929216419400?= 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 8b4a0c1748c03..0d56b19b7511a 100644 --- a/arch/ia64/Kconfig +++ b/arch/ia64/Kconfig @@ -445,7 +445,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:25: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: 51703 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52709wrn; Wed, 1 Feb 2023 21:30:15 -0800 (PST) X-Google-Smtp-Source: AK7set83KmSJ6R9f8y66aiTjdyA4IBTsOgNvUVIyT/rNo7rH503MJr6WlmbXQdT3z0f4JNuXiec6 X-Received: by 2002:a05:6a21:33aa:b0:bc:fe7e:cfd9 with SMTP id yy42-20020a056a2133aa00b000bcfe7ecfd9mr6743292pzb.18.1675315815678; Wed, 01 Feb 2023 21:30:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315815; cv=none; d=google.com; s=arc-20160816; b=xaGuKi28fdnx+SjfoeN7XdJTz6HdhXvEe9EzpveD499CILhsBCIiBNDju5tkav4cLl jdn5HRxPbKLzLyiut/8k481oy6hazdatas/QfJqxJUhBEexH0mq41hg8XEsZoQRlXEf+ r6ZQj0o6aQeCkMtRqIPkHZ3tU/xyKF5z+pxUBjs6DdfHw3HmriTQGMQUDuI0NNMUPscZ EAJbrdg7v+QcyHYWtYr7dbvZAprHXu4Ti/OvidXx0BbIcIDEYSJus1IPp7MBZ8nhzndw iVnvCbZpofl0spihIfIO7+VdTdFfjKrjc/GSWKm9EBQCURHxESMxy3aKOSST0Jnziwfg Jrsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2pa3MaybsIFLyg6DJgnAqTcA2wieNTJIMwteW5Pm7LI=; b=kc+u8h2Mr0atFHKf1EVUGUTizdYimaNpm33KtB17RedOWKTf5cQ0sWqeHMTq6KCBUA stfOTRIfS8h9uiGeItl24UN1X0ESQ4gFgXc16RS3Ed+oGg6F7nivRl63xYGprTf9Bytl abuKEJHSCIwSCV1LRwVBuNUV78h0QfE0nmjYPpSZBHCi9zqJXHL7yp3u8dvAUyQWyWnL 2VSwR5wUc0qFb+EizfXjnb7fvfD2viDBt2kk8KGem9MC19ZIon/EuTfzkjCLrdSPa2l2 mYYkoRxsy/vppxordR5v49Ng//0i9UFgFIWLtWDHC2566ADqCEip9M8+2bdXvLnzV2DM zMPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UbZTii4m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v9-20020a63b649000000b004e1d512286esi1405624pgt.832.2023.02.01.21.30.03; Wed, 01 Feb 2023 21:30:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UbZTii4m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232024AbjBBF2v (ORCPT + 99 others); Thu, 2 Feb 2023 00:28:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229881AbjBBF2V (ORCPT ); Thu, 2 Feb 2023 00:28:21 -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 D8FC618175; Wed, 1 Feb 2023 21:28:08 -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 5F5BEB824B2; Thu, 2 Feb 2023 05:28:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB9C6C433EF; Thu, 2 Feb 2023 05:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315686; bh=lwTsMszefw5rHZqf0ZxqDJa/9KBH+8q5OL/uceUU0fo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UbZTii4mAY4ylde72kctTgOVOT9j9+lZ2Vteuc5VoE1N/86qwf/xs8LfXjEwvwQ7t yVccRvRKsAMqGd8b+G76VZmxQVmg4SWKJwUjwCf7XfPIqfvPGPtdcn7yf/pz0Ma3Ne d9NFQqhZwexls92DUssoVHJ4P8sBAD7QZ6XNbS3n20ivvvcWgZe6QKGLY71/jeXT/f TDUCnSUkcLYs1XasuexX5N99cJ0l5okNpbrau1/OhnRLwfLzBPuL6OhvigCCQGw//9 UNSkiDveRQe9DiAbKHKrrm3lau86pK3tDliQSowLQbfagSz3E3FPwgFChdEIz/pXaE SsvS9kNAHTwyQ== 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.19 09/16] exit: Put an upper limit on how often we can oops Date: Wed, 1 Feb 2023 21:25:57 -0800 Message-Id: <20230202052604.179184-10-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695956555419561?= X-GMAIL-MSGID: =?utf-8?q?1756695956555419561?= 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 db1676525ca35..fd65f4e651d55 100644 --- a/Documentation/sysctl/kernel.txt +++ b/Documentation/sysctl/kernel.txt @@ -51,6 +51,7 @@ show up in /proc/sys/kernel: - msgmnb - msgmni - nmi_watchdog +- oops_limit - osrelease - ostype - overflowgid @@ -555,6 +556,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 2147bbc2c7c32..fa3004ff33362 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--; @@ -924,10 +951,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:25: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: 51705 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52786wrn; Wed, 1 Feb 2023 21:30:25 -0800 (PST) X-Google-Smtp-Source: AK7set9dgqEZS7Pkx4KpprYDI0p+XtNFdrOQ6mAE6E/V3VDYvxwKhIWC7ok2endi176OvBNUkCl8 X-Received: by 2002:a17:90a:6007:b0:230:3af9:186 with SMTP id y7-20020a17090a600700b002303af90186mr956690pji.23.1675315825304; Wed, 01 Feb 2023 21:30:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315825; cv=none; d=google.com; s=arc-20160816; b=zn68Km1iC97Ua7MTlrV8voy7HvixdvM0wV//FlFA2RjSeuAKhi5ODGYJcen/oNUBCD v3NZdIacUY+Ti/AUO4KGFzwy7Ojce8eRVfDxxhC6lzulFzE6J43YzDoowkO5/SrWinIc /GY22lMr3jhun5JyFEMKZwfiadfCcDXgK0avVBVYNm/t2l8x9fZtyITUGmNylKBaY0Y9 i4OBGSOMkKYGIJhs8cWzEV+YBDoKpkfSLXQDDSERKRB9YQokXuTBAZHxnEiUlPaEaEim K0tn+Ns0+hK9IgaFSALktqNAtlTZ39CpTFU2OYiSLK7rzQs8Xc33blaAIWK1GU2uc9Ya 3FIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xXXBSFBpH/w/zkbWV667NnaIg050b/kgNIz+X0gPMSI=; b=INrLqWGnKhRPSuvdfZ6O8Mx2z/7aUxbY74+u6dVrWMGogc95W6BnHqcl64Z/9jxUKq GXRUAHswEiBHhZUSUU10Sq9gGRGCkNUS5vxxyssXGDLhNfXC43pbNw0WBQ8G7zuI8mTj NIcl9gHEeIPk0Fhs2p3vDiiPHKtDLaqP8d/7cJDxdsqZhI50q31NwzhjUrUgmX4iEnKe dkqO5+e4cLkBJ4rjKP36MtWq6PBTuQkv5jQD8vXANnFrrcITX0k4CszCf/qGvsgPQWHL xDEV2Je6dsltkNlj59Veeiadp8UWjC81L9mpfZB3xfD+dIdD2nOAs0t+djAyeTiW2leF xW/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KPtzLG7w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lx3-20020a17090b4b0300b0022bb81526a9si4320481pjb.8.2023.02.01.21.30.13; Wed, 01 Feb 2023 21:30:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KPtzLG7w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229640AbjBBF2l (ORCPT + 99 others); Thu, 2 Feb 2023 00:28:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231872AbjBBF2N (ORCPT ); Thu, 2 Feb 2023 00:28:13 -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 D590D1632E; Wed, 1 Feb 2023 21:28:07 -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 2E933615EF; Thu, 2 Feb 2023 05:28:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46826C4339E; Thu, 2 Feb 2023 05:28:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315686; bh=mLCdAaBunvOHoCrOt7GOusY5wCBMyBacAnEmb2lGEsw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KPtzLG7wxU9csHV6Ur1qYJ8uKhl4YWaozd9ri0rjNiNdl6oiEmYywKs5o7MqtW19/ vlPyIYTKkTJeYnA41oXKOuQOTDMFNvREctoXfue7j3Be5gDUvnjxq7mB8gMQre875y 0BzUTTvT9JwZXjXAsqehGeBpCNhbc5vEZ7FhnB8jICn4OQV1CWhQDSdk3O3UxpeeRu buHudUiJl76Ll6hCAj6hDCuAjoRec0mVgJqNF4LkWrkQfrbNOPbn1Ty01Ql2vQEPbK 9SycmdIkeRdBADvJ5v5uuSqwem7+Xitk9oDej9Yvmx1lUCMy3CwWczjkp14ggSnYNM O1eVmw3ZX2vhA== 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.19 10/16] exit: Expose "oops_count" to sysfs Date: Wed, 1 Feb 2023 21:25:58 -0800 Message-Id: <20230202052604.179184-11-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695966820846642?= X-GMAIL-MSGID: =?utf-8?q?1756695966820846642?= 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 fa3004ff33362..5cd8a34257650 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--; @@ -951,8 +971,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:25: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: 51704 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52731wrn; Wed, 1 Feb 2023 21:30:18 -0800 (PST) X-Google-Smtp-Source: AK7set+ocFccqms0TY2hvxwwN0L3/lLtQkzoRsbl0ebYUmaEF4tbREC9qVOrV8vnqf9ZKbMH1Xqt X-Received: by 2002:a17:902:e550:b0:195:f3e3:b923 with SMTP id n16-20020a170902e55000b00195f3e3b923mr5974102plf.8.1675315818123; Wed, 01 Feb 2023 21:30:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315818; cv=none; d=google.com; s=arc-20160816; b=F6jCrTHTYwyUOBxTyV4vKhduKfkWkik+eS2/PL09/f/R9mgyNrg+1JB/QjtX040AZR lRC8YEogyX8n6EUxQ7wLT3X+W9vTOhoNs9q8XPb2sw64yqLvcnTBH+Y71Zt1Wr1gGL7G +X4wdEx9hSmU0hbqH6YEWTQZJa+2Dl1JLTJIDvV97rhq0C/NOZAQbKAygfSrg5ecCQF2 7J5E2ZJjH4MoExnlJnbyREOnSUdhyckJVadw6eY4EEiUhcDMDUTv+j9Bn7d65cxatu07 OKIBioC8PYcMcXU980wRnPxx8QOa05VYTu2dvsH2Bq/Uvba2bhz9LODmpJRMJk0RTp35 tdIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KMIqUnFpYqAi4nXtm1A6wnfCWHC9OWgQUZeYw0aEKQM=; b=U+6Nw3yNZLiDtwJDlI3cEq8k7X0i7eNIq2QzvrawnGn/dNK6hQXo8Yoez5Wqa0QMMA bT2gnFOf2pSls8P1rbYinmprOgf4/WQckMnPWnTjKlxTBmydrC4VNpIzdNJUSHN/QzMy KD1j6TqAZqXo9g6o0pGckPlh6MC/+Ta638g0iLsfg07G0iDetYKwDEBCRiXAvllZ7b5l 89msdOq2mp8k6jthaNMww7Q/EJVsl7HkZkLFm97sIWtymEw0HmdlQuEdsEtojsmGAdsA vr1oHOebIJTTtb1U2zAjmRGgnfChtb1scc5rFeWydyVLJHoOR0nRrjKCOJGJU8vQ7jdJ C8Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PDOyv9Hy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r206-20020a632bd7000000b004e080a5ba41si18765746pgr.572.2023.02.01.21.30.05; Wed, 01 Feb 2023 21:30:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PDOyv9Hy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232123AbjBBF3R (ORCPT + 99 others); Thu, 2 Feb 2023 00:29:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231936AbjBBF2Z (ORCPT ); Thu, 2 Feb 2023 00:28:25 -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 8563020D32; Wed, 1 Feb 2023 21:28:09 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8B092B824BD; Thu, 2 Feb 2023 05:28:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD25FC4339C; Thu, 2 Feb 2023 05:28:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315687; bh=nv2Qqlsj2+1OK7qBLFpDl9kvNBYUdDR2EUyByUiFUks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PDOyv9HyEEEm1mMma7zFwWbZkwzMocq6zarb2i37VNulT7a3osKH4xFUVY03G0uE1 G9Bwmbvnz5RC4xs3/JXAKDPjHyL8XyQlHwUOfYaY2O7EeS2FYUCn0LqwDkgDfwLfnE s3sda8oybqsTfOSmSaMbXMtcGUfRgWiqyCXHn/z4P+pF49eE3+iYY3FTgmah4dJ+47 //ln2un/CRFL1KDmQJmrY5Tdsts1oSbjNOnJvq7gT10MuzQl2+ZQoBSddMjS6KhSBN EW8r43JO3kEgOgmrmkMwrVmOCjrFGBsIt984oYH9qZmUl3imiZo/eL2Aa3O1lCu2dV HZ4Q10lxbQi0w== 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.19 11/16] exit: Allow oops_limit to be disabled Date: Wed, 1 Feb 2023 21:25:59 -0800 Message-Id: <20230202052604.179184-12-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695959635814278?= X-GMAIL-MSGID: =?utf-8?q?1756695959635814278?= 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 fd65f4e651d55..e1d375df4f286 100644 --- a/Documentation/sysctl/kernel.txt +++ b/Documentation/sysctl/kernel.txt @@ -559,8 +559,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 5cd8a34257650..b2f0aaf6bee78 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -986,7 +986,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:26:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 51706 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52802wrn; Wed, 1 Feb 2023 21:30:27 -0800 (PST) X-Google-Smtp-Source: AK7set8dJJQ0tO4/+smlH/JVSZRBFnC5k3SIcGgiFcwo9ankNnybsJN2akM7yxK/KPhbsBVlqJ89 X-Received: by 2002:a17:902:f202:b0:194:3fa4:3f46 with SMTP id m2-20020a170902f20200b001943fa43f46mr4042102plc.29.1675315826885; Wed, 01 Feb 2023 21:30:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315826; cv=none; d=google.com; s=arc-20160816; b=c9SWt4vwY0mpNkM2mbIBvXRgvrv8nYIrvvgbXqxLKcziC5Ia3MDStogNbaCEli7I65 GqFx0a9l8BwQ1E7sY+lgTlz6Ye/hejgnlxyenz4tUcM6kAknlIVXDiKdZ2fHh3dHjdEU Zj+W9gvhe3gzLKwZNQxDQGDGmm4blosuEDvfKlHy0+uDJXTcSU5GzaNWPzIV8dDG+pDG mOTF/zegoqHMkELZSGlF8PfBVBO18kmciJCs7rePNR2MzTbuXAtyOHlEE786MiKU41eP rf5/v92Q+qlK/vS2uwkQ8lIyOOrrGsYcsmaHYWexjQHRrK4b1DkJD4Z1fXwNUA14qkRC SSvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Po7xxo2rOMSPri8SKf4EkdJBnmJkIyTqB8yrnEGgdek=; b=BrowGp3xgK/zQN2Rig9rj5Zr7U4BLQPlkRUQmwYig7NlV4+8fQ6MMtzaI1GZ4PduWi iyvzSZCdv2Hn/KvjuVtlFBpZL+Gm9Ig+g5z2nMOL7a06qj6pz38EB3sr6AN0jFiqCH7O uEO5JTtimWTXY1PRwFye4rSTCegY6ExqbuaOODZFQk3+UHDxUC1xy3JlRKq5rfUvUyqK 6gY9zgTYozhQaHFfhoWTkhNA3hYxiNC3XMsUxjxYcyXipiImMNOZ/983/URuc++Z9got GmRBteuVp9WmyBoYbI0SrvBq3u2W7eqiE2u9/0buCPj70bWgBr7s2Y6hkQs5NM31oT/h iQug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YmzlX08Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v11-20020a170902d68b00b00194afe281e7si20063884ply.429.2023.02.01.21.30.14; Wed, 01 Feb 2023 21:30:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YmzlX08Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230003AbjBBF2y (ORCPT + 99 others); Thu, 2 Feb 2023 00:28:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231926AbjBBF2V (ORCPT ); Thu, 2 Feb 2023 00:28:21 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC5BD193F3; Wed, 1 Feb 2023 21:28:09 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0A6CB61556; Thu, 2 Feb 2023 05:28:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A12FC43446; Thu, 2 Feb 2023 05:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315688; bh=5Ri/HkVcJ9rh8djKJRfkJzJeteQyLdBfCFzTyQfbWy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YmzlX08QXiBD4TUxauXkYmJsx2KoDJrKqQ5vkMfPTpQqzBuHooHeclBWk2qWvi2zv CnYShkItmuAlZSBTNCVB/OeFI4XYPnrt2rMyTy37/EWCtAeUh1zf9joZ+6ttla43yA j8WiddDXvTQ5hKnBu2E0J1BIUrELHdHye56o77dChXqkWCBkQCDDp3zml10RDZXpzJ 8d8vo6vBUvoh5/IqPq2JoF5AQ8ZZIZqLxa9KXVSTbVIlUHL68+D9ch9Is50phTs9x1 b71QBA3LzaJmGKtz+IKkUeslVcmjszmhFef3jpN8KoiSGypDQOH3HU9Ggg9wx5VWge P6A/Cihwd91EA== From: Eric Biggers To: stable@vger.kernel.org Cc: Harshit Mogalapalli , Kees Cook , SeongJae Park , Seth Jenkins , Jann Horn , "Eric W . Biederman" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Marco Elver , Dmitry Vyukov , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Vincenzo Frascino , Andrew Morton , David Gow , tangmeng , Shuah Khan , Petr Mladek , "Paul E. McKenney" , Sebastian Andrzej Siewior , "Guilherme G. Piccoli" , Tiezhu Yang , kasan-dev@googlegroups.com, linux-mm@kvack.org, Luis Chamberlain Subject: [PATCH 4.19 12/16] panic: Consolidate open-coded panic_on_warn checks Date: Wed, 1 Feb 2023 21:26:00 -0800 Message-Id: <20230202052604.179184-13-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695968368324034?= X-GMAIL-MSGID: =?utf-8?q?1756695968368324034?= From: Kees Cook commit 79cc1ba7badf9e7a12af99695a557e9ce27ee967 upstream. Several run-time checkers (KASAN, UBSAN, KFENCE, KCSAN, sched) roll their own warnings, and each check "panic_on_warn". Consolidate this into a single function so that future instrumentation can be added in a single location. Cc: Marco Elver Cc: Dmitry Vyukov Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Andrey Konovalov Cc: Vincenzo Frascino Cc: Andrew Morton Cc: David Gow Cc: tangmeng Cc: Jann Horn Cc: Shuah Khan Cc: Petr Mladek Cc: "Paul E. McKenney" Cc: Sebastian Andrzej Siewior Cc: "Guilherme G. Piccoli" Cc: Tiezhu Yang Cc: kasan-dev@googlegroups.com Cc: linux-mm@kvack.org Reviewed-by: Luis Chamberlain Signed-off-by: Kees Cook Reviewed-by: Marco Elver Reviewed-by: Andrey Konovalov Link: https://lore.kernel.org/r/20221117234328.594699-4-keescook@chromium.org Signed-off-by: Eric Biggers --- include/linux/kernel.h | 1 + kernel/panic.c | 9 +++++++-- kernel/sched/core.c | 3 +-- mm/kasan/report.c | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 50733abbe548e..a28ec4c2f3f5a 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -327,6 +327,7 @@ extern long (*panic_blink)(int state); __printf(1, 2) void panic(const char *fmt, ...) __noreturn __cold; void nmi_panic(struct pt_regs *regs, const char *msg); +void check_panic_on_warn(const char *origin); extern void oops_enter(void); extern void oops_exit(void); void print_oops_end_marker(void); diff --git a/kernel/panic.c b/kernel/panic.c index a078d413042f2..08b8adc55b2bf 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -125,6 +125,12 @@ void nmi_panic(struct pt_regs *regs, const char *msg) } EXPORT_SYMBOL(nmi_panic); +void check_panic_on_warn(const char *origin) +{ + if (panic_on_warn) + panic("%s: panic_on_warn set ...\n", origin); +} + /** * panic - halt the system * @fmt: The text string to print @@ -540,8 +546,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint, if (args) vprintk(args->fmt, args->args); - if (panic_on_warn) - panic("panic_on_warn set ...\n"); + check_panic_on_warn("kernel"); print_modules(); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a034642497718..46227cc48124d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3316,8 +3316,7 @@ static noinline void __schedule_bug(struct task_struct *prev) print_ip_sym(preempt_disable_ip); pr_cont("\n"); } - if (panic_on_warn) - panic("scheduling while atomic\n"); + check_panic_on_warn("scheduling while atomic"); dump_stack(); add_taint(TAINT_WARN, LOCKDEP_STILL_OK); diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 90fdb261a5e2d..29fd88ddddaeb 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -176,8 +176,8 @@ static void kasan_end_report(unsigned long *flags) pr_err("==================================================================\n"); add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); spin_unlock_irqrestore(&report_lock, *flags); - if (panic_on_warn && !test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags)) - panic("panic_on_warn set ...\n"); + if (!test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags)) + check_panic_on_warn("KASAN"); kasan_enable_current(); } From patchwork Thu Feb 2 05:26: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: 51700 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52659wrn; Wed, 1 Feb 2023 21:30:09 -0800 (PST) X-Google-Smtp-Source: AK7set+dMtvGG5H2EeU4DjspCI/Z49DVwNsR346L5diIM0CBhCtwbcWevEgsGjt0NUqwSDhRomeH X-Received: by 2002:a17:902:d506:b0:198:9e29:cc4f with SMTP id b6-20020a170902d50600b001989e29cc4fmr6777548plg.43.1675315808719; Wed, 01 Feb 2023 21:30:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315808; cv=none; d=google.com; s=arc-20160816; b=f97TVHwDwWFkHukuBrHmYZ25G3AV3EJsAZsxCg312ZhPx+nd+QsQNmpKHPaTPSNh9L I4C7SGVIUW22XGB47DChA9kWimPQAlq6/0frRIJomaVJXty5DPEHENDK+zOQra3Wpul6 Hr/KTpX5lHU2EcNOoDn24wrUY+EJLfwRZlwyltmUtAeR1ocnlm9u07yo5bS2nVWb/ymm Zz+uJ/HCkzSdtUTjKXO5oHTIY+QHywc0wRIPjTulKyRBhsvSR6Hvqab9ATnildpm7lyn 39erYRS2zDrZls0492UGQauLepQqGB/VctJR5cLizOlezK3KBmGIuCQfMCsh10UgEfIr Ikvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wcesQKKxvYorIbnTbKNXep7QqgjOlqPk5sNXgtyqH9I=; b=g9ynIG8pz13+EWNXSRhn1cE/xNFLQRVDGGTT8PNDJ0gbZoO7apoRVgW90fU8wNGVfN I+bwNp99YYtYQEWWohyCb7t+3u7x2d79WcQEr48YqvMERE+WMoPKMTT5aGtJnjrWgSOy wvvfG9F3fLrQDvfKYEHKrsHSyABf3p0ZrHsxqPqg7WvR0jJqzlxS6Y4FHZOPr6gVFqIX nGIOtnZxoRBVPOTBtSTpB0tMuQDp4ql4q1ft8S3kniFSfhGtKQVqCnMkmXHZOa5m3BGU R8EGanLraqjV6FFuKhYF94wTdZw63wXl1G1ZvuZntdw3lo01DZQye00CL/Grb+Pnuc6N 1iKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LlplLbAJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020a170902988100b00194967b7badsi16961549plp.591.2023.02.01.21.29.56; Wed, 01 Feb 2023 21:30:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LlplLbAJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230147AbjBBF3K (ORCPT + 99 others); Thu, 2 Feb 2023 00:29:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231691AbjBBF2Y (ORCPT ); Thu, 2 Feb 2023 00:28:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8310C1F5D6; Wed, 1 Feb 2023 21:28:10 -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 CBFD8615EB; Thu, 2 Feb 2023 05:28:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C096C4339E; Thu, 2 Feb 2023 05:28:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315689; bh=wDzo53Dl0UDwP01U6Ffmf8hrLpT0FCIt+byjVDuB7aY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LlplLbAJlnEemvNaUO2Mz2C0sOMCIG1zXP6tRmNnDsU+D6CxCwFp5IeajaTiCs/2F DmfoAsF5RcQSOP7rw7NMOJrgBnQNHU3UzDgM+uRY3XEAXV4QB57erhrTAemyHhCZsl YSBSgS4+zaiXIIhidKtDXgwOolhfXQjwrZYRBqLbGzBZlRu+yAX0OhSUV6S+3YtL4N nTntuRWBnqbgcPH2od+JnCFH1K1lXb22QX+3LxU4sbAM00ConG16KSuR1iuqN/mnq8 zvxv6jeHbT78QgFezP52ak05ae8BA1O+Ozzr1EEJDyTL7ZqnQGWPi64/yd0hlmQCsz DAr1sLanvmqWw== 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.19 13/16] panic: Introduce warn_limit Date: Wed, 1 Feb 2023 21:26:01 -0800 Message-Id: <20230202052604.179184-14-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695949093524501?= X-GMAIL-MSGID: =?utf-8?q?1756695949093524501?= 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 e1d375df4f286..c8d3dbda3c1e2 100644 --- a/Documentation/sysctl/kernel.txt +++ b/Documentation/sysctl/kernel.txt @@ -97,6 +97,7 @@ show up in /proc/sys/kernel: - threads-max - unprivileged_bpf_disabled - unknown_nmi_panic +- warn_limit - watchdog - watchdog_thresh - version @@ -1114,6 +1115,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 08b8adc55b2bf..d1a5360262f04 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -42,6 +42,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); @@ -50,6 +51,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; @@ -127,8 +148,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:26: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: 51702 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52707wrn; Wed, 1 Feb 2023 21:30:15 -0800 (PST) X-Google-Smtp-Source: AK7set8uX5c8wRn/VUGDLejkD8utV7uPIBcRqzzPuaoOg30YW77Cr5Urdkb/G4v+4SAAOS8uOQnV X-Received: by 2002:a17:90b:1d02:b0:22e:61be:774d with SMTP id on2-20020a17090b1d0200b0022e61be774dmr5368849pjb.16.1675315815222; Wed, 01 Feb 2023 21:30:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315815; cv=none; d=google.com; s=arc-20160816; b=0EQo/ZFWRcnL0ofSsbpA5H593p3fSJ5HnqTvBep+pBAzFEUcwHIuX6Z/kUsOFGjEqr v97pvo7P43kJFJiZoj5bqxyWr1SmDrPP0iQUaeUWvTG0WTfwOcRNWX/4KMkXBHxlhay1 X8VKJhfJABG0wFnjWOmImwz6s8SBXX0A0WrQO6FE0XcfoLipvt96Hq6NsXGe/3EQTWCd mOzRikTHhxepHAfTi/FTd/9Gx04AHuMsu8CLlur4VgBqNqfflJCl5+0yInNHJ4djbi4t w4rHXoF+dk+BAS/EwsYWyV6caTWMz7NZ2euO2v43BDJeHJl+560POAueJjVEt4Yyssj4 kUWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TZji9KvnUEHLfVcLIl8u2LSFYWQGy3myJIRCfXbSjyU=; b=rVygvKUMtBlmsvH4GOQjYvVUv5zpyeMA6mzGLoXGHjdTTj1Y8clm2hM+A71+AO1ajE XyQXzWGPp/MKB6+z/wRoMb+jluznZMaMSOfXp4R+hVJam7GDr3Gxboq0LCv2QM4oZboJ ISd5mcWVopU25RGqjJr9xozrXnFTGNviq9db/IEtOV+4zjdAq9GcRw4VZnpLDoT4/HiC a8YfjKpzjd7iM0uKQCOsQU0RTzOhJ4idEaf6BbewQ02Kiso5Kzm1szEOJBqOZ5ebySKN 8eLrSfzFa6K6RyejfiJEJazD1BFqscWVSLkwyNExu78X6cxWhitej8DNs6orVUtkEAL3 qIzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dnCHJDta; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lx12-20020a17090b4b0c00b002300d3d23a9si4343829pjb.7.2023.02.01.21.30.02; Wed, 01 Feb 2023 21:30:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dnCHJDta; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232168AbjBBF3Y (ORCPT + 99 others); Thu, 2 Feb 2023 00:29:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232014AbjBBF2f (ORCPT ); Thu, 2 Feb 2023 00:28:35 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E39C91F907; Wed, 1 Feb 2023 21:28:12 -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 252DCB824B3; Thu, 2 Feb 2023 05:28:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 689FAC433EF; Thu, 2 Feb 2023 05:28:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315689; bh=WvfZsR/qctVDMMgvWrh4xPNS2c2uTlwTbpaBFr6WSq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dnCHJDtasr2f19ob2DGAk4L2OdO0F3EAo9u/6S0r4glJmrQgyIMB/iYHo3gmdz5ZT NNNHnHNUWlt9yGJz4D4EZNWQvtDDHrQbgNr2hNEQOr/bGMRux9FNoJXn/7KlmYChto q3NggTNo7QLa+gNGA/ceIX6n26A0p15PRqEwp5bHhaxm0arIQ5EbWyxdNxE65DFEd0 qFvKXwD65Yi4Frup0lTJ6tBJa1oiCBoiWRPuFkQ2rxBbsGLoK5cHRLkzzrHL7QPFO+ k+JnbE+U4R2mPM+47lOllum3i6jFfmNf+YD3qHjl/k5/TYkZUF9O4xGX8kZ61PFV4f sEkbQbz5LHnsw== 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.19 14/16] panic: Expose "warn_count" to sysfs Date: Wed, 1 Feb 2023 21:26:02 -0800 Message-Id: <20230202052604.179184-15-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695956204167038?= X-GMAIL-MSGID: =?utf-8?q?1756695956204167038?= 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 d1a5360262f04..dbb6e27d33e10 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #define PANIC_TIMER_STEP 100 @@ -71,6 +72,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; @@ -148,8 +168,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:26: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: 51708 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52875wrn; Wed, 1 Feb 2023 21:30:41 -0800 (PST) X-Google-Smtp-Source: AK7set/XRqD8xTbl5PP6XRpaUUJDChHscNNKakN+RbBKk0ZedjONenwJp0HGkgHMuktJS9YZBb0g X-Received: by 2002:a17:903:191:b0:198:c27f:890c with SMTP id z17-20020a170903019100b00198c27f890cmr1393381plg.34.1675315840834; Wed, 01 Feb 2023 21:30:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315840; cv=none; d=google.com; s=arc-20160816; b=l32yT/oACcjYQGPzgYXYoUDXlZCMApaOgmSWWNOfygQim+drjoKPmao/5eYbmMdNQ8 Z5ZgLtdeBU/7oKp3sd9Yb8P1IjLpPPuRg2jnXtEFf80aAcfnAFShU0Hs16O9pDXGOFnW rSAINNzUMIp3DB7A9H6/+Zyk97zlfwoXRt4OAb0i2aOiY9WxgmWSX+6dW+eeMV2pQaOA fEGfBE+lFzrGHO67WVb2vThO6V0CBP2JybODSvdU/ECqWRv1qX63UOz6gnuc/gxMpwDH 4bSHlaeNXYefl2xv4oAKOfrru8F0E51aszAzm4catEBfWfI0zhuJ5yIPtQg+yEdqzA95 li6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dPFanE1lIcKEepsAUbmGII6ZIu97CogO7PEHfoCPYow=; b=rV6FjRE6O2Gp9Dmu2c6/MYSNywWHgZ9jxhsO8RW7jWUwIL5OIpjUgB8Wt60ndF5Mc8 TKwXkoJKH5L0IrtPFTDxMiFaxr5YCpn+ufAhqfk6O+vcf6jnP7mUdQrr5XZTcZgeg0nV LkrFYYBCZE5EVDnh81cF5qkvqvyCew+YVJMHVI3GwCCaFaMM8Kt3A54kBCdAKw+Gha1B d2P+T1KmDWu/+C//OdldLa7TfqKiTklsxYKCGNGxt0SGn5nmS7ySVQLorazWorNCP82y /YgM3RHEzoJ7rBtoGgIiYAHbTdwvfOjwfEecMiV1NFfPzCBWjYS9goHJfeSF7qhMKhi+ 72og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pJYbG6Mz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jm13-20020a17090304cd00b001966c8c2890si6494017plb.592.2023.02.01.21.30.29; Wed, 01 Feb 2023 21:30:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pJYbG6Mz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232148AbjBBF3T (ORCPT + 99 others); Thu, 2 Feb 2023 00:29:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231956AbjBBF20 (ORCPT ); Thu, 2 Feb 2023 00:28:26 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1236A298E0; Wed, 1 Feb 2023 21:28:12 -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 9ABBBB824B4; Thu, 2 Feb 2023 05:28:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B7FBC4339E; Thu, 2 Feb 2023 05:28:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315690; bh=jO10o07RAKyXXgWsy3XBxX0WTtST48LzT0RY2uOU2ZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pJYbG6MzdPYF9ZY0ifhKKBtcGhNXI2gHdLLRsG6lZ7zYJTR7u1LSKcuhBEFoqyKcH p+BWD8sd/qQCJafibLWpr3F2wISNeLXhmvZySVrFSeBE+E7vGRYalDN1K6RbWFla21 DuphVx+RBCz5e1eYPEKmJTZNeABF1nEtwyP0ZajQQ6zRO95PiGcpU+heUpFCN42LF7 Tqy+hGnTPvn3FeuIjxEW5DYJFzwNDYyosw+Wz//a62eWcsI0kugaBUw4VfUKw6nH+s jwBwYIVlCN8SUAvFxf8HkV1OOn8hTsvylv6Qdbi/B8a7l++NTQ7Pc5/3gDSs4oaokG UZVWTdlP5qJmA== 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.19 15/16] docs: Fix path paste-o for /sys/kernel/warn_count Date: Wed, 1 Feb 2023 21:26:03 -0800 Message-Id: <20230202052604.179184-16-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695982819059936?= X-GMAIL-MSGID: =?utf-8?q?1756695982819059936?= 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:26: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: 51701 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp52694wrn; Wed, 1 Feb 2023 21:30:13 -0800 (PST) X-Google-Smtp-Source: AK7set80b32i7PPoRuH9Ul+8shEnb0a9+JdeIlGDz+llUWRPLwefOKsXpOj2oBpK0ux0ZOJEjunZ X-Received: by 2002:a17:902:d2ca:b0:198:68b1:6251 with SMTP id n10-20020a170902d2ca00b0019868b16251mr7614138plc.4.1675315813468; Wed, 01 Feb 2023 21:30:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675315813; cv=none; d=google.com; s=arc-20160816; b=B4VB7XlDB/Qqlvk/d1gjVgPm16i0o6XYw+dzJwVlQeuMcNX0xIuDdUPEV3JERxEIbN ur4hrD9m2y34B+L+QDb4JjLFPX+sUUbf6rdIdsUjQtwZOXQZHI/iaowRiPNgs99MJyNm XjFcZb49HI5VPqnwOoPuQ66TlHcRHZMUJ3ns2J9C3plWO3zb2T6N/sm3TVoVxdLxH7R2 +0b8xuRVZ5VSpIUg43HQjGh1zW4QlPOAwfP/708aWNGaEDUSWIIR4aNGSCfGOa/DdfIj 1DThcN8swsmb1X8gG1pRasDCnJPIasVYFdGwK+xBj38iPuzE/8UL2YTj66bVxtVUnGgo uOFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=raj1TKjTjDopzSOlHF4NjFCu79RyIcAXg5P6JScheNY=; b=Fh8Ms7yhSYgtkbIBQiAmFTr+sEXPQ4U3H8P8HvDhRCs8OSeZ7UC9gJt1da+csEZapo p2hfYsEc0va5/SNv1wESt4omfASoC6QamRV19XXFungI3TKGfgUjDo9+LJyu+4j9F47w YmVrVUoL/97OQQNsR1fzragyuAEbGT19myEKIIgWTcptdZxU7AUfLUqmCZQ+E0RYcOVj 8hdD+D0pCVXnygvUj6TpV7a15wtWadLdkDGwBXqsZj2WPkTPBcB+BvZL4WIsLA9FsJQU Df0mY73rEEw7QWca2ss6kWLCLaNQDHuX4yqgKlLnWxz0gl1vECtnWRS2c1gN1ehSC3iZ VtRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NjC6Herw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h19-20020a170902f2d300b001926fcc7389si9078357plc.424.2023.02.01.21.30.01; Wed, 01 Feb 2023 21:30:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NjC6Herw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232161AbjBBF3V (ORCPT + 99 others); Thu, 2 Feb 2023 00:29:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231970AbjBBF20 (ORCPT ); Thu, 2 Feb 2023 00:28:26 -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 AD39827998; Wed, 1 Feb 2023 21:28:11 -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 8EA94615EF; Thu, 2 Feb 2023 05:28:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A436C433A1; Thu, 2 Feb 2023 05:28:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675315691; bh=lcs6AXLIFbqkFs6UrWf0Ln1qRWrFsNHR0PXy8tOjKNA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NjC6HerwNYZpDQWHNMEAMOutZtfItpkk143ioeMYmoqxhu5m9RxsfveJYd/9divWh UH1XXeS0GcumS5+3MeUPWE8d7Db4xX1OT0WvLTfXkHMiX3BV92mW9H3upzxduZEEM1 5dmleyl/4f0zT0C2WUinAVirG4+tKVnfWDEVkR9CNKwPeeqY/48sDwPno66qEplyOU 4KcCTTJmup/jgGr6P2U3PXtWnKmL0crqJ+xDqn9KZ9Glogzq7NIUN0iEfSzqwqA9Ak VGBIFaqph4V6WR5JffrXP2Ii1HHVozu15LGGi659U/e+etSoGfvRccQP334dNzKPMf cfN/e1iF17j6g== 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.19 16/16] exit: Use READ_ONCE() for all oops/warn limit reads Date: Wed, 1 Feb 2023 21:26:04 -0800 Message-Id: <20230202052604.179184-17-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202052604.179184-1-ebiggers@kernel.org> References: <20230202052604.179184-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756695954682326886?= X-GMAIL-MSGID: =?utf-8?q?1756695954682326886?= 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 b2f0aaf6bee78..02360ec3b1225 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -975,6 +975,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 @@ -986,8 +987,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 dbb6e27d33e10..982ecba286c08 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -168,12 +168,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); } /**