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>
12 /* #define SECCOMP_DEBUG 1 */
13 #define NR_SECCOMP_MODES 1
16 * Secure computing mode 1 allows only read/write/exit/sigreturn.
17 * To be fully secure this must be combined with rlimit
18 * to limit the stack allocations too.
20 static int mode1_syscalls[] = {
21 __NR_seccomp_read, __NR_seccomp_write, __NR_seccomp_exit, __NR_seccomp_sigreturn,
22 0, /* null terminated */
26 static int mode1_syscalls_32[] = {
27 __NR_seccomp_read_32, __NR_seccomp_write_32, __NR_seccomp_exit_32, __NR_seccomp_sigreturn_32,
28 0, /* null terminated */
32 void __secure_computing(int this_syscall)
34 int mode = current->seccomp.mode;
39 syscall = mode1_syscalls;
41 if (test_thread_flag(TIF_32BIT))
42 syscall = mode1_syscalls_32;
45 if (*syscall == this_syscall)
59 long prctl_get_seccomp(void)
61 return current->seccomp.mode;
64 long prctl_set_seccomp(unsigned long seccomp_mode)
68 /* can set it only once to be even more secure */
70 if (unlikely(current->seccomp.mode))
74 if (seccomp_mode && seccomp_mode <= NR_SECCOMP_MODES) {
75 current->seccomp.mode = seccomp_mode;
76 set_thread_flag(TIF_SECCOMP);