Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

exit: Expose "oops_count" to sysfs

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" <ebiederm@xmission.com>
Cc: Jann Horn <jannh@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20221117234328.594699-3-keescook@chromium.org

+27 -2
+6
Documentation/ABI/testing/sysfs-kernel-oops_count
··· 1 + What: /sys/kernel/oops_count 2 + Date: November 2022 3 + KernelVersion: 6.2.0 4 + Contact: Linux Kernel Hardening List <linux-hardening@vger.kernel.org> 5 + Description: 6 + Shows how many times the system has Oopsed since last boot.
+1
MAINTAINERS
··· 11106 11106 L: linux-hardening@vger.kernel.org 11107 11107 S: Supported 11108 11108 T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening 11109 + F: Documentation/ABI/testing/sysfs-kernel-oops_count 11109 11110 F: include/linux/overflow.h 11110 11111 F: include/linux/randomize_kstack.h 11111 11112 F: mm/usercopy.c
+20 -2
kernel/exit.c
··· 67 67 #include <linux/io_uring.h> 68 68 #include <linux/kprobes.h> 69 69 #include <linux/rethook.h> 70 + #include <linux/sysfs.h> 70 71 71 72 #include <linux/uaccess.h> 72 73 #include <asm/unistd.h> ··· 98 97 return 0; 99 98 } 100 99 late_initcall(kernel_exit_sysctls_init); 100 + #endif 101 + 102 + static atomic_t oops_count = ATOMIC_INIT(0); 103 + 104 + #ifdef CONFIG_SYSFS 105 + static ssize_t oops_count_show(struct kobject *kobj, struct kobj_attribute *attr, 106 + char *page) 107 + { 108 + return sysfs_emit(page, "%d\n", atomic_read(&oops_count)); 109 + } 110 + 111 + static struct kobj_attribute oops_count_attr = __ATTR_RO(oops_count); 112 + 113 + static __init int kernel_exit_sysfs_init(void) 114 + { 115 + sysfs_add_file_to_group(kernel_kobj, &oops_count_attr.attr, NULL); 116 + return 0; 117 + } 118 + late_initcall(kernel_exit_sysfs_init); 101 119 #endif 102 120 103 121 static void __unhash_process(struct task_struct *p, bool group_dead) ··· 921 901 922 902 void __noreturn make_task_dead(int signr) 923 903 { 924 - static atomic_t oops_count = ATOMIC_INIT(0); 925 - 926 904 /* 927 905 * Take the task off the cpu after something catastrophic has 928 906 * happened.