Commit d1199431 authored by Cyril Bur's avatar Cyril Bur Committed by Michael Ellerman

powerpc: signals: Stop using current in signal code

Much of the signal code takes a pt_regs on which it operates. Over
time the signal code has needed to know more about the thread than
what pt_regs can supply, this information is obtained as needed by
using 'current'.

This approach is not strictly incorrect however it does mean that
there is now a hard requirement that the pt_regs being passed around
does belong to current, this is never checked. A safer approach is for
the majority of the signal functions to take a task_struct from which
they can obtain pt_regs and any other information they need. The
caveat that the task_struct they are passed must be current doesn't go
away but can more easily be checked for.

Functions called from outside powerpc signal code are passed a pt_regs
and they can confirm that the pt_regs is that of current and pass
current to other functions, furthurmore, powerpc signal functions can
check that the task_struct they are passed is the same as current
avoiding possible corruption of current (or the task they are passed)
if this assertion ever fails.

CC: paulus@samba.org
Signed-off-by: default avatarCyril Bur <cyrilbur@gmail.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent e909fb83
...@@ -5,6 +5,4 @@ ...@@ -5,6 +5,4 @@
#include <uapi/asm/signal.h> #include <uapi/asm/signal.h>
#include <uapi/asm/ptrace.h> #include <uapi/asm/ptrace.h>
extern unsigned long get_tm_stackpointer(struct pt_regs *regs);
#endif /* _ASM_POWERPC_SIGNAL_H */ #endif /* _ASM_POWERPC_SIGNAL_H */
...@@ -99,22 +99,24 @@ static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka, ...@@ -99,22 +99,24 @@ static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka,
} }
} }
static void do_signal(struct pt_regs *regs) static void do_signal(struct task_struct *tsk)
{ {
sigset_t *oldset = sigmask_to_save(); sigset_t *oldset = sigmask_to_save();
struct ksignal ksig; struct ksignal ksig;
int ret; int ret;
int is32 = is_32bit_task(); int is32 = is_32bit_task();
BUG_ON(tsk != current);
get_signal(&ksig); get_signal(&ksig);
/* Is there any syscall restart business here ? */ /* Is there any syscall restart business here ? */
check_syscall_restart(regs, &ksig.ka, ksig.sig > 0); check_syscall_restart(tsk->thread.regs, &ksig.ka, ksig.sig > 0);
if (ksig.sig <= 0) { if (ksig.sig <= 0) {
/* No signal to deliver -- put the saved sigmask back */ /* No signal to deliver -- put the saved sigmask back */
restore_saved_sigmask(); restore_saved_sigmask();
regs->trap = 0; tsk->thread.regs->trap = 0;
return; /* no signals delivered */ return; /* no signals delivered */
} }
...@@ -124,23 +126,22 @@ static void do_signal(struct pt_regs *regs) ...@@ -124,23 +126,22 @@ static void do_signal(struct pt_regs *regs)
* user space. The DABR will have been cleared if it * user space. The DABR will have been cleared if it
* triggered inside the kernel. * triggered inside the kernel.
*/ */
if (current->thread.hw_brk.address && if (tsk->thread.hw_brk.address && tsk->thread.hw_brk.type)
current->thread.hw_brk.type) __set_breakpoint(&tsk->thread.hw_brk);
__set_breakpoint(&current->thread.hw_brk);
#endif #endif
/* Re-enable the breakpoints for the signal stack */ /* Re-enable the breakpoints for the signal stack */
thread_change_pc(current, regs); thread_change_pc(tsk, tsk->thread.regs);
if (is32) { if (is32) {
if (ksig.ka.sa.sa_flags & SA_SIGINFO) if (ksig.ka.sa.sa_flags & SA_SIGINFO)
ret = handle_rt_signal32(&ksig, oldset, regs); ret = handle_rt_signal32(&ksig, oldset, tsk);
else else
ret = handle_signal32(&ksig, oldset, regs); ret = handle_signal32(&ksig, oldset, tsk);
} else { } else {
ret = handle_rt_signal64(&ksig, oldset, regs); ret = handle_rt_signal64(&ksig, oldset, tsk);
} }
regs->trap = 0; tsk->thread.regs->trap = 0;
signal_setup_done(ret, &ksig, test_thread_flag(TIF_SINGLESTEP)); signal_setup_done(ret, &ksig, test_thread_flag(TIF_SINGLESTEP));
} }
...@@ -151,8 +152,10 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags) ...@@ -151,8 +152,10 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
if (thread_info_flags & _TIF_UPROBE) if (thread_info_flags & _TIF_UPROBE)
uprobe_notify_resume(regs); uprobe_notify_resume(regs);
if (thread_info_flags & _TIF_SIGPENDING) if (thread_info_flags & _TIF_SIGPENDING) {
do_signal(regs); BUG_ON(regs != current->thread.regs);
do_signal(current);
}
if (thread_info_flags & _TIF_NOTIFY_RESUME) { if (thread_info_flags & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME); clear_thread_flag(TIF_NOTIFY_RESUME);
...@@ -162,7 +165,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags) ...@@ -162,7 +165,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
user_enter(); user_enter();
} }
unsigned long get_tm_stackpointer(struct pt_regs *regs) unsigned long get_tm_stackpointer(struct task_struct *tsk)
{ {
/* When in an active transaction that takes a signal, we need to be /* When in an active transaction that takes a signal, we need to be
* careful with the stack. It's possible that the stack has moved back * careful with the stack. It's possible that the stack has moved back
...@@ -187,11 +190,13 @@ unsigned long get_tm_stackpointer(struct pt_regs *regs) ...@@ -187,11 +190,13 @@ unsigned long get_tm_stackpointer(struct pt_regs *regs)
*/ */
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
if (MSR_TM_ACTIVE(regs->msr)) { BUG_ON(tsk != current);
if (MSR_TM_ACTIVE(tsk->thread.regs->msr)) {
tm_reclaim_current(TM_CAUSE_SIGNAL); tm_reclaim_current(TM_CAUSE_SIGNAL);
if (MSR_TM_TRANSACTIONAL(regs->msr)) if (MSR_TM_TRANSACTIONAL(tsk->thread.regs->msr))
return current->thread.ckpt_regs.gpr[1]; return tsk->thread.ckpt_regs.gpr[1];
} }
#endif #endif
return regs->gpr[1]; return tsk->thread.regs->gpr[1];
} }
...@@ -16,10 +16,10 @@ extern void __user *get_sigframe(struct ksignal *ksig, unsigned long sp, ...@@ -16,10 +16,10 @@ extern void __user *get_sigframe(struct ksignal *ksig, unsigned long sp,
size_t frame_size, int is_32); size_t frame_size, int is_32);
extern int handle_signal32(struct ksignal *ksig, sigset_t *oldset, extern int handle_signal32(struct ksignal *ksig, sigset_t *oldset,
struct pt_regs *regs); struct task_struct *tsk);
extern int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, extern int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
struct pt_regs *regs); struct task_struct *tsk);
extern unsigned long copy_fpr_to_user(void __user *to, extern unsigned long copy_fpr_to_user(void __user *to,
struct task_struct *task); struct task_struct *task);
...@@ -29,6 +29,8 @@ extern unsigned long copy_fpr_from_user(struct task_struct *task, ...@@ -29,6 +29,8 @@ extern unsigned long copy_fpr_from_user(struct task_struct *task,
void __user *from); void __user *from);
extern unsigned long copy_transact_fpr_from_user(struct task_struct *task, extern unsigned long copy_transact_fpr_from_user(struct task_struct *task,
void __user *from); void __user *from);
extern unsigned long get_tm_stackpointer(struct task_struct *tsk);
#ifdef CONFIG_VSX #ifdef CONFIG_VSX
extern unsigned long copy_vsx_to_user(void __user *to, extern unsigned long copy_vsx_to_user(void __user *to,
struct task_struct *task); struct task_struct *task);
...@@ -43,12 +45,12 @@ extern unsigned long copy_transact_vsx_from_user(struct task_struct *task, ...@@ -43,12 +45,12 @@ extern unsigned long copy_transact_vsx_from_user(struct task_struct *task,
#ifdef CONFIG_PPC64 #ifdef CONFIG_PPC64
extern int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, extern int handle_rt_signal64(struct ksignal *ksig, sigset_t *set,
struct pt_regs *regs); struct task_struct *tsk);
#else /* CONFIG_PPC64 */ #else /* CONFIG_PPC64 */
static inline int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, static inline int handle_rt_signal64(struct ksignal *ksig, sigset_t *set,
struct pt_regs *regs) struct task_struct *tsk)
{ {
return -EFAULT; return -EFAULT;
} }
......
...@@ -978,7 +978,7 @@ int copy_siginfo_from_user32(siginfo_t *to, struct compat_siginfo __user *from) ...@@ -978,7 +978,7 @@ int copy_siginfo_from_user32(siginfo_t *to, struct compat_siginfo __user *from)
* (one which gets siginfo). * (one which gets siginfo).
*/ */
int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
struct pt_regs *regs) struct task_struct *tsk)
{ {
struct rt_sigframe __user *rt_sf; struct rt_sigframe __user *rt_sf;
struct mcontext __user *frame; struct mcontext __user *frame;
...@@ -987,10 +987,13 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, ...@@ -987,10 +987,13 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
unsigned long newsp = 0; unsigned long newsp = 0;
int sigret; int sigret;
unsigned long tramp; unsigned long tramp;
struct pt_regs *regs = tsk->thread.regs;
BUG_ON(tsk != current);
/* Set up Signal Frame */ /* Set up Signal Frame */
/* Put a Real Time Context onto stack */ /* Put a Real Time Context onto stack */
rt_sf = get_sigframe(ksig, get_tm_stackpointer(regs), sizeof(*rt_sf), 1); rt_sf = get_sigframe(ksig, get_tm_stackpointer(tsk), sizeof(*rt_sf), 1);
addr = rt_sf; addr = rt_sf;
if (unlikely(rt_sf == NULL)) if (unlikely(rt_sf == NULL))
goto badframe; goto badframe;
...@@ -1007,9 +1010,9 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, ...@@ -1007,9 +1010,9 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
/* Save user registers on the stack */ /* Save user registers on the stack */
frame = &rt_sf->uc.uc_mcontext; frame = &rt_sf->uc.uc_mcontext;
addr = frame; addr = frame;
if (vdso32_rt_sigtramp && current->mm->context.vdso_base) { if (vdso32_rt_sigtramp && tsk->mm->context.vdso_base) {
sigret = 0; sigret = 0;
tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp; tramp = tsk->mm->context.vdso_base + vdso32_rt_sigtramp;
} else { } else {
sigret = __NR_rt_sigreturn; sigret = __NR_rt_sigreturn;
tramp = (unsigned long) frame->tramp; tramp = (unsigned long) frame->tramp;
...@@ -1036,7 +1039,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, ...@@ -1036,7 +1039,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
} }
regs->link = tramp; regs->link = tramp;
current->thread.fp_state.fpscr = 0; /* turn off all fp exceptions */ tsk->thread.fp_state.fpscr = 0; /* turn off all fp exceptions */
/* create a stack frame for the caller of the handler */ /* create a stack frame for the caller of the handler */
newsp = ((unsigned long)rt_sf) - (__SIGNAL_FRAMESIZE + 16); newsp = ((unsigned long)rt_sf) - (__SIGNAL_FRAMESIZE + 16);
...@@ -1061,7 +1064,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, ...@@ -1061,7 +1064,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
printk_ratelimited(KERN_INFO printk_ratelimited(KERN_INFO
"%s[%d]: bad frame in handle_rt_signal32: " "%s[%d]: bad frame in handle_rt_signal32: "
"%p nip %08lx lr %08lx\n", "%p nip %08lx lr %08lx\n",
current->comm, current->pid, tsk->comm, tsk->pid,
addr, regs->nip, regs->link); addr, regs->nip, regs->link);
return 1; return 1;
...@@ -1417,7 +1420,8 @@ int sys_debug_setcontext(struct ucontext __user *ctx, ...@@ -1417,7 +1420,8 @@ int sys_debug_setcontext(struct ucontext __user *ctx,
/* /*
* OK, we're invoking a handler * OK, we're invoking a handler
*/ */
int handle_signal32(struct ksignal *ksig, sigset_t *oldset, struct pt_regs *regs) int handle_signal32(struct ksignal *ksig, sigset_t *oldset,
struct task_struct *tsk)
{ {
struct sigcontext __user *sc; struct sigcontext __user *sc;
struct sigframe __user *frame; struct sigframe __user *frame;
...@@ -1425,9 +1429,12 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, struct pt_regs *regs ...@@ -1425,9 +1429,12 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, struct pt_regs *regs
unsigned long newsp = 0; unsigned long newsp = 0;
int sigret; int sigret;
unsigned long tramp; unsigned long tramp;
struct pt_regs *regs = tsk->thread.regs;
BUG_ON(tsk != current);
/* Set up Signal Frame */ /* Set up Signal Frame */
frame = get_sigframe(ksig, get_tm_stackpointer(regs), sizeof(*frame), 1); frame = get_sigframe(ksig, get_tm_stackpointer(tsk), sizeof(*frame), 1);
if (unlikely(frame == NULL)) if (unlikely(frame == NULL))
goto badframe; goto badframe;
sc = (struct sigcontext __user *) &frame->sctx; sc = (struct sigcontext __user *) &frame->sctx;
...@@ -1446,9 +1453,9 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, struct pt_regs *regs ...@@ -1446,9 +1453,9 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, struct pt_regs *regs
|| __put_user(ksig->sig, &sc->signal)) || __put_user(ksig->sig, &sc->signal))
goto badframe; goto badframe;
if (vdso32_sigtramp && current->mm->context.vdso_base) { if (vdso32_sigtramp && tsk->mm->context.vdso_base) {
sigret = 0; sigret = 0;
tramp = current->mm->context.vdso_base + vdso32_sigtramp; tramp = tsk->mm->context.vdso_base + vdso32_sigtramp;
} else { } else {
sigret = __NR_sigreturn; sigret = __NR_sigreturn;
tramp = (unsigned long) frame->mctx.tramp; tramp = (unsigned long) frame->mctx.tramp;
...@@ -1470,7 +1477,7 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, struct pt_regs *regs ...@@ -1470,7 +1477,7 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, struct pt_regs *regs
regs->link = tramp; regs->link = tramp;
current->thread.fp_state.fpscr = 0; /* turn off all fp exceptions */ tsk->thread.fp_state.fpscr = 0; /* turn off all fp exceptions */
/* create a stack frame for the caller of the handler */ /* create a stack frame for the caller of the handler */
newsp = ((unsigned long)frame) - __SIGNAL_FRAMESIZE; newsp = ((unsigned long)frame) - __SIGNAL_FRAMESIZE;
...@@ -1490,7 +1497,7 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, struct pt_regs *regs ...@@ -1490,7 +1497,7 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, struct pt_regs *regs
printk_ratelimited(KERN_INFO printk_ratelimited(KERN_INFO
"%s[%d]: bad frame in handle_signal32: " "%s[%d]: bad frame in handle_signal32: "
"%p nip %08lx lr %08lx\n", "%p nip %08lx lr %08lx\n",
current->comm, current->pid, tsk->comm, tsk->pid,
frame, regs->nip, regs->link); frame, regs->nip, regs->link);
return 1; return 1;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment