Input: hil_mlc.c - make code static
[linux-2.6/mini2440.git] / kernel / seccomp.c
blobad64fcb731f231d22e539d0e1b094cdd59c7d759
1 /*
2 * linux/kernel/seccomp.c
4 * Copyright 2004-2005 Andrea Arcangeli <andrea@cpushare.com>
6 * This defines a simple but solid secure-computing mode.
7 */
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 */
25 #ifdef TIF_32BIT
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 */
30 #endif
32 void __secure_computing(int this_syscall)
34 int mode = current->seccomp.mode;
35 int * syscall;
37 switch (mode) {
38 case 1:
39 syscall = mode1_syscalls;
40 #ifdef TIF_32BIT
41 if (test_thread_flag(TIF_32BIT))
42 syscall = mode1_syscalls_32;
43 #endif
44 do {
45 if (*syscall == this_syscall)
46 return;
47 } while (*++syscall);
48 break;
49 default:
50 BUG();
53 #ifdef SECCOMP_DEBUG
54 dump_stack();
55 #endif
56 do_exit(SIGKILL);
59 long prctl_get_seccomp(void)
61 return current->seccomp.mode;
64 long prctl_set_seccomp(unsigned long seccomp_mode)
66 long ret;
68 /* can set it only once to be even more secure */
69 ret = -EPERM;
70 if (unlikely(current->seccomp.mode))
71 goto out;
73 ret = -EINVAL;
74 if (seccomp_mode && seccomp_mode <= NR_SECCOMP_MODES) {
75 current->seccomp.mode = seccomp_mode;
76 set_thread_flag(TIF_SECCOMP);
77 #ifdef TIF_NOTSC
78 disable_TSC();
79 #endif
80 ret = 0;
83 out:
84 return ret;