lkml.org 
[lkml]   [2020]   [Mar]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC][PATCH 21/22] x86: unsafe_put_... macros for sigcontext and sigmask
Date
From: Al Viro <viro@zeniv.linux.org.uk>

regularizes things a bit

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
arch/x86/kernel/signal.c | 40 ++++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index 50679e8f42d7..52edadca5723 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -196,6 +196,17 @@ static __always_inline int setup_sigcontext(struct sigcontext __user *sc, void _
return -EFAULT;
}

+#define unsafe_put_sigcontext(sc, fpstate, regs, set, label) \
+do { \
+ if (setup_sigcontext(sc, fpstate, regs, set->sig[0])) \
+ goto label; \
+} while(0);
+
+#define unsafe_put_sigmask(set, frame, label) \
+ unsafe_put_user(*(__u64 *)(set), \
+ (__u64 __user *)&(frame)->uc.uc_sigmask, \
+ label)
+
/*
* Set up a signal frame.
*/
@@ -303,8 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
return -EFAULT;

unsafe_put_user(sig, &frame->sig, Efault);
- if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
- goto Efault;
+ unsafe_put_sigcontext(&frame->sc, fpstate, regs, set, Efault);
unsafe_put_user(set->sig[1], &frame->extramask[0], Efault);
if (current->mm->context.vdso)
restorer = current->mm->context.vdso +
@@ -351,9 +361,9 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
{
struct rt_sigframe __user *frame;
void __user *restorer;
- 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)))
return -EFAULT;
@@ -385,11 +395,8 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
* signal handler stack frames.
*/
unsafe_put_user(*((u64 *)&rt_retcode), (u64 *)frame->retcode, Efault);
- if (setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
- regs, set->sig[0]))
- goto Efault;
- unsafe_put_user(*(__u64 *)set,
- (__u64 __user *)&frame->uc.uc_sigmask, Efault);
+ unsafe_put_sigcontext(&frame->uc.uc_mcontext, fp, regs, set, Efault);
+ unsafe_put_sigmask(set, frame, Efault);
user_access_end();

if (copy_siginfo_to_user(&frame->info, &ksig->info))
@@ -453,9 +460,8 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
/* Set up to return from userspace. If provided, use a stub
already in userspace. */
unsafe_put_user(ksig->ka.sa.sa_restorer, &frame->pretcode, Efault);
- if (setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]))
- goto Efault;
- unsafe_put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0], Efault);
+ unsafe_put_sigcontext(&frame->uc.uc_mcontext, fp, regs, set, Efault);
+ unsafe_put_sigmask(set, frame, Efault);
user_access_end();

if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
@@ -514,12 +520,12 @@ static int x32_setup_rt_frame(struct ksignal *ksig,
struct rt_sigframe_x32 __user *frame;
unsigned long uc_flags;
void __user *restorer;
- void __user *fpstate = NULL;
+ void __user *fp = NULL;

if (!(ksig->ka.sa.sa_flags & SA_RESTORER))
return -EFAULT;

- frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
+ frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fp);

uc_flags = frame_uc_flags(regs);

@@ -533,10 +539,8 @@ static int x32_setup_rt_frame(struct ksignal *ksig,
unsafe_put_user(0, &frame->uc.uc__pad0, Efault);
restorer = ksig->ka.sa.sa_restorer;
unsafe_put_user(restorer, (unsigned long __user *)&frame->pretcode, Efault);
- if (setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
- regs, set->sig[0]))
- goto Efault;
- unsafe_put_user(*(__u64 *)set, (__u64 __user *)&frame->uc.uc_sigmask, Efault);
+ unsafe_put_sigcontext(&frame->uc.uc_mcontext, fp, regs, set, Efault);
+ unsafe_put_sigmask(set, frame, Efault);
user_access_end();

if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
--
2.11.0
\
 
 \ /
  Last update: 2020-03-23 19:39    [W:0.107 / U:0.464 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site