Skip to content

Commit 9db89b4

Browse files
committed
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" <[email protected]> Cc: Jann Horn <[email protected]> Cc: Arnd Bergmann <[email protected]> Reviewed-by: Luis Chamberlain <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d4ccd54 commit 9db89b4

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
What: /sys/kernel/oops_count
2+
Date: November 2022
3+
KernelVersion: 6.2.0
4+
Contact: Linux Kernel Hardening List <[email protected]>
5+
Description:
6+
Shows how many times the system has Oopsed since last boot.

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11106,6 +11106,7 @@ M: Kees Cook <[email protected]>
1110611106
1110711107
S: Supported
1110811108
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
1110911110
F: include/linux/overflow.h
1111011111
F: include/linux/randomize_kstack.h
1111111112
F: mm/usercopy.c

kernel/exit.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include <linux/io_uring.h>
6868
#include <linux/kprobes.h>
6969
#include <linux/rethook.h>
70+
#include <linux/sysfs.h>
7071

7172
#include <linux/uaccess.h>
7273
#include <asm/unistd.h>
@@ -99,6 +100,25 @@ static __init int kernel_exit_sysctls_init(void)
99100
late_initcall(kernel_exit_sysctls_init);
100101
#endif
101102

103+
static atomic_t oops_count = ATOMIC_INIT(0);
104+
105+
#ifdef CONFIG_SYSFS
106+
static ssize_t oops_count_show(struct kobject *kobj, struct kobj_attribute *attr,
107+
char *page)
108+
{
109+
return sysfs_emit(page, "%d\n", atomic_read(&oops_count));
110+
}
111+
112+
static struct kobj_attribute oops_count_attr = __ATTR_RO(oops_count);
113+
114+
static __init int kernel_exit_sysfs_init(void)
115+
{
116+
sysfs_add_file_to_group(kernel_kobj, &oops_count_attr.attr, NULL);
117+
return 0;
118+
}
119+
late_initcall(kernel_exit_sysfs_init);
120+
#endif
121+
102122
static void __unhash_process(struct task_struct *p, bool group_dead)
103123
{
104124
nr_threads--;
@@ -901,8 +921,6 @@ void __noreturn do_exit(long code)
901921

902922
void __noreturn make_task_dead(int signr)
903923
{
904-
static atomic_t oops_count = ATOMIC_INIT(0);
905-
906924
/*
907925
* Take the task off the cpu after something catastrophic has
908926
* happened.

0 commit comments

Comments
 (0)