^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/kernel/panic.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * This function is used through-out the kernel (including mm and fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * to indicate a major problem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/debug_locks.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/sched/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/kgdb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/kmsg_dump.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/kallsyms.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/vt_kern.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/ftrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/kexec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/sysrq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/nmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/ratelimit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define PANIC_TIMER_STEP 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define PANIC_BLINK_SPD 18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * Should we dump all CPUs backtraces in an oops event?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * Defaults to 0, can be changed via sysctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned int __read_mostly sysctl_oops_all_cpu_backtrace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #endif /* CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int panic_on_oops = CONFIG_PANIC_ON_OOPS_VALUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static unsigned long tainted_mask =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) IS_ENABLED(CONFIG_GCC_PLUGIN_RANDSTRUCT) ? (1 << TAINT_RANDSTRUCT) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int pause_on_oops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static int pause_on_oops_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static DEFINE_SPINLOCK(pause_on_oops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) bool crash_kexec_post_notifiers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int panic_on_warn __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) unsigned long panic_on_taint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) bool panic_on_taint_nousertaint = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int panic_timeout = CONFIG_PANIC_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) EXPORT_SYMBOL_GPL(panic_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define PANIC_PRINT_TASK_INFO 0x00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define PANIC_PRINT_MEM_INFO 0x00000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define PANIC_PRINT_TIMER_INFO 0x00000004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define PANIC_PRINT_LOCK_INFO 0x00000008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define PANIC_PRINT_FTRACE_INFO 0x00000010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define PANIC_PRINT_ALL_PRINTK_MSG 0x00000020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) unsigned long panic_print;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) EXPORT_SYMBOL(panic_notifier_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static long no_blink(int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* Returns how long it waited in ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) long (*panic_blink)(int state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) EXPORT_SYMBOL(panic_blink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * Stop ourself in panic -- architecture code may override this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) void __weak panic_smp_self_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) while (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * Stop ourselves in NMI context if another CPU has already panicked. Arch code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * may override this to prepare for crash dumping, e.g. save regs info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) void __weak nmi_panic_self_stop(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) panic_smp_self_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * Stop other CPUs in panic. Architecture dependent code may override this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * with more suitable version. For example, if the architecture supports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * crash dump, it should save registers of each stopped CPU and disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * per-CPU features such as virtualization extensions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) void __weak crash_smp_send_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int cpus_stopped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * This function can be called twice in panic path, but obviously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * we execute this only once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (cpus_stopped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * Note smp_send_stop is the usual smp shutdown function, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * unfortunately means it may not be hardened to work in a panic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * situation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) smp_send_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) cpus_stopped = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * A variant of panic() called from NMI context. We return if we've already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * panicked on this CPU. If another CPU already panicked, loop in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * nmi_panic_self_stop() which can provide architecture dependent code such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * as saving register state for crash dump.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) void nmi_panic(struct pt_regs *regs, const char *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int old_cpu, cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) cpu = raw_smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (old_cpu == PANIC_CPU_INVALID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) panic("%s", msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) else if (old_cpu != cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) nmi_panic_self_stop(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) EXPORT_SYMBOL(nmi_panic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static void panic_print_sys_info(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) console_flush_on_panic(CONSOLE_REPLAY_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (panic_print & PANIC_PRINT_TASK_INFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) show_state();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (panic_print & PANIC_PRINT_MEM_INFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) show_mem(0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (panic_print & PANIC_PRINT_TIMER_INFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) sysrq_timer_list_show();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (panic_print & PANIC_PRINT_LOCK_INFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) debug_show_all_locks();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (panic_print & PANIC_PRINT_FTRACE_INFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) ftrace_dump(DUMP_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * panic - halt the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * @fmt: The text string to print
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * Display a message, then perform cleanups.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * This function never returns.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) void panic(const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static char buf[1024];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) long i, i_next = 0, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int old_cpu, this_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) bool _crash_kexec_post_notifiers = crash_kexec_post_notifiers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * Disable local interrupts. This will prevent panic_smp_self_stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * from deadlocking the first cpu that invokes the panic, since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * there is nothing to prevent an interrupt handler (that runs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * after setting panic_cpu) from invoking panic() again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) preempt_disable_notrace();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * It's possible to come here directly from a panic-assertion and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * not have preempt disabled. Some functions called from here want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * preempt to be disabled. No point enabling it later though...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * Only one CPU is allowed to execute the panic code from here. For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * multiple parallel invocations of panic, all other CPUs either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * stop themself or will wait until they are stopped by the 1st CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * with smp_send_stop().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * `old_cpu == PANIC_CPU_INVALID' means this is the 1st CPU which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * comes here, so go ahead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * `old_cpu == this_cpu' means we came from nmi_panic() which sets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * panic_cpu to this CPU. In this case, this is also the 1st CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) this_cpu = raw_smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, this_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (old_cpu != PANIC_CPU_INVALID && old_cpu != this_cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) panic_smp_self_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) console_verbose();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) bust_spinlocks(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) len = vscnprintf(buf, sizeof(buf), fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (len && buf[len - 1] == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) buf[len - 1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) pr_emerg("Kernel panic - not syncing: %s\n", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #ifdef CONFIG_DEBUG_BUGVERBOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * Avoid nested stack-dumping if a panic occurs during oops processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (!test_taint(TAINT_DIE) && oops_in_progress <= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * If kgdb is enabled, give it a chance to run before we stop all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * the other CPUs or else we won't be able to debug processes left
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * running on them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) kgdb_panic(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * If we have crashed and we have a crash kernel loaded let it handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * everything else.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * If we want to run this after calling panic_notifiers, pass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * the "crash_kexec_post_notifiers" option to the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * Bypass the panic_cpu check and call __crash_kexec directly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (!_crash_kexec_post_notifiers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) printk_safe_flush_on_panic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) __crash_kexec(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * Note smp_send_stop is the usual smp shutdown function, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * unfortunately means it may not be hardened to work in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * panic situation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) smp_send_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * If we want to do crash dump after notifier calls and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * kmsg_dump, we will need architecture dependent extra
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * works in addition to stopping other CPUs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) crash_smp_send_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * Run any panic handlers, including those that might need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * add information to the kmsg dump output.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /* Call flush even twice. It tries harder with a single online CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) printk_safe_flush_on_panic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) kmsg_dump(KMSG_DUMP_PANIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * If you doubt kdump always works fine in any situation,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * "crash_kexec_post_notifiers" offers you a chance to run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * panic_notifiers and dumping kmsg before kdump.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * Note: since some panic_notifiers can make crashed kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * more unstable, it can increase risks of the kdump failure too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * Bypass the panic_cpu check and call __crash_kexec directly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (_crash_kexec_post_notifiers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) __crash_kexec(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #ifdef CONFIG_VT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) unblank_screen();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) console_unblank();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * We may have ended up stopping the CPU holding the lock (in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * smp_send_stop()) while still having some valuable data in the console
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * buffer. Try to acquire the lock then release it regardless of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * result. The release will also print the buffers out. Locks debug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * should be disabled to avoid reporting bad unlock balance when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * panic() is not being callled from OOPS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) debug_locks_off();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) console_flush_on_panic(CONSOLE_FLUSH_PENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) panic_print_sys_info();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (!panic_blink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) panic_blink = no_blink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (panic_timeout > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * Delay timeout seconds before rebooting the machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * We can't use the "normal" timers since we just panicked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) pr_emerg("Rebooting in %d seconds..\n", panic_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) for (i = 0; i < panic_timeout * 1000; i += PANIC_TIMER_STEP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) touch_nmi_watchdog();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (i >= i_next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) i += panic_blink(state ^= 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) i_next = i + 3600 / PANIC_BLINK_SPD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) mdelay(PANIC_TIMER_STEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (panic_timeout != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * This will not be a clean reboot, with everything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * shutting down. But if there is a chance of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * rebooting the system it will be rebooted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (panic_reboot_mode != REBOOT_UNDEFINED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) reboot_mode = panic_reboot_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) emergency_restart();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) #ifdef __sparc__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) extern int stop_a_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /* Make sure the user can actually press Stop-A (L1-A) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) stop_a_enabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) pr_emerg("Press Stop-A (L1-A) from sun keyboard or send break\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) "twice on console to return to the boot prom\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) #if defined(CONFIG_S390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) disabled_wait();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) pr_emerg("---[ end Kernel panic - not syncing: %s ]---\n", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /* Do not scroll important messages printed above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) suppress_printk = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) for (i = 0; ; i += PANIC_TIMER_STEP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) touch_softlockup_watchdog();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (i >= i_next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) i += panic_blink(state ^= 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) i_next = i + 3600 / PANIC_BLINK_SPD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) mdelay(PANIC_TIMER_STEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) EXPORT_SYMBOL(panic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * TAINT_FORCED_RMMOD could be a per-module flag but the module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * is being removed anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) [ TAINT_PROPRIETARY_MODULE ] = { 'P', 'G', true },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) [ TAINT_FORCED_MODULE ] = { 'F', ' ', true },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) [ TAINT_CPU_OUT_OF_SPEC ] = { 'S', ' ', false },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) [ TAINT_FORCED_RMMOD ] = { 'R', ' ', false },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) [ TAINT_MACHINE_CHECK ] = { 'M', ' ', false },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) [ TAINT_BAD_PAGE ] = { 'B', ' ', false },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) [ TAINT_USER ] = { 'U', ' ', false },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) [ TAINT_DIE ] = { 'D', ' ', false },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) [ TAINT_OVERRIDDEN_ACPI_TABLE ] = { 'A', ' ', false },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) [ TAINT_WARN ] = { 'W', ' ', false },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) [ TAINT_CRAP ] = { 'C', ' ', true },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) [ TAINT_FIRMWARE_WORKAROUND ] = { 'I', ' ', false },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) [ TAINT_OOT_MODULE ] = { 'O', ' ', true },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) [ TAINT_UNSIGNED_MODULE ] = { 'E', ' ', true },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) [ TAINT_SOFTLOCKUP ] = { 'L', ' ', false },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) [ TAINT_LIVEPATCH ] = { 'K', ' ', true },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) [ TAINT_AUX ] = { 'X', ' ', true },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) [ TAINT_RANDSTRUCT ] = { 'T', ' ', true },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) * print_tainted - return a string to represent the kernel taint state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * For individual taint flag meanings, see Documentation/admin-guide/sysctl/kernel.rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * The string is overwritten by the next call to print_tainted(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * but is always NULL terminated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) const char *print_tainted(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static char buf[TAINT_FLAGS_COUNT + sizeof("Tainted: ")];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) BUILD_BUG_ON(ARRAY_SIZE(taint_flags) != TAINT_FLAGS_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (tainted_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) s = buf + sprintf(buf, "Tainted: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) for (i = 0; i < TAINT_FLAGS_COUNT; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) const struct taint_flag *t = &taint_flags[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) *s++ = test_bit(i, &tainted_mask) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) t->c_true : t->c_false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) *s = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) snprintf(buf, sizeof(buf), "Not tainted");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) int test_taint(unsigned flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return test_bit(flag, &tainted_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) EXPORT_SYMBOL(test_taint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) unsigned long get_taint(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return tainted_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * add_taint: add a taint flag if not already set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * @flag: one of the TAINT_* constants.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * @lockdep_ok: whether lock debugging is still OK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * If something bad has gone wrong, you'll want @lockdebug_ok = false, but for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * some notewortht-but-not-corrupting cases, it can be set to true.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) void add_taint(unsigned flag, enum lockdep_ok lockdep_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (lockdep_ok == LOCKDEP_NOW_UNRELIABLE && __debug_locks_off())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) pr_warn("Disabling lock debugging due to kernel taint\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) set_bit(flag, &tainted_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (tainted_mask & panic_on_taint) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) panic_on_taint = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) panic("panic_on_taint set ...");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) EXPORT_SYMBOL(add_taint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static void spin_msec(int msecs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) for (i = 0; i < msecs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) touch_nmi_watchdog();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * It just happens that oops_enter() and oops_exit() are identically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * implemented...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static void do_oops_enter_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static int spin_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (!pause_on_oops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) spin_lock_irqsave(&pause_on_oops_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (pause_on_oops_flag == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) /* This CPU may now print the oops message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) pause_on_oops_flag = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) /* We need to stall this CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (!spin_counter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) /* This CPU gets to do the counting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) spin_counter = pause_on_oops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) spin_unlock(&pause_on_oops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) spin_msec(MSEC_PER_SEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) spin_lock(&pause_on_oops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) } while (--spin_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) pause_on_oops_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) /* This CPU waits for a different one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) while (spin_counter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) spin_unlock(&pause_on_oops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) spin_msec(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) spin_lock(&pause_on_oops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) spin_unlock_irqrestore(&pause_on_oops_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * Return true if the calling CPU is allowed to print oops-related info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) * This is a bit racy..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) bool oops_may_print(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return pause_on_oops_flag == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * Called when the architecture enters its oops handler, before it prints
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * anything. If this is the first CPU to oops, and it's oopsing the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * time then let it proceed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * This is all enabled by the pause_on_oops kernel boot option. We do all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * this to ensure that oopses don't scroll off the screen. It has the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * side-effect of preventing later-oopsing CPUs from mucking up the display,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) * It turns out that the CPU which is allowed to print ends up pausing for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) * the right duration, whereas all the other CPUs pause for twice as long:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) * once in oops_enter(), once in oops_exit().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) void oops_enter(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) tracing_off();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /* can't trust the integrity of the kernel anymore: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) debug_locks_off();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) do_oops_enter_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (sysctl_oops_all_cpu_backtrace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) trigger_all_cpu_backtrace();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) * 64-bit random ID for oopses:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) static u64 oops_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) static int init_oops_id(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (!oops_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) get_random_bytes(&oops_id, sizeof(oops_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) oops_id++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) late_initcall(init_oops_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static void print_oops_end_marker(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) init_oops_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) pr_warn("---[ end trace %016llx ]---\n", (unsigned long long)oops_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * Called when the architecture exits its oops handler, after printing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) * everything.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) void oops_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) do_oops_enter_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) print_oops_end_marker();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) kmsg_dump(KMSG_DUMP_OOPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) struct warn_args {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) const char *fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) void __warn(const char *file, int line, void *caller, unsigned taint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) struct pt_regs *regs, struct warn_args *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) disable_trace_on_warning();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) raw_smp_processor_id(), current->pid, file, line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) caller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) pr_warn("WARNING: CPU: %d PID: %d at %pS\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) raw_smp_processor_id(), current->pid, caller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) vprintk(args->fmt, args->args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) print_modules();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) show_regs(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (panic_on_warn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) * This thread may hit another WARN() in the panic path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) * Resetting this prevents additional WARN() from panicking the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) * system on this thread. Other threads are blocked by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) * panic_mutex in panic().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) panic_on_warn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) panic("panic_on_warn set ...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) if (!regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) print_irqtrace_events(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) print_oops_end_marker();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) /* Just a warning, don't kill lockdep. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) add_taint(taint, LOCKDEP_STILL_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) #ifndef __WARN_FLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) void warn_slowpath_fmt(const char *file, int line, unsigned taint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) struct warn_args args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) pr_warn(CUT_HERE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) if (!fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) __warn(file, line, __builtin_return_address(0), taint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) args.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) va_start(args.args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) __warn(file, line, __builtin_return_address(0), taint, NULL, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) va_end(args.args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) EXPORT_SYMBOL(warn_slowpath_fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) void __warn_printk(const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) pr_warn(CUT_HERE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) vprintk(fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) EXPORT_SYMBOL(__warn_printk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) #ifdef CONFIG_BUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) /* Support resetting WARN*_ONCE state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) static int clear_warn_once_set(void *data, u64 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) generic_bug_clear_once();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) memset(__start_once, 0, __end_once - __start_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) DEFINE_DEBUGFS_ATTRIBUTE(clear_warn_once_fops, NULL, clear_warn_once_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) "%lld\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) static __init int register_warn_debugfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) /* Don't care about failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) debugfs_create_file_unsafe("clear_warn_once", 0200, NULL, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) &clear_warn_once_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) device_initcall(register_warn_debugfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) #ifdef CONFIG_STACKPROTECTOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) * Called when gcc's -fstack-protector feature is used, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) * gcc detects corruption of the on-stack canary value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) __visible noinstr void __stack_chk_fail(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) instrumentation_begin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) panic("stack-protector: Kernel stack is corrupted in: %pB",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) __builtin_return_address(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) instrumentation_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) EXPORT_SYMBOL(__stack_chk_fail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) core_param(panic, panic_timeout, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) core_param(panic_print, panic_print, ulong, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) core_param(pause_on_oops, pause_on_oops, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) core_param(panic_on_warn, panic_on_warn, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) core_param(crash_kexec_post_notifiers, crash_kexec_post_notifiers, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) static int __init oops_setup(char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (!s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) if (!strcmp(s, "panic"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) panic_on_oops = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) early_param("oops", oops_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) static int __init panic_on_taint_setup(char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) char *taint_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) if (!s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) taint_str = strsep(&s, ",");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (kstrtoul(taint_str, 16, &panic_on_taint))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) /* make sure panic_on_taint doesn't hold out-of-range TAINT flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) panic_on_taint &= TAINT_FLAGS_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) if (!panic_on_taint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (s && !strcmp(s, "nousertaint"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) panic_on_taint_nousertaint = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) pr_info("panic_on_taint: bitmask=0x%lx nousertaint_mode=%sabled\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) panic_on_taint, panic_on_taint_nousertaint ? "en" : "dis");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) early_param("panic_on_taint", panic_on_taint_setup);