Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_SECCOMP_H |
| 2 | #define _LINUX_SECCOMP_H |
| 3 | |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 4 | #include <linux/compiler.h> |
| 5 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 7 | |
| 8 | /* Valid values for seccomp.mode and prctl(PR_SET_SECCOMP, <mode>) */ |
| 9 | #define SECCOMP_MODE_DISABLED 0 /* seccomp is not in use. */ |
| 10 | #define SECCOMP_MODE_STRICT 1 /* uses hard-coded filter. */ |
| 11 | #define SECCOMP_MODE_FILTER 2 /* uses user-supplied filter. */ |
| 12 | |
Kees Cook | 95de3e5 | 2014-06-25 16:08:24 -0700 | [diff] [blame] | 13 | /* Valid operations for seccomp syscall. */ |
| 14 | #define SECCOMP_SET_MODE_STRICT 0 |
| 15 | #define SECCOMP_SET_MODE_FILTER 1 |
| 16 | |
Kees Cook | d32af36 | 2014-06-05 00:23:17 -0700 | [diff] [blame] | 17 | /* Valid flags for SECCOMP_SET_MODE_FILTER */ |
| 18 | #define SECCOMP_FILTER_FLAG_TSYNC 1 |
| 19 | |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 20 | /* |
| 21 | * All BPF programs must return a 32-bit value. |
Will Drewry | 43ec825 | 2012-02-15 20:45:54 -0600 | [diff] [blame] | 22 | * The bottom 16-bits are for optional return data. |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 23 | * The upper 16-bits are ordered from least permissive values to most. |
| 24 | * |
| 25 | * The ordering ensures that a min_t() over composed return values always |
| 26 | * selects the least permissive choice. |
| 27 | */ |
| 28 | #define SECCOMP_RET_KILL 0x00000000U /* kill the task immediately */ |
Will Drewry | 6953702 | 2012-02-09 12:01:37 -0600 | [diff] [blame] | 29 | #define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */ |
Will Drewry | 43ec825 | 2012-02-15 20:45:54 -0600 | [diff] [blame] | 30 | #define SECCOMP_RET_ERRNO 0x00050000U /* returns an errno */ |
Will Drewry | 4ca6e67 | 2012-02-09 12:08:39 -0600 | [diff] [blame] | 31 | #define SECCOMP_RET_TRACE 0x7ff00000U /* pass to a tracer or disallow */ |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 32 | #define SECCOMP_RET_ALLOW 0x7fff0000U /* allow */ |
| 33 | |
| 34 | /* Masks for the return value sections. */ |
| 35 | #define SECCOMP_RET_ACTION 0x7fff0000U |
| 36 | #define SECCOMP_RET_DATA 0x0000ffffU |
| 37 | |
| 38 | /** |
| 39 | * struct seccomp_data - the format the BPF program executes over. |
| 40 | * @nr: the system call number |
| 41 | * @arch: indicates system call convention as an AUDIT_ARCH_* value |
| 42 | * as defined in <linux/audit.h>. |
| 43 | * @instruction_pointer: at the time of the system call. |
| 44 | * @args: up to 6 system call arguments always stored as 64-bit values |
| 45 | * regardless of the architecture. |
| 46 | */ |
| 47 | struct seccomp_data { |
| 48 | int nr; |
| 49 | __u32 arch; |
| 50 | __u64 instruction_pointer; |
| 51 | __u64 args[6]; |
| 52 | }; |
| 53 | |
| 54 | #ifdef __KERNEL__ |
Kees Cook | d32af36 | 2014-06-05 00:23:17 -0700 | [diff] [blame] | 55 | |
| 56 | #define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC) |
| 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #ifdef CONFIG_SECCOMP |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include <linux/thread_info.h> |
| 61 | #include <asm/seccomp.h> |
| 62 | |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 63 | struct seccomp_filter; |
| 64 | /** |
| 65 | * struct seccomp - the state of a seccomp'ed process |
| 66 | * |
| 67 | * @mode: indicates one of the valid values above for controlled |
| 68 | * system calls available to a process. |
Kees Cook | 880e1ab | 2014-06-27 15:18:48 -0700 | [diff] [blame] | 69 | * @filter: must always point to a valid seccomp-filter or NULL as it is |
| 70 | * accessed without locking during system call entry. |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 71 | * |
| 72 | * @filter must only be accessed from the context of current as there |
Kees Cook | 880e1ab | 2014-06-27 15:18:48 -0700 | [diff] [blame] | 73 | * is no read locking. |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 74 | */ |
Will Drewry | 807936e | 2012-01-13 14:40:01 -0600 | [diff] [blame] | 75 | struct seccomp { |
| 76 | int mode; |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 77 | struct seccomp_filter *filter; |
Will Drewry | 807936e | 2012-01-13 14:40:01 -0600 | [diff] [blame] | 78 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Will Drewry | 43ec825 | 2012-02-15 20:45:54 -0600 | [diff] [blame] | 80 | extern int __secure_computing(int); |
| 81 | static inline int secure_computing(int this_syscall) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
| 83 | if (unlikely(test_thread_flag(TIF_SECCOMP))) |
Will Drewry | 43ec825 | 2012-02-15 20:45:54 -0600 | [diff] [blame] | 84 | return __secure_computing(this_syscall); |
| 85 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 88 | extern long prctl_get_seccomp(void); |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 89 | extern long prctl_set_seccomp(unsigned long, char __user *); |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 90 | |
Will Drewry | 807936e | 2012-01-13 14:40:01 -0600 | [diff] [blame] | 91 | static inline int seccomp_mode(struct seccomp *s) |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 92 | { |
| 93 | return s->mode; |
| 94 | } |
| 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | #else /* CONFIG_SECCOMP */ |
| 97 | |
Ralf Baechle | 42a17ad | 2009-04-18 11:30:56 +0200 | [diff] [blame] | 98 | #include <linux/errno.h> |
| 99 | |
Will Drewry | 807936e | 2012-01-13 14:40:01 -0600 | [diff] [blame] | 100 | struct seccomp { }; |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 101 | struct seccomp_filter { }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 103 | #define secure_computing(x) 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 105 | static inline long prctl_get_seccomp(void) |
| 106 | { |
| 107 | return -EINVAL; |
| 108 | } |
| 109 | |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 110 | static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3) |
Andrea Arcangeli | 1d9d02f | 2007-07-15 23:41:32 -0700 | [diff] [blame] | 111 | { |
| 112 | return -EINVAL; |
| 113 | } |
| 114 | |
Will Drewry | 807936e | 2012-01-13 14:40:01 -0600 | [diff] [blame] | 115 | static inline int seccomp_mode(struct seccomp *s) |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 116 | { |
| 117 | return 0; |
| 118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | #endif /* CONFIG_SECCOMP */ |
| 120 | |
Will Drewry | 980e920 | 2012-02-09 11:50:58 -0600 | [diff] [blame] | 121 | #ifdef CONFIG_SECCOMP_FILTER |
| 122 | extern void put_seccomp_filter(struct task_struct *tsk); |
| 123 | extern void get_seccomp_filter(struct task_struct *tsk); |
| 124 | extern u32 seccomp_bpf_load(int off); |
| 125 | #else /* CONFIG_SECCOMP_FILTER */ |
| 126 | static inline void put_seccomp_filter(struct task_struct *tsk) |
| 127 | { |
| 128 | return; |
| 129 | } |
| 130 | static inline void get_seccomp_filter(struct task_struct *tsk) |
| 131 | { |
| 132 | return; |
| 133 | } |
| 134 | #endif /* CONFIG_SECCOMP_FILTER */ |
| 135 | #endif /* __KERNEL__ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | #endif /* _LINUX_SECCOMP_H */ |