1. 25 7月, 2017 1 次提交
    • E
      signal: Remove kernel interal si_code magic · cc731525
      Eric W. Biederman 提交于
      struct siginfo is a union and the kernel since 2.4 has been hiding a union
      tag in the high 16bits of si_code using the values:
      __SI_KILL
      __SI_TIMER
      __SI_POLL
      __SI_FAULT
      __SI_CHLD
      __SI_RT
      __SI_MESGQ
      __SI_SYS
      
      While this looks plausible on the surface, in practice this situation has
      not worked well.
      
      - Injected positive signals are not copied to user space properly
        unless they have these magic high bits set.
      
      - Injected positive signals are not reported properly by signalfd
        unless they have these magic high bits set.
      
      - These kernel internal values leaked to userspace via ptrace_peek_siginfo
      
      - It was possible to inject these kernel internal values and cause the
        the kernel to misbehave.
      
      - Kernel developers got confused and expected these kernel internal values
        in userspace in kernel self tests.
      
      - Kernel developers got confused and set si_code to __SI_FAULT which
        is SI_USER in userspace which causes userspace to think an ordinary user
        sent the signal and that it was not kernel generated.
      
      - The values make it impossible to reorganize the code to transform
        siginfo_copy_to_user into a plain copy_to_user.  As si_code must
        be massaged before being passed to userspace.
      
      So remove these kernel internal si codes and make the kernel code simpler
      and more maintainable.
      
      To replace these kernel internal magic si_codes introduce the helper
      function siginfo_layout, that takes a signal number and an si_code and
      computes which union member of siginfo is being used.  Have
      siginfo_layout return an enumeration so that gcc will have enough
      information to warn if a switch statement does not handle all of union
      members.
      
      A couple of architectures have a messed up ABI that defines signal
      specific duplications of SI_USER which causes more special cases in
      siginfo_layout than I would like.  The good news is only problem
      architectures pay the cost.
      
      Update all of the code that used the previous magic __SI_ values to
      use the new SIL_ values and to call siginfo_layout to get those
      values.  Escept where not all of the cases are handled remove the
      defaults in the switch statements so that if a new case is missed in
      the future the lack will show up at compile time.
      
      Modify the code that copies siginfo si_code to userspace to just copy
      the value and not cast si_code to a short first.  The high bits are no
      longer used to hold a magic union member.
      
      Fixup the siginfo header files to stop including the __SI_ values in
      their constants and for the headers that were missing it to properly
      update the number of si_codes for each signal type.
      
      The fixes to copy_siginfo_from_user32 implementations has the
      interesting property that several of them perviously should never have
      worked as the __SI_ values they depended up where kernel internal.
      With that dependency gone those implementations should work much
      better.
      
      The idea of not passing the __SI_ values out to userspace and then
      not reinserting them has been tested with criu and criu worked without
      changes.
      
      Ref: 2.4.0-test1
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      cc731525
  2. 25 12月, 2016 1 次提交
  3. 30 5月, 2016 1 次提交
  4. 21 3月, 2016 1 次提交
  5. 13 2月, 2015 1 次提交
    • A
      all arches, signal: move restart_block to struct task_struct · f56141e3
      Andy Lutomirski 提交于
      If an attacker can cause a controlled kernel stack overflow, overwriting
      the restart block is a very juicy exploit target.  This is because the
      restart_block is held in the same memory allocation as the kernel stack.
      
      Moving the restart block to struct task_struct prevents this exploit by
      making the restart_block harder to locate.
      
      Note that there are other fields in thread_info that are also easy
      targets, at least on some architectures.
      
      It's also a decent simplification, since the restart code is more or less
      identical on all architectures.
      
      [james.hogan@imgtec.com: metag: align thread_info::supervisor_stack]
      Signed-off-by: NAndy Lutomirski <luto@amacapital.net>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: David Miller <davem@davemloft.net>
      Acked-by: NRichard Weinberger <richard@nod.at>
      Cc: Richard Henderson <rth@twiddle.net>
      Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
      Cc: Matt Turner <mattst88@gmail.com>
      Cc: Vineet Gupta <vgupta@synopsys.com>
      Cc: Russell King <rmk@arm.linux.org.uk>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Haavard Skinnemoen <hskinnemoen@gmail.com>
      Cc: Hans-Christian Egtvedt <egtvedt@samfundet.no>
      Cc: Steven Miao <realmz6@gmail.com>
      Cc: Mark Salter <msalter@redhat.com>
      Cc: Aurelien Jacquiot <a-jacquiot@ti.com>
      Cc: Mikael Starvik <starvik@axis.com>
      Cc: Jesper Nilsson <jesper.nilsson@axis.com>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Richard Kuo <rkuo@codeaurora.org>
      Cc: "Luck, Tony" <tony.luck@intel.com>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Michal Simek <monstr@monstr.eu>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: Jonas Bonn <jonas@southpole.se>
      Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
      Cc: Helge Deller <deller@gmx.de>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Paul Mackerras <paulus@samba.org>
      Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
      Tested-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Chen Liqin <liqin.linux@gmail.com>
      Cc: Lennox Wu <lennox.wu@gmail.com>
      Cc: Chris Metcalf <cmetcalf@ezchip.com>
      Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
      Cc: Chris Zankel <chris@zankel.net>
      Cc: Max Filippov <jcmvbkbc@gmail.com>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Signed-off-by: NJames Hogan <james.hogan@imgtec.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      f56141e3
  6. 19 5月, 2014 2 次提交
    • S
      sparc64: clean up compat_sigset_t.seta handling · c19ac326
      Sam Ravnborg 提交于
      Use compat_sigset_t rather than opencode the array
      Drop "switch (_NSIG_WORDS)" as we know this is always 1
      Introduce BUILD_BUG_ON() to catch if this changes
      
      As a side-effect of this fix following sparse warnings:
      signal32.c:220:60: warning: invalid access past the end of 'seta' (12 8)
      signal32.c:220:42: warning: invalid access past the end of 'seta' (8 8)
      signal32.c:219:60: warning: invalid access past the end of 'seta' (20 8)
      signal32.c:219:42: warning: invalid access past the end of 'seta' (16 8)
      signal32.c:218:60: warning: invalid access past the end of 'seta' (28 8)
      signal32.c:218:42: warning: invalid access past the end of 'seta' (24 8)
      signal32.c:309:68: warning: invalid access past the end of 'seta' (12 8)
      signal32.c:309:46: warning: invalid access past the end of 'seta' (8 8)
      signal32.c:308:68: warning: invalid access past the end of 'seta' (20 8)
      signal32.c:308:46: warning: invalid access past the end of 'seta' (16 8)
      signal32.c:307:68: warning: invalid access past the end of 'seta' (28 8)
      signal32.c:307:46: warning: invalid access past the end of 'seta' (24 8)
      
      They all pointed to code that was never executed - so no bugs fixed.
      Signed-off-by: NSam Ravnborg <sam@ravnborg.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      c19ac326
    • S
      sparc64: fix sparse "Should it be static?" warnings in signal32.c · abaff455
      Sam Ravnborg 提交于
      Fix following warnings:
      signal32.c:140:6: warning: symbol 'do_sigreturn32' was not declared. Should it be static?
      signal32.c:230:17: warning: symbol 'do_rt_sigreturn32' was not declared. Should it be static?
      signal32.c:729:6: warning: symbol 'do_signal32' was not declared. Should it be static?
      signal32.c:773:16: warning: symbol 'do_sys32_sigstack' was not declared. Should it be static?
      
      Add proper prototypes and drop local prototype
      Signed-off-by: NSam Ravnborg <sam@ravnborg.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      abaff455
  7. 09 11月, 2013 1 次提交
  8. 02 3月, 2013 1 次提交
  9. 14 2月, 2013 1 次提交
  10. 04 2月, 2013 1 次提交
  11. 06 10月, 2012 1 次提交
    • D
      compat: move compat_siginfo_t definition to asm/compat.h · 751f409d
      Denys Vlasenko 提交于
      This is a preparatory patch for the introduction of NT_SIGINFO elf note.
      
      Make the location of compat_siginfo_t uniform across eight architectures
      which have it.  Now it can be pulled in by including asm/compat.h or
      linux/compat.h.
      
      Most of the copies are verbatim.  compat_uid[32]_t had to be replaced by
      __compat_uid[32]_t.  compat_uptr_t had to be moved up before
      compat_siginfo_t in asm/compat.h on a several architectures (tile already
      had it moved up).  compat_sigval_t had to be relocated from linux/compat.h
      to asm/compat.h.
      Signed-off-by: NDenys Vlasenko <vda.linux@googlemail.com>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Amerigo Wang <amwang@redhat.com>
      Cc: "Jonathan M. Foote" <jmfoote@cert.org>
      Cc: Roland McGrath <roland@hack.frob.com>
      Cc: Pedro Alves <palves@redhat.com>
      Cc: Fengguang Wu <fengguang.wu@intel.com>
      Cc: Stephen Rothwell <sfr@canb.auug.org.au>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      751f409d
  12. 02 6月, 2012 4 次提交
  13. 22 5月, 2012 1 次提交
  14. 29 3月, 2012 1 次提交
  15. 22 3月, 2012 1 次提交
  16. 16 11月, 2011 1 次提交
    • D
      sparc: Stash orig_i0 into %g6 instead of %g2 · e88d2468
      David S. Miller 提交于
      As per the comments added by this commit, %g2 turns out to not be a
      usable place to save away orig_i0 for syscall restart handling.
      
      In fact all of %g2, %g3, %g4, and %g5 are assumed to be saved across
      a system call by various bits of code in glibc.
      
      %g1 can't be used because that holds the syscall number, which would
      need to be saved and restored for syscall restart handling too, and
      that would only compound our problems :-)
      
      This leaves us with %g6 and %g7 which are for "system use".  %g7 is
      used as the "thread register" by glibc, but %g6 is used as a compiler
      and assembler temporary scratch register.  And in no instance is %g6
      used to hold a value across a system call.
      
      Therefore %g6 is safe for storing away orig_i0, at least for now.
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      e88d2468
  17. 15 11月, 2011 1 次提交
    • D
      sparc: Fix handling of orig_i0 wrt. debugging when restarting syscalls. · 1d299bc7
      David S. Miller 提交于
      Although we provide a proper way for a debugger to control whether
      syscall restart occurs, we run into problems because orig_i0 is not
      saved and restored properly.
      
      Luckily we can solve this problem without having to make debuggers
      aware of the issue.  Across system calls, several registers are
      considered volatile and can be safely clobbered.
      
      Therefore we use the pt_regs save area of one of those registers, %g2,
      as a place to save and restore orig_i0.
      
      Debuggers transparently will do the right thing because they save and
      restore this register already.
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      1d299bc7
  18. 13 10月, 2011 2 次提交
  19. 21 8月, 2011 1 次提交
    • D
      sparc: Allow handling signals when stack is corrupted. · 5598473a
      David S. Miller 提交于
      If we can't push the pending register windows onto the user's stack,
      we disallow signal delivery even if the signal would be delivered on a
      valid seperate signal stack.
      
      Add a register window save area in the signal frame, and store any
      unsavable windows there.
      
      On sigreturn, if any windows are still queued up in the signal frame,
      try to push them back onto the stack and if that fails we kill the
      process immediately.
      
      This allows the debug/tst-longjmp_chk2 glibc test case to pass.
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      5598473a
  20. 22 9月, 2010 2 次提交
  21. 21 9月, 2010 1 次提交
  22. 10 2月, 2010 1 次提交
  23. 05 12月, 2008 1 次提交
    • S
      sparc,sparc64: unify kernel/ · a88b5ba8
      Sam Ravnborg 提交于
      o Move all files from sparc64/kernel/ to sparc/kernel
        - rename as appropriate
      o Update sparc/Makefile to the changes
      o Update sparc/kernel/Makefile to include the sparc64 files
      
      NOTE: This commit changes link order on sparc64!
      
      Link order had to change for either of sparc32 and sparc64.
      And assuming sparc64 see more testing than sparc32 change link
      order on sparc64 where issues will be caught faster.
      Signed-off-by: NSam Ravnborg <sam@ravnborg.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      a88b5ba8
  24. 28 7月, 2008 1 次提交
  25. 13 5月, 2008 1 次提交
  26. 11 5月, 2008 1 次提交
    • D
      sparc: Fix debugger syscall restart interactions. · 28e61036
      David S. Miller 提交于
      So, forever, we've had this ptrace_signal_deliver implementation
      which tries to handle all of the nasties that can occur when the
      debugger looks at a process about to take a signal.  It's meant
      to address all of these issues inside of the kernel so that the
      debugger need not be mindful of such things.
      
      Problem is, this doesn't work.
      
      The idea was that we should do the syscall restart business first, so
      that the debugger captures that state.  Otherwise, if the debugger for
      example saves the child's state, makes the child execute something
      else, then restores the saved state, we won't handle the syscall
      restart properly because we lose the "we're in a syscall" state.
      
      The code here worked for most cases, but if the debugger actually
      passes the signal through to the child unaltered, it's possible that
      we would do a syscall restart when we shouldn't have.
      
      In particular this breaks the case of debugging a process under a gdb
      which is being debugged by yet another gdb.  gdb uses sigsuspend
      to wait for SIGCHLD of the inferior, but if gdb itself is being
      debugged by a top-level gdb we get a ptrace_stop().  The top-level gdb
      does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
      signal.  But ptrace_signal_deliver() assumed the debugger would cancel
      out the signal and therefore did a syscall restart, because the return
      error was ERESTARTNOHAND.
      
      Fix this by simply making ptrace_signal_deliver() a nop, and providing
      a way for the debugger to control system call restarting properly:
      
      1) Report a "in syscall" software bit in regs->{tstate,psr}.
         It is set early on in trap entry to a system call and is fully
         visible to the debugger via ptrace() and regsets.
      
      2) Test this bit right before doing a syscall restart.  We have
         to do a final recheck right after get_signal_to_deliver() in
         case the debugger cleared the bit during ptrace_stop().
      
      3) Clear the bit in trap return so we don't accidently try to set
         that bit in the real register.
      
      As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
      like sparc64 has.
      
      M68K has this same exact bug, and is now the only other user of the
      ptrace_signal_deliver hook.  It needs to be fixed in the same exact
      way as sparc.
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      28e61036
  27. 08 5月, 2008 1 次提交
    • D
      sparc: Fix SA_ONSTACK signal handling. · dc5dc7e6
      David S. Miller 提交于
      We need to be more liberal about the alignment of the buffer given to
      us by sigaltstack().  The user should not need to be mindful of all of
      the alignment constraints we have for the stack frame.
      
      This mirrors how we handle this situation in clone() as well.
      
      Also, we align the stack even in non-SA_ONSTACK cases so that signals
      due to bad stack alignment can be delivered properly.  This makes such
      errors easier to debug and recover from.
      
      Finally, add the sanity check x86 has to make sure we won't overflow
      the signal stack.
      
      This fixes glibc testcases nptl/tst-cancel20.c and
      nptl/tst-cancelx20.c
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      dc5dc7e6
  28. 02 5月, 2008 1 次提交
    • D
      sparc64: Fix syscall restart, for real... · 2678fefe
      David S. Miller 提交于
      The change I put into copy_thread() just papered over the real
      problem.
      
      When we are looking to see if we should do a syscall restart, when
      deliverying a signal, we should only interpret the syscall return
      value as an error if the carry condition code(s) are set.
      
      Otherwise it's a success return.
      
      Also, sigreturn paths should do a pt_regs_clear_trap_type().
      
      It turns out that doing a syscall restart when returning from a fork()
      does and should happen, from time to time.  Even if copy_thread()
      returns success, copy_process() can still unwind and signal
      -ERESTARTNOINTR in the parent.
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      2678fefe
  29. 27 4月, 2008 1 次提交
    • D
      sparc: Remove old style signal frame support. · 5526b7e4
      David S. Miller 提交于
      Back around the same time we were bootstrapping the first 32-bit sparc
      Linux kernel with a SunOS userland, we made the signal frame match
      that of SunOS.
      
      By the time we even started putting together a native Linux userland
      for 32-bit Sparc we realized this layout wasn't sufficient for Linux's
      needs.
      
      Therefore we changed the layout, yet kept support for the old style
      signal frame layout in there.  The detection mechanism is that we had
      sys_sigaction() start passing in a negative signal number to indicate
      "new style signal frames please".
      
      Anyways, no binaries exist in the world that use the old stuff.  In
      fact, I bet Jakub Jelinek and myself are the only two people who ever
      had such binaries to be honest.
      
      So let's get rid of this stuff.
      
      I added an assertion using WARN_ON_ONCE() that makes sure 32-bit
      applications are passing in that negative signal number still.
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      5526b7e4
  30. 24 4月, 2008 1 次提交
  31. 22 4月, 2008 1 次提交
  32. 09 5月, 2007 1 次提交
  33. 03 10月, 2006 1 次提交
  34. 19 1月, 2006 1 次提交