2019-05-26 23:55:05 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003 Broadcom Corporation
|
|
|
|
*/
|
2005-06-15 06:00:12 -07:00
|
|
|
#include <linux/cache.h>
|
|
|
|
#include <linux/sched.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/unistd.h>
|
|
|
|
#include <linux/compat.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
|
2007-02-15 04:40:37 -07:00
|
|
|
#include <asm/abi.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <asm/asm.h>
|
|
|
|
#include <asm/cacheflush.h>
|
2007-02-12 17:05:11 -07:00
|
|
|
#include <asm/compat-signal.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <asm/sim.h>
|
2016-12-24 12:46:01 -07:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <asm/ucontext.h>
|
|
|
|
#include <asm/fpu.h>
|
|
|
|
#include <asm/cpu-features.h>
|
2023-12-04 04:56:52 -07:00
|
|
|
#include <asm/syscalls.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
#include "signal-common.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Including <asm/unistd.h> would give use the 64-bit syscall numbers ...
|
|
|
|
*/
|
|
|
|
#define __NR_N32_restart_syscall 6214
|
|
|
|
|
|
|
|
struct ucontextn32 {
|
2013-01-22 04:59:30 -07:00
|
|
|
u32 uc_flags;
|
|
|
|
s32 uc_link;
|
2012-12-23 01:13:40 -07:00
|
|
|
compat_stack_t uc_stack;
|
2005-04-16 15:20:36 -07:00
|
|
|
struct sigcontext uc_mcontext;
|
2013-01-22 04:59:30 -07:00
|
|
|
compat_sigset_t uc_sigmask; /* mask last for extensibility */
|
2005-04-16 15:20:36 -07:00
|
|
|
};
|
|
|
|
|
2007-02-05 07:24:21 -07:00
|
|
|
struct rt_sigframe_n32 {
|
|
|
|
u32 rs_ass[4]; /* argument save space for o32 */
|
2010-02-18 17:13:05 -07:00
|
|
|
u32 rs_pad[2]; /* Was: signal trampoline */
|
2007-06-05 02:42:20 -07:00
|
|
|
struct compat_siginfo rs_info;
|
2007-02-05 07:24:21 -07:00
|
|
|
struct ucontextn32 rs_uc;
|
2005-04-16 15:20:36 -07:00
|
|
|
};
|
|
|
|
|
2018-08-01 13:12:42 -07:00
|
|
|
asmlinkage void sysn32_rt_sigreturn(void)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-01-31 09:41:09 -07:00
|
|
|
struct rt_sigframe_n32 __user *frame;
|
2018-08-01 13:12:42 -07:00
|
|
|
struct pt_regs *regs;
|
2005-04-16 15:20:36 -07:00
|
|
|
sigset_t set;
|
2007-03-09 09:03:48 -07:00
|
|
|
int sig;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2018-08-01 13:12:42 -07:00
|
|
|
regs = current_pt_regs();
|
|
|
|
frame = (struct rt_sigframe_n32 __user *)regs->regs[29];
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-03 19:57:57 -07:00
|
|
|
if (!access_ok(frame, sizeof(*frame)))
|
2005-04-16 15:20:36 -07:00
|
|
|
goto badframe;
|
2007-02-12 17:05:11 -07:00
|
|
|
if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask))
|
2005-04-16 15:20:36 -07:00
|
|
|
goto badframe;
|
|
|
|
|
2012-02-14 04:40:52 -07:00
|
|
|
set_current_blocked(&set);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2018-08-01 13:12:42 -07:00
|
|
|
sig = restore_sigcontext(regs, &frame->rs_uc.uc_mcontext);
|
2007-03-09 09:03:48 -07:00
|
|
|
if (sig < 0)
|
2005-04-16 15:20:36 -07:00
|
|
|
goto badframe;
|
2007-03-09 09:03:48 -07:00
|
|
|
else if (sig)
|
2019-05-23 08:17:27 -07:00
|
|
|
force_sig(sig);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2012-12-23 01:13:40 -07:00
|
|
|
if (compat_restore_altstack(&frame->rs_uc.uc_stack))
|
2005-04-16 15:20:36 -07:00
|
|
|
goto badframe;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't let your children do this ...
|
|
|
|
*/
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"move\t$29, %0\n\t"
|
|
|
|
"j\tsyscall_exit"
|
2018-08-01 13:12:42 -07:00
|
|
|
: /* no outputs */
|
|
|
|
: "r" (regs));
|
2005-04-16 15:20:36 -07:00
|
|
|
/* Unreached */
|
|
|
|
|
|
|
|
badframe:
|
2019-05-23 08:17:27 -07:00
|
|
|
force_sig(SIGSEGV);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2013-10-06 13:25:42 -07:00
|
|
|
static int setup_rt_frame_n32(void *sig_return, struct ksignal *ksig,
|
|
|
|
struct pt_regs *regs, sigset_t *set)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-01-31 09:41:09 -07:00
|
|
|
struct rt_sigframe_n32 __user *frame;
|
2005-04-16 15:20:36 -07:00
|
|
|
int err = 0;
|
|
|
|
|
2014-03-05 07:35:41 -07:00
|
|
|
frame = get_sigframe(ksig, regs, sizeof(*frame));
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-03 19:57:57 -07:00
|
|
|
if (!access_ok(frame, sizeof (*frame)))
|
2013-10-06 13:25:42 -07:00
|
|
|
return -EFAULT;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/* Create siginfo. */
|
2013-10-06 13:25:42 -07:00
|
|
|
err |= copy_siginfo_to_user32(&frame->rs_info, &ksig->info);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2013-01-22 04:59:30 -07:00
|
|
|
/* Create the ucontext. */
|
2005-04-16 15:20:36 -07:00
|
|
|
err |= __put_user(0, &frame->rs_uc.uc_flags);
|
|
|
|
err |= __put_user(0, &frame->rs_uc.uc_link);
|
2012-12-23 01:13:40 -07:00
|
|
|
err |= __compat_save_altstack(&frame->rs_uc.uc_stack, regs->regs[29]);
|
2005-04-16 15:20:36 -07:00
|
|
|
err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
|
2007-02-12 17:05:11 -07:00
|
|
|
err |= __copy_conv_sigset_to_user(&frame->rs_uc.uc_sigmask, set);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
if (err)
|
2013-10-06 13:25:42 -07:00
|
|
|
return -EFAULT;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Arguments to signal handler:
|
|
|
|
*
|
|
|
|
* a0 = signal number
|
|
|
|
* a1 = 0 (should be cause)
|
|
|
|
* a2 = pointer to ucontext
|
|
|
|
*
|
|
|
|
* $25 and c0_epc point to the signal handler, $29 points to
|
|
|
|
* the struct rt_sigframe.
|
|
|
|
*/
|
2013-10-06 13:25:42 -07:00
|
|
|
regs->regs[ 4] = ksig->sig;
|
2005-04-16 15:20:36 -07:00
|
|
|
regs->regs[ 5] = (unsigned long) &frame->rs_info;
|
|
|
|
regs->regs[ 6] = (unsigned long) &frame->rs_uc;
|
|
|
|
regs->regs[29] = (unsigned long) frame;
|
2010-02-18 17:13:05 -07:00
|
|
|
regs->regs[31] = (unsigned long) sig_return;
|
2013-10-06 13:25:42 -07:00
|
|
|
regs->cp0_epc = regs->regs[25] = (unsigned long) ksig->ka.sa.sa_handler;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-02-05 07:24:24 -07:00
|
|
|
DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
|
2005-04-16 15:20:36 -07:00
|
|
|
current->comm, current->pid,
|
|
|
|
frame, regs->cp0_epc, regs->regs[31]);
|
2007-02-05 07:24:24 -07:00
|
|
|
|
2006-02-08 05:58:41 -07:00
|
|
|
return 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
2007-02-15 04:40:37 -07:00
|
|
|
|
|
|
|
struct mips_abi mips_abi_n32 = {
|
2013-01-22 04:59:30 -07:00
|
|
|
.setup_rt_frame = setup_rt_frame_n32,
|
2015-07-27 12:58:14 -07:00
|
|
|
.restart = __NR_N32_restart_syscall,
|
|
|
|
|
|
|
|
.off_sc_fpregs = offsetof(struct sigcontext, sc_fpregs),
|
|
|
|
.off_sc_fpc_csr = offsetof(struct sigcontext, sc_fpc_csr),
|
|
|
|
.off_sc_used_math = offsetof(struct sigcontext, sc_used_math),
|
2015-10-21 01:54:38 -07:00
|
|
|
|
|
|
|
.vdso = &vdso_image_n32,
|
2007-02-15 04:40:37 -07:00
|
|
|
};
|