mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andi Kleen <ak@suse.de>
To: akpm@digeo.com, linux-kernel@vger.kernel.org, torvalds@transmeta.com
Subject: [PATCH] Exception trace for i386, mark II
Date: Sat, 31 May 2003 14:05:14 +0200	[thread overview]
Message-ID: <20030531120514.GA11898@wotan.suse.de> (raw)


This is a new implementation of exception trace for i386.

It adds a new exception-trace sysctl (default to off), which when enabled
triggers printk for unhandled fault signals (SIGSEGV etc.).  This is 
very useful to catch silent segfaults, e.g. from programs who run 
in unwritable directories and cannot coredump. It's also very useful
for running LTP. In general it gives you an early warning when something
is wrong with your system.

It won't trigger on intentional signal users who catch the signal or
when an debugger is active.  This also makes the similar facility which
has been in amd64 for a long time switchable using the sysctl. The default 
behaviour does not change.

-Andi


Index: linux/arch/i386/kernel/traps.c
===================================================================
RCS file: /home/cvs/linux-2.5/arch/i386/kernel/traps.c,v
retrieving revision 1.62
diff -u -u -r1.62 traps.c
--- linux/arch/i386/kernel/traps.c	30 May 2003 20:11:26 -0000	1.62
+++ linux/arch/i386/kernel/traps.c	31 May 2003 10:24:21 -0000
@@ -53,6 +53,8 @@
 
 #include "mach_traps.h"
 
+extern int exception_trace;
+
 asmlinkage int system_call(void);
 asmlinkage void lcall7(void);
 asmlinkage void lcall27(void);
@@ -303,6 +305,13 @@
 
 	trap_signal: {
 		struct task_struct *tsk = current;
+
+		if (exception_trace && !(tsk->flags & PT_PTRACED) && 
+		    (tsk->sighand->action[signr-1].sa.sa_handler == SIG_IGN ||
+		     (tsk->sighand->action[signr-1].sa.sa_handler == SIG_DFL)))   
+			printk(KERN_INFO "%s[%d] trap %s at eip:%lx esp:%lx err:%lx\n",
+		       tsk->comm, tsk->pid, str, regs->eip, regs->esp, error_code);
+			
 		tsk->thread.error_code = error_code;
 		tsk->thread.trap_no = trapnr;
 		if (info)
@@ -372,15 +381,22 @@
 
 asmlinkage void do_general_protection(struct pt_regs * regs, long error_code)
 {
+	struct task_struct *tsk = current;
 	if (regs->eflags & VM_MASK)
 		goto gp_in_vm86;
 
 	if (!(regs->xcs & 3))
 		goto gp_in_kernel;
 
-	current->thread.error_code = error_code;
-	current->thread.trap_no = 13;
-	force_sig(SIGSEGV, current);
+	if (exception_trace && !(tsk->flags & PT_PTRACED) && 
+	    (tsk->sighand->action[SIGSEGV-1].sa.sa_handler == SIG_IGN ||
+	     (tsk->sighand->action[SIGSEGV-1].sa.sa_handler == SIG_DFL)))
+		printk(KERN_INFO "%s[%d] gpf at eip:%lx esp:%lx err:%lx\n",
+		       tsk->comm, tsk->pid, regs->eip, regs->esp, error_code);
+	
+	tsk->thread.error_code = error_code;
+	tsk->thread.trap_no = 13;
+	force_sig(SIGSEGV, tsk);
 	return;
 
 gp_in_vm86:
Index: linux/arch/i386/mm/fault.c
===================================================================
RCS file: /home/cvs/linux-2.5/arch/i386/mm/fault.c,v
retrieving revision 1.35
diff -u -u -r1.35 fault.c
--- linux/arch/i386/mm/fault.c	30 May 2003 20:10:34 -0000	1.35
+++ linux/arch/i386/mm/fault.c	31 May 2003 10:24:21 -0000
@@ -57,6 +57,8 @@
 
 asmlinkage void do_invalid_op(struct pt_regs *, unsigned long);
 
+int exception_trace;
+
 /*
  * This routine handles page faults.  It determines the address,
  * and the problem, and then passes it off to one of the appropriate
@@ -200,6 +202,15 @@
 
 	/* User mode accesses just cause a SIGSEGV */
 	if (error_code & 4) {
+
+		if (exception_trace && !(tsk->flags & PT_PTRACED) && 
+		    (tsk->sighand->action[SIGSEGV-1].sa.sa_handler == SIG_IGN ||
+		    (tsk->sighand->action[SIGSEGV-1].sa.sa_handler == SIG_DFL)))
+			printk(KERN_INFO 
+		       "%s[%d] segfault at eip:%lx esp:%lx adr:%lx err:%lx\n",
+		       tsk->comm, tsk->pid, regs->eip, regs->esp, address, 
+		       error_code);
+
 		tsk->thread.cr2 = address;
 		tsk->thread.error_code = error_code;
 		tsk->thread.trap_no = 14;
Index: linux/include/linux/sysctl.h
===================================================================
RCS file: /home/cvs/linux-2.5/include/linux/sysctl.h,v
retrieving revision 1.52
diff -u -u -r1.52 sysctl.h
--- linux/include/linux/sysctl.h	30 May 2003 20:12:50 -0000	1.52
+++ linux/include/linux/sysctl.h	31 May 2003 10:24:25 -0000
@@ -130,6 +130,7 @@
 	KERN_PIDMAX=55,		/* int: PID # limit */
   	KERN_CORE_PATTERN=56,	/* string: pattern for core-file names */
 	KERN_PANIC_ON_OOPS=57,  /* int: whether we will panic on an oops */
+	KERN_EXCEPTION_TRACE=58, /* int: log user traps in kernel log */
 };
 
 
Index: linux/kernel/sysctl.c
===================================================================
RCS file: /home/cvs/linux-2.5/kernel/sysctl.c,v
retrieving revision 1.50
diff -u -u -r1.50 sysctl.c
--- linux/kernel/sysctl.c	30 May 2003 20:11:11 -0000	1.50
+++ linux/kernel/sysctl.c	31 May 2003 10:24:26 -0000
@@ -57,6 +57,7 @@
 extern int cad_pid;
 extern int pid_max;
 extern int sysctl_lower_zone_protection;
+extern int exception_trace;
 
 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
 static int maxolduid = 65535;
@@ -265,6 +266,10 @@
 	 0600, NULL, &proc_dointvec},
 	{KERN_PANIC_ON_OOPS,"panic_on_oops",
 	 &panic_on_oops,sizeof(int),0644,NULL,&proc_dointvec},
+#ifdef CONFIG_X86
+	{KERN_EXCEPTION_TRACE,"exception_trace",
+	 &exception_trace,sizeof(int),0644,NULL,&proc_dointvec},
+#endif
 	{0}
 };
 

             reply	other threads:[~2003-05-31 11:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-31 12:05 Andi Kleen [this message]
     [not found] <20030531121008$2041@gated-at.bofh.it>
2003-05-31 14:39 ` Arnd Bergmann
2003-05-31 15:16   ` Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030531120514.GA11898@wotan.suse.de \
    --to=ak@suse.de \
    --cc=akpm@digeo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®