Commit b00d8f8f authored by Al Viro's avatar Al Viro

x86: setup_sigcontext(): list user_access_{begin,end}() into callers

Similar to ia32_setup_sigcontext() change several commits ago, make it
__always_inline.  In cases when there is a user_access_{begin,end}()
section nearby, just move the call over there.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 119cd59f
...@@ -140,12 +140,10 @@ static int restore_sigcontext(struct pt_regs *regs, ...@@ -140,12 +140,10 @@ static int restore_sigcontext(struct pt_regs *regs,
IS_ENABLED(CONFIG_X86_32)); IS_ENABLED(CONFIG_X86_32));
} }
static int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate, static __always_inline int
__unsafe_setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
struct pt_regs *regs, unsigned long mask) struct pt_regs *regs, unsigned long mask)
{ {
if (!user_access_begin(sc, sizeof(struct sigcontext)))
return -EFAULT;
#ifdef CONFIG_X86_32 #ifdef CONFIG_X86_32
unsafe_put_user(get_user_gs(regs), unsafe_put_user(get_user_gs(regs),
(unsigned int __user *)&sc->gs, Efault); (unsigned int __user *)&sc->gs, Efault);
...@@ -194,13 +192,17 @@ static int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate, ...@@ -194,13 +192,17 @@ static int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
/* non-iBCS2 extensions.. */ /* non-iBCS2 extensions.. */
unsafe_put_user(mask, &sc->oldmask, Efault); unsafe_put_user(mask, &sc->oldmask, Efault);
unsafe_put_user(current->thread.cr2, &sc->cr2, Efault); unsafe_put_user(current->thread.cr2, &sc->cr2, Efault);
user_access_end();
return 0; return 0;
Efault: Efault:
user_access_end();
return -EFAULT; return -EFAULT;
} }
#define unsafe_put_sigcontext(sc, fp, regs, set, label) \
do { \
if (__unsafe_setup_sigcontext(sc, fp, regs, set->sig[0])) \
goto label; \
} while(0);
/* /*
* Set up a signal frame. * Set up a signal frame.
*/ */
...@@ -301,9 +303,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set, ...@@ -301,9 +303,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
struct sigframe __user *frame; struct sigframe __user *frame;
void __user *restorer; void __user *restorer;
int err = 0; int err = 0;
void __user *fpstate = NULL; void __user *fp = NULL;
frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate); frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fp);
if (!access_ok(frame, sizeof(*frame))) if (!access_ok(frame, sizeof(*frame)))
return -EFAULT; return -EFAULT;
...@@ -311,8 +313,10 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set, ...@@ -311,8 +313,10 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
if (__put_user(sig, &frame->sig)) if (__put_user(sig, &frame->sig))
return -EFAULT; return -EFAULT;
if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0])) if (!user_access_begin(&frame->sc, sizeof(struct sigcontext)))
return -EFAULT; return -EFAULT;
unsafe_put_sigcontext(&frame->sc, fp, regs, set, Efault);
user_access_end();
if (__put_user(set->sig[1], &frame->extramask[0])) if (__put_user(set->sig[1], &frame->extramask[0]))
return -EFAULT; return -EFAULT;
...@@ -353,6 +357,10 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set, ...@@ -353,6 +357,10 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
regs->cs = __USER_CS; regs->cs = __USER_CS;
return 0; return 0;
Efault:
user_access_end();
return -EFAULT;
} }
static int __setup_rt_frame(int sig, struct ksignal *ksig, static int __setup_rt_frame(int sig, struct ksignal *ksig,
...@@ -361,9 +369,9 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig, ...@@ -361,9 +369,9 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
struct rt_sigframe __user *frame; struct rt_sigframe __user *frame;
void __user *restorer; void __user *restorer;
int err = 0; int err = 0;
void __user *fpstate = NULL; void __user *fp = NULL;
frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate); frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fp);
if (!user_access_begin(frame, sizeof(*frame))) if (!user_access_begin(frame, sizeof(*frame)))
return -EFAULT; return -EFAULT;
...@@ -395,13 +403,11 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig, ...@@ -395,13 +403,11 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
* signal handler stack frames. * signal handler stack frames.
*/ */
unsafe_put_user(*((u64 *)&rt_retcode), (u64 *)frame->retcode, Efault); unsafe_put_user(*((u64 *)&rt_retcode), (u64 *)frame->retcode, Efault);
unsafe_put_sigcontext(&frame->uc.uc_mcontext, fp, regs, set, Efault);
user_access_end(); user_access_end();
err |= copy_siginfo_to_user(&frame->info, &ksig->info); err |= copy_siginfo_to_user(&frame->info, &ksig->info);
err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
regs, set->sig[0]);
err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
if (err) if (err)
return -EFAULT; return -EFAULT;
...@@ -472,9 +478,8 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig, ...@@ -472,9 +478,8 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
/* 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. */
unsafe_put_user(ksig->ka.sa.sa_restorer, &frame->pretcode, Efault); unsafe_put_user(ksig->ka.sa.sa_restorer, &frame->pretcode, Efault);
unsafe_put_sigcontext(&frame->uc.uc_mcontext, fp, regs, set, Efault);
user_access_end(); user_access_end();
err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
err |= __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]); err |= __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
if (err) if (err)
...@@ -532,12 +537,12 @@ static int x32_setup_rt_frame(struct ksignal *ksig, ...@@ -532,12 +537,12 @@ static int x32_setup_rt_frame(struct ksignal *ksig,
unsigned long uc_flags; unsigned long uc_flags;
void __user *restorer; void __user *restorer;
int err = 0; int err = 0;
void __user *fpstate = NULL; void __user *fp = NULL;
if (!(ksig->ka.sa.sa_flags & SA_RESTORER)) if (!(ksig->ka.sa.sa_flags & SA_RESTORER))
return -EFAULT; return -EFAULT;
frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate); frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fp);
if (!access_ok(frame, sizeof(*frame))) if (!access_ok(frame, sizeof(*frame)))
return -EFAULT; return -EFAULT;
...@@ -559,10 +564,8 @@ static int x32_setup_rt_frame(struct ksignal *ksig, ...@@ -559,10 +564,8 @@ static int x32_setup_rt_frame(struct ksignal *ksig,
unsafe_put_user(0, &frame->uc.uc__pad0, Efault); unsafe_put_user(0, &frame->uc.uc__pad0, Efault);
restorer = ksig->ka.sa.sa_restorer; restorer = ksig->ka.sa.sa_restorer;
unsafe_put_user(restorer, (unsigned long __user *)&frame->pretcode, Efault); unsafe_put_user(restorer, (unsigned long __user *)&frame->pretcode, Efault);
unsafe_put_sigcontext(&frame->uc.uc_mcontext, fp, regs, set, Efault);
user_access_end(); user_access_end();
err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
regs, set->sig[0]);
err |= __put_user(*(__u64 *)set, (__u64 __user *)&frame->uc.uc_sigmask); err |= __put_user(*(__u64 *)set, (__u64 __user *)&frame->uc.uc_sigmask);
if (err) if (err)
......
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