sysctl: Add panic-fatal-signals
PATCH v2 1/1 sysctl: Add panic-fatal-signals
Add a sysctl which asks the kernel to panic when any userspace process receives a fatal signal which would trigger a core dump. This has proven to be quite useful when debugging problems seen during testing of embedded systems: When combined with kernel core dumps (saved due to the panic), it allows easier debugging of crashes which have their origin in system-wide problems such as buggy drivers or other kernel or hardware-related issues.
The crashing process's core dump can be extracted from the kernel core dump using tools such as the crash utility's gcore extension.
---
v2: Put the sysctl behind a config option
include/linux/signal.h | 1 + init/Kconfig | 14 ++++++++++++++ kernel/signal.c | 5 ++++- kernel/sysctl.c | 9 +++++++++ 4 files changed, 28 insertions(+), 1 deletion(-)
include/linux/signal.h +1 -0
@@ -10,6 +10,7 @@ struct task_struct;/* for sysctl */ extern int print_fatal_signals; +extern int panic_fatal_signals;static inline void copy_siginfo (kernel_siginfo_t *to,const kernel_siginfo_t *from)
init/Kconfig +14 -0
@@ -1242,6 +1242,20 @@ config SYSCTL_SYSCALL If unsure say N here. +config SYSCTL_PANIC_FATAL_SIGNALS + bool "panic-fatal-signals sysctl" if EXPERT + depends on PROC_SYSCTL + help + If you say Y here, a kernel.panic-fatal-signals sysctl will be + offered. If this sysctl is turned on, the kernel will panic if any + userspace process receives a fatal signal which would trigger a core + dump. + + When used together with kernel core dumps, this can be useful for + debugging some system-wide problems, primarily on embedded systems. + + If unsure, say N. + config FHANDLE bool "open by fhandle syscalls" if EXPERT select EXPORTFS
kernel/signal.c +4 -1
@@ -59,6 +59,7 @@static struct kmem_cache *sigqueue_cachep;int print_fatal_signals__read_mostly ; +int panic_fatal_signals__read_mostly ;static void __user *sig_handler (struct task_struct *t,int sig) {
@@ -2497,8 +2498,10 @@ bool get_signal(struct ksignal *ksig) current->flags |=PF_SIGNALED ;if (sig_kernel_coredump (signr)) { -if (print_fatal_signals) +if (print_fatal_signals || panic_fatal_signals)print_fatal_signal (ksig->info.si_signo); +if (panic_fatal_signals) +panic ("Fatal signal and panic_fatal_signals=1" );proc_coredump_connector (current);/* * If it was able to dump core, this kills all
kernel/sysctl.c +9 -0
@@ -557,6 +557,15 @@ static struct ctl_table kern_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, +#ifdef CONFIG_SYSCTL_PANIC_FATAL_SIGNALS + { + .procname = "panic-fatal-signals", + .data = &panic_fatal_signals, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, +#endif #ifdef CONFIG_SPARC { .procname = "reboot-cmd",
Signature · 1 line
2.20.0
Quoted 11 lines · On Mon, 28 Jan 2019 09:49:59 +0100 Vincent Whitchurch…
Add a sysctl which asks the kernel to panic when any userspace process receives a fatal signal which would trigger a core dump. This has proven to be quite useful when debugging problems seen during testing of embedded systems: When combined with kernel core dumps (saved due to the panic), it allows easier debugging of crashes which have their origin in system-wide problems such as buggy drivers or other kernel or hardware-related issues.
The crashing process's core dump can be extracted from the kernel core dump using tools such as the crash utility's gcore extension.
I can't speak to the usefulness of this, but the feature is small and simple.
Some documentation would be appreciated. I assume in Documentation/sysctl/kernel.txt. Please also check that print-fatal-signals is appropriately documented while we're in there - it's documented in Documentation/admin-guide/kernel-parameters.rst but not Documentation/sysctl/kernel.txt.
Quoted 1 line
v2: Put the sysctl behind a config option
I suppose so... The option is root-only (surely?) so I'm not sure this is really needed.
Quoted 11 lines
...
init/Kconfig +3
-0@@ -1242,6 +1242,20 @@ config SYSCTL_SYSCALL If unsure say N here. +config SYSCTL_PANIC_FATAL_SIGNALS + bool "panic-fatal-signals sysctl" if EXPERT + depends on PROC_SYSCTL
init/Kconfig config SYSCTL_SYSCALL · line 1257
Quoted 10 lines
init/Kconfig +10
-0+ help + If you say Y here, a kernel.panic-fatal-signals sysctl will be + offered. If this sysctl is turned on, the kernel will panic if any + userspace process receives a fatal signal which would trigger a core + dump. + + When used together with kernel core dumps, this can be useful for + debugging some system-wide problems, primarily on embedded systems. + + If unsure, say N.
I suggest that the Kconfig help and the forthcoming documentation should clearly explain the dangers of enabling this!
Quoted 7 lines · Andrew Morton
Quoted 6 lines · On Mon, 28 Jan 2019 09:49:59 +0100 Vincent Whitchurch…
init/Kconfig +0
-0@@ -1242,6 +1242,20 @@ config SYSCTL_SYSCALL If unsure say N here.
Quoted 16 lines
init/Kconfig config SYSCTL_SYSCALL · line 1257
Quoted 13 lines
init/Kconfig +13
-0+config SYSCTL_PANIC_FATAL_SIGNALS + bool "panic-fatal-signals sysctl" if EXPERT + depends on PROC_SYSCTL + help + If you say Y here, a kernel.panic-fatal-signals sysctl will be + offered. If this sysctl is turned on, the kernel will panic if any + userspace process receives a fatal signal which would trigger a core + dump. + + When used together with kernel core dumps, this can be useful for + debugging some system-wide problems, primarily on embedded systems. + + If unsure, say N.I suggest that the
Kconfighelp and the forthcoming documentation should clearly explain the dangers of enabling this!
And so, should default to n.
Luis
Quoted 26 lines · Luis Chamberlain
Quoted 7 lines · Andrew Morton
Quoted 6 lines · On Mon, 28 Jan 2019 09:49:59 +0100 Vincent Whitchurch…
init/Kconfig +0
-0@@ -1242,6 +1242,20 @@ config SYSCTL_SYSCALL If unsure say N here.Quoted 16 lines
init/Kconfig config SYSCTL_SYSCALL · line 1257
Quoted 13 lines
init/Kconfig +13
-0+config SYSCTL_PANIC_FATAL_SIGNALS + bool "panic-fatal-signals sysctl" if EXPERT + depends on PROC_SYSCTL + help + If you say Y here, a kernel.panic-fatal-signals sysctl will be + offered. If this sysctl is turned on, the kernel will panic if any + userspace process receives a fatal signal which would trigger a core + dump. + + When used together with kernel core dumps, this can be useful for + debugging some system-wide problems, primarily on embedded systems. + + If unsure, say N.I suggest that the
Kconfighelp and the forthcoming documentation should clearly explain the dangers of enabling this!
Quoted 3 lines
And so, should default to n.
Luis
Hmm, why can't this be a core dump helper?
Such as:
#!/bin/sh
# Usage:
# echo "|/root/crash.sh %p %e %s" > /proc/sys/kernel/core_pattern
PID="$1"
COMM="$2"
SIGNAL="$3"
echo "$COMM ($PID) died by signal $SIGNAL, killing kernel" > /dev/kmsg echo c > /proc/sysrq-trigger
Signature · 2 lines
Thanks, //richard
Quoted 5 lines · Richard Weinberger
Hmm, why can't this be a core dump helper?
Such as:#!/bin/sh
# Usage:
Quoted 8 lines
# echo "|/root/crash.sh %p %e %s" > /proc/sys/kernel/core_patternPID="$1"
COMM="$2"
SIGNAL="$3"echo "$COMM ($PID) died by signal $SIGNAL, killing kernel" >
/dev/kmsgecho c >/proc/sysrq-trigger
Yes, that looks like it should work. Thanks.