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/audit.h>
10 #include <linux/seccomp.h>
11 #include <linux/sched.h>
12 #include <linux/compat.h>
14 /* #define SECCOMP_DEBUG 1 */
15 #define NR_SECCOMP_MODES 1
18 * Secure computing mode 1 allows only read/write/exit/sigreturn.
19 * To be fully secure this must be combined with rlimit
20 * to limit the stack allocations too.
22 static int mode1_syscalls[] = {
23 __NR_seccomp_read, __NR_seccomp_write, __NR_seccomp_exit, __NR_seccomp_sigreturn,
24 0, /* null terminated */
28 static int mode1_syscalls_32[] = {
29 __NR_seccomp_read_32, __NR_seccomp_write_32, __NR_seccomp_exit_32, __NR_seccomp_sigreturn_32,
30 0, /* null terminated */
34 void __secure_computing(int this_syscall)
36 int mode = current->seccomp.mode;
41 syscall = mode1_syscalls;
44 syscall = mode1_syscalls_32;
47 if (*syscall == this_syscall)
58 audit_seccomp(this_syscall);
62 long prctl_get_seccomp(void)
64 return current->seccomp.mode;
67 long prctl_set_seccomp(unsigned long seccomp_mode)
71 /* can set it only once to be even more secure */
73 if (unlikely(current->seccomp.mode))
77 if (seccomp_mode && seccomp_mode <= NR_SECCOMP_MODES) {
78 current->seccomp.mode = seccomp_mode;
79 set_thread_flag(TIF_SECCOMP);