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.