2008-04-27 05:26:36 -04:00
|
|
|
/* linux/arch/sparc/kernel/signal.c
|
2005-04-16 18:20:36 -04: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 06:38:53 -04:00
|
|
|
#include <linux/tracehook.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <asm/ptrace.h>
|
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/cacheflush.h> /* flush_sig_insns */
|
|
|
|
|
|
|
|
#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
|
|
|
|
|
|
|
|
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 05:26:36 -04:00
|
|
|
struct signal_frame {
|
2005-04-16 18:20:36 -04:00
|
|
|
struct sparc_stackf ss;
|
2009-01-02 22:32:59 -05:00
|
|
|
__siginfo32_t info;
|
2005-04-16 18:20:36 -04: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 */
|
|
|
|
__siginfo_fpu_t fpu_state;
|
|
|
|
};
|
|
|
|
|
|
|
|
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 */
|
|
|
|
__siginfo_fpu_t fpu_state;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Align macros */
|
2008-04-27 05:26:36 -04:00
|
|
|
#define SF_ALIGNEDSZ (((sizeof(struct signal_frame) + 7) & (~7)))
|
2005-04-16 18:20:36 -04:00
|
|
|
#define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame) + 7) & (~7)))
|
|
|
|
|
2006-01-19 05:42:49 -05:00
|
|
|
static int _sigpause_common(old_sigset_t set)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
set &= _BLOCKABLE;
|
|
|
|
spin_lock_irq(¤t->sighand->siglock);
|
2006-01-19 05:42:49 -05:00
|
|
|
current->saved_sigmask = current->blocked;
|
2005-04-16 18:20:36 -04:00
|
|
|
siginitset(¤t->blocked, set);
|
|
|
|
recalc_sigpending();
|
|
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
|
|
|
|
2006-01-19 05:42:49 -05:00
|
|
|
current->state = TASK_INTERRUPTIBLE;
|
|
|
|
schedule();
|
|
|
|
set_thread_flag(TIF_RESTORE_SIGMASK);
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2006-01-19 05:42:49 -05:00
|
|
|
return -ERESTARTNOHAND;
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
2006-01-19 05:42:49 -05:00
|
|
|
asmlinkage int sys_sigsuspend(old_sigset_t set)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2006-01-19 05:42:49 -05:00
|
|
|
return _sigpause_common(set);
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
restore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
if (test_tsk_thread_flag(current, TIF_USEDFPU))
|
|
|
|
regs->psr &= ~PSR_EF;
|
|
|
|
#else
|
|
|
|
if (current == last_task_used_math) {
|
|
|
|
last_task_used_math = NULL;
|
|
|
|
regs->psr &= ~PSR_EF;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
set_used_math();
|
|
|
|
clear_tsk_thread_flag(current, TIF_USEDFPU);
|
|
|
|
|
|
|
|
if (!access_ok(VERIFY_READ, fpu, sizeof(*fpu)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
err = __copy_from_user(¤t->thread.float_regs[0], &fpu->si_float_regs[0],
|
|
|
|
(sizeof(unsigned long) * 32));
|
|
|
|
err |= __get_user(current->thread.fsr, &fpu->si_fsr);
|
|
|
|
err |= __get_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
|
|
|
|
if (current->thread.fpqdepth != 0)
|
|
|
|
err |= __copy_from_user(¤t->thread.fpqueue[0],
|
|
|
|
&fpu->si_fpqueue[0],
|
|
|
|
((sizeof(unsigned long) +
|
|
|
|
(sizeof(unsigned long *)))*16));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-04-27 05:26:36 -04:00
|
|
|
asmlinkage void do_sigreturn(struct pt_regs *regs)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2008-04-27 05:26:36 -04:00
|
|
|
struct signal_frame __user *sf;
|
2005-04-16 18:20:36 -04:00
|
|
|
unsigned long up_psr, pc, npc;
|
|
|
|
sigset_t set;
|
|
|
|
__siginfo_fpu_t __user *fpu_save;
|
|
|
|
int err;
|
|
|
|
|
2008-04-27 05:26:36 -04:00
|
|
|
/* Always make any pending restarted system calls return -EINTR */
|
|
|
|
current_thread_info()->restart_block.fn = do_no_restart_syscall;
|
|
|
|
|
|
|
|
synchronize_user_stack();
|
|
|
|
|
|
|
|
sf = (struct signal_frame __user *) regs->u_regs[UREG_FP];
|
2005-04-16 18:20:36 -04: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 05:07:19 -04:00
|
|
|
/* Prevent syscall restart. */
|
|
|
|
pt_regs_clear_syscall(regs);
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
err |= __get_user(fpu_save, &sf->fpu_save);
|
|
|
|
|
|
|
|
if (fpu_save)
|
|
|
|
err |= restore_fpu_state(regs, fpu_save);
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
sigdelsetmask(&set, ~_BLOCKABLE);
|
|
|
|
spin_lock_irq(¤t->sighand->siglock);
|
|
|
|
current->blocked = set;
|
|
|
|
recalc_sigpending();
|
|
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
|
|
|
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;
|
|
|
|
mm_segment_t old_fs;
|
|
|
|
sigset_t set;
|
|
|
|
stack_t st;
|
|
|
|
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 05:07:19 -04:00
|
|
|
/* Prevent syscall restart. */
|
|
|
|
pt_regs_clear_syscall(regs);
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
err |= __get_user(fpu_save, &sf->fpu_save);
|
|
|
|
|
|
|
|
if (fpu_save)
|
|
|
|
err |= restore_fpu_state(regs, fpu_save);
|
|
|
|
err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
|
|
|
|
|
|
|
|
err |= __copy_from_user(&st, &sf->stack, sizeof(stack_t));
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto segv;
|
|
|
|
|
|
|
|
regs->pc = pc;
|
|
|
|
regs->npc = npc;
|
|
|
|
|
|
|
|
/* It is more difficult to avoid calling this function than to
|
|
|
|
* call it and ignore errors.
|
|
|
|
*/
|
|
|
|
old_fs = get_fs();
|
|
|
|
set_fs(KERNEL_DS);
|
|
|
|
do_sigaltstack((const stack_t __user *) &st, NULL, (unsigned long)sf);
|
|
|
|
set_fs(old_fs);
|
|
|
|
|
|
|
|
sigdelsetmask(&set, ~_BLOCKABLE);
|
|
|
|
spin_lock_irq(¤t->sighand->siglock);
|
|
|
|
current->blocked = set;
|
|
|
|
recalc_sigpending();
|
|
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
|
|
|
return;
|
|
|
|
segv:
|
|
|
|
force_sig(SIGSEGV, current);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks if the fp is valid */
|
|
|
|
static inline int invalid_frame_pointer(void __user *fp, int fplen)
|
|
|
|
{
|
|
|
|
if ((((unsigned long) fp) & 7) ||
|
|
|
|
!__access_ok((unsigned long)fp, fplen) ||
|
|
|
|
((sparc_cpu_model == sun4 || sparc_cpu_model == sun4c) &&
|
|
|
|
((unsigned long) fp < 0xe0000000 && (unsigned long) fp >= 0x20000000)))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __user *get_sigframe(struct sigaction *sa, struct pt_regs *regs, unsigned long framesize)
|
|
|
|
{
|
2008-05-07 21:54:05 -04:00
|
|
|
unsigned long sp = regs->u_regs[UREG_FP];
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2008-05-07 21:54:05 -04: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 18:20:36 -04:00
|
|
|
|
|
|
|
/* This is the X/Open sanctioned signal stack switching. */
|
|
|
|
if (sa->sa_flags & SA_ONSTACK) {
|
2008-05-07 21:54:05 -04:00
|
|
|
if (sas_ss_flags(sp) == 0)
|
2005-04-16 18:20:36 -04:00
|
|
|
sp = current->sas_ss_sp + current->sas_ss_size;
|
|
|
|
}
|
2008-05-07 21:54:05 -04: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.
|
|
|
|
*/
|
|
|
|
sp &= ~7UL;
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
return (void __user *)(sp - framesize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
save_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
if (test_tsk_thread_flag(current, TIF_USEDFPU)) {
|
|
|
|
put_psr(get_psr() | PSR_EF);
|
|
|
|
fpsave(¤t->thread.float_regs[0], ¤t->thread.fsr,
|
|
|
|
¤t->thread.fpqueue[0], ¤t->thread.fpqdepth);
|
|
|
|
regs->psr &= ~(PSR_EF);
|
|
|
|
clear_tsk_thread_flag(current, TIF_USEDFPU);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (current == last_task_used_math) {
|
|
|
|
put_psr(get_psr() | PSR_EF);
|
|
|
|
fpsave(¤t->thread.float_regs[0], ¤t->thread.fsr,
|
|
|
|
¤t->thread.fpqueue[0], ¤t->thread.fpqdepth);
|
|
|
|
last_task_used_math = NULL;
|
|
|
|
regs->psr &= ~(PSR_EF);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
err |= __copy_to_user(&fpu->si_float_regs[0],
|
|
|
|
¤t->thread.float_regs[0],
|
|
|
|
(sizeof(unsigned long) * 32));
|
|
|
|
err |= __put_user(current->thread.fsr, &fpu->si_fsr);
|
|
|
|
err |= __put_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
|
|
|
|
if (current->thread.fpqdepth != 0)
|
|
|
|
err |= __copy_to_user(&fpu->si_fpqueue[0],
|
|
|
|
¤t->thread.fpqueue[0],
|
|
|
|
((sizeof(unsigned long) +
|
|
|
|
(sizeof(unsigned long *)))*16));
|
|
|
|
clear_used_math();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-04-27 05:26:36 -04:00
|
|
|
static void setup_frame(struct k_sigaction *ka, struct pt_regs *regs,
|
|
|
|
int signo, sigset_t *oldset)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2008-04-27 05:26:36 -04:00
|
|
|
struct signal_frame __user *sf;
|
2005-04-16 18:20:36 -04:00
|
|
|
int sigframe_size, err;
|
|
|
|
|
|
|
|
/* 1. Make sure everything is clean */
|
|
|
|
synchronize_user_stack();
|
|
|
|
|
2008-04-27 05:26:36 -04:00
|
|
|
sigframe_size = SF_ALIGNEDSZ;
|
2005-04-16 18:20:36 -04:00
|
|
|
if (!used_math())
|
|
|
|
sigframe_size -= sizeof(__siginfo_fpu_t);
|
|
|
|
|
2008-04-27 05:26:36 -04:00
|
|
|
sf = (struct signal_frame __user *)
|
2005-04-16 18:20:36 -04:00
|
|
|
get_sigframe(&ka->sa, regs, sigframe_size);
|
|
|
|
|
|
|
|
if (invalid_frame_pointer(sf, sigframe_size))
|
|
|
|
goto sigill_and_return;
|
|
|
|
|
|
|
|
if (current_thread_info()->w_saved != 0)
|
|
|
|
goto sigill_and_return;
|
|
|
|
|
|
|
|
/* 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()) {
|
|
|
|
err |= save_fpu_state(regs, &sf->fpu_state);
|
|
|
|
err |= __put_user(&sf->fpu_state, &sf->fpu_save);
|
|
|
|
} else {
|
|
|
|
err |= __put_user(0, &sf->fpu_save);
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
|
2009-01-02 22:32:59 -05:00
|
|
|
sizeof(struct reg_window32));
|
2005-04-16 18:20:36 -04:00
|
|
|
if (err)
|
|
|
|
goto sigsegv;
|
|
|
|
|
|
|
|
/* 3. signal handler back-trampoline and parameters */
|
|
|
|
regs->u_regs[UREG_FP] = (unsigned long) sf;
|
|
|
|
regs->u_regs[UREG_I0] = signo;
|
|
|
|
regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
|
|
|
|
regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
|
|
|
|
|
|
|
|
/* 4. signal handler */
|
|
|
|
regs->pc = (unsigned long) ka->sa.sa_handler;
|
|
|
|
regs->npc = (regs->pc + 4);
|
|
|
|
|
|
|
|
/* 5. return to kernel instructions */
|
|
|
|
if (ka->ka_restorer)
|
|
|
|
regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
|
|
|
|
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)
|
|
|
|
goto sigsegv;
|
|
|
|
|
|
|
|
/* Flush instruction space. */
|
|
|
|
flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
sigill_and_return:
|
|
|
|
do_exit(SIGILL);
|
|
|
|
sigsegv:
|
|
|
|
force_sigsegv(signo, current);
|
|
|
|
}
|
|
|
|
|
2008-04-27 05:26:36 -04:00
|
|
|
static void setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs,
|
|
|
|
int signo, sigset_t *oldset, siginfo_t *info)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
struct rt_signal_frame __user *sf;
|
|
|
|
int sigframe_size;
|
|
|
|
unsigned int psr;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
synchronize_user_stack();
|
|
|
|
sigframe_size = RT_ALIGNEDSZ;
|
|
|
|
if (!used_math())
|
|
|
|
sigframe_size -= sizeof(__siginfo_fpu_t);
|
|
|
|
sf = (struct rt_signal_frame __user *)
|
|
|
|
get_sigframe(&ka->sa, regs, sigframe_size);
|
|
|
|
if (invalid_frame_pointer(sf, sigframe_size))
|
|
|
|
goto sigill;
|
|
|
|
if (current_thread_info()->w_saved != 0)
|
|
|
|
goto sigill;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
err |= save_fpu_state(regs, &sf->fpu_state);
|
|
|
|
err |= __put_user(&sf->fpu_state, &sf->fpu_save);
|
|
|
|
} else {
|
|
|
|
err |= __put_user(0, &sf->fpu_save);
|
|
|
|
}
|
|
|
|
err |= __copy_to_user(&sf->mask, &oldset->sig[0], sizeof(sigset_t));
|
|
|
|
|
|
|
|
/* Setup sigaltstack */
|
|
|
|
err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp);
|
|
|
|
err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags);
|
|
|
|
err |= __put_user(current->sas_ss_size, &sf->stack.ss_size);
|
|
|
|
|
|
|
|
err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
|
2009-01-02 22:32:59 -05:00
|
|
|
sizeof(struct reg_window32));
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
err |= copy_siginfo_to_user(&sf->info, info);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto sigsegv;
|
|
|
|
|
|
|
|
regs->u_regs[UREG_FP] = (unsigned long) sf;
|
|
|
|
regs->u_regs[UREG_I0] = signo;
|
|
|
|
regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
|
|
|
|
regs->u_regs[UREG_I2] = (unsigned long) &sf->regs;
|
|
|
|
|
|
|
|
regs->pc = (unsigned long) ka->sa.sa_handler;
|
|
|
|
regs->npc = (regs->pc + 4);
|
|
|
|
|
|
|
|
if (ka->ka_restorer)
|
|
|
|
regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
|
|
|
|
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)
|
|
|
|
goto sigsegv;
|
|
|
|
|
|
|
|
/* Flush instruction space. */
|
|
|
|
flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
sigill:
|
|
|
|
do_exit(SIGILL);
|
|
|
|
sigsegv:
|
|
|
|
force_sigsegv(signo, current);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
handle_signal(unsigned long signr, struct k_sigaction *ka,
|
2008-04-20 05:14:23 -04:00
|
|
|
siginfo_t *info, sigset_t *oldset, struct pt_regs *regs)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2008-04-20 05:14:23 -04:00
|
|
|
if (ka->sa.sa_flags & SA_SIGINFO)
|
2008-04-27 05:26:36 -04:00
|
|
|
setup_rt_frame(ka, regs, signr, oldset, info);
|
2008-04-20 05:14:23 -04:00
|
|
|
else
|
2008-04-27 05:26:36 -04:00
|
|
|
setup_frame(ka, regs, signr, oldset);
|
2008-04-20 05:14:23 -04:00
|
|
|
|
[PATCH] convert signal handling of NODEFER to act like other Unix boxes.
It has been reported that the way Linux handles NODEFER for signals is
not consistent with the way other Unix boxes handle it. I've written a
program to test the behavior of how this flag affects signals and had
several reports from people who ran this on various Unix boxes,
confirming that Linux seems to be unique on the way this is handled.
The way NODEFER affects signals on other Unix boxes is as follows:
1) If NODEFER is set, other signals in sa_mask are still blocked.
2) If NODEFER is set and the signal is in sa_mask, then the signal is
still blocked. (Note: this is the behavior of all tested but Linux _and_
NetBSD 2.0 *).
The way NODEFER affects signals on Linux:
1) If NODEFER is set, other signals are _not_ blocked regardless of
sa_mask (Even NetBSD doesn't do this).
2) If NODEFER is set and the signal is in sa_mask, then the signal being
handled is not blocked.
The patch converts signal handling in all current Linux architectures to
the way most Unix boxes work.
Unix boxes that were tested: DU4, AIX 5.2, Irix 6.5, NetBSD 2.0, SFU
3.5 on WinXP, AIX 5.3, Mac OSX, and of course Linux 2.6.13-rcX.
* NetBSD was the only other Unix to behave like Linux on point #2. The
main concern was brought up by point #1 which even NetBSD isn't like
Linux. So with this patch, we leave NetBSD as the lonely one that
behaves differently here with #2.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-08-29 11:44:09 -04:00
|
|
|
spin_lock_irq(¤t->sighand->siglock);
|
|
|
|
sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
|
|
|
|
if (!(ka->sa.sa_flags & SA_NOMASK))
|
2005-04-16 18:20:36 -04:00
|
|
|
sigaddset(¤t->blocked, signr);
|
[PATCH] convert signal handling of NODEFER to act like other Unix boxes.
It has been reported that the way Linux handles NODEFER for signals is
not consistent with the way other Unix boxes handle it. I've written a
program to test the behavior of how this flag affects signals and had
several reports from people who ran this on various Unix boxes,
confirming that Linux seems to be unique on the way this is handled.
The way NODEFER affects signals on other Unix boxes is as follows:
1) If NODEFER is set, other signals in sa_mask are still blocked.
2) If NODEFER is set and the signal is in sa_mask, then the signal is
still blocked. (Note: this is the behavior of all tested but Linux _and_
NetBSD 2.0 *).
The way NODEFER affects signals on Linux:
1) If NODEFER is set, other signals are _not_ blocked regardless of
sa_mask (Even NetBSD doesn't do this).
2) If NODEFER is set and the signal is in sa_mask, then the signal being
handled is not blocked.
The patch converts signal handling in all current Linux architectures to
the way most Unix boxes work.
Unix boxes that were tested: DU4, AIX 5.2, Irix 6.5, NetBSD 2.0, SFU
3.5 on WinXP, AIX 5.3, Mac OSX, and of course Linux 2.6.13-rcX.
* NetBSD was the only other Unix to behave like Linux on point #2. The
main concern was brought up by point #1 which even NetBSD isn't like
Linux. So with this patch, we leave NetBSD as the lonely one that
behaves differently here with #2.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-08-29 11:44:09 -04:00
|
|
|
recalc_sigpending();
|
|
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
2005-04-16 18:20:36 -04: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 06:38:53 -04:00
|
|
|
static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
struct k_sigaction ka;
|
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 05:07:19 -04:00
|
|
|
int restart_syscall;
|
2006-01-19 05:42:49 -05:00
|
|
|
sigset_t *oldset;
|
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 05:07:19 -04:00
|
|
|
siginfo_t info;
|
|
|
|
int signr;
|
2005-04-16 18:20:36 -04: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 05:07:19 -04:00
|
|
|
if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C))
|
|
|
|
restart_syscall = 1;
|
|
|
|
else
|
|
|
|
restart_syscall = 0;
|
2005-04-16 18:20:36 -04:00
|
|
|
|
2006-01-19 05:42:49 -05:00
|
|
|
if (test_thread_flag(TIF_RESTORE_SIGMASK))
|
|
|
|
oldset = ¤t->saved_sigmask;
|
|
|
|
else
|
2005-04-16 18:20:36 -04:00
|
|
|
oldset = ¤t->blocked;
|
|
|
|
|
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 05:07:19 -04:00
|
|
|
signr = get_signal_to_deliver(&info, &ka, regs, NULL);
|
|
|
|
|
|
|
|
/* If the debugger messes with the program counter, it clears
|
|
|
|
* the software "in syscall" bit, directing us to not perform
|
|
|
|
* a syscall restart.
|
|
|
|
*/
|
|
|
|
if (restart_syscall && !pt_regs_is_syscall(regs))
|
|
|
|
restart_syscall = 0;
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
if (signr > 0) {
|
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 05:07:19 -04:00
|
|
|
if (restart_syscall)
|
|
|
|
syscall_restart(orig_i0, regs, &ka.sa);
|
2008-04-20 05:14:23 -04:00
|
|
|
handle_signal(signr, &ka, &info, oldset, regs);
|
|
|
|
|
2006-01-19 05:42:49 -05:00
|
|
|
/* a signal was successfully delivered; the saved
|
|
|
|
* sigmask will have been stored in the signal frame,
|
|
|
|
* and will be restored by sigreturn, so we can simply
|
|
|
|
* clear the TIF_RESTORE_SIGMASK flag.
|
|
|
|
*/
|
|
|
|
if (test_thread_flag(TIF_RESTORE_SIGMASK))
|
|
|
|
clear_thread_flag(TIF_RESTORE_SIGMASK);
|
2008-07-27 06:40:53 -04:00
|
|
|
|
|
|
|
tracehook_signal_handler(signr, &info, &ka, regs, 0);
|
2006-01-19 05:42:49 -05:00
|
|
|
return;
|
2005-04-16 18:20:36 -04: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 05:07:19 -04:00
|
|
|
if (restart_syscall &&
|
2005-04-16 18:20:36 -04:00
|
|
|
(regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
|
|
|
|
regs->u_regs[UREG_I0] == ERESTARTSYS ||
|
|
|
|
regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
|
|
|
|
/* replay the system call when we are done */
|
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 05:07:19 -04:00
|
|
|
regs->u_regs[UREG_I0] = orig_i0;
|
2005-04-16 18:20:36 -04:00
|
|
|
regs->pc -= 4;
|
|
|
|
regs->npc -= 4;
|
|
|
|
}
|
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 05:07:19 -04:00
|
|
|
if (restart_syscall &&
|
2005-04-16 18:20:36 -04:00
|
|
|
regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
|
|
|
|
regs->u_regs[UREG_G1] = __NR_restart_syscall;
|
|
|
|
regs->pc -= 4;
|
|
|
|
regs->npc -= 4;
|
|
|
|
}
|
2006-01-19 05:42:49 -05:00
|
|
|
|
|
|
|
/* if there's no signal to deliver, we just put the saved sigmask
|
|
|
|
* back
|
|
|
|
*/
|
|
|
|
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
|
|
|
|
clear_thread_flag(TIF_RESTORE_SIGMASK);
|
|
|
|
sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL);
|
|
|
|
}
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
2008-07-27 06:38:53 -04:00
|
|
|
void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0,
|
|
|
|
unsigned long thread_info_flags)
|
|
|
|
{
|
|
|
|
if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
|
|
|
|
do_signal(regs, orig_i0);
|
|
|
|
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
|
|
|
|
clear_thread_flag(TIF_NOTIFY_RESUME);
|
|
|
|
tracehook_notify_resume(regs);
|
KEYS: Add a keyctl to install a process's session keyring on its parent [try #6]
Add a keyctl to install a process's session keyring onto its parent. This
replaces the parent's session keyring. Because the COW credential code does
not permit one process to change another process's credentials directly, the
change is deferred until userspace next starts executing again. Normally this
will be after a wait*() syscall.
To support this, three new security hooks have been provided:
cred_alloc_blank() to allocate unset security creds, cred_transfer() to fill in
the blank security creds and key_session_to_parent() - which asks the LSM if
the process may replace its parent's session keyring.
The replacement may only happen if the process has the same ownership details
as its parent, and the process has LINK permission on the session keyring, and
the session keyring is owned by the process, and the LSM permits it.
Note that this requires alteration to each architecture's notify_resume path.
This has been done for all arches barring blackfin, m68k* and xtensa, all of
which need assembly alteration to support TIF_NOTIFY_RESUME. This allows the
replacement to be performed at the point the parent process resumes userspace
execution.
This allows the userspace AFS pioctl emulation to fully emulate newpag() and
the VIOCSETTOK and VIOCSETTOK2 pioctls, all of which require the ability to
alter the parent process's PAG membership. However, since kAFS doesn't use
PAGs per se, but rather dumps the keys into the session keyring, the session
keyring of the parent must be replaced if, for example, VIOCSETTOK is passed
the newpag flag.
This can be tested with the following program:
#include <stdio.h>
#include <stdlib.h>
#include <keyutils.h>
#define KEYCTL_SESSION_TO_PARENT 18
#define OSERROR(X, S) do { if ((long)(X) == -1) { perror(S); exit(1); } } while(0)
int main(int argc, char **argv)
{
key_serial_t keyring, key;
long ret;
keyring = keyctl_join_session_keyring(argv[1]);
OSERROR(keyring, "keyctl_join_session_keyring");
key = add_key("user", "a", "b", 1, keyring);
OSERROR(key, "add_key");
ret = keyctl(KEYCTL_SESSION_TO_PARENT);
OSERROR(ret, "KEYCTL_SESSION_TO_PARENT");
return 0;
}
Compiled and linked with -lkeyutils, you should see something like:
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
355907932 --alswrv 4043 -1 \_ keyring: _uid.4043
[dhowells@andromeda ~]$ /tmp/newpag
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
1055658746 --alswrv 4043 4043 \_ user: a
[dhowells@andromeda ~]$ /tmp/newpag hello
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: hello
340417692 --alswrv 4043 4043 \_ user: a
Where the test program creates a new session keyring, sticks a user key named
'a' into it and then installs it on its parent.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
2009-09-02 04:14:21 -04:00
|
|
|
if (current->replacement_session_keyring)
|
|
|
|
key_replace_session_keyring();
|
2008-07-27 06:38:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-16 18:20:36 -04:00
|
|
|
asmlinkage int
|
|
|
|
do_sys_sigstack(struct sigstack __user *ssptr, struct sigstack __user *ossptr,
|
|
|
|
unsigned long sp)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|