Skip to content
This repository has been archived by the owner on Apr 13, 2019. It is now read-only.

Commit

Permalink
riscv: add support for seccomp
Browse files Browse the repository at this point in the history
  • Loading branch information
terpstra committed Apr 16, 2018
1 parent 2b0aa1d commit 0712587
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 3 deletions.
17 changes: 17 additions & 0 deletions arch/riscv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ config RISCV
select GENERIC_SMP_IDLE_THREAD
select GENERIC_ATOMIC64 if !64BIT || !RISCV_ISA_A
select ARCH_WANT_OPTIONAL_GPIOLIB
select HAVE_ARCH_SECCOMP_FILTER
select HAVE_MEMBLOCK
select HAVE_MEMBLOCK_NODE_MAP
select HAVE_DMA_API_DEBUG
Expand Down Expand Up @@ -328,6 +329,22 @@ config CMDLINE_OVERRIDE

If you don't know what to do here, say N.

config SECCOMP
bool
prompt "Enable seccomp to safely compute untrusted bytecode"
---help---
This kernel feature is useful for number crunching applications
that may need to compute untrusted bytecode during their
execution. By using pipes or other transports made available to
the process as file descriptors supporting the read/write
syscalls, it's possible to isolate those applications in
their own address space using seccomp. Once seccomp is
enabled via prctl(PR_SET_SECCOMP), it cannot be disabled
and the task is only allowed to execute a few safe syscalls
defined by each seccomp mode.

If unsure, say Y. Only embedded should say N here.

config EARLY_PRINTK
def_bool y

Expand Down
3 changes: 0 additions & 3 deletions arch/riscv/include/asm/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#include <asm/auxvec.h>
#include <asm/byteorder.h>

/* TODO: Move definition into include/uapi/linux/elf-em.h */
#define EM_RISCV 0xF3

/*
* These are used to set parameters in the core dumps.
*/
Expand Down
17 changes: 17 additions & 0 deletions arch/riscv/include/asm/seccomp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_RISCV_SECCOMP_H
#define _ASM_RISCV_SECCOMP_H

#include <asm/unistd.h>

#ifdef CONFIG_COMPAT
#include <asm/ia32_unistd.h>
#define __NR_seccomp_read_32 __NR_ia32_read
#define __NR_seccomp_write_32 __NR_ia32_write
#define __NR_seccomp_exit_32 __NR_ia32_exit
#define __NR_seccomp_sigreturn_32 __NR_ia32_sigreturn
#endif

#include <asm-generic/seccomp.h>

#endif /* _ASM_RISCV_SECCOMP_H */
6 changes: 6 additions & 0 deletions arch/riscv/include/asm/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define _ASM_RISCV_SYSCALL_H

#include <linux/sched.h>
#include <uapi/linux/audit.h>
#include <linux/err.h>

/* The array of function pointers for syscalls. */
Expand Down Expand Up @@ -99,4 +100,9 @@ static inline void syscall_set_arguments(struct task_struct *task,
memcpy(&regs->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0));
}

static inline int syscall_get_arch(void)
{
return AUDIT_ARCH_RISCV;
}

#endif /* _ASM_RISCV_SYSCALL_H */
1 change: 1 addition & 0 deletions arch/riscv/include/asm/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct thread_info {
#define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */
#define TIF_MEMDIE 5 /* is terminating due to OOM killer */
#define TIF_SYSCALL_TRACEPOINT 6 /* syscall tracepoint instrumentation */
#define TIF_SECCOMP 7 /* seccomp syscall filtering active */

#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
Expand Down
1 change: 1 addition & 0 deletions include/uapi/linux/audit.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ enum {
/* do not define AUDIT_ARCH_PPCLE since it is not supported by audit */
#define AUDIT_ARCH_PPC64 (EM_PPC64|__AUDIT_ARCH_64BIT)
#define AUDIT_ARCH_PPC64LE (EM_PPC64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
#define AUDIT_ARCH_RISCV (EM_RISCV)
#define AUDIT_ARCH_S390 (EM_S390)
#define AUDIT_ARCH_S390X (EM_S390|__AUDIT_ARCH_64BIT)
#define AUDIT_ARCH_SH (EM_SH)
Expand Down
1 change: 1 addition & 0 deletions include/uapi/linux/elf-em.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define EM_TILEPRO 188 /* Tilera TILEPro */
#define EM_MICROBLAZE 189 /* Xilinx MicroBlaze */
#define EM_TILEGX 191 /* Tilera TILE-Gx */
#define EM_RISCV 228 /* RISC-V */
#define EM_BPF 247 /* Linux BPF - in-kernel virtual machine */
#define EM_FRV 0x5441 /* Fujitsu FR-V */

Expand Down

0 comments on commit 0712587

Please sign in to comment.