Skip to content

Commit 79cc1ba

Browse files
committed
panic: Consolidate open-coded panic_on_warn checks
Several run-time checkers (KASAN, UBSAN, KFENCE, KCSAN, sched) roll their own warnings, and each check "panic_on_warn". Consolidate this into a single function so that future instrumentation can be added in a single location. Cc: Marco Elver <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Juri Lelli <[email protected]> Cc: Vincent Guittot <[email protected]> Cc: Dietmar Eggemann <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Ben Segall <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Daniel Bristot de Oliveira <[email protected]> Cc: Valentin Schneider <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Vincenzo Frascino <[email protected]> Cc: Andrew Morton <[email protected]> Cc: David Gow <[email protected]> Cc: tangmeng <[email protected]> Cc: Jann Horn <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Petr Mladek <[email protected]> Cc: "Paul E. McKenney" <[email protected]> Cc: Sebastian Andrzej Siewior <[email protected]> Cc: "Guilherme G. Piccoli" <[email protected]> Cc: Tiezhu Yang <[email protected]> Cc: [email protected] Cc: [email protected] Reviewed-by: Luis Chamberlain <[email protected]> Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Marco Elver <[email protected]> Reviewed-by: Andrey Konovalov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent de92f65 commit 79cc1ba

File tree

7 files changed

+14
-12
lines changed

7 files changed

+14
-12
lines changed

include/linux/panic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern long (*panic_blink)(int state);
1111
__printf(1, 2)
1212
void panic(const char *fmt, ...) __noreturn __cold;
1313
void nmi_panic(struct pt_regs *regs, const char *msg);
14+
void check_panic_on_warn(const char *origin);
1415
extern void oops_enter(void);
1516
extern void oops_exit(void);
1617
extern bool oops_may_print(void);

kernel/kcsan/report.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,7 @@ static void print_report(enum kcsan_value_change value_change,
492492
dump_stack_print_info(KERN_DEFAULT);
493493
pr_err("==================================================================\n");
494494

495-
if (panic_on_warn)
496-
panic("panic_on_warn set ...\n");
495+
check_panic_on_warn("KCSAN");
497496
}
498497

499498
static void release_report(unsigned long *flags, struct other_info *other_info)

kernel/panic.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ static void panic_print_sys_info(bool console_flush)
201201
ftrace_dump(DUMP_ALL);
202202
}
203203

204+
void check_panic_on_warn(const char *origin)
205+
{
206+
if (panic_on_warn)
207+
panic("%s: panic_on_warn set ...\n", origin);
208+
}
209+
204210
/**
205211
* panic - halt the system
206212
* @fmt: The text string to print
@@ -619,8 +625,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
619625
if (regs)
620626
show_regs(regs);
621627

622-
if (panic_on_warn)
623-
panic("panic_on_warn set ...\n");
628+
check_panic_on_warn("kernel");
624629

625630
if (!regs)
626631
dump_stack();

kernel/sched/core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5729,8 +5729,7 @@ static noinline void __schedule_bug(struct task_struct *prev)
57295729
pr_err("Preemption disabled at:");
57305730
print_ip_sym(KERN_ERR, preempt_disable_ip);
57315731
}
5732-
if (panic_on_warn)
5733-
panic("scheduling while atomic\n");
5732+
check_panic_on_warn("scheduling while atomic");
57345733

57355734
dump_stack();
57365735
add_taint(TAINT_WARN, LOCKDEP_STILL_OK);

lib/ubsan.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ static void ubsan_epilogue(void)
154154

155155
current->in_ubsan--;
156156

157-
if (panic_on_warn)
158-
panic("panic_on_warn set ...\n");
157+
check_panic_on_warn("UBSAN");
159158
}
160159

161160
void __ubsan_handle_divrem_overflow(void *_data, void *lhs, void *rhs)

mm/kasan/report.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ static void end_report(unsigned long *flags, void *addr)
164164
(unsigned long)addr);
165165
pr_err("==================================================================\n");
166166
spin_unlock_irqrestore(&report_lock, *flags);
167-
if (panic_on_warn && !test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags))
168-
panic("panic_on_warn set ...\n");
167+
if (!test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags))
168+
check_panic_on_warn("KASAN");
169169
if (kasan_arg_fault == KASAN_ARG_FAULT_PANIC)
170170
panic("kasan.fault=panic set ...\n");
171171
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);

mm/kfence/report.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ void kfence_report_error(unsigned long address, bool is_write, struct pt_regs *r
268268

269269
lockdep_on();
270270

271-
if (panic_on_warn)
272-
panic("panic_on_warn set ...\n");
271+
check_panic_on_warn("KFENCE");
273272

274273
/* We encountered a memory safety error, taint the kernel! */
275274
add_taint(TAINT_BAD_PAGE, LOCKDEP_STILL_OK);

0 commit comments

Comments
 (0)