From patchwork Thu Feb 2 04:42: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: 51680 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp37778wrn; Wed, 1 Feb 2023 20:46:15 -0800 (PST) X-Google-Smtp-Source: AK7set8CGhoh6Gv4GYrlPZF+zFsSFCbddnGR/4+DkskVx4hf0r42UstsDeN8/LtVxyiMYvnQKrf8 X-Received: by 2002:a05:6a20:2a0f:b0:bf:4563:e647 with SMTP id e15-20020a056a202a0f00b000bf4563e647mr4216221pzh.40.1675313175627; Wed, 01 Feb 2023 20:46:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675313175; cv=none; d=google.com; s=arc-20160816; b=IQ/I5BedLUMxGTfOVF3sswcQeB5Z51fBc0vBZbGeXdPaNPpNY7/YgyTi3zr2P9S9ad 7psxUXZ4crLXdk6g8aJ47zy+xyekcCF4CLGvqEjwknkq+blmTXtEna1MPnbWNc26R2kk x1Z5/v13IU16LRms5+aINnhG+bddkjcNZmJO1XuV0a9bbk1YQJV2wXrD+ZJyiIffQE0r X8/2qturxOmZQMQ2ia19leGct91y8ZK/b+ruMStwfMi9N+ixG4ScXY1xiittv3ezKyGB 5eRFcPDMTJ4vb7M5h/QfiiiiMMgxF0FGaZGfVyeAzqeUePatftLJRTb6q7Ykzkd1nkgz mQJQ== 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=o0lx7EbwtycnKw9wBcQaAg1UuCEdMv8tTJYAD1BRee8=; b=wI7GOF3tmv0hmwTu/IuzcW7ibmZlyZCI7GSKTEV9k1I2+cXD81uTXxtaFiKWNAhjjc Cz3X7zYPCxSxFroiRUxeKGfafdlb9F+3xZLe+8KfCrRi48FvRYJVf7qfvN8YoZXwElI+ Z/oLSjemPnaosGIZUc5YdU/51pZekNmol9fcub8MacpRKXg+beVFG9sFBVBDmFLLZ/IS zEuFaS2bu/kD3OELiDIyhZ50eIq3RanYBHyUVtq2KR44uOMwL3nATZN0Wxv6qCafGEKT h8YiADs5JicfrA7PnLSdMxnK8r1E18nM+gZuNnlDHuORUCIoTcO7aODpEn1vqmYVorc1 IXhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GQtBzWYu; 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 bu21-20020a632955000000b004df6beb6e39si19616244pgb.683.2023.02.01.20.46.03; Wed, 01 Feb 2023 20:46: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=GQtBzWYu; 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 S231895AbjBBEpb (ORCPT + 99 others); Wed, 1 Feb 2023 23:45:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231612AbjBBEoa (ORCPT ); Wed, 1 Feb 2023 23:44:30 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B2887AE50; Wed, 1 Feb 2023 20:43:56 -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 034E861A01; Thu, 2 Feb 2023 04:43:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A00FC433A8; Thu, 2 Feb 2023 04:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675313035; bh=F0/lM0ehn2dBgPa8cBm0sLlTTLRWC+SL/tZ/GpO45lI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GQtBzWYu3FDPs3gks4gvD/ybtlukRJG4c4dOKW7kzFU1ctOO2lNJEQWeJbIJxWbAA gGlcK/yq474y5U4bJ1NVNdZQsvnJW6C3cpeAim6F4VLimHMjAmBd33pfvXw7NrcBjC mp7HVlBF/cubFD+1F4PZVc/FsKFwLa2aeQSLardlN1xUP44b/fcvoNmHZwCN3qPVmE VwusoFBGesu2lBYOu6r6PpcUypI60Rl37TFFkXuZO2p5NzIb/fpqbWfjly51WAveAg X8tkRZkF7GyEu/EjtE6fZsJ8FfOssaUWl0H6w5bO5nPVIPf6+gku8a3c3QAI6B4vAL PM/hs1uYoPMRw== 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 5.4 15/17] panic: Expose "warn_count" to sysfs Date: Wed, 1 Feb 2023 20:42:53 -0800 Message-Id: <20230202044255.128815-16-ebiggers@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230202044255.128815-1-ebiggers@kernel.org> References: <20230202044255.128815-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?1756693188689783828?= X-GMAIL-MSGID: =?utf-8?q?1756693188689783828?= 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 8f72305dd501d..2c118645e7408 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #define PANIC_TIMER_STEP 100 @@ -81,6 +82,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; @@ -179,8 +199,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);