seccomp.h 2.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
#ifndef _LINUX_SECCOMP_H
#define _LINUX_SECCOMP_H

4
#include <uapi/linux/seccomp.h>
5

6 7
#define SECCOMP_FILTER_FLAG_MASK	(SECCOMP_FILTER_FLAG_TSYNC)

L
Linus Torvalds 已提交
8 9 10 11 12
#ifdef CONFIG_SECCOMP

#include <linux/thread_info.h>
#include <asm/seccomp.h>

13 14 15 16 17 18
struct seccomp_filter;
/**
 * struct seccomp - the state of a seccomp'ed process
 *
 * @mode:  indicates one of the valid values above for controlled
 *         system calls available to a process.
K
Kees Cook 已提交
19 20
 * @filter: must always point to a valid seccomp-filter or NULL as it is
 *          accessed without locking during system call entry.
21 22
 *
 *          @filter must only be accessed from the context of current as there
K
Kees Cook 已提交
23
 *          is no read locking.
24
 */
25 26
struct seccomp {
	int mode;
27
	struct seccomp_filter *filter;
28
};
L
Linus Torvalds 已提交
29

30
#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
31 32
extern int __secure_computing(const struct seccomp_data *sd);
static inline int secure_computing(const struct seccomp_data *sd)
L
Linus Torvalds 已提交
33 34
{
	if (unlikely(test_thread_flag(TIF_SECCOMP)))
35
		return  __secure_computing(sd);
W
Will Drewry 已提交
36
	return 0;
L
Linus Torvalds 已提交
37
}
38 39 40 41

#define SECCOMP_PHASE1_OK	0
#define SECCOMP_PHASE1_SKIP	1

42
extern u32 seccomp_phase1(struct seccomp_data *sd);
43
int seccomp_phase2(u32 phase1_result);
44 45 46
#else
extern void secure_computing_strict(int this_syscall);
#endif
47

48
extern long prctl_get_seccomp(void);
49
extern long prctl_set_seccomp(unsigned long, char __user *);
50

51
static inline int seccomp_mode(struct seccomp *s)
52 53 54 55
{
	return s->mode;
}

L
Linus Torvalds 已提交
56 57
#else /* CONFIG_SECCOMP */

58 59
#include <linux/errno.h>

60
struct seccomp { };
61
struct seccomp_filter { };
L
Linus Torvalds 已提交
62

63
#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
64
static inline int secure_computing(struct seccomp_data *sd) { return 0; }
65
#else
66
static inline void secure_computing_strict(int this_syscall) { return; }
67
#endif
L
Linus Torvalds 已提交
68

69 70 71 72 73
static inline long prctl_get_seccomp(void)
{
	return -EINVAL;
}

74
static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3)
75 76 77 78
{
	return -EINVAL;
}

79
static inline int seccomp_mode(struct seccomp *s)
80
{
81
	return SECCOMP_MODE_DISABLED;
82
}
L
Linus Torvalds 已提交
83 84
#endif /* CONFIG_SECCOMP */

85 86 87 88 89 90 91 92 93 94 95 96 97
#ifdef CONFIG_SECCOMP_FILTER
extern void put_seccomp_filter(struct task_struct *tsk);
extern void get_seccomp_filter(struct task_struct *tsk);
#else  /* CONFIG_SECCOMP_FILTER */
static inline void put_seccomp_filter(struct task_struct *tsk)
{
	return;
}
static inline void get_seccomp_filter(struct task_struct *tsk)
{
	return;
}
#endif /* CONFIG_SECCOMP_FILTER */
98 99 100 101 102 103 104 105 106 107 108

#if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE)
extern long seccomp_get_filter(struct task_struct *task,
			       unsigned long filter_off, void __user *data);
#else
static inline long seccomp_get_filter(struct task_struct *task,
				      unsigned long n, void __user *data)
{
	return -EINVAL;
}
#endif /* CONFIG_SECCOMP_FILTER && CONFIG_CHECKPOINT_RESTORE */
L
Linus Torvalds 已提交
109
#endif /* _LINUX_SECCOMP_H */