Skip to content

Commit 8b05aa2

Browse files
committed
panic: Expose "warn_count" to sysfs
Since Warn count is now tracked and is a fairly interesting signal, add the entry /sys/kernel/warn_count to expose it to userspace. Cc: Petr Mladek <[email protected]> Cc: Andrew Morton <[email protected]> Cc: tangmeng <[email protected]> Cc: "Guilherme G. Piccoli" <[email protected]> Cc: Sebastian Andrzej Siewior <[email protected]> Cc: Tiezhu Yang <[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 9fc9e27 commit 8b05aa2

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 Warned since last boot.

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11107,6 +11107,7 @@ L: [email protected]
1110711107
S: Supported
1110811108
T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening
1110911109
F: Documentation/ABI/testing/sysfs-kernel-oops_count
11110+
F: Documentation/ABI/testing/sysfs-kernel-warn_count
1111011111
F: include/linux/overflow.h
1111111112
F: include/linux/randomize_kstack.h
1111211113
F: mm/usercopy.c

kernel/panic.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/bug.h>
3333
#include <linux/ratelimit.h>
3434
#include <linux/debugfs.h>
35+
#include <linux/sysfs.h>
3536
#include <trace/events/error_report.h>
3637
#include <asm/sections.h>
3738

@@ -107,6 +108,25 @@ static __init int kernel_panic_sysctls_init(void)
107108
late_initcall(kernel_panic_sysctls_init);
108109
#endif
109110

111+
static atomic_t warn_count = ATOMIC_INIT(0);
112+
113+
#ifdef CONFIG_SYSFS
114+
static ssize_t warn_count_show(struct kobject *kobj, struct kobj_attribute *attr,
115+
char *page)
116+
{
117+
return sysfs_emit(page, "%d\n", atomic_read(&warn_count));
118+
}
119+
120+
static struct kobj_attribute warn_count_attr = __ATTR_RO(warn_count);
121+
122+
static __init int kernel_panic_sysfs_init(void)
123+
{
124+
sysfs_add_file_to_group(kernel_kobj, &warn_count_attr.attr, NULL);
125+
return 0;
126+
}
127+
late_initcall(kernel_panic_sysfs_init);
128+
#endif
129+
110130
static long no_blink(int state)
111131
{
112132
return 0;
@@ -211,8 +231,6 @@ static void panic_print_sys_info(bool console_flush)
211231

212232
void check_panic_on_warn(const char *origin)
213233
{
214-
static atomic_t warn_count = ATOMIC_INIT(0);
215-
216234
if (panic_on_warn)
217235
panic("%s: panic_on_warn set ...\n", origin);
218236

0 commit comments

Comments
 (0)