Skip to contentSkip to conversation

vdso: print fatal signals

PATCH In review Ingo Molnar 2 participants 2 messages May 23, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 vdso: print fatal signals

From: Ingo Molnar <[email protected]>

Add the print-fatal-signals=1 boot option and the /proc/sys/kernel/print-fatal-signals runtime switch.

This feature prints some minimal information about userspace segfaults to the kernel console. This is useful to find early bootup bugs where userspace debugging is very hard.

Defaults to off.

---

 Documentation/kernel-parameters.txt |    6 ++++++
 include/linux/sysctl.h              |    1 +
 kernel/signal.c                     |   33 +++++++++++++++++++++++++++++++++
 kernel/sysctl.c                     |    9 +++++++++
 4 files changed, 49 insertions(+)
Documentation/kernel-parameters.txt +6 -0
Index: linux-vdso-rand.q/Documentation/kernel-parameters.txt
===================================================================
@@ -1261,6 +1261,12 @@ running once the system is up.
 			autoconfiguration.
 			Ranges are in pairs (memory base and size).
 
+	print-fatal-signals=
+			[KNL] debug: print fatal signals
+			print-fatal-signals=1: print segfault info to
+			the kernel console.
+			default: off.
+
 	profile=	[KNL] Enable kernel profiling via /proc/profile
 			Format: [schedule,]<number>
 			Param: "schedule" - profile schedule points.
include/linux/sysctl.h +1 -0
Index: linux-vdso-rand.q/include/linux/sysctl.h
===================================================================
@@ -93,6 +93,7 @@ enum
 	KERN_CAP_BSET=14,	/* int: capability bounding set */
 	KERN_PANIC=15,		/* int: panic timeout */
 	KERN_REALROOTDEV=16,	/* real root device to mount after initrd */
+	KERN_PRINT_FATAL=17,	/* int: print fatal signals (0/1) */
 
 	KERN_SPARC_REBOOT=21,	/* reboot command on Sparc */
 	KERN_CTLALTDEL=22,	/* int: allow ctl-alt-del to reboot */
kernel/signal.c +33 -0
Index: linux-vdso-rand.q/kernel/signal.c
===================================================================
@@ -763,6 +763,37 @@ out_set:
 #define LEGACY_QUEUE(sigptr, sig) \
 	(((sig) < SIGRTMIN) && sigismember(&(sigptr)->signal, (sig)))
 
+int print_fatal_signals = 0;
+
+static void print_fatal_signal(struct pt_regs *regs, int signr)
+{
+	printk("%s/%d: potentially unexpected fatal signal %d.\n",
+		current->comm, current->pid, signr);
+
+#ifdef __i386__
+	printk("code at %08lx: ", regs->eip);
+	{
+		int i;
+		for (i = 0; i < 16; i++) {
+			unsigned char insn;
+
+			__get_user(insn, (unsigned char *)(regs->eip + i));
+			printk("%02x ", insn);
+		}
+	}
+#endif
+	printk("\n");
+	show_regs(regs);
+}
+
+static int __init setup_print_fatal_signals(char *str)
+{
+	get_option (&str, &print_fatal_signals);
+
+	return 1;
+}
+
+__setup("print-fatal-signals=", setup_print_fatal_signals);
 
 static int
 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
@@ -1843,6 +1874,8 @@ relock:
 		 * Anything else is fatal, maybe with a core dump.
 		 */
 		current->flags |= PF_SIGNALED;
+		if ((signr != SIGKILL) && print_fatal_signals)
+			print_fatal_signal(regs, signr);
 		if (sig_kernel_coredump(signr)) {
 			/*
 			 * If it was able to dump core, this kills all
kernel/sysctl.c +9 -0
Index: linux-vdso-rand.q/kernel/sysctl.c
===================================================================
@@ -72,6 +72,7 @@ extern int printk_ratelimit_burst;
 extern int pid_max_min, pid_max_max;
 extern int sysctl_drop_caches;
 extern int percpu_pagelist_fraction;
+extern int print_fatal_signals;
 
 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
 int unknown_nmi_panic;
@@ -326,6 +327,14 @@ static ctl_table kern_table[] = {
 		.proc_handler	= &proc_dointvec,
 	},
 #endif
+	{
+		.ctl_name	= KERN_PRINT_FATAL,
+		.procname	= "print-fatal-signals",
+		.data		= &print_fatal_signals,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= &proc_dointvec,
+	},
 #ifdef __sparc__
 	{
 		.ctl_name	= KERN_SPARC_REBOOT,
#1 lore raw
Quoted 18 lines · Ingo Molnar

Index: linux-vdso-rand.q/kernel/signal.c
===================================================================

kernel/signal.c +10 -0
@@ -763,6 +763,37 @@ out_set:
 #define LEGACY_QUEUE(sigptr, sig) \
 	(((sig) < SIGRTMIN) && sigismember(&(sigptr)->signal, (sig)))
 
+int print_fatal_signals = 0;
+
+static void print_fatal_signal(struct pt_regs *regs, int signr)
+{
+	printk("%s/%d: potentially unexpected fatal signal %d.\n",
+		current->comm, current->pid, signr);
+
+#ifdef __i386__
+	printk("code at %08lx: ", regs->eip);
+	{

kernel/signal.c out_set: · line 785

Quoted 10 lines
kernel/signal.c +9 -0
+		int i;
+		for (i = 0; i < 16; i++) {
+			unsigned char insn;
+
+			__get_user(insn, (unsigned char *)(regs->eip + i));
+			printk("%02x ", insn);
+		}
+	}
+#endif
 

This looks ok for debugging boot problems. Perhaps you could print the registers too? The instruction dump won't help much for indirect access.

The get_user of eip+i is ok, but doesn't account for segment offsets. Not that I think it needs to here. But it is one of a many growing number of places that now try to inspect or modify a potentially segmented area of memory (page fault handler must inspect for prefetch instructions, kprobes reads and patches code, FPU emulation). Perhaps a common interface would be a nice thing at some point in time.

Zach