summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Leroy <christophe.leroy@csgroup.eu>2020-08-18 17:19:30 +0000
committerMichael Ellerman <mpe@ellerman.id.au>2020-12-04 01:01:13 +1100
commit9504db3e90b22dca19d8152ed5a82c68512dac0e (patch)
tree1cc936b6404054657d991f8a14f571062b2f3ba3
parentad65f4909fd3736d84533784cd9ab76905536b34 (diff)
powerpc/signal32: Switch handle_rt_signal32() to user_access_begin() logic
On the same way as handle_signal32(), replace all user accesses with equivalent unsafe_ versions, and move the trampoline code icache flush outside the user access block. Functions that have no unsafe_ equivalent also remains outside the access block. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/2974314226256f958e2984912b48883ef1754185.1597770847.git.christophe.leroy@csgroup.eu
-rw-r--r--arch/powerpc/kernel/signal_32.c55
1 files changed, 34 insertions, 21 deletions
diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
index fc8ba4b29edf..93c2d6304831 100644
--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -58,8 +58,6 @@
#define mcontext mcontext32
#define ucontext ucontext32
-#define __save_altstack __compat_save_altstack
-
/*
* Userspace code may pass a ucontext which doesn't include VSX added
* at the end. We need to check for this case.
@@ -745,16 +743,28 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
tm_mctx = &frame->uc_transact.uc_mcontext;
#endif
- if (!access_ok(frame, sizeof(*frame)))
+ if (!user_write_access_begin(frame, sizeof(*frame)))
goto badframe;
/* Put the siginfo & fill in most of the ucontext */
- if (copy_siginfo_to_user(&frame->info, &ksig->info) ||
- __put_user(0, &frame->uc.uc_flags) ||
- __save_altstack(&frame->uc.uc_stack, regs->gpr[1]) ||
- __put_user(to_user_ptr(&frame->uc.uc_mcontext), &frame->uc.uc_regs) ||
- put_sigset_t(&frame->uc.uc_sigmask, oldset))
- goto badframe;
+ unsafe_put_user(0, &frame->uc.uc_flags, failed);
+#ifdef CONFIG_PPC64
+ unsafe_compat_save_altstack(&frame->uc.uc_stack, regs->gpr[1], failed);
+#else
+ unsafe_save_altstack(&frame->uc.uc_stack, regs->gpr[1], failed);
+#endif
+ unsafe_put_user(to_user_ptr(&frame->uc.uc_mcontext), &frame->uc.uc_regs, failed);
+
+ if (MSR_TM_ACTIVE(msr)) {
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+ unsafe_put_user((unsigned long)&frame->uc_transact,
+ &frame->uc.uc_link, failed);
+ unsafe_put_user((unsigned long)tm_mctx,
+ &frame->uc_transact.uc_regs, failed);
+#endif
+ } else {
+ unsafe_put_user(0, &frame->uc.uc_link, failed);
+ }
/* Save user registers on the stack */
if (vdso32_rt_sigtramp && tsk->mm->context.vdso_base) {
@@ -762,28 +772,28 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
} else {
tramp = (unsigned long)mctx->mc_pad;
/* Set up the sigreturn trampoline: li r0,sigret; sc */
- if (__put_user(PPC_INST_ADDI + __NR_sigreturn, &mctx->mc_pad[0]))
- goto badframe;
- if (__put_user(PPC_INST_SC, &mctx->mc_pad[1]))
- goto badframe;
- flush_icache_range(tramp, tramp + 2 * sizeof(unsigned long));
+ unsafe_put_user(PPC_INST_ADDI + __NR_rt_sigreturn, &mctx->mc_pad[0],
+ failed);
+ unsafe_put_user(PPC_INST_SC, &mctx->mc_pad[1], failed);
}
+ user_write_access_end();
+
+ if (put_sigset_t(&frame->uc.uc_sigmask, oldset))
+ goto badframe;
+ if (copy_siginfo_to_user(&frame->info, &ksig->info))
+ goto badframe;
+
+ if (tramp == (unsigned long)mctx->mc_pad)
+ flush_icache_range(tramp, tramp + 2 * sizeof(unsigned long));
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
if (MSR_TM_ACTIVE(msr)) {
- if (__put_user((unsigned long)&frame->uc_transact,
- &frame->uc.uc_link) ||
- __put_user((unsigned long)tm_mctx,
- &frame->uc_transact.uc_regs))
- goto badframe;
if (save_tm_user_regs(regs, mctx, tm_mctx, msr))
goto badframe;
}
else
#endif
{
- if (__put_user(0, &frame->uc.uc_link))
- goto badframe;
if (save_user_regs(regs, mctx, tm_mctx, 1))
goto badframe;
}
@@ -810,6 +820,9 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
regs->msr |= (MSR_KERNEL & MSR_LE);
return 0;
+failed:
+ user_write_access_end();
+
badframe:
signal_fault(tsk, regs, "handle_rt_signal32", frame);