2008-04-27 09:26:36 +00:00
|
|
|
/* linux/arch/sparc/kernel/signal.c
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
|
|
* Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
|
|
|
|
* Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
|
|
|
|
* Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/unistd.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/binfmts.h> /* do_coredum */
|
|
|
|
#include <linux/bitops.h>
|
2008-07-27 10:38:53 +00:00
|
|
|
#include <linux/tracehook.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <asm/ptrace.h>
|
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/cacheflush.h> /* flush_sig_insns */
|
2012-03-28 17:30:03 +00:00
|
|
|
#include <asm/switch_to.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-08-21 00:14:54 +00:00
|
|
|
#include "sigutil.h"
|
2014-04-21 19:39:26 +00:00
|
|
|
#include "kernel.h"
|
2011-08-21 00:14:54 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
|
|
|
|
void *fpqueue, unsigned long *fpqdepth);
|
|
|
|
extern void fpload(unsigned long *fpregs, unsigned long *fsr);
|
|
|
|
|
2008-04-27 09:26:36 +00:00
|
|
|
struct signal_frame {
|
2005-04-16 22:20:36 +00:00
|
|
|
struct sparc_stackf ss;
|
2009-01-03 03:32:59 +00:00
|
|
|
__siginfo32_t info;
|
2005-04-16 22:20:36 +00:00
|
|
|
__siginfo_fpu_t __user *fpu_save;
|
|
|
|
unsigned long insns[2] __attribute__ ((aligned (8)));
|
|
|
|
unsigned int extramask[_NSIG_WORDS - 1];
|
|
|
|
unsigned int extra_size; /* Should be 0 */
|
2011-08-21 00:14:54 +00:00
|
|
|
__siginfo_rwin_t __user *rwin_save;
|
|
|
|
} __attribute__((aligned(8)));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
struct rt_signal_frame {
|
|
|
|
struct sparc_stackf ss;
|
|
|
|
siginfo_t info;
|
|
|
|
struct pt_regs regs;
|
|
|
|
sigset_t mask;
|
|
|
|
__siginfo_fpu_t __user *fpu_save;
|
|
|
|
unsigned int insns[2];
|
|
|
|
stack_t stack;
|
|
|
|
unsigned int extra_size; /* Should be 0 */
|
2011-08-21 00:14:54 +00:00
|
|
|
__siginfo_rwin_t __user *rwin_save;
|
|
|
|
} __attribute__((aligned(8)));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Align macros */
|
2008-04-27 09:26:36 +00:00
|
|
|
#define SF_ALIGNEDSZ (((sizeof(struct signal_frame) + 7) & (~7)))
|
2005-04-16 22:20:36 +00:00
|
|
|
#define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame) + 7) & (~7)))
|
|
|
|
|
2008-04-27 09:26:36 +00:00
|
|
|
asmlinkage void do_sigreturn(struct pt_regs *regs)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-04-27 09:26:36 +00:00
|
|
|
struct signal_frame __user *sf;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long up_psr, pc, npc;
|
|
|
|
sigset_t set;
|
|
|
|
__siginfo_fpu_t __user *fpu_save;
|
2011-08-21 00:14:54 +00:00
|
|
|
__siginfo_rwin_t __user *rwin_save;
|
2005-04-16 22:20:36 +00:00
|
|
|
int err;
|
|
|
|
|
2008-04-27 09:26:36 +00:00
|
|
|
/* Always make any pending restarted system calls return -EINTR */
|
2015-02-12 23:01:14 +00:00
|
|
|
current->restart_block.fn = do_no_restart_syscall;
|
2008-04-27 09:26:36 +00:00
|
|
|
|
|
|
|
synchronize_user_stack();
|
|
|
|
|
|
|
|
sf = (struct signal_frame __user *) regs->u_regs[UREG_FP];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* 1. Make sure we are not getting garbage from the user */
|
|
|
|
if (!access_ok(VERIFY_READ, sf, sizeof(*sf)))
|
|
|
|
goto segv_and_exit;
|
|
|
|
|
|
|
|
if (((unsigned long) sf) & 3)
|
|
|
|
goto segv_and_exit;
|
|
|
|
|
|
|
|
err = __get_user(pc, &sf->info.si_regs.pc);
|
|
|
|
err |= __get_user(npc, &sf->info.si_regs.npc);
|
|
|
|
|
|
|
|
if ((pc | npc) & 3)
|
|
|
|
goto segv_and_exit;
|
|
|
|
|
|
|
|
/* 2. Restore the state */
|
|
|
|
up_psr = regs->psr;
|
|
|
|
err |= __copy_from_user(regs, &sf->info.si_regs, sizeof(struct pt_regs));
|
|
|
|
|
|
|
|
/* User can only change condition codes and FPU enabling in %psr. */
|
|
|
|
regs->psr = (up_psr & ~(PSR_ICC | PSR_EF))
|
|
|
|
| (regs->psr & (PSR_ICC | PSR_EF));
|
|
|
|
|
sparc: Fix debugger syscall restart interactions.
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: David S. Miller <davem@davemloft.net>
2008-05-11 09:07:19 +00:00
|
|
|
/* Prevent syscall restart. */
|
|
|
|
pt_regs_clear_syscall(regs);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
err |= __get_user(fpu_save, &sf->fpu_save);
|
|
|
|
if (fpu_save)
|
|
|
|
err |= restore_fpu_state(regs, fpu_save);
|
2011-08-21 00:14:54 +00:00
|
|
|
err |= __get_user(rwin_save, &sf->rwin_save);
|
|
|
|
if (rwin_save)
|
|
|
|
err |= restore_rwin_state(rwin_save);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* This is pretty much atomic, no amount locking would prevent
|
|
|
|
* the races which exist anyways.
|
|
|
|
*/
|
|
|
|
err |= __get_user(set.sig[0], &sf->info.si_mask);
|
|
|
|
err |= __copy_from_user(&set.sig[1], &sf->extramask,
|
|
|
|
(_NSIG_WORDS-1) * sizeof(unsigned int));
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto segv_and_exit;
|
|
|
|
|
2011-08-11 13:57:02 +00:00
|
|
|
set_current_blocked(&set);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
segv_and_exit:
|
|
|
|
force_sig(SIGSEGV, current);
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage void do_rt_sigreturn(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
struct rt_signal_frame __user *sf;
|
|
|
|
unsigned int psr, pc, npc;
|
|
|
|
__siginfo_fpu_t __user *fpu_save;
|
2011-08-21 00:14:54 +00:00
|
|
|
__siginfo_rwin_t __user *rwin_save;
|
2005-04-16 22:20:36 +00:00
|
|
|
sigset_t set;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
synchronize_user_stack();
|
|
|
|
sf = (struct rt_signal_frame __user *) regs->u_regs[UREG_FP];
|
|
|
|
if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) ||
|
|
|
|
(((unsigned long) sf) & 0x03))
|
|
|
|
goto segv;
|
|
|
|
|
|
|
|
err = __get_user(pc, &sf->regs.pc);
|
|
|
|
err |= __get_user(npc, &sf->regs.npc);
|
|
|
|
err |= ((pc | npc) & 0x03);
|
|
|
|
|
|
|
|
err |= __get_user(regs->y, &sf->regs.y);
|
|
|
|
err |= __get_user(psr, &sf->regs.psr);
|
|
|
|
|
|
|
|
err |= __copy_from_user(®s->u_regs[UREG_G1],
|
|
|
|
&sf->regs.u_regs[UREG_G1], 15 * sizeof(u32));
|
|
|
|
|
|
|
|
regs->psr = (regs->psr & ~PSR_ICC) | (psr & PSR_ICC);
|
|
|
|
|
sparc: Fix debugger syscall restart interactions.
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: David S. Miller <davem@davemloft.net>
2008-05-11 09:07:19 +00:00
|
|
|
/* Prevent syscall restart. */
|
|
|
|
pt_regs_clear_syscall(regs);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
err |= __get_user(fpu_save, &sf->fpu_save);
|
2011-08-21 00:14:54 +00:00
|
|
|
if (!err && fpu_save)
|
2005-04-16 22:20:36 +00:00
|
|
|
err |= restore_fpu_state(regs, fpu_save);
|
|
|
|
err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
|
2012-12-23 08:41:17 +00:00
|
|
|
err |= restore_altstack(&sf->stack);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto segv;
|
|
|
|
|
|
|
|
regs->pc = pc;
|
|
|
|
regs->npc = npc;
|
|
|
|
|
2011-08-21 00:14:54 +00:00
|
|
|
err |= __get_user(rwin_save, &sf->rwin_save);
|
|
|
|
if (!err && rwin_save) {
|
|
|
|
if (restore_rwin_state(rwin_save))
|
|
|
|
goto segv;
|
|
|
|
}
|
|
|
|
|
2011-08-11 13:57:02 +00:00
|
|
|
set_current_blocked(&set);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
segv:
|
|
|
|
force_sig(SIGSEGV, current);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks if the fp is valid */
|
|
|
|
static inline int invalid_frame_pointer(void __user *fp, int fplen)
|
|
|
|
{
|
2012-05-11 11:35:14 +00:00
|
|
|
if ((((unsigned long) fp) & 7) || !__access_ok((unsigned long)fp, fplen))
|
2005-04-16 22:20:36 +00:00
|
|
|
return 1;
|
2012-05-11 11:35:14 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
static inline void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs, unsigned long framesize)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-05-08 01:54:05 +00:00
|
|
|
unsigned long sp = regs->u_regs[UREG_FP];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-05-08 01:54:05 +00:00
|
|
|
/*
|
|
|
|
* If we are on the alternate signal stack and would overflow it, don't.
|
|
|
|
* Return an always-bogus address instead so we will die with SIGSEGV.
|
|
|
|
*/
|
|
|
|
if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize)))
|
|
|
|
return (void __user *) -1L;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* This is the X/Open sanctioned signal stack switching. */
|
2012-11-08 04:48:13 +00:00
|
|
|
sp = sigsp(sp, ksig) - framesize;
|
2010-02-10 00:18:40 +00:00
|
|
|
|
2008-05-08 01:54:05 +00:00
|
|
|
/* Always align the stack frame. This handles two cases. First,
|
|
|
|
* sigaltstack need not be mindful of platform specific stack
|
|
|
|
* alignment. Second, if we took this signal because the stack
|
|
|
|
* is not aligned properly, we'd like to take the signal cleanly
|
|
|
|
* and report that.
|
|
|
|
*/
|
2010-02-10 00:18:40 +00:00
|
|
|
sp &= ~15UL;
|
2008-05-08 01:54:05 +00:00
|
|
|
|
2010-02-10 00:18:40 +00:00
|
|
|
return (void __user *) sp;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
static int setup_frame(struct ksignal *ksig, struct pt_regs *regs,
|
|
|
|
sigset_t *oldset)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-04-27 09:26:36 +00:00
|
|
|
struct signal_frame __user *sf;
|
2011-08-21 00:14:54 +00:00
|
|
|
int sigframe_size, err, wsaved;
|
|
|
|
void __user *tail;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* 1. Make sure everything is clean */
|
|
|
|
synchronize_user_stack();
|
|
|
|
|
2011-08-21 00:14:54 +00:00
|
|
|
wsaved = current_thread_info()->w_saved;
|
|
|
|
|
|
|
|
sigframe_size = sizeof(*sf);
|
|
|
|
if (used_math())
|
|
|
|
sigframe_size += sizeof(__siginfo_fpu_t);
|
|
|
|
if (wsaved)
|
|
|
|
sigframe_size += sizeof(__siginfo_rwin_t);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-27 09:26:36 +00:00
|
|
|
sf = (struct signal_frame __user *)
|
2012-11-08 04:48:13 +00:00
|
|
|
get_sigframe(ksig, regs, sigframe_size);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
if (invalid_frame_pointer(sf, sigframe_size)) {
|
|
|
|
do_exit(SIGILL);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-08-21 00:14:54 +00:00
|
|
|
tail = sf + 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* 2. Save the current process state */
|
|
|
|
err = __copy_to_user(&sf->info.si_regs, regs, sizeof(struct pt_regs));
|
|
|
|
|
|
|
|
err |= __put_user(0, &sf->extra_size);
|
|
|
|
|
|
|
|
if (used_math()) {
|
2011-08-21 00:14:54 +00:00
|
|
|
__siginfo_fpu_t __user *fp = tail;
|
|
|
|
tail += sizeof(*fp);
|
|
|
|
err |= save_fpu_state(regs, fp);
|
|
|
|
err |= __put_user(fp, &sf->fpu_save);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
|
|
|
err |= __put_user(0, &sf->fpu_save);
|
|
|
|
}
|
2011-08-21 00:14:54 +00:00
|
|
|
if (wsaved) {
|
|
|
|
__siginfo_rwin_t __user *rwp = tail;
|
|
|
|
tail += sizeof(*rwp);
|
|
|
|
err |= save_rwin_state(wsaved, rwp);
|
|
|
|
err |= __put_user(rwp, &sf->rwin_save);
|
|
|
|
} else {
|
|
|
|
err |= __put_user(0, &sf->rwin_save);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err |= __put_user(oldset->sig[0], &sf->info.si_mask);
|
|
|
|
err |= __copy_to_user(sf->extramask, &oldset->sig[1],
|
|
|
|
(_NSIG_WORDS - 1) * sizeof(unsigned int));
|
2011-08-21 00:14:54 +00:00
|
|
|
if (!wsaved) {
|
|
|
|
err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
|
|
|
|
sizeof(struct reg_window32));
|
|
|
|
} else {
|
|
|
|
struct reg_window32 *rp;
|
|
|
|
|
|
|
|
rp = ¤t_thread_info()->reg_window[wsaved - 1];
|
|
|
|
err |= __copy_to_user(sf, rp, sizeof(struct reg_window32));
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err)
|
2012-11-08 04:48:13 +00:00
|
|
|
return err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* 3. signal handler back-trampoline and parameters */
|
|
|
|
regs->u_regs[UREG_FP] = (unsigned long) sf;
|
2012-11-08 04:48:13 +00:00
|
|
|
regs->u_regs[UREG_I0] = ksig->sig;
|
2005-04-16 22:20:36 +00:00
|
|
|
regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
|
|
|
|
regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
|
|
|
|
|
|
|
|
/* 4. signal handler */
|
2012-11-08 04:48:13 +00:00
|
|
|
regs->pc = (unsigned long) ksig->ka.sa.sa_handler;
|
2005-04-16 22:20:36 +00:00
|
|
|
regs->npc = (regs->pc + 4);
|
|
|
|
|
|
|
|
/* 5. return to kernel instructions */
|
2012-11-08 04:48:13 +00:00
|
|
|
if (ksig->ka.ka_restorer)
|
|
|
|
regs->u_regs[UREG_I7] = (unsigned long)ksig->ka.ka_restorer;
|
2005-04-16 22:20:36 +00:00
|
|
|
else {
|
|
|
|
regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2);
|
|
|
|
|
|
|
|
/* mov __NR_sigreturn, %g1 */
|
|
|
|
err |= __put_user(0x821020d8, &sf->insns[0]);
|
|
|
|
|
|
|
|
/* t 0x10 */
|
|
|
|
err |= __put_user(0x91d02010, &sf->insns[1]);
|
|
|
|
if (err)
|
2012-11-08 04:48:13 +00:00
|
|
|
return err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Flush instruction space. */
|
|
|
|
flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
|
|
|
|
}
|
2010-09-22 04:41:12 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
static int setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs,
|
|
|
|
sigset_t *oldset)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct rt_signal_frame __user *sf;
|
2011-08-21 00:14:54 +00:00
|
|
|
int sigframe_size, wsaved;
|
|
|
|
void __user *tail;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int psr;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
synchronize_user_stack();
|
2011-08-21 00:14:54 +00:00
|
|
|
wsaved = current_thread_info()->w_saved;
|
|
|
|
sigframe_size = sizeof(*sf);
|
|
|
|
if (used_math())
|
|
|
|
sigframe_size += sizeof(__siginfo_fpu_t);
|
|
|
|
if (wsaved)
|
|
|
|
sigframe_size += sizeof(__siginfo_rwin_t);
|
2005-04-16 22:20:36 +00:00
|
|
|
sf = (struct rt_signal_frame __user *)
|
2012-11-08 04:48:13 +00:00
|
|
|
get_sigframe(ksig, regs, sigframe_size);
|
|
|
|
if (invalid_frame_pointer(sf, sigframe_size)) {
|
|
|
|
do_exit(SIGILL);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-08-21 00:14:54 +00:00
|
|
|
tail = sf + 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
err = __put_user(regs->pc, &sf->regs.pc);
|
|
|
|
err |= __put_user(regs->npc, &sf->regs.npc);
|
|
|
|
err |= __put_user(regs->y, &sf->regs.y);
|
|
|
|
psr = regs->psr;
|
|
|
|
if (used_math())
|
|
|
|
psr |= PSR_EF;
|
|
|
|
err |= __put_user(psr, &sf->regs.psr);
|
|
|
|
err |= __copy_to_user(&sf->regs.u_regs, regs->u_regs, sizeof(regs->u_regs));
|
|
|
|
err |= __put_user(0, &sf->extra_size);
|
|
|
|
|
|
|
|
if (psr & PSR_EF) {
|
2014-04-21 19:39:26 +00:00
|
|
|
__siginfo_fpu_t __user *fp = tail;
|
2011-08-21 00:14:54 +00:00
|
|
|
tail += sizeof(*fp);
|
|
|
|
err |= save_fpu_state(regs, fp);
|
|
|
|
err |= __put_user(fp, &sf->fpu_save);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
|
|
|
err |= __put_user(0, &sf->fpu_save);
|
|
|
|
}
|
2011-08-21 00:14:54 +00:00
|
|
|
if (wsaved) {
|
2014-04-21 19:39:26 +00:00
|
|
|
__siginfo_rwin_t __user *rwp = tail;
|
2011-08-21 00:14:54 +00:00
|
|
|
tail += sizeof(*rwp);
|
|
|
|
err |= save_rwin_state(wsaved, rwp);
|
|
|
|
err |= __put_user(rwp, &sf->rwin_save);
|
|
|
|
} else {
|
|
|
|
err |= __put_user(0, &sf->rwin_save);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
err |= __copy_to_user(&sf->mask, &oldset->sig[0], sizeof(sigset_t));
|
|
|
|
|
|
|
|
/* Setup sigaltstack */
|
2012-12-23 08:41:17 +00:00
|
|
|
err |= __save_altstack(&sf->stack, regs->u_regs[UREG_FP]);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-08-21 00:14:54 +00:00
|
|
|
if (!wsaved) {
|
|
|
|
err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
|
|
|
|
sizeof(struct reg_window32));
|
|
|
|
} else {
|
|
|
|
struct reg_window32 *rp;
|
|
|
|
|
|
|
|
rp = ¤t_thread_info()->reg_window[wsaved - 1];
|
|
|
|
err |= __copy_to_user(sf, rp, sizeof(struct reg_window32));
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
err |= copy_siginfo_to_user(&sf->info, &ksig->info);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (err)
|
2012-11-08 04:48:13 +00:00
|
|
|
return err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
regs->u_regs[UREG_FP] = (unsigned long) sf;
|
2012-11-08 04:48:13 +00:00
|
|
|
regs->u_regs[UREG_I0] = ksig->sig;
|
2005-04-16 22:20:36 +00:00
|
|
|
regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
|
|
|
|
regs->u_regs[UREG_I2] = (unsigned long) &sf->regs;
|
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
regs->pc = (unsigned long) ksig->ka.sa.sa_handler;
|
2005-04-16 22:20:36 +00:00
|
|
|
regs->npc = (regs->pc + 4);
|
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
if (ksig->ka.ka_restorer)
|
|
|
|
regs->u_regs[UREG_I7] = (unsigned long)ksig->ka.ka_restorer;
|
2005-04-16 22:20:36 +00:00
|
|
|
else {
|
|
|
|
regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2);
|
|
|
|
|
|
|
|
/* mov __NR_sigreturn, %g1 */
|
|
|
|
err |= __put_user(0x821020d8, &sf->insns[0]);
|
|
|
|
|
|
|
|
/* t 0x10 */
|
|
|
|
err |= __put_user(0x91d02010, &sf->insns[1]);
|
|
|
|
if (err)
|
2012-11-08 04:48:13 +00:00
|
|
|
return err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Flush instruction space. */
|
|
|
|
flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
|
|
|
|
}
|
2010-09-22 04:41:12 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-05-22 03:42:15 +00:00
|
|
|
static inline void
|
2012-11-08 04:48:13 +00:00
|
|
|
handle_signal(struct ksignal *ksig, struct pt_regs *regs)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-05-02 13:59:21 +00:00
|
|
|
sigset_t *oldset = sigmask_to_save();
|
2010-09-22 04:41:12 +00:00
|
|
|
int err;
|
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
if (ksig->ka.sa.sa_flags & SA_SIGINFO)
|
|
|
|
err = setup_rt_frame(ksig, regs, oldset);
|
2008-04-20 09:14:23 +00:00
|
|
|
else
|
2012-11-08 04:48:13 +00:00
|
|
|
err = setup_frame(ksig, regs, oldset);
|
|
|
|
signal_setup_done(err, ksig, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
|
|
|
|
struct sigaction *sa)
|
|
|
|
{
|
|
|
|
switch(regs->u_regs[UREG_I0]) {
|
|
|
|
case ERESTART_RESTARTBLOCK:
|
|
|
|
case ERESTARTNOHAND:
|
|
|
|
no_system_call_restart:
|
|
|
|
regs->u_regs[UREG_I0] = EINTR;
|
|
|
|
regs->psr |= PSR_C;
|
|
|
|
break;
|
|
|
|
case ERESTARTSYS:
|
|
|
|
if (!(sa->sa_flags & SA_RESTART))
|
|
|
|
goto no_system_call_restart;
|
|
|
|
/* fallthrough */
|
|
|
|
case ERESTARTNOINTR:
|
|
|
|
regs->u_regs[UREG_I0] = orig_i0;
|
|
|
|
regs->pc -= 4;
|
|
|
|
regs->npc -= 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that 'init' is a special process: it doesn't get signals it doesn't
|
|
|
|
* want to handle. Thus you cannot kill init even with a SIGKILL even by
|
|
|
|
* mistake.
|
|
|
|
*/
|
2008-07-27 10:38:53 +00:00
|
|
|
static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-11-08 04:48:13 +00:00
|
|
|
struct ksignal ksig;
|
sparc: Fix debugger syscall restart interactions.
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: David S. Miller <davem@davemloft.net>
2008-05-11 09:07:19 +00:00
|
|
|
int restart_syscall;
|
2012-11-08 04:48:13 +00:00
|
|
|
bool has_handler;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-11-15 04:32:16 +00:00
|
|
|
/* It's a lot of work and synchronization to add a new ptrace
|
|
|
|
* register for GDB to save and restore in order to get
|
|
|
|
* orig_i0 correct for syscall restarts when debugging.
|
|
|
|
*
|
2011-11-15 20:57:00 +00:00
|
|
|
* Although it should be the case that most of the global
|
|
|
|
* registers are volatile across a system call, glibc already
|
|
|
|
* depends upon that fact that we preserve them. So we can't
|
|
|
|
* just use any global register to save away the orig_i0 value.
|
|
|
|
*
|
|
|
|
* In particular %g2, %g3, %g4, and %g5 are all assumed to be
|
|
|
|
* preserved across a system call trap by various pieces of
|
|
|
|
* code in glibc.
|
|
|
|
*
|
|
|
|
* %g7 is used as the "thread register". %g6 is not used in
|
|
|
|
* any fixed manner. %g6 is used as a scratch register and
|
|
|
|
* a compiler temporary, but it's value is never used across
|
|
|
|
* a system call. Therefore %g6 is usable for orig_i0 storage.
|
2011-11-15 04:32:16 +00:00
|
|
|
*/
|
sparc: Fix debugger syscall restart interactions.
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: David S. Miller <davem@davemloft.net>
2008-05-11 09:07:19 +00:00
|
|
|
if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C))
|
2011-11-15 20:57:00 +00:00
|
|
|
regs->u_regs[UREG_G6] = orig_i0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
has_handler = get_signal(&ksig);
|
sparc: Fix debugger syscall restart interactions.
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: David S. Miller <davem@davemloft.net>
2008-05-11 09:07:19 +00:00
|
|
|
|
|
|
|
/* If the debugger messes with the program counter, it clears
|
|
|
|
* the software "in syscall" bit, directing us to not perform
|
|
|
|
* a syscall restart.
|
|
|
|
*/
|
2011-11-15 04:32:16 +00:00
|
|
|
restart_syscall = 0;
|
|
|
|
if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C)) {
|
|
|
|
restart_syscall = 1;
|
2011-11-15 20:57:00 +00:00
|
|
|
orig_i0 = regs->u_regs[UREG_G6];
|
2011-11-15 04:32:16 +00:00
|
|
|
}
|
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
if (has_handler) {
|
sparc: Fix debugger syscall restart interactions.
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: David S. Miller <davem@davemloft.net>
2008-05-11 09:07:19 +00:00
|
|
|
if (restart_syscall)
|
2012-11-08 04:48:13 +00:00
|
|
|
syscall_restart(orig_i0, regs, &ksig.ka.sa);
|
|
|
|
handle_signal(&ksig, regs);
|
|
|
|
} else {
|
|
|
|
if (restart_syscall) {
|
|
|
|
switch (regs->u_regs[UREG_I0]) {
|
|
|
|
case ERESTARTNOHAND:
|
|
|
|
case ERESTARTSYS:
|
|
|
|
case ERESTARTNOINTR:
|
|
|
|
/* replay the system call when we are done */
|
|
|
|
regs->u_regs[UREG_I0] = orig_i0;
|
|
|
|
regs->pc -= 4;
|
|
|
|
regs->npc -= 4;
|
|
|
|
pt_regs_clear_syscall(regs);
|
|
|
|
case ERESTART_RESTARTBLOCK:
|
|
|
|
regs->u_regs[UREG_G1] = __NR_restart_syscall;
|
|
|
|
regs->pc -= 4;
|
|
|
|
regs->npc -= 4;
|
|
|
|
pt_regs_clear_syscall(regs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
restore_saved_sigmask();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-27 10:38:53 +00:00
|
|
|
void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0,
|
|
|
|
unsigned long thread_info_flags)
|
|
|
|
{
|
2012-05-23 19:28:58 +00:00
|
|
|
if (thread_info_flags & _TIF_SIGPENDING)
|
2008-07-27 10:38:53 +00:00
|
|
|
do_signal(regs, orig_i0);
|
|
|
|
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
|
|
|
|
clear_thread_flag(TIF_NOTIFY_RESUME);
|
|
|
|
tracehook_notify_resume(regs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-21 19:39:26 +00:00
|
|
|
asmlinkage int do_sys_sigstack(struct sigstack __user *ssptr,
|
|
|
|
struct sigstack __user *ossptr,
|
|
|
|
unsigned long sp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int ret = -EFAULT;
|
|
|
|
|
|
|
|
/* First see if old state is wanted. */
|
|
|
|
if (ossptr) {
|
|
|
|
if (put_user(current->sas_ss_sp + current->sas_ss_size,
|
|
|
|
&ossptr->the_stack) ||
|
|
|
|
__put_user(on_sig_stack(sp), &ossptr->cur_status))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now see if we want to update the new state. */
|
|
|
|
if (ssptr) {
|
|
|
|
char *ss_sp;
|
|
|
|
|
|
|
|
if (get_user(ss_sp, &ssptr->the_stack))
|
|
|
|
goto out;
|
|
|
|
/* If the current stack was set with sigaltstack, don't
|
|
|
|
swap stacks while we are on it. */
|
|
|
|
ret = -EPERM;
|
|
|
|
if (current->sas_ss_sp && on_sig_stack(sp))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Since we don't know the extent of the stack, and we don't
|
|
|
|
track onstack-ness, but rather calculate it, we must
|
|
|
|
presume a size. Ho hum this interface is lossy. */
|
|
|
|
current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ;
|
|
|
|
current->sas_ss_size = SIGSTKSZ;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|