Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_SECCOMP_H |
| 2 | #define _LINUX_SECCOMP_H |
| 3 | |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 4 | #include <uapi/linux/seccomp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | |
| 6 | #ifdef CONFIG_SECCOMP |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/thread_info.h> |
| 9 | #include <asm/seccomp.h> |
| 10 | |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 11 | struct seccomp_filter; |
| 12 | /** |
| 13 | * struct seccomp - the state of a seccomp'ed process |
| 14 | * |
| 15 | * @mode: indicates one of the valid values above for controlled |
| 16 | * system calls available to a process. |
| 17 | * @filter: The metadata and ruleset for determining what system calls |
| 18 | * are allowed for a task. |
| 19 | * |
| 20 | * @filter must only be accessed from the context of current as there |
| 21 | * is no locking. |
| 22 | */ |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 23 | struct seccomp { |
| 24 | int mode; |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 25 | struct seccomp_filter *filter; |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 26 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Will Drewry | acf3b2c | 2012-04-12 16:47:59 -0500 | [diff] [blame] | 28 | extern int __secure_computing(int); |
| 29 | static inline int secure_computing(int this_syscall) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | { |
| 31 | if (unlikely(test_thread_flag(TIF_SECCOMP))) |
Will Drewry | acf3b2c | 2012-04-12 16:47:59 -0500 | [diff] [blame] | 32 | return __secure_computing(this_syscall); |
| 33 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Will Drewry | e4da89d | 2012-04-17 14:48:57 -0500 | [diff] [blame] | 36 | /* A wrapper for architectures supporting only SECCOMP_MODE_STRICT. */ |
| 37 | static inline void secure_computing_strict(int this_syscall) |
| 38 | { |
| 39 | BUG_ON(secure_computing(this_syscall) != 0); |
| 40 | } |
| 41 | |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 42 | extern long prctl_get_seccomp(void); |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 43 | extern long prctl_set_seccomp(unsigned long, char __user *); |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 44 | |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 45 | static inline int seccomp_mode(struct seccomp *s) |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 46 | { |
| 47 | return s->mode; |
| 48 | } |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #else /* CONFIG_SECCOMP */ |
| 51 | |
Ralf Baechle | 42a17ad | 2009-04-18 11:30:56 +0200 | [diff] [blame] | 52 | #include <linux/errno.h> |
| 53 | |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 54 | struct seccomp { }; |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 55 | struct seccomp_filter { }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Stephen Rothwell | b1fa650 | 2012-04-17 12:08:48 +1000 | [diff] [blame] | 57 | static inline int secure_computing(int this_syscall) { return 0; } |
Will Drewry | e4da89d | 2012-04-17 14:48:57 -0500 | [diff] [blame] | 58 | static inline void secure_computing_strict(int this_syscall) { return; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 60 | static inline long prctl_get_seccomp(void) |
| 61 | { |
| 62 | return -EINVAL; |
| 63 | } |
| 64 | |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 65 | static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3) |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 66 | { |
| 67 | return -EINVAL; |
| 68 | } |
| 69 | |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 70 | static inline int seccomp_mode(struct seccomp *s) |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 71 | { |
| 72 | return 0; |
| 73 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #endif /* CONFIG_SECCOMP */ |
| 75 | |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 76 | #ifdef CONFIG_SECCOMP_FILTER |
| 77 | extern void put_seccomp_filter(struct task_struct *tsk); |
| 78 | extern void get_seccomp_filter(struct task_struct *tsk); |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 79 | #else /* CONFIG_SECCOMP_FILTER */ |
| 80 | static inline void put_seccomp_filter(struct task_struct *tsk) |
| 81 | { |
| 82 | return; |
| 83 | } |
| 84 | static inline void get_seccomp_filter(struct task_struct *tsk) |
| 85 | { |
| 86 | return; |
| 87 | } |
| 88 | #endif /* CONFIG_SECCOMP_FILTER */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | #endif /* _LINUX_SECCOMP_H */ |