2 * linux/kernel/seccomp.c
4 * Copyright 2004-2005 Andrea Arcangeli <andrea@cpushare.com>
6 * This defines a simple but solid secure-computing mode.
9 #include <linux/seccomp.h>
10 #include <linux/sched.h>
11 #include <linux/compat.h>
13 /* #define SECCOMP_DEBUG 1 */
14 #define NR_SECCOMP_MODES 1
17 * Secure computing mode 1 allows only read/write/exit/sigreturn.
18 * To be fully secure this must be combined with rlimit
19 * to limit the stack allocations too.
21 static int mode1_syscalls[] = {
22 __NR_seccomp_read, __NR_seccomp_write, __NR_seccomp_exit, __NR_seccomp_sigreturn,
23 0, /* null terminated */
27 static int mode1_syscalls_32[] = {
28 __NR_seccomp_read_32, __NR_seccomp_write_32, __NR_seccomp_exit_32, __NR_seccomp_sigreturn_32,
29 0, /* null terminated */
33 void __secure_computing(int this_syscall)
35 int mode = current->seccomp.mode;
40 syscall = mode1_syscalls;
43 syscall = mode1_syscalls_32;
46 if (*syscall == this_syscall)
60 long prctl_get_seccomp(void)
62 return current->seccomp.mode;
65 long prctl_set_seccomp(unsigned long seccomp_mode)
69 /* can set it only once to be even more secure */
71 if (unlikely(current->seccomp.mode))
75 if (seccomp_mode && seccomp_mode <= NR_SECCOMP_MODES) {
76 current->seccomp.mode = seccomp_mode;
77 set_thread_flag(TIF_SECCOMP);