mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-07 22:03:14 +00:00
1930a6e739
This set of changes removes tracehook.h, moves modification of all of the ptrace fields inside of siglock to remove races, adds a missing permission check to ptrace.c The removal of tracehook.h is quite significant as it has been a major source of confusion in recent years. Much of that confusion was around task_work and TIF_NOTIFY_SIGNAL (which I have now decoupled making the semantics clearer). For people who don't know tracehook.h is a vestiage of an attempt to implement uprobes like functionality that was never fully merged, and was later superseeded by uprobes when uprobes was merged. For many years now we have been removing what tracehook functionaly a little bit at a time. To the point where now anything left in tracehook.h is some weird strange thing that is difficult to understand. Eric W. Biederman (15): ptrace: Move ptrace_report_syscall into ptrace.h ptrace/arm: Rename tracehook_report_syscall report_syscall ptrace: Create ptrace_report_syscall_{entry,exit} in ptrace.h ptrace: Remove arch_syscall_{enter,exit}_tracehook ptrace: Remove tracehook_signal_handler task_work: Remove unnecessary include from posix_timers.h task_work: Introduce task_work_pending task_work: Call tracehook_notify_signal from get_signal on all architectures task_work: Decouple TIF_NOTIFY_SIGNAL and task_work signal: Move set_notify_signal and clear_notify_signal into sched/signal.h resume_user_mode: Remove #ifdef TIF_NOTIFY_RESUME in set_notify_resume resume_user_mode: Move to resume_user_mode.h tracehook: Remove tracehook.h ptrace: Move setting/clearing ptrace_message into ptrace_stop ptrace: Return the signal to continue with from ptrace_stop Jann Horn (1): ptrace: Check PTRACE_O_SUSPEND_SECCOMP permission on PTRACE_SEIZE Yang Li (1): ptrace: Remove duplicated include in ptrace.c MAINTAINERS | 1 - arch/Kconfig | 5 +- arch/alpha/kernel/ptrace.c | 5 +- arch/alpha/kernel/signal.c | 4 +- arch/arc/kernel/ptrace.c | 5 +- arch/arc/kernel/signal.c | 4 +- arch/arm/kernel/ptrace.c | 12 +- arch/arm/kernel/signal.c | 4 +- arch/arm64/kernel/ptrace.c | 14 +-- arch/arm64/kernel/signal.c | 4 +- arch/csky/kernel/ptrace.c | 5 +- arch/csky/kernel/signal.c | 4 +- arch/h8300/kernel/ptrace.c | 5 +- arch/h8300/kernel/signal.c | 4 +- arch/hexagon/kernel/process.c | 4 +- arch/hexagon/kernel/signal.c | 1 - arch/hexagon/kernel/traps.c | 6 +- arch/ia64/kernel/process.c | 4 +- arch/ia64/kernel/ptrace.c | 6 +- arch/ia64/kernel/signal.c | 1 - arch/m68k/kernel/ptrace.c | 5 +- arch/m68k/kernel/signal.c | 4 +- arch/microblaze/kernel/ptrace.c | 5 +- arch/microblaze/kernel/signal.c | 4 +- arch/mips/kernel/ptrace.c | 5 +- arch/mips/kernel/signal.c | 4 +- arch/nds32/include/asm/syscall.h | 2 +- arch/nds32/kernel/ptrace.c | 5 +- arch/nds32/kernel/signal.c | 4 +- arch/nios2/kernel/ptrace.c | 5 +- arch/nios2/kernel/signal.c | 4 +- arch/openrisc/kernel/ptrace.c | 5 +- arch/openrisc/kernel/signal.c | 4 +- arch/parisc/kernel/ptrace.c | 7 +- arch/parisc/kernel/signal.c | 4 +- arch/powerpc/kernel/ptrace/ptrace.c | 8 +- arch/powerpc/kernel/signal.c | 4 +- arch/riscv/kernel/ptrace.c | 5 +- arch/riscv/kernel/signal.c | 4 +- arch/s390/include/asm/entry-common.h | 1 - arch/s390/kernel/ptrace.c | 1 - arch/s390/kernel/signal.c | 5 +- arch/sh/kernel/ptrace_32.c | 5 +- arch/sh/kernel/signal_32.c | 4 +- arch/sparc/kernel/ptrace_32.c | 5 +- arch/sparc/kernel/ptrace_64.c | 5 +- arch/sparc/kernel/signal32.c | 1 - arch/sparc/kernel/signal_32.c | 4 +- arch/sparc/kernel/signal_64.c | 4 +- arch/um/kernel/process.c | 4 +- arch/um/kernel/ptrace.c | 5 +- arch/x86/kernel/ptrace.c | 1 - arch/x86/kernel/signal.c | 5 +- arch/x86/mm/tlb.c | 1 + arch/xtensa/kernel/ptrace.c | 5 +- arch/xtensa/kernel/signal.c | 4 +- block/blk-cgroup.c | 2 +- fs/coredump.c | 1 - fs/exec.c | 1 - fs/io-wq.c | 6 +- fs/io_uring.c | 11 +- fs/proc/array.c | 1 - fs/proc/base.c | 1 - include/asm-generic/syscall.h | 2 +- include/linux/entry-common.h | 47 +------- include/linux/entry-kvm.h | 2 +- include/linux/posix-timers.h | 1 - include/linux/ptrace.h | 81 ++++++++++++- include/linux/resume_user_mode.h | 64 ++++++++++ include/linux/sched/signal.h | 17 +++ include/linux/task_work.h | 5 + include/linux/tracehook.h | 226 ----------------------------------- include/uapi/linux/ptrace.h | 2 +- kernel/entry/common.c | 19 +-- kernel/entry/kvm.c | 9 +- kernel/exit.c | 3 +- kernel/livepatch/transition.c | 1 - kernel/ptrace.c | 47 +++++--- kernel/seccomp.c | 1 - kernel/signal.c | 62 +++++----- kernel/task_work.c | 4 +- kernel/time/posix-cpu-timers.c | 1 + mm/memcontrol.c | 2 +- security/apparmor/domain.c | 1 - security/selinux/hooks.c | 1 - 85 files changed, 372 insertions(+), 495 deletions(-) Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEgjlraLDcwBA2B+6cC/v6Eiajj0AFAmJCQkoACgkQC/v6Eiaj j0DCWQ/5AZVFU+hX32obUNCLackHTwgcCtSOs3JNBmNA/zL/htPiYYG0ghkvtlDR Dw5J5DnxC6P7PVAdAqrpvx2uX2FebHYU0bRlyLx8LYUEP5dhyNicxX9jA882Z+vw Ud0Ue9EojwGWS76dC9YoKUj3slThMATbhA2r4GVEoof8fSNJaBxQIqath44t0FwU DinWa+tIOvZANGBZr6CUUINNIgqBIZCH/R4h6ArBhMlJpuQ5Ufk2kAaiWFwZCkX4 0LuuAwbKsCKkF8eap5I2KrIg/7zZVgxAg9O3cHOzzm8OPbKzRnNnQClcDe8perqp S6e/f3MgpE+eavd1EiLxevZ660cJChnmikXVVh8ZYYoefaMKGqBaBSsB38bNcLjY 3+f2dB+TNBFRnZs1aCujK3tWBT9QyjZDKtCBfzxDNWBpXGLhHH6j6lA5Lj+Cef5K /HNHFb+FuqedlFZh5m1Y+piFQ70hTgCa2u8b+FSOubI2hW9Zd+WzINV0ANaZ2LvZ 4YGtcyDNk1q1+c87lxP9xMRl/xi6rNg+B9T2MCo4IUnHgpSVP6VEB3osgUmrrrN0 eQlUI154G/AaDlqXLgmn1xhRmlPGfmenkxpok1AuzxvNJsfLKnpEwQSc13g3oiZr disZQxNY0kBO2Nv3G323Z6PLinhbiIIFez6cJzK5v0YJ2WtO3pY= =uEro -----END PGP SIGNATURE----- Merge tag 'ptrace-cleanups-for-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace Pull ptrace cleanups from Eric Biederman: "This set of changes removes tracehook.h, moves modification of all of the ptrace fields inside of siglock to remove races, adds a missing permission check to ptrace.c The removal of tracehook.h is quite significant as it has been a major source of confusion in recent years. Much of that confusion was around task_work and TIF_NOTIFY_SIGNAL (which I have now decoupled making the semantics clearer). For people who don't know tracehook.h is a vestiage of an attempt to implement uprobes like functionality that was never fully merged, and was later superseeded by uprobes when uprobes was merged. For many years now we have been removing what tracehook functionaly a little bit at a time. To the point where anything left in tracehook.h was some weird strange thing that was difficult to understand" * tag 'ptrace-cleanups-for-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: ptrace: Remove duplicated include in ptrace.c ptrace: Check PTRACE_O_SUSPEND_SECCOMP permission on PTRACE_SEIZE ptrace: Return the signal to continue with from ptrace_stop ptrace: Move setting/clearing ptrace_message into ptrace_stop tracehook: Remove tracehook.h resume_user_mode: Move to resume_user_mode.h resume_user_mode: Remove #ifdef TIF_NOTIFY_RESUME in set_notify_resume signal: Move set_notify_signal and clear_notify_signal into sched/signal.h task_work: Decouple TIF_NOTIFY_SIGNAL and task_work task_work: Call tracehook_notify_signal from get_signal on all architectures task_work: Introduce task_work_pending task_work: Remove unnecessary include from posix_timers.h ptrace: Remove tracehook_signal_handler ptrace: Remove arch_syscall_{enter,exit}_tracehook ptrace: Create ptrace_report_syscall_{entry,exit} in ptrace.h ptrace/arm: Rename tracehook_report_syscall report_syscall ptrace: Move ptrace_report_syscall into ptrace.h
566 lines
15 KiB
C
566 lines
15 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* linux/arch/sparc/kernel/signal.c
|
|
*
|
|
* 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>
|
|
#include <linux/resume_user_mode.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
#include <asm/ptrace.h>
|
|
#include <asm/cacheflush.h> /* flush_sig_insns */
|
|
#include <asm/switch_to.h>
|
|
|
|
#include "sigutil.h"
|
|
#include "kernel.h"
|
|
|
|
extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
|
|
void *fpqueue, unsigned long *fpqdepth);
|
|
extern void fpload(unsigned long *fpregs, unsigned long *fsr);
|
|
|
|
struct signal_frame {
|
|
struct sparc_stackf ss;
|
|
__siginfo32_t info;
|
|
__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_rwin_t __user *rwin_save;
|
|
} __attribute__((aligned(8)));
|
|
|
|
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_rwin_t __user *rwin_save;
|
|
} __attribute__((aligned(8)));
|
|
|
|
/* Align macros */
|
|
#define SF_ALIGNEDSZ (((sizeof(struct signal_frame) + 7) & (~7)))
|
|
#define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame) + 7) & (~7)))
|
|
|
|
/* Checks if the fp is valid. We always build signal frames which are
|
|
* 16-byte aligned, therefore we can always enforce that the restore
|
|
* frame has that property as well.
|
|
*/
|
|
static inline bool invalid_frame_pointer(void __user *fp, int fplen)
|
|
{
|
|
if ((((unsigned long) fp) & 15) || !access_ok(fp, fplen))
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
asmlinkage void do_sigreturn(struct pt_regs *regs)
|
|
{
|
|
unsigned long up_psr, pc, npc, ufp;
|
|
struct signal_frame __user *sf;
|
|
sigset_t set;
|
|
__siginfo_fpu_t __user *fpu_save;
|
|
__siginfo_rwin_t __user *rwin_save;
|
|
int err;
|
|
|
|
/* Always make any pending restarted system calls return -EINTR */
|
|
current->restart_block.fn = do_no_restart_syscall;
|
|
|
|
synchronize_user_stack();
|
|
|
|
sf = (struct signal_frame __user *) regs->u_regs[UREG_FP];
|
|
|
|
/* 1. Make sure we are not getting garbage from the user */
|
|
if (invalid_frame_pointer(sf, sizeof(*sf)))
|
|
goto segv_and_exit;
|
|
|
|
if (get_user(ufp, &sf->info.si_regs.u_regs[UREG_FP]))
|
|
goto segv_and_exit;
|
|
|
|
if (ufp & 0x7)
|
|
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));
|
|
|
|
/* Prevent syscall restart. */
|
|
pt_regs_clear_syscall(regs);
|
|
|
|
err |= __get_user(fpu_save, &sf->fpu_save);
|
|
if (fpu_save)
|
|
err |= restore_fpu_state(regs, fpu_save);
|
|
err |= __get_user(rwin_save, &sf->rwin_save);
|
|
if (rwin_save)
|
|
err |= restore_rwin_state(rwin_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;
|
|
|
|
set_current_blocked(&set);
|
|
return;
|
|
|
|
segv_and_exit:
|
|
force_sig(SIGSEGV);
|
|
}
|
|
|
|
asmlinkage void do_rt_sigreturn(struct pt_regs *regs)
|
|
{
|
|
struct rt_signal_frame __user *sf;
|
|
unsigned int psr, pc, npc, ufp;
|
|
__siginfo_fpu_t __user *fpu_save;
|
|
__siginfo_rwin_t __user *rwin_save;
|
|
sigset_t set;
|
|
int err;
|
|
|
|
synchronize_user_stack();
|
|
sf = (struct rt_signal_frame __user *) regs->u_regs[UREG_FP];
|
|
if (invalid_frame_pointer(sf, sizeof(*sf)))
|
|
goto segv;
|
|
|
|
if (get_user(ufp, &sf->regs.u_regs[UREG_FP]))
|
|
goto segv;
|
|
|
|
if (ufp & 0x7)
|
|
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);
|
|
|
|
/* Prevent syscall restart. */
|
|
pt_regs_clear_syscall(regs);
|
|
|
|
err |= __get_user(fpu_save, &sf->fpu_save);
|
|
if (!err && fpu_save)
|
|
err |= restore_fpu_state(regs, fpu_save);
|
|
err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
|
|
err |= restore_altstack(&sf->stack);
|
|
|
|
if (err)
|
|
goto segv;
|
|
|
|
regs->pc = pc;
|
|
regs->npc = npc;
|
|
|
|
err |= __get_user(rwin_save, &sf->rwin_save);
|
|
if (!err && rwin_save) {
|
|
if (restore_rwin_state(rwin_save))
|
|
goto segv;
|
|
}
|
|
|
|
set_current_blocked(&set);
|
|
return;
|
|
segv:
|
|
force_sig(SIGSEGV);
|
|
}
|
|
|
|
static inline void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs, unsigned long framesize)
|
|
{
|
|
unsigned long sp = regs->u_regs[UREG_FP];
|
|
|
|
/*
|
|
* 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;
|
|
|
|
/* This is the X/Open sanctioned signal stack switching. */
|
|
sp = sigsp(sp, ksig) - framesize;
|
|
|
|
/* 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 &= ~15UL;
|
|
|
|
return (void __user *) sp;
|
|
}
|
|
|
|
static int setup_frame(struct ksignal *ksig, struct pt_regs *regs,
|
|
sigset_t *oldset)
|
|
{
|
|
struct signal_frame __user *sf;
|
|
int sigframe_size, err, wsaved;
|
|
void __user *tail;
|
|
|
|
/* 1. Make sure everything is clean */
|
|
synchronize_user_stack();
|
|
|
|
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);
|
|
|
|
sf = (struct signal_frame __user *)
|
|
get_sigframe(ksig, regs, sigframe_size);
|
|
|
|
if (invalid_frame_pointer(sf, sigframe_size)) {
|
|
force_exit_sig(SIGILL);
|
|
return -EINVAL;
|
|
}
|
|
|
|
tail = sf + 1;
|
|
|
|
/* 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()) {
|
|
__siginfo_fpu_t __user *fp = tail;
|
|
tail += sizeof(*fp);
|
|
err |= save_fpu_state(regs, fp);
|
|
err |= __put_user(fp, &sf->fpu_save);
|
|
} else {
|
|
err |= __put_user(0, &sf->fpu_save);
|
|
}
|
|
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);
|
|
}
|
|
|
|
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));
|
|
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));
|
|
}
|
|
if (err)
|
|
return err;
|
|
|
|
/* 3. signal handler back-trampoline and parameters */
|
|
regs->u_regs[UREG_FP] = (unsigned long) sf;
|
|
regs->u_regs[UREG_I0] = ksig->sig;
|
|
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) ksig->ka.sa.sa_handler;
|
|
regs->npc = (regs->pc + 4);
|
|
|
|
/* 5. return to kernel instructions */
|
|
if (ksig->ka.ka_restorer)
|
|
regs->u_regs[UREG_I7] = (unsigned long)ksig->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)
|
|
return err;
|
|
|
|
/* Flush instruction space. */
|
|
flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs,
|
|
sigset_t *oldset)
|
|
{
|
|
struct rt_signal_frame __user *sf;
|
|
int sigframe_size, wsaved;
|
|
void __user *tail;
|
|
unsigned int psr;
|
|
int err;
|
|
|
|
synchronize_user_stack();
|
|
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);
|
|
sf = (struct rt_signal_frame __user *)
|
|
get_sigframe(ksig, regs, sigframe_size);
|
|
if (invalid_frame_pointer(sf, sigframe_size)) {
|
|
force_exit_sig(SIGILL);
|
|
return -EINVAL;
|
|
}
|
|
|
|
tail = sf + 1;
|
|
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) {
|
|
__siginfo_fpu_t __user *fp = tail;
|
|
tail += sizeof(*fp);
|
|
err |= save_fpu_state(regs, fp);
|
|
err |= __put_user(fp, &sf->fpu_save);
|
|
} else {
|
|
err |= __put_user(0, &sf->fpu_save);
|
|
}
|
|
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);
|
|
}
|
|
err |= __copy_to_user(&sf->mask, &oldset->sig[0], sizeof(sigset_t));
|
|
|
|
/* Setup sigaltstack */
|
|
err |= __save_altstack(&sf->stack, regs->u_regs[UREG_FP]);
|
|
|
|
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));
|
|
}
|
|
|
|
err |= copy_siginfo_to_user(&sf->info, &ksig->info);
|
|
|
|
if (err)
|
|
return err;
|
|
|
|
regs->u_regs[UREG_FP] = (unsigned long) sf;
|
|
regs->u_regs[UREG_I0] = ksig->sig;
|
|
regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
|
|
regs->u_regs[UREG_I2] = (unsigned long) &sf->regs;
|
|
|
|
regs->pc = (unsigned long) ksig->ka.sa.sa_handler;
|
|
regs->npc = (regs->pc + 4);
|
|
|
|
if (ksig->ka.ka_restorer)
|
|
regs->u_regs[UREG_I7] = (unsigned long)ksig->ka.ka_restorer;
|
|
else {
|
|
regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2);
|
|
|
|
/* mov __NR_rt_sigreturn, %g1 */
|
|
err |= __put_user(0x82102065, &sf->insns[0]);
|
|
|
|
/* t 0x10 */
|
|
err |= __put_user(0x91d02010, &sf->insns[1]);
|
|
if (err)
|
|
return err;
|
|
|
|
/* Flush instruction space. */
|
|
flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static inline void
|
|
handle_signal(struct ksignal *ksig, struct pt_regs *regs)
|
|
{
|
|
sigset_t *oldset = sigmask_to_save();
|
|
int err;
|
|
|
|
if (ksig->ka.sa.sa_flags & SA_SIGINFO)
|
|
err = setup_rt_frame(ksig, regs, oldset);
|
|
else
|
|
err = setup_frame(ksig, regs, oldset);
|
|
signal_setup_done(err, ksig, 0);
|
|
}
|
|
|
|
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.
|
|
*/
|
|
static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
|
|
{
|
|
struct ksignal ksig;
|
|
int restart_syscall;
|
|
bool has_handler;
|
|
|
|
/* 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.
|
|
*
|
|
* 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.
|
|
*/
|
|
if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C))
|
|
regs->u_regs[UREG_G6] = orig_i0;
|
|
|
|
has_handler = get_signal(&ksig);
|
|
|
|
/* If the debugger messes with the program counter, it clears
|
|
* the software "in syscall" bit, directing us to not perform
|
|
* a syscall restart.
|
|
*/
|
|
restart_syscall = 0;
|
|
if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C)) {
|
|
restart_syscall = 1;
|
|
orig_i0 = regs->u_regs[UREG_G6];
|
|
}
|
|
|
|
if (has_handler) {
|
|
if (restart_syscall)
|
|
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);
|
|
fallthrough;
|
|
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();
|
|
}
|
|
}
|
|
|
|
void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0,
|
|
unsigned long thread_info_flags)
|
|
{
|
|
if (thread_info_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
|
|
do_signal(regs, orig_i0);
|
|
if (thread_info_flags & _TIF_NOTIFY_RESUME)
|
|
resume_user_mode_work(regs);
|
|
}
|
|
|
|
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;
|
|
}
|