Skip to content

Commit 9fc9e27

Browse files
committed
panic: Introduce warn_limit
Like oops_limit, add warn_limit for limiting the number of warnings when panic_on_warn is not set. Cc: Jonathan Corbet <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Baolin Wang <[email protected]> Cc: "Jason A. Donenfeld" <[email protected]> Cc: Eric Biggers <[email protected]> Cc: Huang Ying <[email protected]> Cc: Petr Mladek <[email protected]> Cc: tangmeng <[email protected]> Cc: "Guilherme G. Piccoli" <[email protected]> Cc: Tiezhu Yang <[email protected]> Cc: Sebastian Andrzej Siewior <[email protected]> Cc: [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 79cc1ba commit 9fc9e27

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Documentation/admin-guide/sysctl/kernel.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,16 @@ entry will default to 2 instead of 0.
15091509
2 Unprivileged calls to ``bpf()`` are disabled
15101510
= =============================================================
15111511

1512+
1513+
warn_limit
1514+
==========
1515+
1516+
Number of kernel warnings after which the kernel should panic when
1517+
``panic_on_warn`` is not set. Setting this to 0 disables checking
1518+
the warning count. Setting this to 1 has the same effect as setting
1519+
``panic_on_warn=1``. The default value is 0.
1520+
1521+
15121522
watchdog
15131523
========
15141524

kernel/panic.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ bool crash_kexec_post_notifiers;
5858
int panic_on_warn __read_mostly;
5959
unsigned long panic_on_taint;
6060
bool panic_on_taint_nousertaint = false;
61+
static unsigned int warn_limit __read_mostly;
6162

6263
int panic_timeout = CONFIG_PANIC_TIMEOUT;
6364
EXPORT_SYMBOL_GPL(panic_timeout);
@@ -88,6 +89,13 @@ static struct ctl_table kern_panic_table[] = {
8889
.extra2 = SYSCTL_ONE,
8990
},
9091
#endif
92+
{
93+
.procname = "warn_limit",
94+
.data = &warn_limit,
95+
.maxlen = sizeof(warn_limit),
96+
.mode = 0644,
97+
.proc_handler = proc_douintvec,
98+
},
9199
{ }
92100
};
93101

@@ -203,8 +211,14 @@ static void panic_print_sys_info(bool console_flush)
203211

204212
void check_panic_on_warn(const char *origin)
205213
{
214+
static atomic_t warn_count = ATOMIC_INIT(0);
215+
206216
if (panic_on_warn)
207217
panic("%s: panic_on_warn set ...\n", origin);
218+
219+
if (atomic_inc_return(&warn_count) >= READ_ONCE(warn_limit) && warn_limit)
220+
panic("%s: system warned too often (kernel.warn_limit is %d)",
221+
origin, warn_limit);
208222
}
209223

210224
/**

0 commit comments

Comments
 (0)