Commit c40702c4 authored by Al Viro's avatar Al Viro

new helpers: __save_altstack/__compat_save_altstack, switch x86 and um to those

note that they are relying on access_ok() already checked by caller.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 90268439
...@@ -467,10 +467,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -467,10 +467,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
else else
put_user_ex(0, &frame->uc.uc_flags); put_user_ex(0, &frame->uc.uc_flags);
put_user_ex(0, &frame->uc.uc_link); put_user_ex(0, &frame->uc.uc_link);
put_user_ex(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); err |= __compat_save_altstack(&frame->uc.uc_stack, regs->sp);
put_user_ex(sas_ss_flags(regs->sp),
&frame->uc.uc_stack.ss_flags);
put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
if (ka->sa.sa_flags & SA_RESTORER) if (ka->sa.sa_flags & SA_RESTORER)
restorer = ka->sa.sa_restorer; restorer = ka->sa.sa_restorer;
......
...@@ -363,10 +363,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -363,10 +363,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
else else
put_user_ex(0, &frame->uc.uc_flags); put_user_ex(0, &frame->uc.uc_flags);
put_user_ex(0, &frame->uc.uc_link); put_user_ex(0, &frame->uc.uc_link);
put_user_ex(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
put_user_ex(sas_ss_flags(regs->sp),
&frame->uc.uc_stack.ss_flags);
put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
/* Set up to return from userspace. */ /* Set up to return from userspace. */
restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn); restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
...@@ -413,7 +410,6 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -413,7 +410,6 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
struct rt_sigframe __user *frame; struct rt_sigframe __user *frame;
void __user *fp = NULL; void __user *fp = NULL;
int err = 0; int err = 0;
struct task_struct *me = current;
frame = get_sigframe(ka, regs, sizeof(struct rt_sigframe), &fp); frame = get_sigframe(ka, regs, sizeof(struct rt_sigframe), &fp);
...@@ -432,10 +428,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -432,10 +428,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
else else
put_user_ex(0, &frame->uc.uc_flags); put_user_ex(0, &frame->uc.uc_flags);
put_user_ex(0, &frame->uc.uc_link); put_user_ex(0, &frame->uc.uc_link);
put_user_ex(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp); err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
put_user_ex(sas_ss_flags(regs->sp),
&frame->uc.uc_stack.ss_flags);
put_user_ex(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
/* Set up to return from userspace. If provided, use a stub /* Set up to return from userspace. If provided, use a stub
already in userspace. */ already in userspace. */
...@@ -502,10 +495,7 @@ static int x32_setup_rt_frame(int sig, struct k_sigaction *ka, ...@@ -502,10 +495,7 @@ static int x32_setup_rt_frame(int sig, struct k_sigaction *ka,
else else
put_user_ex(0, &frame->uc.uc_flags); put_user_ex(0, &frame->uc.uc_flags);
put_user_ex(0, &frame->uc.uc_link); put_user_ex(0, &frame->uc.uc_link);
put_user_ex(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); err |= __compat_save_altstack(&frame->uc.uc_stack, regs->sp);
put_user_ex(sas_ss_flags(regs->sp),
&frame->uc.uc_stack.ss_flags);
put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
put_user_ex(0, &frame->uc.uc__pad0); put_user_ex(0, &frame->uc.uc__pad0);
if (ka->sa.sa_flags & SA_RESTORER) { if (ka->sa.sa_flags & SA_RESTORER) {
...@@ -651,7 +641,7 @@ long sys_rt_sigreturn(struct pt_regs *regs) ...@@ -651,7 +641,7 @@ long sys_rt_sigreturn(struct pt_regs *regs)
if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
goto badframe; goto badframe;
if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT) if (restore_altstack(&frame->uc.uc_stack))
goto badframe; goto badframe;
return ax; return ax;
......
...@@ -342,9 +342,7 @@ static int copy_ucontext_to_user(struct ucontext __user *uc, ...@@ -342,9 +342,7 @@ static int copy_ucontext_to_user(struct ucontext __user *uc,
{ {
int err = 0; int err = 0;
err |= put_user(current->sas_ss_sp, &uc->uc_stack.ss_sp); err |= __save_altstack(&uc->uc_stack, sp);
err |= put_user(sas_ss_flags(sp), &uc->uc_stack.ss_flags);
err |= put_user(current->sas_ss_size, &uc->uc_stack.ss_size);
err |= copy_sc_to_user(&uc->uc_mcontext, fp, &current->thread.regs, 0); err |= copy_sc_to_user(&uc->uc_mcontext, fp, &current->thread.regs, 0);
err |= copy_to_user(&uc->uc_sigmask, set, sizeof(*set)); err |= copy_to_user(&uc->uc_sigmask, set, sizeof(*set));
return err; return err;
...@@ -529,10 +527,7 @@ int setup_signal_stack_si(unsigned long stack_top, int sig, ...@@ -529,10 +527,7 @@ int setup_signal_stack_si(unsigned long stack_top, int sig,
/* Create the ucontext. */ /* Create the ucontext. */
err |= __put_user(0, &frame->uc.uc_flags); err |= __put_user(0, &frame->uc.uc_flags);
err |= __put_user(0, &frame->uc.uc_link); err |= __put_user(0, &frame->uc.uc_link);
err |= __put_user(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp); err |= __save_altstack(&frame->uc.uc_stack, PT_REGS_SP(regs));
err |= __put_user(sas_ss_flags(PT_REGS_SP(regs)),
&frame->uc.uc_stack.ss_flags);
err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
err |= copy_sc_to_user(&frame->uc.uc_mcontext, &frame->fpstate, regs, err |= copy_sc_to_user(&frame->uc.uc_mcontext, &frame->fpstate, regs,
set->sig[0]); set->sig[0]);
err |= __put_user(&frame->fpstate, &frame->uc.uc_mcontext.fpstate); err |= __put_user(&frame->fpstate, &frame->uc.uc_mcontext.fpstate);
......
...@@ -647,6 +647,7 @@ asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr, ...@@ -647,6 +647,7 @@ asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
compat_stack_t __user *uoss_ptr); compat_stack_t __user *uoss_ptr);
int compat_restore_altstack(const compat_stack_t __user *uss); int compat_restore_altstack(const compat_stack_t __user *uss);
int __compat_save_altstack(compat_stack_t __user *, unsigned long);
#endif #endif
#else #else
......
...@@ -386,5 +386,6 @@ int unhandled_signal(struct task_struct *tsk, int sig); ...@@ -386,5 +386,6 @@ int unhandled_signal(struct task_struct *tsk, int sig);
void signals_init(void); void signals_init(void);
int restore_altstack(const stack_t __user *); int restore_altstack(const stack_t __user *);
int __save_altstack(stack_t __user *, unsigned long);
#endif /* _LINUX_SIGNAL_H */ #endif /* _LINUX_SIGNAL_H */
...@@ -3117,6 +3117,14 @@ int restore_altstack(const stack_t __user *uss) ...@@ -3117,6 +3117,14 @@ int restore_altstack(const stack_t __user *uss)
return err == -EFAULT ? err : 0; return err == -EFAULT ? err : 0;
} }
int __save_altstack(stack_t __user *uss, unsigned long sp)
{
struct task_struct *t = current;
return __put_user((void __user *)t->sas_ss_sp, &uss->ss_sp) |
__put_user(sas_ss_flags(sp), &uss->ss_flags) |
__put_user(t->sas_ss_size, &uss->ss_size);
}
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
#ifdef CONFIG_GENERIC_SIGALTSTACK #ifdef CONFIG_GENERIC_SIGALTSTACK
asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr, asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
...@@ -3158,6 +3166,14 @@ int compat_restore_altstack(const compat_stack_t __user *uss) ...@@ -3158,6 +3166,14 @@ int compat_restore_altstack(const compat_stack_t __user *uss)
/* squash all but -EFAULT for now */ /* squash all but -EFAULT for now */
return err == -EFAULT ? err : 0; return err == -EFAULT ? err : 0;
} }
int __compat_save_altstack(compat_stack_t __user *uss, unsigned long sp)
{
struct task_struct *t = current;
return __put_user(ptr_to_compat((void __user *)t->sas_ss_sp), &uss->ss_sp) |
__put_user(sas_ss_flags(sp), &uss->ss_flags) |
__put_user(t->sas_ss_size, &uss->ss_size);
}
#endif #endif
#endif #endif
......
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