Skip to content

Commit a1ae65b

Browse files
AKASHI Takahirowildea01
authored andcommitted
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>
1 parent cc5e909 commit a1ae65b

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎arch/arm64/Kconfig‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ config ARM64
3838
select HAVE_ARCH_AUDITSYSCALL
3939
select HAVE_ARCH_JUMP_LABEL
4040
select HAVE_ARCH_KGDB
41+
select HAVE_ARCH_SECCOMP_FILTER
4142
select HAVE_ARCH_TRACEHOOK
4243
select HAVE_BPF_JIT
4344
select HAVE_C_RECORDMCOUNT
@@ -455,6 +456,19 @@ config ARCH_HAS_CACHE_LINE_SIZE
455456

456457
source "mm/Kconfig"
457458

459+
config 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+
458472
config XEN_DOM0
459473
def_bool y
460474
depends on XEN

‎arch/arm64/include/asm/seccomp.h‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */

‎arch/arm64/include/asm/unistd.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
* Compat syscall numbers used by the AArch64 kernel.
3232
*/
3333
#define __NR_compat_restart_syscall 0
34+
#define __NR_compat_exit 1
35+
#define __NR_compat_read 3
36+
#define __NR_compat_write 4
3437
#define __NR_compat_sigreturn 119
3538
#define __NR_compat_rt_sigreturn 173
3639

‎arch/arm64/kernel/ptrace.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/smp.h>
2828
#include <linux/ptrace.h>
2929
#include <linux/user.h>
30+
#include <linux/seccomp.h>
3031
#include <linux/security.h>
3132
#include <linux/init.h>
3233
#include <linux/signal.h>
@@ -1149,6 +1150,10 @@ static void tracehook_report_syscall(struct pt_regs *regs,
11491150

11501151
asmlinkage int syscall_trace_enter(struct pt_regs *regs)
11511152
{
1153+
/* Do the secure computing check first; failures should be fast. */
1154+
if (secure_computing() == -1)
1155+
return -1;
1156+
11521157
if (test_thread_flag(TIF_SYSCALL_TRACE))
11531158
tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
11541159

0 commit comments

Comments
 (0)