2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* PowerPC version
|
|
|
|
* Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
|
|
|
|
*
|
|
|
|
* Derived from "arch/m68k/kernel/ptrace.c"
|
|
|
|
* Copyright (C) 1994 by Hamish Macdonald
|
|
|
|
* Taken from linux/kernel/ptrace.c and modified for M680x0.
|
|
|
|
* linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
|
|
|
|
*
|
|
|
|
* Modified by Cort Dougan (cort@hq.fsmlabs.com)
|
2005-10-20 07:11:29 +08:00
|
|
|
* and Paul Mackerras (paulus@samba.org).
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General
|
|
|
|
* Public License. See the file README.legal in the main directory of
|
|
|
|
* this archive for more details.
|
|
|
|
*/
|
|
|
|
|
2007-12-20 19:57:34 +08:00
|
|
|
#include <linux/regset.h>
|
2008-07-27 14:51:03 +08:00
|
|
|
#include <linux/tracehook.h>
|
2005-05-08 22:56:09 +08:00
|
|
|
#include <linux/audit.h>
|
2013-05-14 00:16:40 +08:00
|
|
|
#include <linux/context_tracking.h>
|
2020-02-28 08:14:38 +08:00
|
|
|
#include <linux/syscalls.h>
|
|
|
|
|
2012-03-29 01:30:02 +08:00
|
|
|
#include <asm/switch_to.h>
|
2016-09-06 13:32:43 +08:00
|
|
|
#include <asm/asm-prototypes.h>
|
2018-03-27 12:37:18 +08:00
|
|
|
#include <asm/debug.h>
|
2005-11-19 17:47:22 +08:00
|
|
|
|
2011-02-03 01:27:24 +08:00
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include <trace/events/syscalls.h>
|
|
|
|
|
2020-02-28 08:14:41 +08:00
|
|
|
#include "ptrace-decl.h"
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Called by kernel/ptrace.c when detaching..
|
|
|
|
*
|
|
|
|
* Make sure single step bits etc are not set.
|
|
|
|
*/
|
|
|
|
void ptrace_disable(struct task_struct *child)
|
|
|
|
{
|
|
|
|
/* make sure the single step bit is not set. */
|
2008-01-30 20:30:51 +08:00
|
|
|
user_disable_single_step(child);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-10-28 06:33:47 +08:00
|
|
|
long arch_ptrace(struct task_struct *child, long request,
|
|
|
|
unsigned long addr, unsigned long data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int ret = -EPERM;
|
2010-10-28 06:34:01 +08:00
|
|
|
void __user *datavp = (void __user *) data;
|
|
|
|
unsigned long __user *datalp = datavp;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (request) {
|
|
|
|
/* read the word at location addr in the USER area. */
|
|
|
|
case PTRACE_PEEKUSR: {
|
|
|
|
unsigned long index, tmp;
|
|
|
|
|
|
|
|
ret = -EIO;
|
|
|
|
/* convert to index and check */
|
2005-10-13 13:52:04 +08:00
|
|
|
#ifdef CONFIG_PPC32
|
2010-10-28 06:33:47 +08:00
|
|
|
index = addr >> 2;
|
2005-10-13 13:52:04 +08:00
|
|
|
if ((addr & 3) || (index > PT_FPSCR)
|
|
|
|
|| (child->thread.regs == NULL))
|
|
|
|
#else
|
2010-10-28 06:33:47 +08:00
|
|
|
index = addr >> 3;
|
2005-10-13 13:52:04 +08:00
|
|
|
if ((addr & 7) || (index > PT_FPSCR))
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
CHECK_FULL_REGS(child->thread.regs);
|
|
|
|
if (index < PT_FPR0) {
|
2013-02-15 01:44:23 +08:00
|
|
|
ret = ptrace_get_reg(child, (int) index, &tmp);
|
|
|
|
if (ret)
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2011-09-27 03:37:57 +08:00
|
|
|
unsigned int fpidx = index - PT_FPR0;
|
|
|
|
|
2005-10-13 13:52:04 +08:00
|
|
|
flush_fp_to_thread(child);
|
2011-09-27 03:37:57 +08:00
|
|
|
if (fpidx < (PT_FPSCR - PT_FPR0))
|
2013-12-12 12:59:34 +08:00
|
|
|
memcpy(&tmp, &child->thread.TS_FPR(fpidx),
|
2013-09-23 10:04:38 +08:00
|
|
|
sizeof(long));
|
2011-09-27 03:37:57 +08:00
|
|
|
else
|
2013-09-10 18:20:42 +08:00
|
|
|
tmp = child->thread.fp_state.fpscr;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-10-28 06:34:01 +08:00
|
|
|
ret = put_user(tmp, datalp);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write the word at location addr in the USER area */
|
|
|
|
case PTRACE_POKEUSR: {
|
|
|
|
unsigned long index;
|
|
|
|
|
|
|
|
ret = -EIO;
|
|
|
|
/* convert to index and check */
|
2005-10-13 13:52:04 +08:00
|
|
|
#ifdef CONFIG_PPC32
|
2010-10-28 06:33:47 +08:00
|
|
|
index = addr >> 2;
|
2005-10-13 13:52:04 +08:00
|
|
|
if ((addr & 3) || (index > PT_FPSCR)
|
|
|
|
|| (child->thread.regs == NULL))
|
|
|
|
#else
|
2010-10-28 06:33:47 +08:00
|
|
|
index = addr >> 3;
|
2005-10-13 13:52:04 +08:00
|
|
|
if ((addr & 7) || (index > PT_FPSCR))
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
CHECK_FULL_REGS(child->thread.regs);
|
|
|
|
if (index < PT_FPR0) {
|
2007-06-04 13:15:44 +08:00
|
|
|
ret = ptrace_put_reg(child, index, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2011-09-27 03:37:57 +08:00
|
|
|
unsigned int fpidx = index - PT_FPR0;
|
|
|
|
|
2005-10-13 13:52:04 +08:00
|
|
|
flush_fp_to_thread(child);
|
2011-09-27 03:37:57 +08:00
|
|
|
if (fpidx < (PT_FPSCR - PT_FPR0))
|
2013-12-12 12:59:34 +08:00
|
|
|
memcpy(&child->thread.TS_FPR(fpidx), &data,
|
2013-09-23 10:04:38 +08:00
|
|
|
sizeof(long));
|
2011-09-27 03:37:57 +08:00
|
|
|
else
|
2013-09-10 18:20:42 +08:00
|
|
|
child->thread.fp_state.fpscr = data;
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-08 19:51:05 +08:00
|
|
|
case PPC_PTRACE_GETHWDBGINFO: {
|
|
|
|
struct ppc_debug_info dbginfo;
|
|
|
|
|
2020-02-28 08:14:48 +08:00
|
|
|
ppc_gethwdinfo(&dbginfo);
|
2010-02-08 19:51:05 +08:00
|
|
|
|
2018-05-29 20:57:38 +08:00
|
|
|
if (copy_to_user(datavp, &dbginfo,
|
|
|
|
sizeof(struct ppc_debug_info)))
|
2010-02-08 19:51:05 +08:00
|
|
|
return -EFAULT;
|
2018-05-29 20:57:38 +08:00
|
|
|
return 0;
|
2010-02-08 19:51:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case PPC_PTRACE_SETHWDEBUG: {
|
|
|
|
struct ppc_hw_breakpoint bp_info;
|
|
|
|
|
2018-05-29 20:57:38 +08:00
|
|
|
if (copy_from_user(&bp_info, datavp,
|
|
|
|
sizeof(struct ppc_hw_breakpoint)))
|
2010-02-08 19:51:05 +08:00
|
|
|
return -EFAULT;
|
2018-05-29 20:57:38 +08:00
|
|
|
return ppc_set_hwdebug(child, &bp_info);
|
2010-02-08 19:51:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case PPC_PTRACE_DELHWDEBUG: {
|
2012-10-28 23:13:17 +08:00
|
|
|
ret = ppc_del_hwdebug(child, data);
|
2010-02-08 19:51:05 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-28 08:14:47 +08:00
|
|
|
case PTRACE_GET_DEBUGREG:
|
|
|
|
ret = ptrace_get_debugreg(child, addr, datalp);
|
2005-10-13 13:52:04 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PTRACE_SET_DEBUGREG:
|
|
|
|
ret = ptrace_set_debugreg(child, addr, data);
|
|
|
|
break;
|
|
|
|
|
[POWERPC] ptrace updates & new, better requests
The powerpc ptrace interface is dodgy at best. We have defined our
"own" versions of GETREGS/SETREGS/GETFPREGS/SETFPREGS that strangely
take arguments in reverse order from other archs (in addition to having
different request numbers) and have subtle issue, like not accessing
all of the registers in their respective categories.
This patch moves the implementation of those to a separate function
in order to facilitate their deprecation in the future, and provides
new ptrace requests that mirror the x86 and sparc ones and use the
same numbers:
PTRACE_GETREGS : returns an entire pt_regs (the whole thing,
not only the 32 GPRs, though that doesn't
include the FPRs etc... There's a compat version
for 32 bits that returns a 32 bits compatible
pt_regs (44 uints)
PTRACE_SETREGS : sets an entire pt_regs (the whole thing,
not only the 32 GPRs, though that doesn't
include the FPRs etc... Some registers cannot be
written to and will just be dropped, this is the
same as with POKEUSR, that is anything above MQ
on 32 bits and CCR on 64 bits. There is a compat
version as well.
PTRACE_GETFPREGS : returns all the FP registers -including- the FPSCR
that is 33 doubles (regardless of 32/64 bits)
PTRACE_SETFPREGS : sets all the FP registers -including- the FPSCR
that is 33 doubles (regardless of 32/64 bits)
And two that only exist on 64 bits kernels:
PTRACE_GETREGS64 : Same as PTRACE_GETREGS, except there is no compat
function, a 32 bits process will obtain the full 64
bits registers
PTRACE_SETREGS64 : Same as PTRACE_SETREGS, except there is no compat
function, a 32 bits process will set the full 64
bits registers
The two later ones makes things easier to have a 32 bits debugger on a
64 bits program (or on a 32 bits program that uses the full 64 bits of
the GPRs, which is possible though has issues that will be fixed in a
later patch).
Finally, while at it, the patch removes a whole bunch of code duplication
between ptrace32.c and ptrace.c, in large part by having the former call
into the later for all requests that don't need any special "compat"
treatment.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-06-04 13:15:43 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
case PTRACE_GETREGS64:
|
|
|
|
#endif
|
2007-12-20 19:58:36 +08:00
|
|
|
case PTRACE_GETREGS: /* Get all pt_regs from the child. */
|
|
|
|
return copy_regset_to_user(child, &user_ppc_native_view,
|
|
|
|
REGSET_GPR,
|
2018-10-12 21:39:31 +08:00
|
|
|
0, sizeof(struct user_pt_regs),
|
2010-10-28 06:34:01 +08:00
|
|
|
datavp);
|
2005-10-13 13:52:04 +08:00
|
|
|
|
[POWERPC] ptrace updates & new, better requests
The powerpc ptrace interface is dodgy at best. We have defined our
"own" versions of GETREGS/SETREGS/GETFPREGS/SETFPREGS that strangely
take arguments in reverse order from other archs (in addition to having
different request numbers) and have subtle issue, like not accessing
all of the registers in their respective categories.
This patch moves the implementation of those to a separate function
in order to facilitate their deprecation in the future, and provides
new ptrace requests that mirror the x86 and sparc ones and use the
same numbers:
PTRACE_GETREGS : returns an entire pt_regs (the whole thing,
not only the 32 GPRs, though that doesn't
include the FPRs etc... There's a compat version
for 32 bits that returns a 32 bits compatible
pt_regs (44 uints)
PTRACE_SETREGS : sets an entire pt_regs (the whole thing,
not only the 32 GPRs, though that doesn't
include the FPRs etc... Some registers cannot be
written to and will just be dropped, this is the
same as with POKEUSR, that is anything above MQ
on 32 bits and CCR on 64 bits. There is a compat
version as well.
PTRACE_GETFPREGS : returns all the FP registers -including- the FPSCR
that is 33 doubles (regardless of 32/64 bits)
PTRACE_SETFPREGS : sets all the FP registers -including- the FPSCR
that is 33 doubles (regardless of 32/64 bits)
And two that only exist on 64 bits kernels:
PTRACE_GETREGS64 : Same as PTRACE_GETREGS, except there is no compat
function, a 32 bits process will obtain the full 64
bits registers
PTRACE_SETREGS64 : Same as PTRACE_SETREGS, except there is no compat
function, a 32 bits process will set the full 64
bits registers
The two later ones makes things easier to have a 32 bits debugger on a
64 bits program (or on a 32 bits program that uses the full 64 bits of
the GPRs, which is possible though has issues that will be fixed in a
later patch).
Finally, while at it, the patch removes a whole bunch of code duplication
between ptrace32.c and ptrace.c, in large part by having the former call
into the later for all requests that don't need any special "compat"
treatment.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-06-04 13:15:43 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
case PTRACE_SETREGS64:
|
|
|
|
#endif
|
2007-12-20 19:58:36 +08:00
|
|
|
case PTRACE_SETREGS: /* Set all gp regs in the child. */
|
|
|
|
return copy_regset_from_user(child, &user_ppc_native_view,
|
|
|
|
REGSET_GPR,
|
2018-10-12 21:39:31 +08:00
|
|
|
0, sizeof(struct user_pt_regs),
|
2010-10-28 06:34:01 +08:00
|
|
|
datavp);
|
2007-12-20 19:58:36 +08:00
|
|
|
|
|
|
|
case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */
|
|
|
|
return copy_regset_to_user(child, &user_ppc_native_view,
|
|
|
|
REGSET_FPR,
|
|
|
|
0, sizeof(elf_fpregset_t),
|
2010-10-28 06:34:01 +08:00
|
|
|
datavp);
|
2007-12-20 19:58:36 +08:00
|
|
|
|
|
|
|
case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */
|
|
|
|
return copy_regset_from_user(child, &user_ppc_native_view,
|
|
|
|
REGSET_FPR,
|
|
|
|
0, sizeof(elf_fpregset_t),
|
2010-10-28 06:34:01 +08:00
|
|
|
datavp);
|
2005-10-13 13:52:04 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_ALTIVEC
|
|
|
|
case PTRACE_GETVRREGS:
|
2007-12-20 19:58:36 +08:00
|
|
|
return copy_regset_to_user(child, &user_ppc_native_view,
|
|
|
|
REGSET_VMX,
|
|
|
|
0, (33 * sizeof(vector128) +
|
|
|
|
sizeof(u32)),
|
2010-10-28 06:34:01 +08:00
|
|
|
datavp);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
case PTRACE_SETVRREGS:
|
2007-12-20 19:58:36 +08:00
|
|
|
return copy_regset_from_user(child, &user_ppc_native_view,
|
|
|
|
REGSET_VMX,
|
|
|
|
0, (33 * sizeof(vector128) +
|
|
|
|
sizeof(u32)),
|
2010-10-28 06:34:01 +08:00
|
|
|
datavp);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2008-06-25 12:07:18 +08:00
|
|
|
#ifdef CONFIG_VSX
|
|
|
|
case PTRACE_GETVSRREGS:
|
|
|
|
return copy_regset_to_user(child, &user_ppc_native_view,
|
|
|
|
REGSET_VSX,
|
2008-07-28 23:13:14 +08:00
|
|
|
0, 32 * sizeof(double),
|
2010-10-28 06:34:01 +08:00
|
|
|
datavp);
|
2008-06-25 12:07:18 +08:00
|
|
|
|
|
|
|
case PTRACE_SETVSRREGS:
|
|
|
|
return copy_regset_from_user(child, &user_ppc_native_view,
|
|
|
|
REGSET_VSX,
|
2008-07-28 23:13:14 +08:00
|
|
|
0, 32 * sizeof(double),
|
2010-10-28 06:34:01 +08:00
|
|
|
datavp);
|
2008-06-25 12:07:18 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_SPE
|
|
|
|
case PTRACE_GETEVRREGS:
|
|
|
|
/* Get the child spe register state. */
|
2007-12-20 19:58:36 +08:00
|
|
|
return copy_regset_to_user(child, &user_ppc_native_view,
|
|
|
|
REGSET_SPE, 0, 35 * sizeof(u32),
|
2010-10-28 06:34:01 +08:00
|
|
|
datavp);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
case PTRACE_SETEVRREGS:
|
|
|
|
/* Set the child spe register state. */
|
2007-12-20 19:58:36 +08:00
|
|
|
return copy_regset_from_user(child, &user_ppc_native_view,
|
|
|
|
REGSET_SPE, 0, 35 * sizeof(u32),
|
2010-10-28 06:34:01 +08:00
|
|
|
datavp);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = ptrace_request(child, request, addr, data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
powerpc/kernel: Enable seccomp filter
This commit enables seccomp filter on powerpc, now that we have all the
necessary pieces in place.
To support seccomp's desire to modify the syscall return value under
some circumstances, we use a different ABI to the ptrace ABI. That is we
use r3 as the syscall return value, and orig_gpr3 is the first syscall
parameter.
This means the seccomp code, or a ptracer via SECCOMP_RET_TRACE, will
see -ENOSYS preloaded in r3. This is identical to the behaviour on x86,
and allows seccomp or the ptracer to either leave the -ENOSYS or change
it to something else, as well as rejecting or not the syscall by
modifying r0.
If seccomp does not reject the syscall, we restore the register state to
match what ptrace and audit expect, ie. r3 is the first syscall
parameter again. We do this restore using orig_gpr3, which may have been
modified by seccomp, which allows seccomp to modify the first syscall
paramater and allow the syscall to proceed.
We need to #ifdef the the additional handling of r3 for seccomp, so move
it all out of line.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Kees Cook <keescook@chromium.org>
2015-07-23 18:21:09 +08:00
|
|
|
#ifdef CONFIG_SECCOMP
|
|
|
|
static int do_seccomp(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
if (!test_thread_flag(TIF_SECCOMP))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The ABI we present to seccomp tracers is that r3 contains
|
|
|
|
* the syscall return value and orig_gpr3 contains the first
|
|
|
|
* syscall parameter. This is different to the ptrace ABI where
|
|
|
|
* both r3 and orig_gpr3 contain the first syscall parameter.
|
|
|
|
*/
|
|
|
|
regs->gpr[3] = -ENOSYS;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We use the __ version here because we have already checked
|
|
|
|
* TIF_SECCOMP. If this fails, there is nothing left to do, we
|
|
|
|
* have already loaded -ENOSYS into r3, or seccomp has put
|
|
|
|
* something else in r3 (via SECCOMP_RET_ERRNO/TRACE).
|
|
|
|
*/
|
2016-05-28 03:57:02 +08:00
|
|
|
if (__secure_computing(NULL))
|
powerpc/kernel: Enable seccomp filter
This commit enables seccomp filter on powerpc, now that we have all the
necessary pieces in place.
To support seccomp's desire to modify the syscall return value under
some circumstances, we use a different ABI to the ptrace ABI. That is we
use r3 as the syscall return value, and orig_gpr3 is the first syscall
parameter.
This means the seccomp code, or a ptracer via SECCOMP_RET_TRACE, will
see -ENOSYS preloaded in r3. This is identical to the behaviour on x86,
and allows seccomp or the ptracer to either leave the -ENOSYS or change
it to something else, as well as rejecting or not the syscall by
modifying r0.
If seccomp does not reject the syscall, we restore the register state to
match what ptrace and audit expect, ie. r3 is the first syscall
parameter again. We do this restore using orig_gpr3, which may have been
modified by seccomp, which allows seccomp to modify the first syscall
paramater and allow the syscall to proceed.
We need to #ifdef the the additional handling of r3 for seccomp, so move
it all out of line.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Kees Cook <keescook@chromium.org>
2015-07-23 18:21:09 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The syscall was allowed by seccomp, restore the register
|
2016-06-03 10:55:09 +08:00
|
|
|
* state to what audit expects.
|
powerpc/kernel: Enable seccomp filter
This commit enables seccomp filter on powerpc, now that we have all the
necessary pieces in place.
To support seccomp's desire to modify the syscall return value under
some circumstances, we use a different ABI to the ptrace ABI. That is we
use r3 as the syscall return value, and orig_gpr3 is the first syscall
parameter.
This means the seccomp code, or a ptracer via SECCOMP_RET_TRACE, will
see -ENOSYS preloaded in r3. This is identical to the behaviour on x86,
and allows seccomp or the ptracer to either leave the -ENOSYS or change
it to something else, as well as rejecting or not the syscall by
modifying r0.
If seccomp does not reject the syscall, we restore the register state to
match what ptrace and audit expect, ie. r3 is the first syscall
parameter again. We do this restore using orig_gpr3, which may have been
modified by seccomp, which allows seccomp to modify the first syscall
paramater and allow the syscall to proceed.
We need to #ifdef the the additional handling of r3 for seccomp, so move
it all out of line.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Kees Cook <keescook@chromium.org>
2015-07-23 18:21:09 +08:00
|
|
|
* Note that we use orig_gpr3, which means a seccomp tracer can
|
|
|
|
* modify the first syscall parameter (in orig_gpr3) and also
|
|
|
|
* allow the syscall to proceed.
|
|
|
|
*/
|
|
|
|
regs->gpr[3] = regs->orig_gpr3;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline int do_seccomp(struct pt_regs *regs) { return 0; }
|
|
|
|
#endif /* CONFIG_SECCOMP */
|
|
|
|
|
2015-07-23 18:21:02 +08:00
|
|
|
/**
|
|
|
|
* do_syscall_trace_enter() - Do syscall tracing on kernel entry.
|
|
|
|
* @regs: the pt_regs of the task to trace (current)
|
|
|
|
*
|
|
|
|
* Performs various types of tracing on syscall entry. This includes seccomp,
|
|
|
|
* ptrace, syscall tracepoints and audit.
|
|
|
|
*
|
|
|
|
* The pt_regs are potentially visible to userspace via ptrace, so their
|
|
|
|
* contents is ABI.
|
|
|
|
*
|
|
|
|
* One or more of the tracers may modify the contents of pt_regs, in particular
|
|
|
|
* to modify arguments or even the syscall number itself.
|
|
|
|
*
|
|
|
|
* It's also possible that a tracer can choose to reject the system call. In
|
|
|
|
* that case this function will return an illegal syscall number, and will put
|
|
|
|
* an appropriate return value in regs->r3.
|
|
|
|
*
|
|
|
|
* Return: the (possibly changed) syscall number.
|
2008-07-27 14:51:03 +08:00
|
|
|
*/
|
|
|
|
long do_syscall_trace_enter(struct pt_regs *regs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-12-17 01:28:28 +08:00
|
|
|
u32 flags;
|
|
|
|
|
2013-05-14 00:16:40 +08:00
|
|
|
user_exit();
|
|
|
|
|
2018-12-17 01:28:28 +08:00
|
|
|
flags = READ_ONCE(current_thread_info()->flags) &
|
|
|
|
(_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE);
|
powerpc/ptrace: Add support for PTRACE_SYSEMU
This is a patch that adds support for PTRACE_SYSEMU ptrace request in
PowerPC architecture.
When ptrace(PTRACE_SYSEMU, ...) request is called, it will be handled by
the arch independent function ptrace_resume(), which will tag the task with
the TIF_SYSCALL_EMU flag. This flag needs to be handled from a platform
dependent point of view, which is what this patch does.
This patch adds this task's flag as part of the _TIF_SYSCALL_DOTRACE, which
is the MACRO that is used to trace syscalls at entrance/exit.
Since TIF_SYSCALL_EMU is now part of _TIF_SYSCALL_DOTRACE, if the task has
_TIF_SYSCALL_DOTRACE set, it will hit do_syscall_trace_enter() at syscall
entrance and do_syscall_trace_leave() at syscall leave.
do_syscall_trace_enter() needs to handle the TIF_SYSCALL_EMU flag properly,
which will interrupt the syscall executing if TIF_SYSCALL_EMU is set. The
output values should not be changed, i.e. the return value (r3) should
contain the original syscall argument on exit.
With this flag set, the syscall is not executed fundamentally, because
do_syscall_trace_enter() is returning -1 which is bigger than NR_syscall,
thus, skipping the syscall execution and exiting userspace.
Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-09-21 00:45:06 +08:00
|
|
|
|
2018-12-17 01:28:28 +08:00
|
|
|
if (flags) {
|
|
|
|
int rc = tracehook_report_syscall_entry(regs);
|
|
|
|
|
|
|
|
if (unlikely(flags & _TIF_SYSCALL_EMU)) {
|
|
|
|
/*
|
|
|
|
* A nonzero return code from
|
|
|
|
* tracehook_report_syscall_entry() tells us to prevent
|
|
|
|
* the syscall execution, but we are not going to
|
|
|
|
* execute it anyway.
|
|
|
|
*
|
|
|
|
* Returning -1 will skip the syscall execution. We want
|
|
|
|
* to avoid clobbering any registers, so we don't goto
|
|
|
|
* the skip label below.
|
|
|
|
*/
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
/*
|
|
|
|
* The tracer decided to abort the syscall. Note that
|
|
|
|
* the tracer may also just change regs->gpr[0] to an
|
|
|
|
* invalid syscall number, that is handled below on the
|
|
|
|
* exit path.
|
|
|
|
*/
|
|
|
|
goto skip;
|
|
|
|
}
|
|
|
|
}
|
2016-06-03 10:55:09 +08:00
|
|
|
|
|
|
|
/* Run seccomp after ptrace; allow it to set gpr[3]. */
|
powerpc/kernel: Enable seccomp filter
This commit enables seccomp filter on powerpc, now that we have all the
necessary pieces in place.
To support seccomp's desire to modify the syscall return value under
some circumstances, we use a different ABI to the ptrace ABI. That is we
use r3 as the syscall return value, and orig_gpr3 is the first syscall
parameter.
This means the seccomp code, or a ptracer via SECCOMP_RET_TRACE, will
see -ENOSYS preloaded in r3. This is identical to the behaviour on x86,
and allows seccomp or the ptracer to either leave the -ENOSYS or change
it to something else, as well as rejecting or not the syscall by
modifying r0.
If seccomp does not reject the syscall, we restore the register state to
match what ptrace and audit expect, ie. r3 is the first syscall
parameter again. We do this restore using orig_gpr3, which may have been
modified by seccomp, which allows seccomp to modify the first syscall
paramater and allow the syscall to proceed.
We need to #ifdef the the additional handling of r3 for seccomp, so move
it all out of line.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Kees Cook <keescook@chromium.org>
2015-07-23 18:21:09 +08:00
|
|
|
if (do_seccomp(regs))
|
|
|
|
return -1;
|
2005-10-13 13:52:04 +08:00
|
|
|
|
2016-06-03 10:55:09 +08:00
|
|
|
/* Avoid trace and audit when syscall is invalid. */
|
|
|
|
if (regs->gpr[0] >= NR_syscalls)
|
|
|
|
goto skip;
|
2005-05-08 22:56:09 +08:00
|
|
|
|
2011-02-03 01:27:24 +08:00
|
|
|
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
|
|
|
|
trace_sys_enter(regs, regs->gpr[0]);
|
|
|
|
|
2012-01-04 03:23:06 +08:00
|
|
|
if (!is_32bit_task())
|
2014-03-12 01:29:28 +08:00
|
|
|
audit_syscall_entry(regs->gpr[0], regs->gpr[3], regs->gpr[4],
|
2012-01-04 03:23:06 +08:00
|
|
|
regs->gpr[5], regs->gpr[6]);
|
|
|
|
else
|
2014-03-12 01:29:28 +08:00
|
|
|
audit_syscall_entry(regs->gpr[0],
|
2012-01-04 03:23:06 +08:00
|
|
|
regs->gpr[3] & 0xffffffff,
|
|
|
|
regs->gpr[4] & 0xffffffff,
|
|
|
|
regs->gpr[5] & 0xffffffff,
|
|
|
|
regs->gpr[6] & 0xffffffff);
|
2008-07-27 14:51:03 +08:00
|
|
|
|
2015-07-23 18:21:02 +08:00
|
|
|
/* Return the possibly modified but valid syscall number */
|
|
|
|
return regs->gpr[0];
|
2016-06-03 10:55:09 +08:00
|
|
|
|
|
|
|
skip:
|
|
|
|
/*
|
|
|
|
* If we are aborting explicitly, or if the syscall number is
|
|
|
|
* now invalid, set the return value to -ENOSYS.
|
|
|
|
*/
|
|
|
|
regs->gpr[3] = -ENOSYS;
|
|
|
|
return -1;
|
2005-05-08 22:56:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void do_syscall_trace_leave(struct pt_regs *regs)
|
|
|
|
{
|
2008-07-27 14:51:03 +08:00
|
|
|
int step;
|
|
|
|
|
2012-01-04 03:23:06 +08:00
|
|
|
audit_syscall_exit(regs);
|
2005-05-08 22:56:09 +08:00
|
|
|
|
2011-02-03 01:27:24 +08:00
|
|
|
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
|
|
|
|
trace_sys_exit(regs, regs->result);
|
|
|
|
|
2008-07-27 14:51:03 +08:00
|
|
|
step = test_thread_flag(TIF_SINGLESTEP);
|
|
|
|
if (step || test_thread_flag(TIF_SYSCALL_TRACE))
|
|
|
|
tracehook_report_syscall_exit(regs, step);
|
2013-05-14 00:16:40 +08:00
|
|
|
|
|
|
|
user_enter();
|
2005-05-08 22:56:09 +08:00
|
|
|
}
|
2018-10-12 20:13:17 +08:00
|
|
|
|
2018-12-08 23:46:23 +08:00
|
|
|
void __init pt_regs_check(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dummy function, its purpose is to break the build if struct pt_regs and
|
|
|
|
* struct user_pt_regs don't match.
|
|
|
|
*/
|
2018-10-12 20:13:17 +08:00
|
|
|
void __init pt_regs_check(void)
|
|
|
|
{
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, gpr) !=
|
|
|
|
offsetof(struct user_pt_regs, gpr));
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, nip) !=
|
|
|
|
offsetof(struct user_pt_regs, nip));
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, msr) !=
|
|
|
|
offsetof(struct user_pt_regs, msr));
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, msr) !=
|
|
|
|
offsetof(struct user_pt_regs, msr));
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
|
|
|
|
offsetof(struct user_pt_regs, orig_gpr3));
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, ctr) !=
|
|
|
|
offsetof(struct user_pt_regs, ctr));
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, link) !=
|
|
|
|
offsetof(struct user_pt_regs, link));
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, xer) !=
|
|
|
|
offsetof(struct user_pt_regs, xer));
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, ccr) !=
|
|
|
|
offsetof(struct user_pt_regs, ccr));
|
|
|
|
#ifdef __powerpc64__
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, softe) !=
|
|
|
|
offsetof(struct user_pt_regs, softe));
|
|
|
|
#else
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, mq) !=
|
|
|
|
offsetof(struct user_pt_regs, mq));
|
|
|
|
#endif
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, trap) !=
|
|
|
|
offsetof(struct user_pt_regs, trap));
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, dar) !=
|
|
|
|
offsetof(struct user_pt_regs, dar));
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, dsisr) !=
|
|
|
|
offsetof(struct user_pt_regs, dsisr));
|
|
|
|
BUILD_BUG_ON(offsetof(struct pt_regs, result) !=
|
|
|
|
offsetof(struct user_pt_regs, result));
|
|
|
|
|
|
|
|
BUILD_BUG_ON(sizeof(struct user_pt_regs) > sizeof(struct pt_regs));
|
2019-10-30 19:12:31 +08:00
|
|
|
|
|
|
|
// Now check that the pt_regs offsets match the uapi #defines
|
|
|
|
#define CHECK_REG(_pt, _reg) \
|
|
|
|
BUILD_BUG_ON(_pt != (offsetof(struct user_pt_regs, _reg) / \
|
|
|
|
sizeof(unsigned long)));
|
|
|
|
|
|
|
|
CHECK_REG(PT_R0, gpr[0]);
|
|
|
|
CHECK_REG(PT_R1, gpr[1]);
|
|
|
|
CHECK_REG(PT_R2, gpr[2]);
|
|
|
|
CHECK_REG(PT_R3, gpr[3]);
|
|
|
|
CHECK_REG(PT_R4, gpr[4]);
|
|
|
|
CHECK_REG(PT_R5, gpr[5]);
|
|
|
|
CHECK_REG(PT_R6, gpr[6]);
|
|
|
|
CHECK_REG(PT_R7, gpr[7]);
|
|
|
|
CHECK_REG(PT_R8, gpr[8]);
|
|
|
|
CHECK_REG(PT_R9, gpr[9]);
|
|
|
|
CHECK_REG(PT_R10, gpr[10]);
|
|
|
|
CHECK_REG(PT_R11, gpr[11]);
|
|
|
|
CHECK_REG(PT_R12, gpr[12]);
|
|
|
|
CHECK_REG(PT_R13, gpr[13]);
|
|
|
|
CHECK_REG(PT_R14, gpr[14]);
|
|
|
|
CHECK_REG(PT_R15, gpr[15]);
|
|
|
|
CHECK_REG(PT_R16, gpr[16]);
|
|
|
|
CHECK_REG(PT_R17, gpr[17]);
|
|
|
|
CHECK_REG(PT_R18, gpr[18]);
|
|
|
|
CHECK_REG(PT_R19, gpr[19]);
|
|
|
|
CHECK_REG(PT_R20, gpr[20]);
|
|
|
|
CHECK_REG(PT_R21, gpr[21]);
|
|
|
|
CHECK_REG(PT_R22, gpr[22]);
|
|
|
|
CHECK_REG(PT_R23, gpr[23]);
|
|
|
|
CHECK_REG(PT_R24, gpr[24]);
|
|
|
|
CHECK_REG(PT_R25, gpr[25]);
|
|
|
|
CHECK_REG(PT_R26, gpr[26]);
|
|
|
|
CHECK_REG(PT_R27, gpr[27]);
|
|
|
|
CHECK_REG(PT_R28, gpr[28]);
|
|
|
|
CHECK_REG(PT_R29, gpr[29]);
|
|
|
|
CHECK_REG(PT_R30, gpr[30]);
|
|
|
|
CHECK_REG(PT_R31, gpr[31]);
|
|
|
|
CHECK_REG(PT_NIP, nip);
|
|
|
|
CHECK_REG(PT_MSR, msr);
|
|
|
|
CHECK_REG(PT_ORIG_R3, orig_gpr3);
|
|
|
|
CHECK_REG(PT_CTR, ctr);
|
|
|
|
CHECK_REG(PT_LNK, link);
|
|
|
|
CHECK_REG(PT_XER, xer);
|
|
|
|
CHECK_REG(PT_CCR, ccr);
|
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
CHECK_REG(PT_SOFTE, softe);
|
|
|
|
#else
|
|
|
|
CHECK_REG(PT_MQ, mq);
|
|
|
|
#endif
|
|
|
|
CHECK_REG(PT_TRAP, trap);
|
|
|
|
CHECK_REG(PT_DAR, dar);
|
|
|
|
CHECK_REG(PT_DSISR, dsisr);
|
|
|
|
CHECK_REG(PT_RESULT, result);
|
|
|
|
#undef CHECK_REG
|
|
|
|
|
|
|
|
BUILD_BUG_ON(PT_REGS_COUNT != sizeof(struct user_pt_regs) / sizeof(unsigned long));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PT_DSCR isn't a real reg, but it's important that it doesn't overlap the
|
|
|
|
* real registers.
|
|
|
|
*/
|
|
|
|
BUILD_BUG_ON(PT_DSCR < sizeof(struct user_pt_regs) / sizeof(unsigned long));
|
2018-10-12 20:13:17 +08:00
|
|
|
}
|