From patchwork Tue Jan 24 19:29: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: 47868 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2337448wrn; Tue, 24 Jan 2023 11:36:35 -0800 (PST) X-Google-Smtp-Source: AK7set8vJ3zaqA1P+j18Tx2YNIqMPaoLkdNwRYQOyEEbrgKvw6CkZdyd6dutcwJbzdwZ1arZCaUg X-Received: by 2002:a17:902:e542:b0:196:d0a:fa46 with SMTP id n2-20020a170902e54200b001960d0afa46mr6451761plf.27.1674588994507; Tue, 24 Jan 2023 11:36:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674588994; cv=none; d=google.com; s=arc-20160816; b=A31m07YnUhptp8sW3jAQP+1A+InQ9pNbQyWFRv+7WfOEyR4GckPmMPN2GseKBfo1s1 T1BTl9tlKmK/ODZikDr50pOV7Rgr4IKbOBzVQuMc7Cd6uwODNDFvQNV/G2j37Do0WInG PohO/hn/sDIaczglOaCRisovZ5iEwLdEu2+SiQe3cblZNg2jlpQmSba+lvY2Jd8JcPj6 ZrSGAOpxVSv33THi2XX00nmA6DliO7jBFM7HYJOit7abq7+F7tUkTczWrKz7RPkWON+8 hXiE2ML9j2qBuT8b2Z6DLbLtPV+Rqhqq1iV9DCyjUgLDrqIP+/scEednXB8kh6xdc2Ic 84Og== 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=IbQWmbSog0cAUtGM2TpTpDFiT8kTlEBKGAdSKvMjHvw=; b=Xk0zCoPGfAkGvupqTsZ2A8Fn5gDcFEZiLyqbr50egqJneQvSsIXzlVme73gaWYj6Gg Yigo8YIyGTP4frnFomSs0Bt5kU3kcZuh+NneeAlA5UOohHgqsSgg6SFZ8+U6ieWMziJe V+PiMCXoYaEMg8FnYW1ss/I4fqI02P8MjX3NL0f4g6xqdVtjw8GDo/D2H8x0Glae6A4u I7JdtvdmPrgjC0sIYQ7e5rwnsSJTMxTTD3RcwKurZKvxOOS/5q8Iouas/BPCL1hqAsrA bmyzaqJfVhx+KVgM5tR86ZBkxpF+Ui3e5mjdEl/oKMKzcXcJzj+1M3SNq/5WhwpFe4Oc wmYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lQGWnkLN; 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 y17-20020a63b511000000b0049f1702457bsi2783628pge.685.2023.01.24.11.36.22; Tue, 24 Jan 2023 11:36:34 -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=lQGWnkLN; 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 S234840AbjAXTgC (ORCPT + 99 others); Tue, 24 Jan 2023 14:36:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234367AbjAXTfY (ORCPT ); Tue, 24 Jan 2023 14:35:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A54DADBF2; Tue, 24 Jan 2023 11:35:23 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2C87F61347; Tue, 24 Jan 2023 19:35:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42649C433D2; Tue, 24 Jan 2023 19:35:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674588922; bh=6t6f3jXEKls3E1tdtYCAnI7LHjKYAYFJlGQw+/uTZXY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lQGWnkLNPH5MqlpPsn+XsyN1wraqWuxJVY1GFDRsEhznR/cIM4UUCbmLcMbP13cQr f1q6VQswLFOWq5CVsZ3m915ibihp8/ygmS6SrxPliPs0BUD6xAb38wGSUWNUkn5dUS NEMgt8IuRNVOCCqr4AzXbEVh1T//9tZ0YxCRiffo/RvdJzP9zcs6OQpuvCVEN9YirM HjlyMvj9pbk16fo0Xqa3CnJrZVnO/LA2hPa4U+uN8CBZzi1cxGQMYRJ5/GBXm5rQU5 peX8QDaw6mQxFjSLis4touFVGPp6wIgBwwvMfTKiSgoe47MZAijoqtE/31RnQWKSB1 KXdPlyVDgFlEg== 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, Arnd Bergmann , Luis Chamberlain Subject: [PATCH 5.10 14/20] exit: Expose "oops_count" to sysfs Date: Tue, 24 Jan 2023 11:29:58 -0800 Message-Id: <20230124193004.206841-15-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?1755933829548551105?= X-GMAIL-MSGID: =?utf-8?q?1755933829548551105?= 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 db832cff6b7b2..b519abee2c541 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include @@ -96,6 +97,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--; @@ -892,8 +912,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.