linux/arch/cris/arch-v32/kernel
Rabin Vincent 0f72e5c0df CRISv32: prevent bogus restarts on sigreturn
Al Viro noted that CRIS is vulnerable to bogus restarts on sigreturn.

The fixes CRISv32 by using regs->exs as an additional indicator to
whether we should attempt to restart the syscall or not.  EXS is only
used in the sigtrap handling, and in that path we already have r9 (the
other indicator, which indicates if we're in a syscall or not) cleared.

Test case, a port of Al's ARM version from 653d48b221 ("arm: fix
really nasty sigreturn bug"):

  #include <unistd.h>
  #include <signal.h>
  #include <stdlib.h>
  #include <sys/time.h>
  #include <errno.h>

  void f(int n)
  {
  	register int r10 asm ("r10") = n;

          __asm__ __volatile__(
  		"ba	1f	\n"
  		"nop		\n"
  		"break	8	\n"
  		"1: ba	.	\n"
  		"nop		\n"
  		:
  		: "r" (r10)
  		: "memory");
  }

  void handler1(int sig) { }
  void handler2(int sig) { raise(1); }
  void handler3(int sig) { exit(0); }

  int main(int argc, char *argv[])
  {
          struct sigaction s = {.sa_handler = handler2};
          struct itimerval t1 = { .it_value = {1} };
          struct itimerval t2 = { .it_value = {2} };

          signal(1, handler1);

          sigemptyset(&s.sa_mask);
          sigaddset(&s.sa_mask, 1);
          sigaction(SIGALRM, &s, NULL);

          signal(SIGVTALRM, handler3);

          setitimer(ITIMER_REAL, &t1, NULL);
          setitimer(ITIMER_VIRTUAL, &t2, NULL);

          f(-513); /* -ERESTARTNOINTR */

          return 0;
  }

Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
Link: http://lkml.kernel.org/r/20121208074429.GC4939@ZenIV.linux.org.uk
Signed-off-by: Rabin Vincent <rabin@rab.in>
Signed-off-by: Jesper Nilsson <jespern@axis.com>
2015-03-25 10:51:53 +01:00
..
cache.c [CRIS] Move header files from include to arch/cris/include. 2008-10-29 17:29:44 +01:00
cacheflush.S CRIS: Add debug for assembler functions 2010-08-04 12:59:43 +02:00
crisksyms.c CRIS: Don't use mask_irq as symbol name 2010-05-25 17:48:14 +02:00
debugport.c CRISv32: Implement early console 2014-12-20 00:05:49 +01:00
entry.S CRISv32: prevent bogus restarts on sigreturn 2015-03-25 10:51:53 +01:00
fasttimer.c cris: remove deprecated IRQF_DISABLED 2014-01-08 16:10:18 +01:00
head.S CRIS: Remove VCS simulator specific code 2012-10-03 09:57:01 +02:00
irq.c CRISv32: add irq domains support 2015-03-25 09:47:43 +01:00
kgdb_asm.S CRIS: v32: Correct path for intr_vect.h 2010-08-04 13:00:53 +02:00
kgdb.c CRIS: Remove VCS simulator specific code 2012-10-03 09:57:01 +02:00
Makefile CRISv32: Remove obsolete vcs_hook.o from Makefile 2009-04-21 13:10:33 +02:00
process.c dump_stack: unify debug information printed by show_regs() 2013-04-30 17:04:02 -07:00
ptrace.c cris:removed the unused variable 2012-04-03 13:09:18 +02:00
setup.c CRIS: More ARTPEC-3 support and i2c-boardinfo. 2010-08-04 13:01:50 +02:00
signal.c CRISv32: prevent bogus restarts on sigreturn 2015-03-25 10:51:53 +01:00
smp.c cris: remove deprecated IRQF_DISABLED 2014-01-08 16:10:18 +01:00
time.c CRISv32: Avoid warning of unused variable 2015-01-29 10:10:08 +01:00
traps.c CRIS: Minor formatting fix in traps.c 2010-08-04 13:02:15 +02:00