Commit 9504db3e authored by Christophe Leroy's avatar Christophe Leroy Committed by Michael Ellerman

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: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/2974314226256f958e2984912b48883ef1754185.1597770847.git.christophe.leroy@csgroup.eu
parent ad65f490
...@@ -58,8 +58,6 @@ ...@@ -58,8 +58,6 @@
#define mcontext mcontext32 #define mcontext mcontext32
#define ucontext ucontext32 #define ucontext ucontext32
#define __save_altstack __compat_save_altstack
/* /*
* Userspace code may pass a ucontext which doesn't include VSX added * Userspace code may pass a ucontext which doesn't include VSX added
* at the end. We need to check for this case. * at the end. We need to check for this case.
...@@ -745,16 +743,28 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, ...@@ -745,16 +743,28 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
tm_mctx = &frame->uc_transact.uc_mcontext; tm_mctx = &frame->uc_transact.uc_mcontext;
#endif #endif
if (!access_ok(frame, sizeof(*frame))) if (!user_write_access_begin(frame, sizeof(*frame)))
goto badframe; goto badframe;
/* Put the siginfo & fill in most of the ucontext */ /* Put the siginfo & fill in most of the ucontext */
if (copy_siginfo_to_user(&frame->info, &ksig->info) || unsafe_put_user(0, &frame->uc.uc_flags, failed);
__put_user(0, &frame->uc.uc_flags) || #ifdef CONFIG_PPC64
__save_altstack(&frame->uc.uc_stack, regs->gpr[1]) || unsafe_compat_save_altstack(&frame->uc.uc_stack, regs->gpr[1], failed);
__put_user(to_user_ptr(&frame->uc.uc_mcontext), &frame->uc.uc_regs) || #else
put_sigset_t(&frame->uc.uc_sigmask, oldset)) unsafe_save_altstack(&frame->uc.uc_stack, regs->gpr[1], failed);
goto badframe; #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 */ /* Save user registers on the stack */
if (vdso32_rt_sigtramp && tsk->mm->context.vdso_base) { if (vdso32_rt_sigtramp && tsk->mm->context.vdso_base) {
...@@ -762,28 +772,28 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, ...@@ -762,28 +772,28 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
} else { } else {
tramp = (unsigned long)mctx->mc_pad; tramp = (unsigned long)mctx->mc_pad;
/* Set up the sigreturn trampoline: li r0,sigret; sc */ /* Set up the sigreturn trampoline: li r0,sigret; sc */
if (__put_user(PPC_INST_ADDI + __NR_sigreturn, &mctx->mc_pad[0])) unsafe_put_user(PPC_INST_ADDI + __NR_rt_sigreturn, &mctx->mc_pad[0],
goto badframe; failed);
if (__put_user(PPC_INST_SC, &mctx->mc_pad[1])) unsafe_put_user(PPC_INST_SC, &mctx->mc_pad[1], failed);
goto badframe;
flush_icache_range(tramp, tramp + 2 * sizeof(unsigned long));
} }
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 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
if (MSR_TM_ACTIVE(msr)) { 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)) if (save_tm_user_regs(regs, mctx, tm_mctx, msr))
goto badframe; goto badframe;
} }
else else
#endif #endif
{ {
if (__put_user(0, &frame->uc.uc_link))
goto badframe;
if (save_user_regs(regs, mctx, tm_mctx, 1)) if (save_user_regs(regs, mctx, tm_mctx, 1))
goto badframe; goto badframe;
} }
...@@ -810,6 +820,9 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, ...@@ -810,6 +820,9 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
regs->msr |= (MSR_KERNEL & MSR_LE); regs->msr |= (MSR_KERNEL & MSR_LE);
return 0; return 0;
failed:
user_write_access_end();
badframe: badframe:
signal_fault(tsk, regs, "handle_rt_signal32", frame); signal_fault(tsk, regs, "handle_rt_signal32", frame);
......
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