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