forked from Minki/linux
f9369910a6
Pull first series of signal handling cleanups from Al Viro: "This is just the first part of the queue (about a half of it); assorted fixes all over the place in signal handling. This one ends with all sigsuspend() implementations switched to generic one (->saved_sigmask-based). With this, a bunch of assorted old buglets are fixed and most of the missing bits of NOTIFY_RESUME hookup are in place. Two more fixes sit in arm and um trees respectively, and there's a couple of broken ones that need obvious fixes - parisc and avr32 check TIF_NOTIFY_RESUME only on one of two codepaths; fixes for that will happen in the next series" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal: (55 commits) unicore32: if there's no handler we need to restore sigmask, syscall or no syscall xtensa: add handling of TIF_NOTIFY_RESUME microblaze: drop 'oldset' argument of do_notify_resume() microblaze: handle TIF_NOTIFY_RESUME score: add handling of NOTIFY_RESUME to do_notify_resume() m68k: add TIF_NOTIFY_RESUME and handle it. sparc: kill ancient comment in sparc_sigaction() h8300: missing checks of __get_user()/__put_user() return values frv: missing checks of __get_user()/__put_user() return values cris: missing checks of __get_user()/__put_user() return values powerpc: missing checks of __get_user()/__put_user() return values sh: missing checks of __get_user()/__put_user() return values sparc: missing checks of __get_user()/__put_user() return values avr32: struct old_sigaction is never used m32r: struct old_sigaction is never used xtensa: xtensa_sigaction doesn't exist alpha: tidy signal delivery up score: don't open-code force_sigsegv() cris: don't open-code force_sigsegv() blackfin: don't open-code force_sigsegv() ...
159 lines
4.0 KiB
C
159 lines
4.0 KiB
C
/*
|
|
* Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
|
* Licensed under the GPL
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/ptrace.h>
|
|
#include <linux/sched.h>
|
|
#include <asm/siginfo.h>
|
|
#include <asm/signal.h>
|
|
#include <asm/unistd.h>
|
|
#include "frame_kern.h"
|
|
#include "kern_util.h"
|
|
|
|
EXPORT_SYMBOL(block_signals);
|
|
EXPORT_SYMBOL(unblock_signals);
|
|
|
|
#define _S(nr) (1<<((nr)-1))
|
|
|
|
#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
|
|
|
|
/*
|
|
* OK, we're invoking a handler
|
|
*/
|
|
static int handle_signal(struct pt_regs *regs, unsigned long signr,
|
|
struct k_sigaction *ka, siginfo_t *info,
|
|
sigset_t *oldset)
|
|
{
|
|
unsigned long sp;
|
|
int err;
|
|
|
|
/* Did we come from a system call? */
|
|
if (PT_REGS_SYSCALL_NR(regs) >= 0) {
|
|
/* If so, check system call restarting.. */
|
|
switch (PT_REGS_SYSCALL_RET(regs)) {
|
|
case -ERESTART_RESTARTBLOCK:
|
|
case -ERESTARTNOHAND:
|
|
PT_REGS_SYSCALL_RET(regs) = -EINTR;
|
|
break;
|
|
|
|
case -ERESTARTSYS:
|
|
if (!(ka->sa.sa_flags & SA_RESTART)) {
|
|
PT_REGS_SYSCALL_RET(regs) = -EINTR;
|
|
break;
|
|
}
|
|
/* fallthrough */
|
|
case -ERESTARTNOINTR:
|
|
PT_REGS_RESTART_SYSCALL(regs);
|
|
PT_REGS_ORIG_SYSCALL(regs) = PT_REGS_SYSCALL_NR(regs);
|
|
break;
|
|
}
|
|
}
|
|
|
|
sp = PT_REGS_SP(regs);
|
|
if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags(sp) == 0))
|
|
sp = current->sas_ss_sp + current->sas_ss_size;
|
|
|
|
#ifdef CONFIG_ARCH_HAS_SC_SIGNALS
|
|
if (!(ka->sa.sa_flags & SA_SIGINFO))
|
|
err = setup_signal_stack_sc(sp, signr, ka, regs, oldset);
|
|
else
|
|
#endif
|
|
err = setup_signal_stack_si(sp, signr, ka, regs, info, oldset);
|
|
|
|
if (err)
|
|
force_sigsegv(signr, current);
|
|
else
|
|
block_sigmask(ka, signr);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int kern_do_signal(struct pt_regs *regs)
|
|
{
|
|
struct k_sigaction ka_copy;
|
|
siginfo_t info;
|
|
int sig, handled_sig = 0;
|
|
|
|
while ((sig = get_signal_to_deliver(&info, &ka_copy, regs, NULL)) > 0) {
|
|
sigset_t *oldset;
|
|
if (test_thread_flag(TIF_RESTORE_SIGMASK))
|
|
oldset = ¤t->saved_sigmask;
|
|
else
|
|
oldset = ¤t->blocked;
|
|
handled_sig = 1;
|
|
/* Whee! Actually deliver the signal. */
|
|
if (!handle_signal(regs, sig, &ka_copy, &info, oldset)) {
|
|
/*
|
|
* 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);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* Did we come from a system call? */
|
|
if (!handled_sig && (PT_REGS_SYSCALL_NR(regs) >= 0)) {
|
|
/* Restart the system call - no handlers present */
|
|
switch (PT_REGS_SYSCALL_RET(regs)) {
|
|
case -ERESTARTNOHAND:
|
|
case -ERESTARTSYS:
|
|
case -ERESTARTNOINTR:
|
|
PT_REGS_ORIG_SYSCALL(regs) = PT_REGS_SYSCALL_NR(regs);
|
|
PT_REGS_RESTART_SYSCALL(regs);
|
|
break;
|
|
case -ERESTART_RESTARTBLOCK:
|
|
PT_REGS_ORIG_SYSCALL(regs) = __NR_restart_syscall;
|
|
PT_REGS_RESTART_SYSCALL(regs);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* This closes a way to execute a system call on the host. If
|
|
* you set a breakpoint on a system call instruction and singlestep
|
|
* from it, the tracing thread used to PTRACE_SINGLESTEP the process
|
|
* rather than PTRACE_SYSCALL it, allowing the system call to execute
|
|
* on the host. The tracing thread will check this flag and
|
|
* PTRACE_SYSCALL if necessary.
|
|
*/
|
|
if (current->ptrace & PT_DTRACE)
|
|
current->thread.singlestep_syscall =
|
|
is_syscall(PT_REGS_IP(¤t->thread.regs));
|
|
|
|
/*
|
|
* if there's no signal to deliver, we just put the saved sigmask
|
|
* back
|
|
*/
|
|
if (!handled_sig && test_thread_flag(TIF_RESTORE_SIGMASK)) {
|
|
clear_thread_flag(TIF_RESTORE_SIGMASK);
|
|
sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL);
|
|
}
|
|
return handled_sig;
|
|
}
|
|
|
|
int do_signal(void)
|
|
{
|
|
return kern_do_signal(¤t->thread.regs);
|
|
}
|
|
|
|
/*
|
|
* Atomically swap in the new signal mask, and wait for a signal.
|
|
*/
|
|
long sys_sigsuspend(int history0, int history1, old_sigset_t mask)
|
|
{
|
|
sigset_t blocked;
|
|
siginitset(&blocked, mask);
|
|
return sigsuspend(&blocked);
|
|
}
|
|
|
|
long sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
|
|
{
|
|
return do_sigaltstack(uss, uoss, PT_REGS_SP(¤t->thread.regs));
|
|
}
|