seccomp: release filter after task is fully dead
[linux-block.git] / include / linux / seccomp.h
CommitLineData
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
TA
10 SECCOMP_FILTER_FLAG_NEW_LISTENER | \
11 SECCOMP_FILTER_FLAG_TSYNC_ESRCH)
c2e1f2e3 12
1da177e4
LT
13#ifdef CONFIG_SECCOMP
14
1da177e4 15#include <linux/thread_info.h>
c818c03b 16#include <linux/atomic.h>
1da177e4
LT
17#include <asm/seccomp.h>
18
e2cfabdf
WD
19struct seccomp_filter;
20/**
21 * struct seccomp - the state of a seccomp'ed process
22 *
23 * @mode: indicates one of the valid values above for controlled
24 * system calls available to a process.
dbd95212
KC
25 * @filter: must always point to a valid seccomp-filter or NULL as it is
26 * accessed without locking during system call entry.
e2cfabdf
WD
27 *
28 * @filter must only be accessed from the context of current as there
dbd95212 29 * is no read locking.
e2cfabdf 30 */
932ecebb
WD
31struct seccomp {
32 int mode;
c818c03b 33 atomic_t filter_count;
e2cfabdf 34 struct seccomp_filter *filter;
932ecebb 35};
1da177e4 36
a4412fc9 37#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
2f275de5 38extern int __secure_computing(const struct seccomp_data *sd);
fefad9ef 39static inline int secure_computing(void)
1da177e4
LT
40{
41 if (unlikely(test_thread_flag(TIF_SECCOMP)))
fefad9ef 42 return __secure_computing(NULL);
acf3b2c7 43 return 0;
1da177e4 44}
a4412fc9
AL
45#else
46extern void secure_computing_strict(int this_syscall);
47#endif
e4da89d0 48
1d9d02fe 49extern long prctl_get_seccomp(void);
a5662e4d 50extern long prctl_set_seccomp(unsigned long, void __user *);
1d9d02fe 51
932ecebb 52static inline int seccomp_mode(struct seccomp *s)
5cec93c2
AL
53{
54 return s->mode;
55}
56
1da177e4
LT
57#else /* CONFIG_SECCOMP */
58
42a17ad2
RB
59#include <linux/errno.h>
60
932ecebb 61struct seccomp { };
e2cfabdf 62struct seccomp_filter { };
1da177e4 63
a4412fc9 64#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
fefad9ef 65static inline int secure_computing(void) { return 0; }
a4412fc9 66#else
e4da89d0 67static inline void secure_computing_strict(int this_syscall) { return; }
a4412fc9 68#endif
1da177e4 69
1d9d02fe
AA
70static inline long prctl_get_seccomp(void)
71{
72 return -EINVAL;
73}
74
e2cfabdf 75static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3)
1d9d02fe
AA
76{
77 return -EINVAL;
78}
79
932ecebb 80static inline int seccomp_mode(struct seccomp *s)
5cec93c2 81{
221272f9 82 return SECCOMP_MODE_DISABLED;
5cec93c2 83}
1da177e4
LT
84#endif /* CONFIG_SECCOMP */
85
e2cfabdf 86#ifdef CONFIG_SECCOMP_FILTER
3a15fb6e 87extern void seccomp_filter_release(struct task_struct *tsk);
e2cfabdf 88extern void get_seccomp_filter(struct task_struct *tsk);
e2cfabdf 89#else /* CONFIG_SECCOMP_FILTER */
3a15fb6e 90static inline void seccomp_filter_release(struct task_struct *tsk)
e2cfabdf
WD
91{
92 return;
93}
94static inline void get_seccomp_filter(struct task_struct *tsk)
95{
96 return;
97}
98#endif /* CONFIG_SECCOMP_FILTER */
f8e529ed
TA
99
100#if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE)
101extern long seccomp_get_filter(struct task_struct *task,
102 unsigned long filter_off, void __user *data);
26500475
TA
103extern long seccomp_get_metadata(struct task_struct *task,
104 unsigned long filter_off, void __user *data);
f8e529ed
TA
105#else
106static inline long seccomp_get_filter(struct task_struct *task,
107 unsigned long n, void __user *data)
108{
109 return -EINVAL;
110}
26500475
TA
111static inline long seccomp_get_metadata(struct task_struct *task,
112 unsigned long filter_off,
113 void __user *data)
114{
115 return -EINVAL;
116}
f8e529ed 117#endif /* CONFIG_SECCOMP_FILTER && CONFIG_CHECKPOINT_RESTORE */
1da177e4 118#endif /* _LINUX_SECCOMP_H */