Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _LINUX_SECCOMP_H |
3 | #define _LINUX_SECCOMP_H | |
4 | ||
607ca46e | 5 | #include <uapi/linux/seccomp.h> |
e2cfabdf | 6 | |
6a21cc50 TA |
7 | #define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC | \ |
8 | SECCOMP_FILTER_FLAG_LOG | \ | |
9 | SECCOMP_FILTER_FLAG_SPEC_ALLOW | \ | |
51891498 | 10 | SECCOMP_FILTER_FLAG_NEW_LISTENER | \ |
c2aa2dfe SD |
11 | SECCOMP_FILTER_FLAG_TSYNC_ESRCH | \ |
12 | SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV) | |
c2e1f2e3 | 13 | |
7cf97b12 SD |
14 | /* sizeof() the first published struct seccomp_notif_addfd */ |
15 | #define SECCOMP_NOTIFY_ADDFD_SIZE_VER0 24 | |
16 | #define SECCOMP_NOTIFY_ADDFD_SIZE_LATEST SECCOMP_NOTIFY_ADDFD_SIZE_VER0 | |
17 | ||
1da177e4 LT |
18 | #ifdef CONFIG_SECCOMP |
19 | ||
1da177e4 | 20 | #include <linux/thread_info.h> |
c818c03b | 21 | #include <linux/atomic.h> |
1da177e4 LT |
22 | #include <asm/seccomp.h> |
23 | ||
e2cfabdf WD |
24 | struct seccomp_filter; |
25 | /** | |
26 | * struct seccomp - the state of a seccomp'ed process | |
27 | * | |
28 | * @mode: indicates one of the valid values above for controlled | |
29 | * system calls available to a process. | |
b9069728 | 30 | * @filter_count: number of seccomp filters |
dbd95212 KC |
31 | * @filter: must always point to a valid seccomp-filter or NULL as it is |
32 | * accessed without locking during system call entry. | |
e2cfabdf WD |
33 | * |
34 | * @filter must only be accessed from the context of current as there | |
dbd95212 | 35 | * is no read locking. |
e2cfabdf | 36 | */ |
932ecebb WD |
37 | struct seccomp { |
38 | int mode; | |
c818c03b | 39 | atomic_t filter_count; |
e2cfabdf | 40 | struct seccomp_filter *filter; |
932ecebb | 41 | }; |
1da177e4 | 42 | |
a4412fc9 | 43 | #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER |
2f275de5 | 44 | extern int __secure_computing(const struct seccomp_data *sd); |
fefad9ef | 45 | static inline int secure_computing(void) |
1da177e4 | 46 | { |
23d67a54 | 47 | if (unlikely(test_syscall_work(SECCOMP))) |
fefad9ef | 48 | return __secure_computing(NULL); |
acf3b2c7 | 49 | return 0; |
1da177e4 | 50 | } |
a4412fc9 AL |
51 | #else |
52 | extern void secure_computing_strict(int this_syscall); | |
53 | #endif | |
e4da89d0 | 54 | |
1d9d02fe | 55 | extern long prctl_get_seccomp(void); |
a5662e4d | 56 | extern long prctl_set_seccomp(unsigned long, void __user *); |
1d9d02fe | 57 | |
932ecebb | 58 | static inline int seccomp_mode(struct seccomp *s) |
5cec93c2 AL |
59 | { |
60 | return s->mode; | |
61 | } | |
62 | ||
1da177e4 LT |
63 | #else /* CONFIG_SECCOMP */ |
64 | ||
42a17ad2 RB |
65 | #include <linux/errno.h> |
66 | ||
932ecebb | 67 | struct seccomp { }; |
e2cfabdf | 68 | struct seccomp_filter { }; |
3135f5b7 | 69 | struct seccomp_data; |
1da177e4 | 70 | |
a4412fc9 | 71 | #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER |
fefad9ef | 72 | static inline int secure_computing(void) { return 0; } |
3135f5b7 | 73 | static inline int __secure_computing(const struct seccomp_data *sd) { return 0; } |
a4412fc9 | 74 | #else |
e4da89d0 | 75 | static inline void secure_computing_strict(int this_syscall) { return; } |
a4412fc9 | 76 | #endif |
1da177e4 | 77 | |
1d9d02fe AA |
78 | static inline long prctl_get_seccomp(void) |
79 | { | |
80 | return -EINVAL; | |
81 | } | |
82 | ||
e2cfabdf | 83 | static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3) |
1d9d02fe AA |
84 | { |
85 | return -EINVAL; | |
86 | } | |
87 | ||
932ecebb | 88 | static inline int seccomp_mode(struct seccomp *s) |
5cec93c2 | 89 | { |
221272f9 | 90 | return SECCOMP_MODE_DISABLED; |
5cec93c2 | 91 | } |
1da177e4 LT |
92 | #endif /* CONFIG_SECCOMP */ |
93 | ||
e2cfabdf | 94 | #ifdef CONFIG_SECCOMP_FILTER |
3a15fb6e | 95 | extern void seccomp_filter_release(struct task_struct *tsk); |
e2cfabdf | 96 | extern void get_seccomp_filter(struct task_struct *tsk); |
e2cfabdf | 97 | #else /* CONFIG_SECCOMP_FILTER */ |
3a15fb6e | 98 | static inline void seccomp_filter_release(struct task_struct *tsk) |
e2cfabdf WD |
99 | { |
100 | return; | |
101 | } | |
102 | static inline void get_seccomp_filter(struct task_struct *tsk) | |
103 | { | |
104 | return; | |
105 | } | |
106 | #endif /* CONFIG_SECCOMP_FILTER */ | |
f8e529ed TA |
107 | |
108 | #if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE) | |
109 | extern long seccomp_get_filter(struct task_struct *task, | |
110 | unsigned long filter_off, void __user *data); | |
26500475 TA |
111 | extern long seccomp_get_metadata(struct task_struct *task, |
112 | unsigned long filter_off, void __user *data); | |
f8e529ed TA |
113 | #else |
114 | static inline long seccomp_get_filter(struct task_struct *task, | |
115 | unsigned long n, void __user *data) | |
116 | { | |
117 | return -EINVAL; | |
118 | } | |
26500475 TA |
119 | static inline long seccomp_get_metadata(struct task_struct *task, |
120 | unsigned long filter_off, | |
121 | void __user *data) | |
122 | { | |
123 | return -EINVAL; | |
124 | } | |
f8e529ed | 125 | #endif /* CONFIG_SECCOMP_FILTER && CONFIG_CHECKPOINT_RESTORE */ |
0d8315dd YZ |
126 | |
127 | #ifdef CONFIG_SECCOMP_CACHE_DEBUG | |
128 | struct seq_file; | |
129 | ||
130 | int proc_pid_seccomp_cache(struct seq_file *m, struct pid_namespace *ns, | |
131 | struct pid *pid, struct task_struct *task); | |
132 | #endif | |
1da177e4 | 133 | #endif /* _LINUX_SECCOMP_H */ |