aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAKASHI Takahiro <takahiro.akashi@linaro.org>2014-11-28 00:26:39 -0500
committerWill Deacon <will.deacon@arm.com>2014-11-28 05:24:59 -0500
commita1ae65b219416a72c15577bd4c8c11174fffbb8b (patch)
tree653e0ac5fd6ffd3beb5dc78755a9f89602bc5b56
parentcc5e9097c9aad6b186a568c534e26746d6bfa483 (diff)
arm64: add seccomp support
secure_computing() is called first in syscall_trace_enter() so that a system call will be aborted quickly without doing succeeding syscall tracing if seccomp rules want to deny that system call. On compat task, syscall numbers for system calls allowed in seccomp mode 1 are different from those on normal tasks, and so _NR_seccomp_xxx_32's need to be redefined. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r--arch/arm64/Kconfig14
-rw-r--r--arch/arm64/include/asm/seccomp.h25
-rw-r--r--arch/arm64/include/asm/unistd.h3
-rw-r--r--arch/arm64/kernel/ptrace.c5
4 files changed, 47 insertions, 0 deletions
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index f5412d628ff6..7c79c6494379 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -38,6 +38,7 @@ config ARM64
38 select HAVE_ARCH_AUDITSYSCALL 38 select HAVE_ARCH_AUDITSYSCALL
39 select HAVE_ARCH_JUMP_LABEL 39 select HAVE_ARCH_JUMP_LABEL
40 select HAVE_ARCH_KGDB 40 select HAVE_ARCH_KGDB
41 select HAVE_ARCH_SECCOMP_FILTER
41 select HAVE_ARCH_TRACEHOOK 42 select HAVE_ARCH_TRACEHOOK
42 select HAVE_BPF_JIT 43 select HAVE_BPF_JIT
43 select HAVE_C_RECORDMCOUNT 44 select HAVE_C_RECORDMCOUNT
@@ -455,6 +456,19 @@ config ARCH_HAS_CACHE_LINE_SIZE
455 456
456source "mm/Kconfig" 457source "mm/Kconfig"
457 458
459config SECCOMP
460 bool "Enable seccomp to safely compute untrusted bytecode"
461 ---help---
462 This kernel feature is useful for number crunching applications
463 that may need to compute untrusted bytecode during their
464 execution. By using pipes or other transports made available to
465 the process as file descriptors supporting the read/write
466 syscalls, it's possible to isolate those applications in
467 their own address space using seccomp. Once seccomp is
468 enabled via prctl(PR_SET_SECCOMP), it cannot be disabled
469 and the task is only allowed to execute a few safe syscalls
470 defined by each seccomp mode.
471
458config XEN_DOM0 472config XEN_DOM0
459 def_bool y 473 def_bool y
460 depends on XEN 474 depends on XEN
diff --git a/arch/arm64/include/asm/seccomp.h b/arch/arm64/include/asm/seccomp.h
new file mode 100644
index 000000000000..c76fac979629
--- /dev/null
+++ b/arch/arm64/include/asm/seccomp.h
@@ -0,0 +1,25 @@
1/*
2 * arch/arm64/include/asm/seccomp.h
3 *
4 * Copyright (C) 2014 Linaro Limited
5 * Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#ifndef _ASM_SECCOMP_H
12#define _ASM_SECCOMP_H
13
14#include <asm/unistd.h>
15
16#ifdef CONFIG_COMPAT
17#define __NR_seccomp_read_32 __NR_compat_read
18#define __NR_seccomp_write_32 __NR_compat_write
19#define __NR_seccomp_exit_32 __NR_compat_exit
20#define __NR_seccomp_sigreturn_32 __NR_compat_rt_sigreturn
21#endif /* CONFIG_COMPAT */
22
23#include <asm-generic/seccomp.h>
24
25#endif /* _ASM_SECCOMP_H */
diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 6d2bf419431d..49c9aefd24a5 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -31,6 +31,9 @@
31 * Compat syscall numbers used by the AArch64 kernel. 31 * Compat syscall numbers used by the AArch64 kernel.
32 */ 32 */
33#define __NR_compat_restart_syscall 0 33#define __NR_compat_restart_syscall 0
34#define __NR_compat_exit 1
35#define __NR_compat_read 3
36#define __NR_compat_write 4
34#define __NR_compat_sigreturn 119 37#define __NR_compat_sigreturn 119
35#define __NR_compat_rt_sigreturn 173 38#define __NR_compat_rt_sigreturn 173
36 39
diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index f576781d8d3b..d882b833dbdb 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -27,6 +27,7 @@
27#include <linux/smp.h> 27#include <linux/smp.h>
28#include <linux/ptrace.h> 28#include <linux/ptrace.h>
29#include <linux/user.h> 29#include <linux/user.h>
30#include <linux/seccomp.h>
30#include <linux/security.h> 31#include <linux/security.h>
31#include <linux/init.h> 32#include <linux/init.h>
32#include <linux/signal.h> 33#include <linux/signal.h>
@@ -1149,6 +1150,10 @@ static void tracehook_report_syscall(struct pt_regs *regs,
1149 1150
1150asmlinkage int syscall_trace_enter(struct pt_regs *regs) 1151asmlinkage int syscall_trace_enter(struct pt_regs *regs)
1151{ 1152{
1153 /* Do the secure computing check first; failures should be fast. */
1154 if (secure_computing() == -1)
1155 return -1;
1156
1152 if (test_thread_flag(TIF_SYSCALL_TRACE)) 1157 if (test_thread_flag(TIF_SYSCALL_TRACE))
1153 tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER); 1158 tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
1154 1159