Skip to content

Commit c41f4a3

Browse files
automerging branch "kernel.org-palmer-linux/wip-seccomp" into "riscv-all"
2 parents ed54725 + a012750 commit c41f4a3

File tree

7 files changed

+43
-3
lines changed

7 files changed

+43
-3
lines changed

arch/riscv/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ config RISCV
2626
select GENERIC_STRNLEN_USER
2727
select GENERIC_SMP_IDLE_THREAD
2828
select GENERIC_ATOMIC64 if !64BIT || !RISCV_ISA_A
29+
select HAVE_ARCH_SECCOMP_FILTER
2930
select HAVE_MEMBLOCK
3031
select HAVE_MEMBLOCK_NODE_MAP
3132
select HAVE_DMA_API_DEBUG
@@ -325,6 +326,22 @@ config CMDLINE_FORCE
325326

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

329+
config SECCOMP
330+
bool
331+
prompt "Enable seccomp to safely compute untrusted bytecode"
332+
---help---
333+
This kernel feature is useful for number crunching applications
334+
that may need to compute untrusted bytecode during their
335+
execution. By using pipes or other transports made available to
336+
the process as file descriptors supporting the read/write
337+
syscalls, it's possible to isolate those applications in
338+
their own address space using seccomp. Once seccomp is
339+
enabled via prctl(PR_SET_SECCOMP), it cannot be disabled
340+
and the task is only allowed to execute a few safe syscalls
341+
defined by each seccomp mode.
342+
343+
If unsure, say Y. Only embedded should say N here.
344+
328345
config EARLY_PRINTK
329346
def_bool y
330347

arch/riscv/include/asm/elf.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
#include <asm/auxvec.h>
1717
#include <asm/byteorder.h>
1818

19-
/* TODO: Move definition into include/uapi/linux/elf-em.h */
20-
#define EM_RISCV 0xF3
21-
2219
/*
2320
* These are used to set parameters in the core dumps.
2421
*/

arch/riscv/include/asm/seccomp.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_RISCV_SECCOMP_H
3+
#define _ASM_RISCV_SECCOMP_H
4+
5+
#include <asm/unistd.h>
6+
7+
#ifdef CONFIG_COMPAT
8+
#include <asm/ia32_unistd.h>
9+
#define __NR_seccomp_read_32 __NR_ia32_read
10+
#define __NR_seccomp_write_32 __NR_ia32_write
11+
#define __NR_seccomp_exit_32 __NR_ia32_exit
12+
#define __NR_seccomp_sigreturn_32 __NR_ia32_sigreturn
13+
#endif
14+
15+
#include <asm-generic/seccomp.h>
16+
17+
#endif /* _ASM_RISCV_SECCOMP_H */

arch/riscv/include/asm/syscall.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define _ASM_RISCV_SYSCALL_H
2020

2121
#include <linux/sched.h>
22+
#include <uapi/linux/audit.h>
2223
#include <linux/err.h>
2324

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

103+
static inline int syscall_get_arch(void)
104+
{
105+
return AUDIT_ARCH_RISCV;
106+
}
107+
102108
#endif /* _ASM_RISCV_SYSCALL_H */

arch/riscv/include/asm/thread_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct thread_info {
8080
#define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */
8181
#define TIF_MEMDIE 5 /* is terminating due to OOM killer */
8282
#define TIF_SYSCALL_TRACEPOINT 6 /* syscall tracepoint instrumentation */
83+
#define TIF_SECCOMP 7 /* seccomp syscall filtering active */
8384

8485
#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
8586
#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)

include/uapi/linux/audit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ enum {
396396
/* do not define AUDIT_ARCH_PPCLE since it is not supported by audit */
397397
#define AUDIT_ARCH_PPC64 (EM_PPC64|__AUDIT_ARCH_64BIT)
398398
#define AUDIT_ARCH_PPC64LE (EM_PPC64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
399+
#define AUDIT_ARCH_RISCV (EM_RISCV)
399400
#define AUDIT_ARCH_S390 (EM_S390)
400401
#define AUDIT_ARCH_S390X (EM_S390|__AUDIT_ARCH_64BIT)
401402
#define AUDIT_ARCH_SH (EM_SH)

include/uapi/linux/elf-em.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#define EM_TILEPRO 188 /* Tilera TILEPro */
4242
#define EM_MICROBLAZE 189 /* Xilinx MicroBlaze */
4343
#define EM_TILEGX 191 /* Tilera TILE-Gx */
44+
#define EM_RISCV 243 /* RISC-V */
4445
#define EM_BPF 247 /* Linux BPF - in-kernel virtual machine */
4546
#define EM_FRV 0x5441 /* Fujitsu FR-V */
4647

0 commit comments

Comments
 (0)