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 | |
Kees Cook | c2e1f2e | 2014-06-05 00:23:17 -0700 | [diff] [blame] | 6 | #define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC) |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #ifdef CONFIG_SECCOMP |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/thread_info.h> |
| 11 | #include <asm/seccomp.h> |
| 12 | |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 13 | struct seccomp_filter; |
| 14 | /** |
| 15 | * struct seccomp - the state of a seccomp'ed process |
| 16 | * |
| 17 | * @mode: indicates one of the valid values above for controlled |
| 18 | * system calls available to a process. |
Kees Cook | dbd95212 | 2014-06-27 15:18:48 -0700 | [diff] [blame] | 19 | * @filter: must always point to a valid seccomp-filter or NULL as it is |
| 20 | * accessed without locking during system call entry. |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 21 | * |
| 22 | * @filter must only be accessed from the context of current as there |
Kees Cook | dbd95212 | 2014-06-27 15:18:48 -0700 | [diff] [blame] | 23 | * is no read locking. |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 24 | */ |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 25 | struct seccomp { |
| 26 | int mode; |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 27 | struct seccomp_filter *filter; |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 28 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Andy Lutomirski | a4412fc | 2014-07-21 18:49:14 -0700 | [diff] [blame] | 30 | #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER |
| 31 | extern int __secure_computing(void); |
| 32 | static inline int secure_computing(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | { |
| 34 | if (unlikely(test_thread_flag(TIF_SECCOMP))) |
Andy Lutomirski | a4412fc | 2014-07-21 18:49:14 -0700 | [diff] [blame] | 35 | return __secure_computing(); |
Will Drewry | acf3b2c | 2012-04-12 16:47:59 -0500 | [diff] [blame] | 36 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
Andy Lutomirski | 13aa72f0 | 2014-07-21 18:49:15 -0700 | [diff] [blame] | 38 | |
| 39 | #define SECCOMP_PHASE1_OK 0 |
| 40 | #define SECCOMP_PHASE1_SKIP 1 |
| 41 | |
Andy Lutomirski | d39bd00 | 2014-07-21 18:49:16 -0700 | [diff] [blame] | 42 | extern u32 seccomp_phase1(struct seccomp_data *sd); |
Andy Lutomirski | 13aa72f0 | 2014-07-21 18:49:15 -0700 | [diff] [blame] | 43 | int seccomp_phase2(u32 phase1_result); |
Andy Lutomirski | a4412fc | 2014-07-21 18:49:14 -0700 | [diff] [blame] | 44 | #else |
| 45 | extern void secure_computing_strict(int this_syscall); |
| 46 | #endif |
Will Drewry | e4da89d | 2012-04-17 14:48:57 -0500 | [diff] [blame] | 47 | |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 48 | extern long prctl_get_seccomp(void); |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 49 | extern long prctl_set_seccomp(unsigned long, char __user *); |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 50 | |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 51 | static inline int seccomp_mode(struct seccomp *s) |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 52 | { |
| 53 | return s->mode; |
| 54 | } |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #else /* CONFIG_SECCOMP */ |
| 57 | |
Ralf Baechle | 42a17ad | 2009-04-18 11:30:56 +0200 | [diff] [blame] | 58 | #include <linux/errno.h> |
| 59 | |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 60 | struct seccomp { }; |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 61 | struct seccomp_filter { }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Andy Lutomirski | a4412fc | 2014-07-21 18:49:14 -0700 | [diff] [blame] | 63 | #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER |
| 64 | static inline int secure_computing(void) { return 0; } |
| 65 | #else |
Will Drewry | e4da89d | 2012-04-17 14:48:57 -0500 | [diff] [blame] | 66 | static inline void secure_computing_strict(int this_syscall) { return; } |
Andy Lutomirski | a4412fc | 2014-07-21 18:49:14 -0700 | [diff] [blame] | 67 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 69 | static inline long prctl_get_seccomp(void) |
| 70 | { |
| 71 | return -EINVAL; |
| 72 | } |
| 73 | |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 74 | static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3) |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 75 | { |
| 76 | return -EINVAL; |
| 77 | } |
| 78 | |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 79 | static inline int seccomp_mode(struct seccomp *s) |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 80 | { |
| 81 | return 0; |
| 82 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #endif /* CONFIG_SECCOMP */ |
| 84 | |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 85 | #ifdef CONFIG_SECCOMP_FILTER |
| 86 | extern void put_seccomp_filter(struct task_struct *tsk); |
| 87 | extern void get_seccomp_filter(struct task_struct *tsk); |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 88 | #else /* CONFIG_SECCOMP_FILTER */ |
| 89 | static inline void put_seccomp_filter(struct task_struct *tsk) |
| 90 | { |
| 91 | return; |
| 92 | } |
| 93 | static inline void get_seccomp_filter(struct task_struct *tsk) |
| 94 | { |
| 95 | return; |
| 96 | } |
| 97 | #endif /* CONFIG_SECCOMP_FILTER */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | #endif /* _LINUX_SECCOMP_H */ |