Skip to content

Commit da94a40

Browse files
committed
xtensa: add seccomp support
Add SECCOMP to xtensa Kconfig, select HAVE_ARCH_SECCOMP_FILTER, add TIF_SECCOMP and call secure_computing from do_syscall_trace_enter. Signed-off-by: Max Filippov <[email protected]>
1 parent 8b7a87a commit da94a40

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

Documentation/features/seccomp/seccomp-filter/arch-support.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@
3030
| um: | ok |
3131
| unicore32: | TODO |
3232
| x86: | ok |
33-
| xtensa: | TODO |
33+
| xtensa: | ok |
3434
-----------------------

arch/xtensa/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ config XTENSA
2424
select HAVE_ARCH_AUDITSYSCALL
2525
select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL
2626
select HAVE_ARCH_KASAN if MMU && !XIP_KERNEL
27+
select HAVE_ARCH_SECCOMP_FILTER
2728
select HAVE_ARCH_TRACEHOOK
2829
select HAVE_COPY_THREAD_TLS
2930
select HAVE_DEBUG_KMEMLEAK
@@ -217,6 +218,20 @@ config HOTPLUG_CPU
217218

218219
Say N if you want to disable CPU hotplug.
219220

221+
config SECCOMP
222+
bool
223+
prompt "Enable seccomp to safely compute untrusted bytecode"
224+
help
225+
This kernel feature is useful for number crunching applications
226+
that may need to compute untrusted bytecode during their
227+
execution. By using pipes or other transports made available to
228+
the process as file descriptors supporting the read/write
229+
syscalls, it's possible to isolate those applications in
230+
their own address space using seccomp. Once seccomp is
231+
enabled via prctl(PR_SET_SECCOMP), it cannot be disabled
232+
and the task is only allowed to execute a few safe syscalls
233+
defined by each seccomp mode.
234+
220235
config FAST_SYSCALL_XTENSA
221236
bool "Enable fast atomic syscalls"
222237
default n

arch/xtensa/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ generic-y += mcs_spinlock.h
77
generic-y += param.h
88
generic-y += qrwlock.h
99
generic-y += qspinlock.h
10+
generic-y += seccomp.h
1011
generic-y += user.h

arch/xtensa/include/asm/thread_info.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,19 @@ static inline struct thread_info *current_thread_info(void)
112112
#define TIF_NOTIFY_RESUME 7 /* callback before returning to user */
113113
#define TIF_DB_DISABLED 8 /* debug trap disabled for syscall */
114114
#define TIF_SYSCALL_AUDIT 9 /* syscall auditing active */
115+
#define TIF_SECCOMP 10 /* secure computing */
115116

116117
#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
117118
#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
118119
#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
119120
#define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP)
120121
#define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
121122
#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
123+
#define _TIF_SECCOMP (1<<TIF_SECCOMP)
122124

123125
#define _TIF_WORK_MASK (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP | \
124-
_TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_AUDIT)
126+
_TIF_SYSCALL_TRACEPOINT | \
127+
_TIF_SYSCALL_AUDIT | _TIF_SECCOMP)
125128

126129
#define THREAD_SIZE KERNEL_STACK_SIZE
127130
#define THREAD_SIZE_ORDER (KERNEL_STACK_SHIFT - PAGE_SHIFT)

arch/xtensa/kernel/ptrace.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/regset.h>
2323
#include <linux/sched.h>
2424
#include <linux/sched/task_stack.h>
25+
#include <linux/seccomp.h>
2526
#include <linux/security.h>
2627
#include <linux/signal.h>
2728
#include <linux/smp.h>
@@ -559,7 +560,8 @@ int do_syscall_trace_enter(struct pt_regs *regs)
559560
return 0;
560561
}
561562

562-
if (regs->syscall == NO_SYSCALL) {
563+
if (regs->syscall == NO_SYSCALL ||
564+
secure_computing() == -1) {
563565
do_syscall_trace_leave(regs);
564566
return 0;
565567
}

0 commit comments

Comments
 (0)