mirror of
https://github.com/torvalds/linux
synced 2024-11-05 18:23:50 +00:00
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>
This commit is contained in:
parent
1b60bab04e
commit
2449acc534
2 changed files with 41 additions and 1 deletions
|
@ -159,6 +159,7 @@ config PPC
|
|||
select EDAC_SUPPORT
|
||||
select EDAC_ATOMIC_SCRUB
|
||||
select ARCH_HAS_DMA_SET_COHERENT_MASK
|
||||
select HAVE_ARCH_SECCOMP_FILTER
|
||||
|
||||
config GENERIC_CSUM
|
||||
def_bool CPU_LITTLE_ENDIAN
|
||||
|
|
|
@ -1762,6 +1762,44 @@ long arch_ptrace(struct task_struct *child, long request,
|
|||
return ret;
|
||||
}
|
||||
|
||||
#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).
|
||||
*/
|
||||
if (__secure_computing())
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* The syscall was allowed by seccomp, restore the register
|
||||
* state to what ptrace and audit expect.
|
||||
* 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 */
|
||||
|
||||
/**
|
||||
* do_syscall_trace_enter() - Do syscall tracing on kernel entry.
|
||||
* @regs: the pt_regs of the task to trace (current)
|
||||
|
@ -1787,7 +1825,8 @@ long do_syscall_trace_enter(struct pt_regs *regs)
|
|||
|
||||
user_exit();
|
||||
|
||||
secure_computing_strict(regs->gpr[0]);
|
||||
if (do_seccomp(regs))
|
||||
return -1;
|
||||
|
||||
if (test_thread_flag(TIF_SYSCALL_TRACE)) {
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue