um: Add seccomp support
authorMickaël Salaün <mic@digikod.net>
Tue, 29 Dec 2015 20:35:47 +0000 (21:35 +0100)
committerRichard Weinberger <richard@nod.at>
Sun, 10 Jan 2016 20:49:49 +0000 (21:49 +0100)
This brings SECCOMP_MODE_STRICT and SECCOMP_MODE_FILTER support through
prctl(2) and seccomp(2) to User-mode Linux for i386 and x86_64
subarchitectures.

secure_computing() is called first in handle_syscall() so that the
syscall emulation will be aborted quickly if matching a seccomp rule.

This is inspired from Meredydd Luff's patch
(https://gerrit.chromium.org/gerrit/21425).

Signed-off-by: Mickaël Salaün <mic@digikod.net>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Will Drewry <wad@chromium.org>
Cc: Chris Metcalf <cmetcalf@ezchip.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: Meredydd Luff <meredydd@senatehouse.org>
Cc: David Drysdale <drysdale@google.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Kees Cook <keescook@chromium.org>
Documentation/features/seccomp/seccomp-filter/arch-support.txt
arch/um/Kconfig.common
arch/um/Kconfig.um
arch/um/include/asm/thread_info.h
arch/um/kernel/skas/syscall.c

index 76d39d66a5d754ed15d39285bd7742d9af1c2be7..4f66ec13395112ae9be41a7250f0152963995a1c 100644 (file)
@@ -33,7 +33,7 @@
     |          sh: | TODO |
     |       sparc: | TODO |
     |        tile: |  ok  |
-    |          um: | TODO |
+    |          um: |  ok  |
     |   unicore32: | TODO |
     |         x86: |  ok  |
     |      xtensa: | TODO |
index d195a87ca542b75e919055b30a72bf60f1ba132c..cc001347544416ca4c3f7e2bca2dedca5a674a42 100644 (file)
@@ -2,6 +2,7 @@ config UML
        bool
        default y
        select HAVE_ARCH_AUDITSYSCALL
+       select HAVE_ARCH_SECCOMP_FILTER
        select HAVE_UID16
        select HAVE_FUTEX_CMPXCHG if FUTEX
        select GENERIC_IRQ_SHOW
index 28a9885e3a37a4815f5cd635f0071865a42e6c4e..4b2ed5858b2ee0797215279c8d6decadb91298d4 100644 (file)
@@ -104,3 +104,19 @@ config PGTABLE_LEVELS
        int
        default 3 if 3_LEVEL_PGTABLES
        default 2
+
+config SECCOMP
+       def_bool y
+       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.
index 53968aaf76f9a48b69ff54dbedadb2a332f7f6a2..053baff036746f8360a6ff81034a6e3bcc332156 100644 (file)
@@ -62,11 +62,13 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_SYSCALL_AUDIT      6
 #define TIF_RESTORE_SIGMASK    7
 #define TIF_NOTIFY_RESUME      8
+#define TIF_SECCOMP            9       /* secure computing */
 
 #define _TIF_SYSCALL_TRACE     (1 << TIF_SYSCALL_TRACE)
 #define _TIF_SIGPENDING                (1 << TIF_SIGPENDING)
 #define _TIF_NEED_RESCHED      (1 << TIF_NEED_RESCHED)
 #define _TIF_MEMDIE            (1 << TIF_MEMDIE)
 #define _TIF_SYSCALL_AUDIT     (1 << TIF_SYSCALL_AUDIT)
+#define _TIF_SECCOMP           (1 << TIF_SECCOMP)
 
 #endif
index 6cadce761bcf29c0dc170d97bfa4c9b8fed64de3..48b0dcbd87bef3913cfe8330b0ee6965a8c6ce6d 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <linux/kernel.h>
 #include <linux/ptrace.h>
+#include <linux/seccomp.h>
 #include <kern_util.h>
 #include <sysdep/ptrace.h>
 #include <sysdep/ptrace_user.h>
@@ -19,6 +20,10 @@ void handle_syscall(struct uml_pt_regs *r)
        UPT_SYSCALL_NR(r) = PT_SYSCALL_NR(r->gp);
        PT_REGS_SET_SYSCALL_RETURN(regs, -ENOSYS);
 
+       /* Do the secure computing check first; failures should be fast. */
+       if (secure_computing() == -1)
+               return;
+
        if (syscall_trace_enter(regs))
                goto out;