Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef _LINUX_SECCOMP_H |
| 3 | #define _LINUX_SECCOMP_H |
| 4 | |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 5 | #include <uapi/linux/seccomp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | |
Kees Cook | 00a02d0 | 2018-05-03 14:56:12 -0700 | [diff] [blame^] | 7 | #define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC | \ |
| 8 | SECCOMP_FILTER_FLAG_LOG | \ |
| 9 | SECCOMP_FILTER_FLAG_SPEC_ALLOW) |
Kees Cook | c2e1f2e | 2014-06-05 00:23:17 -0700 | [diff] [blame] | 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #ifdef CONFIG_SECCOMP |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/thread_info.h> |
| 14 | #include <asm/seccomp.h> |
| 15 | |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 16 | struct seccomp_filter; |
| 17 | /** |
| 18 | * struct seccomp - the state of a seccomp'ed process |
| 19 | * |
| 20 | * @mode: indicates one of the valid values above for controlled |
| 21 | * system calls available to a process. |
Kees Cook | dbd95212 | 2014-06-27 15:18:48 -0700 | [diff] [blame] | 22 | * @filter: must always point to a valid seccomp-filter or NULL as it is |
| 23 | * accessed without locking during system call entry. |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 24 | * |
| 25 | * @filter must only be accessed from the context of current as there |
Kees Cook | dbd95212 | 2014-06-27 15:18:48 -0700 | [diff] [blame] | 26 | * is no read locking. |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 27 | */ |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 28 | struct seccomp { |
| 29 | int mode; |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 30 | struct seccomp_filter *filter; |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 31 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Andy Lutomirski | a4412fc | 2014-07-21 18:49:14 -0700 | [diff] [blame] | 33 | #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER |
Andy Lutomirski | 2f275de | 2016-05-27 12:57:02 -0700 | [diff] [blame] | 34 | extern int __secure_computing(const struct seccomp_data *sd); |
| 35 | static inline int secure_computing(const struct seccomp_data *sd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { |
| 37 | if (unlikely(test_thread_flag(TIF_SECCOMP))) |
Andy Lutomirski | 2f275de | 2016-05-27 12:57:02 -0700 | [diff] [blame] | 38 | return __secure_computing(sd); |
Will Drewry | acf3b2c | 2012-04-12 16:47:59 -0500 | [diff] [blame] | 39 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
Andy Lutomirski | a4412fc | 2014-07-21 18:49:14 -0700 | [diff] [blame] | 41 | #else |
| 42 | extern void secure_computing_strict(int this_syscall); |
| 43 | #endif |
Will Drewry | e4da89d | 2012-04-17 14:48:57 -0500 | [diff] [blame] | 44 | |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 45 | extern long prctl_get_seccomp(void); |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 46 | extern long prctl_set_seccomp(unsigned long, char __user *); |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 47 | |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 48 | static inline int seccomp_mode(struct seccomp *s) |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 49 | { |
| 50 | return s->mode; |
| 51 | } |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #else /* CONFIG_SECCOMP */ |
| 54 | |
Ralf Baechle | 42a17ad | 2009-04-18 11:30:56 +0200 | [diff] [blame] | 55 | #include <linux/errno.h> |
| 56 | |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 57 | struct seccomp { }; |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 58 | struct seccomp_filter { }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Andy Lutomirski | a4412fc | 2014-07-21 18:49:14 -0700 | [diff] [blame] | 60 | #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER |
Andy Lutomirski | 2f275de | 2016-05-27 12:57:02 -0700 | [diff] [blame] | 61 | static inline int secure_computing(struct seccomp_data *sd) { return 0; } |
Andy Lutomirski | a4412fc | 2014-07-21 18:49:14 -0700 | [diff] [blame] | 62 | #else |
Will Drewry | e4da89d | 2012-04-17 14:48:57 -0500 | [diff] [blame] | 63 | static inline void secure_computing_strict(int this_syscall) { return; } |
Andy Lutomirski | a4412fc | 2014-07-21 18:49:14 -0700 | [diff] [blame] | 64 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 66 | static inline long prctl_get_seccomp(void) |
| 67 | { |
| 68 | return -EINVAL; |
| 69 | } |
| 70 | |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 71 | static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3) |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 72 | { |
| 73 | return -EINVAL; |
| 74 | } |
| 75 | |
Will Drewry | 932eceb | 2012-04-12 16:47:54 -0500 | [diff] [blame] | 76 | static inline int seccomp_mode(struct seccomp *s) |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 77 | { |
Kees Cook | 221272f | 2015-06-15 15:29:16 -0700 | [diff] [blame] | 78 | return SECCOMP_MODE_DISABLED; |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 79 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #endif /* CONFIG_SECCOMP */ |
| 81 | |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 82 | #ifdef CONFIG_SECCOMP_FILTER |
| 83 | extern void put_seccomp_filter(struct task_struct *tsk); |
| 84 | extern void get_seccomp_filter(struct task_struct *tsk); |
Will Drewry | e2cfabdf | 2012-04-12 16:47:57 -0500 | [diff] [blame] | 85 | #else /* CONFIG_SECCOMP_FILTER */ |
| 86 | static inline void put_seccomp_filter(struct task_struct *tsk) |
| 87 | { |
| 88 | return; |
| 89 | } |
| 90 | static inline void get_seccomp_filter(struct task_struct *tsk) |
| 91 | { |
| 92 | return; |
| 93 | } |
| 94 | #endif /* CONFIG_SECCOMP_FILTER */ |
Tycho Andersen | f8e529e | 2015-10-27 09:23:59 +0900 | [diff] [blame] | 95 | |
| 96 | #if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE) |
| 97 | extern long seccomp_get_filter(struct task_struct *task, |
| 98 | unsigned long filter_off, void __user *data); |
Tycho Andersen | 2650047 | 2017-10-11 09:39:21 -0600 | [diff] [blame] | 99 | extern long seccomp_get_metadata(struct task_struct *task, |
| 100 | unsigned long filter_off, void __user *data); |
Tycho Andersen | f8e529e | 2015-10-27 09:23:59 +0900 | [diff] [blame] | 101 | #else |
| 102 | static inline long seccomp_get_filter(struct task_struct *task, |
| 103 | unsigned long n, void __user *data) |
| 104 | { |
| 105 | return -EINVAL; |
| 106 | } |
Tycho Andersen | 2650047 | 2017-10-11 09:39:21 -0600 | [diff] [blame] | 107 | static inline long seccomp_get_metadata(struct task_struct *task, |
| 108 | unsigned long filter_off, |
| 109 | void __user *data) |
| 110 | { |
| 111 | return -EINVAL; |
| 112 | } |
Tycho Andersen | f8e529e | 2015-10-27 09:23:59 +0900 | [diff] [blame] | 113 | #endif /* CONFIG_SECCOMP_FILTER && CONFIG_CHECKPOINT_RESTORE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | #endif /* _LINUX_SECCOMP_H */ |