sysctl: Add panic-fatal-signals
PATCH 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.
--- include/linux/signal.h | 1 + kernel/signal.c | 5 ++++- kernel/sysctl.c | 7 +++++++ 3 files changed, 12 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)
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 +7 -0
@@ -557,6 +557,13 @@ static struct ctl_table kern_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, + { + .procname = "panic-fatal-signals", + .data = &panic_fatal_signals, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, #ifdef CONFIG_SPARC { .procname = "reboot-cmd",
Signature · 1 line
2.20.0
Quoted 9 lines · 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.
Quoted 4 lines
The crashing process's core dump can be extracted from the kernel core dump using tools such as the crash utility's gcore extension.
Signed-off-by Vincent Whitchurch <[email protected]>
Whoa. That's intense. :) If you have a use-case for it, then I guess I can't complain. Given that this is an instant DoS for a system that isn't expecting it, I do wonder if it should live behind a CONFIG or something to make it available only when really wanted?
-Kees
Quoted 63 lines
--- include/linux/signal.h | 1 + kernel/signal.c | 5 ++++- kernel/sysctl.c | 7 +++++++ 3 files changed, 12 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)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 +7
-1@@ -557,6 +557,13 @@ static struct ctl_table kern_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, + { + .procname = "panic-fatal-signals", + .data = &panic_fatal_signals, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, #ifdef CONFIG_SPARC { .procname = "reboot-cmd", --2.20.0
Signature · 1 line
Kees Cook
Quoted 10 lines · Kees Cook
Quoted 8 lines · 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.
Quoted 4 lines
Quoted 2 lines
The crashing process's core dump can be extracted from the kernel core dump using tools such as the crash utility's gcore extension.
Whoa. That's intense. :)
"Insane" is the word I used myself in an earlier draft of the commit message. :)
Quoted 4 lines
If you have a use-case for it, then I guess I
can't complain. Given that this is an instant DoS for a system that isn't expecting it, I do wonder if it should live behind a CONFIG or something to make it available only when really wanted?
Sure, I can put it behind a "depends on EXPERT" config option. Distros and the like should have no reason to provide access to such a sysctl.