From patchwork Tue Jan 24 19:30: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: 47874 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2337749wrn; Tue, 24 Jan 2023 11:37:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXsVcFhUtysjB8toobHpT36ipH9KM+sxj3RDJsrLnpo+e11GepIeq+r+tVfpKBsE9pOJEqdw X-Received: by 2002:a17:906:6d99:b0:870:58ae:842e with SMTP id h25-20020a1709066d9900b0087058ae842emr29245149ejt.24.1674589045786; Tue, 24 Jan 2023 11:37:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674589045; cv=none; d=google.com; s=arc-20160816; b=R5/LIQLB1Gj2r3C03LCnXJdbzuT2Njc5cYLBUj/GxUthJ8OLaFaOVY54N5JcpF5Xhw LvsVRIouSFax7sZuvaBDCuGY8z5bNx0viyUa6CUjGgAgYSxBYnncl4ral4hROgIHjZd7 HlZ2X+oDLEqwp4c5TtYjzccQIyzcQpv0SacGFkUbhzQkqmsCDKGFE0dFDfAPm+B7mffz noimFTdRXPztEPGhV2rpfkAmAGjhQP55r21T1Z/p2rf0GAFETe0DZ8gxuFLDczTPp9kN 191XvqXhtY9kkJqoo1CPUMATy6gPlBwZkYoCgSUVP7nSUBzLTk+fv4WW2iK5uL6fa7Vr WxcQ== 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=3/KJqUrTfvruKDz35bvIh35F58aIgMSgt+Z26rpJdgA=; b=V+oTTEflVy7YsP3z4bVNty5cE4zjkM+WXUtNtAgbCXkjpFO4UUIhIFmNnG+OYDj2ie vremP0Ll+R81mVktT6KP2RW0wrnZxXZAzOPwfSOBHOuQWG7ZbxyJJDvRJ05L7Mh/9xEg AfMJ49yX32TageKzJZxjgT6CjXZInZ/u2iBOyYvr983a1MdRhSNaCZAynUoMaWiTjMrI Sq1Tl58hjoMQqDcCcKb2flIMvM9InYRNX8eMAb1PmWqWn9itqlyO4NFePB5Ln4dCHHqc Ky/RVZ3QOkQI8WHPeVJ1P51ux/R9pRWppVIRIWoNJzZ/llfBXXOWzs/HZIHkzOFpxUpb Sgiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OxZbmFtJ; 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 vw4-20020a170907058400b008699e402620si2976299ejb.518.2023.01.24.11.37.01; Tue, 24 Jan 2023 11:37: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=OxZbmFtJ; 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 S234187AbjAXTgc (ORCPT + 99 others); Tue, 24 Jan 2023 14:36:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234745AbjAXTfk (ORCPT ); Tue, 24 Jan 2023 14:35:40 -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 1FDE822A22; Tue, 24 Jan 2023 11:35:28 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3FE1EB815DA; Tue, 24 Jan 2023 19:35:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72053C433A0; Tue, 24 Jan 2023 19:35:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674588925; bh=upf6vrbB2iqM5yS6hjS4TpP3gQP9b55tufNSyIjyms8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OxZbmFtJLMBBpiC+ASagxMkdl7d/Sn+bHDMCGmWU6SYPDjzU9YcgnEUgRbdEbo/94 d5V5y9OOhRNNjyf92gJFlci8SeMe8A8XXrwaqfwWYE4MN1aykFiP1z0oD+PJUpjhaz kcsjag7+ICAATbL/YXugT075tqeWgZPJg8yopI5S5z9nGrnEQW3HIIJptpdzewUKOs /9Lt5LLROnhDP8bB6hOU2LBuUVN3kfoJB+QrXmro65Ti5uVTLM0bXyn49Dpu+5wqOM 0KvDCKlL4PY+1oEjyNaUfHMiPVzyiB+wD2tCJGq7TIxFwnlN7uxXKfBH+5uvud5u+/ EpO8zug7WTK7g== From: Eric Biggers To: stable@vger.kernel.org, Greg Kroah-Hartman Cc: 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 5.10 18/20] panic: Expose "warn_count" to sysfs Date: Tue, 24 Jan 2023 11:30:02 -0800 Message-Id: <20230124193004.206841-19-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230124193004.206841-1-ebiggers@kernel.org> References: <20230124193004.206841-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?1755933883459522378?= X-GMAIL-MSGID: =?utf-8?q?1755933883459522378?= 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 e341366bd3e8b..6e30455eb2e7c 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #define PANIC_TIMER_STEP 100 @@ -104,6 +105,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; @@ -202,8 +222,6 @@ static void panic_print_sys_info(void) 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);