linux-mips
[Top] [All Lists]

Re: setup_frame() failure

To: Atsushi Nemoto <nemoto@toshiba-tops.co.jp>
Subject: Re: setup_frame() failure
From: Ralf Baechle <ralf@oss.sgi.com>
Date: Sat, 8 Sep 2001 01:36:38 +0200
Cc: linux-mips@oss.sgi.com
In-reply-to: <20010907.202652.71083122.nemoto@toshiba-tops.co.jp>; from nemoto@toshiba-tops.co.jp on Fri, Sep 07, 2001 at 08:26:52PM +0900
References: <20010907.202652.71083122.nemoto@toshiba-tops.co.jp>
Sender: owner-linux-mips@oss.sgi.com
User-agent: Mutt/1.2.5i
On Fri, Sep 07, 2001 at 08:26:52PM +0900, Atsushi Nemoto wrote:

> I found that if setup_frame() fails in certain conditions the process
> which caused the signal grabs CPU and never be killed.
> 
> Here is a sample test program.
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <signal.h>
> 
> void sighandler(int sig)
> {
>       printf("SIGNAL %d!\n", sig);
>       exit(2);
> }
> void setup_signal(int sig)
> {
>       struct sigaction act;
>       memset(&act, 0, sizeof(act));
>       act.sa_handler = sighandler;
>       act.sa_flags = SA_NOMASK | SA_RESTART;
>       sigaction(sig, &act, 0);
> }
> 
> int main(int argc, char **argv)
> {
>       setup_signal(SIGILL);
>       setup_signal(SIGQUIT);
>       setup_signal(SIGINT);
> 
>       __asm__ __volatile__("move $29,$0");
>       __asm__ __volatile__("mfc0 $0,$0");
>       printf("done!\n");
>       return 0;
> }
> 
> 
> This program setups signal handlers and causes Coprocessor Unusable
> Exception with $sp == 0.
> 
> If we run this program,
> 
> 1.  "mfc1" instruction raises a exception.
> 2.  The exception handler queues SIGILL(4).
> 3.  do_signal() dequeue a signal with LOWEST number.
> 4.  setup_frame() fails and queues SIGSEGV(11).
> 5.  returns to user process.
> 6.  again from 1. (forever)
> 
> So, even SIGKILL can not kill the process.  (SIGHUP can do it).
> 
> I make a change for do_signal() to check failure of setup_frame() and
> continue processing pending signals.  It seems work for me.  Here is
> the patch.  Any comments are welcome.

Nice test case.  Thanks. I decied for a differnet fix attached below.

  Ralf

Index: arch/mips64/kernel/traps.c
===================================================================
RCS file: /home/pub/cvs/linux/arch/mips64/kernel/traps.c,v
retrieving revision 1.20
diff -u -r1.20 traps.c
--- arch/mips64/kernel/traps.c 2001/07/11 23:32:54 1.20  
+++ arch/mips64/kernel/traps.c 2001/09/07 23:29:16   
@@ -347,11 +347,9 @@
 
 void do_ri(struct pt_regs *regs)
 {
-       printk("Cpu%d[%s:%d] Illegal instruction at %08lx ra=%08lx\n",
-               smp_processor_id(), current->comm, current->pid, regs->cp0_epc, 
-               regs->regs[31]);
        if (compute_return_epc(regs))
                return;
+
        force_sig(SIGILL, current);
 }
 
@@ -388,6 +386,7 @@
        return;
 
 bad_cid:
+       compute_return_epc(regs);
        force_sig(SIGILL, current);
 }
 
Index: arch/mips/kernel/traps.c
===================================================================
RCS file: /home/pub/cvs/linux/arch/mips/kernel/traps.c,v
retrieving revision 1.78
diff -u -r1.78 traps.c
--- arch/mips/kernel/traps.c 2001/09/06 13:22:24 1.78  
+++ arch/mips/kernel/traps.c 2001/09/07 23:29:16   
@@ -606,9 +606,6 @@
 
 asmlinkage void do_ri(struct pt_regs *regs)
 {
-       unsigned int opcode;
-
-       get_insn_opcode(regs, &opcode);
        if (compute_return_epc(regs))
                return;
 
@@ -659,6 +656,7 @@
        return;
 
 bad_cid:
+       compute_return_epc(regs);
        force_sig(SIGILL, current);
 }
 

<Prev in Thread] Current Thread [Next in Thread>