From patchwork Thu Nov 17 23:43:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13047482 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 794E8C4321E for ; Thu, 17 Nov 2022 23:43:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4967C8E0006; Thu, 17 Nov 2022 18:43:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D0E18E0002; Thu, 17 Nov 2022 18:43:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 271798E0006; Thu, 17 Nov 2022 18:43:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 12F2E8E0002 for ; Thu, 17 Nov 2022 18:43:34 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D9308AB388 for ; Thu, 17 Nov 2022 23:43:33 +0000 (UTC) X-FDA: 80144563506.16.1381697 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf23.hostedemail.com (Postfix) with ESMTP id 84DEB140005 for ; Thu, 17 Nov 2022 23:43:32 +0000 (UTC) Received: by mail-pf1-f179.google.com with SMTP id d192so3337170pfd.0 for ; Thu, 17 Nov 2022 15:43:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jEctX2gK/ElW3R9ceKOIZ71qq6p0GHil0cFCvNxx9OU=; b=g/cPhiEF39Jvwi7g1+Xq/pr38nMj44Nu7s3aqvgVZ1DuDpYFoo3QSUKLFZp+RMwqwL g5oKfoC/3yNkyhPPEKYdkg/utc2TP4MAjs/KblO7vXyah7+sZr2ylyYvIb8fIxIUDBNi KVyAxBdO6D26J0+lG5kgCcL5Y7eu/9gjkucTM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jEctX2gK/ElW3R9ceKOIZ71qq6p0GHil0cFCvNxx9OU=; b=XaJMPh8fcWwDCAjAsv6oq4IB35JuHXd7x7pM7PscclJPq2F5FJHA6pyTJ7xmoS4+rX cMFhHipwrT9JBXZIO2hNbdV6j2Xni04TpJxQrdAS4KM6zYRN/9GmrrmaFaqu+Qjq/j9u 5X0QEeQXSWML/qYsYYqBZ/Yvv8mGg0cJ09bwaCMvKyd/p4i6G0ARPYkqC87Hi37PBp5l Qfr863FuZyD0waLI/1rBFYxiFU2sLrwuAkMKIaLD0hfBG9ipJBoSoYCKlrYDzALl7L6r JSom4Puvi3uBlF2VejebbvcQUGnNdIGxH2AynrQ8EzoBXtnEJ7UgLL8/Bwz71BynspkB bfJQ== X-Gm-Message-State: ANoB5pnvS+1QdQFtPsqic2i8f0RBZzpLSKXuy8dd85A+XOgthklCkuRd iHK48/ZNLOQBn9f9pc/nUNe15Q== X-Google-Smtp-Source: AA0mqf4M/o7GhXpsftplQmBpm+8mjuCK9Jc0JOK5XP71hY2vvCFVWcsgoDClF4tpNfGyM5thbqjLnQ== X-Received: by 2002:aa7:92d3:0:b0:571:fa1d:85b7 with SMTP id k19-20020aa792d3000000b00571fa1d85b7mr5205770pfa.39.1668728611497; Thu, 17 Nov 2022 15:43:31 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id a27-20020aa794bb000000b0056e8eb09d57sm1740441pfl.63.2022.11.17.15.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 15:43:29 -0800 (PST) From: Kees Cook To: Jann Horn Cc: Kees Cook , "Eric W. Biederman" , Arnd Bergmann , Luis Chamberlain , Seth Jenkins , Greg KH , Linus Torvalds , Andy Lutomirski , Andrew Morton , tangmeng , "Guilherme G. Piccoli" , Tiezhu Yang , Sebastian Andrzej Siewior , Dmitry Vyukov , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Daniel Bristot de Oliveira , Valentin Schneider , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Vincenzo Frascino , David Gow , "Paul E. McKenney" , Jonathan Corbet , Baolin Wang , "Jason A. Donenfeld" , Eric Biggers , Huang Ying , Anton Vorontsov , Mauro Carvalho Chehab , Laurent Dufour , Rob Herring , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v3 3/6] exit: Expose "oops_count" to sysfs Date: Thu, 17 Nov 2022 15:43:23 -0800 Message-Id: <20221117234328.594699-3-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221117233838.give.484-kees@kernel.org> References: <20221117233838.give.484-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2942; h=from:subject; bh=6N9/v4YXpaCj0jy2bGs74rqpXsiLoI6QvjFrvLVEdiU=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjdscdh2yxsYpUSBCFMx+XWPrp5jq3lGnveBJJoWti eB8Nl9WJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCY3bHHQAKCRCJcvTf3G3AJjt4EA CjpotPoy23FlY4Qe6SzOgM/fewK8Qusqvop3tumZYb1OmUZ3CgaaTE15vdIUaf/nsyYtA1FhiPGV/U YQy1UTWXdQA2wt++NQZfMTdEMdmBItLvn+FAGrDmZpojr50i2xvPqQ4ZlTzhRzMA4NgWg+La/tm6rj rrsKc6k4YwSUes7KJWCF2R81GXMgfp2I13qsOUoqTmeeoWTkj9NQDzd+tbrjQ3C4gdqQUywUnDjZth U2HhrYciP9QXml569OiVFVdJqdk5r06EornXt5+0ffDu464SSxJdveFq11X9OGsM93M1T0Ct0tTfTD jCaFKZm4SdH8BPjWDdZd8WV1oscg2YS+C0ZlJ1IIHmRbDOeyPpsZyHgSzry1ErZrI++9xrESX6Rnk9 WFfS6UoZwKN6RXQFCh8dszPl/D23nHXp0TcN9D352o4kt4QnP8NrMRHB2c4akAbPZVmrBJrWhTFS7A IFJforSkglRfDq1Q4pY+zYhYCHA0IcvyOXU8zHLrw3SiT79IM/ELZb5Vif026dvQAFGc2H2zhqtJsA IPMHAhfLn32+WmGmgb3y8FYwiPnuNtRPq3hPthUqpNGpteOifZBwly3+o0FnPEoLYzAIRHq5tDL10c Sq+p7wxTwnoc9TVGptRmQKHqr92CO9QKe0gKg2UpDHcOAlTJ5znFcTS2wcxQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668728612; a=rsa-sha256; cv=none; b=o+5vYIyLXOjBv8PZeR91c6i3o2zNTHp7D05qjvzxaxUqn2OnHqwGI3dr7Kkd0M/KtFojci ACeg0DlyKVntwGaYXVvq1+WbKGgoNc/blu8oafVS1t47nbw9eLo3pL/a04r4IWEOZfsapC 7ks8NZPh191OKNRekeIeeZkgfOKxIoE= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="g/cPhiEF"; spf=pass (imf23.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.179 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668728612; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jEctX2gK/ElW3R9ceKOIZ71qq6p0GHil0cFCvNxx9OU=; b=PyzyvqIG8PxxiE0uJ9M2J2r/3YG0PMSFW8uL+6zNO+OieHCYUhrLI8zGhiTeaZrehvxhKX PGAD7jdz6boCdSknr82kQkBOKzEMHpKCg7L+GEcLMxnqFbfrr+dEgfwiMTooPCTtzJkLqc PFb9MBgRI3hKas5aD04DGGL0IKkUiW8= X-Stat-Signature: puryw5ky7jk394t6rebjcehtzf7jadpo X-Rspamd-Queue-Id: 84DEB140005 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="g/cPhiEF"; spf=pass (imf23.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.179 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1668728612-834661 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- .../ABI/testing/sysfs-kernel-oops_count | 6 +++++ MAINTAINERS | 1 + kernel/exit.c | 22 +++++++++++++++++-- 3 files changed, 27 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 000000000000..156cca9dbc96 --- /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/MAINTAINERS b/MAINTAINERS index 1cd80c113721..0a1e95a58e54 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11106,6 +11106,7 @@ M: Kees Cook L: linux-hardening@vger.kernel.org S: Supported T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening +F: Documentation/ABI/testing/sysfs-kernel-oops_count F: include/linux/overflow.h F: include/linux/randomize_kstack.h F: mm/usercopy.c diff --git a/kernel/exit.c b/kernel/exit.c index 799c5edd6be6..bc62bfe75bc7 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -67,6 +67,7 @@ #include #include #include +#include #include #include @@ -99,6 +100,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--; @@ -901,8 +921,6 @@ void __noreturn do_exit(long code) 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.