blob: ecc296c137cd2e3e926821dc357e5c00563bedd4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_SECCOMP_H
2#define _LINUX_SECCOMP_H
3
David Howells607ca462012-10-13 10:46:48 +01004#include <uapi/linux/seccomp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
Kees Cookc2e1f2e2014-06-05 00:23:17 -07006#define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC)
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#ifdef CONFIG_SECCOMP
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/thread_info.h>
11#include <asm/seccomp.h>
12
Will Drewrye2cfabdf2012-04-12 16:47:57 -050013struct seccomp_filter;
14/**
15 * struct seccomp - the state of a seccomp'ed process
16 *
17 * @mode: indicates one of the valid values above for controlled
18 * system calls available to a process.
Kees Cookdbd952122014-06-27 15:18:48 -070019 * @filter: must always point to a valid seccomp-filter or NULL as it is
20 * accessed without locking during system call entry.
Will Drewrye2cfabdf2012-04-12 16:47:57 -050021 *
22 * @filter must only be accessed from the context of current as there
Kees Cookdbd952122014-06-27 15:18:48 -070023 * is no read locking.
Will Drewrye2cfabdf2012-04-12 16:47:57 -050024 */
Will Drewry932eceb2012-04-12 16:47:54 -050025struct seccomp {
26 int mode;
Will Drewrye2cfabdf2012-04-12 16:47:57 -050027 struct seccomp_filter *filter;
Will Drewry932eceb2012-04-12 16:47:54 -050028};
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070030#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
Andy Lutomirski2f275de2016-05-27 12:57:02 -070031extern int __secure_computing(const struct seccomp_data *sd);
32static inline int secure_computing(const struct seccomp_data *sd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
34 if (unlikely(test_thread_flag(TIF_SECCOMP)))
Andy Lutomirski2f275de2016-05-27 12:57:02 -070035 return __secure_computing(sd);
Will Drewryacf3b2c2012-04-12 16:47:59 -050036 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037}
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070038#else
39extern void secure_computing_strict(int this_syscall);
40#endif
Will Drewrye4da89d2012-04-17 14:48:57 -050041
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070042extern long prctl_get_seccomp(void);
Will Drewrye2cfabdf2012-04-12 16:47:57 -050043extern long prctl_set_seccomp(unsigned long, char __user *);
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070044
Will Drewry932eceb2012-04-12 16:47:54 -050045static inline int seccomp_mode(struct seccomp *s)
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040046{
47 return s->mode;
48}
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#else /* CONFIG_SECCOMP */
51
Ralf Baechle42a17ad2009-04-18 11:30:56 +020052#include <linux/errno.h>
53
Will Drewry932eceb2012-04-12 16:47:54 -050054struct seccomp { };
Will Drewrye2cfabdf2012-04-12 16:47:57 -050055struct seccomp_filter { };
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070057#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
Andy Lutomirski2f275de2016-05-27 12:57:02 -070058static inline int secure_computing(struct seccomp_data *sd) { return 0; }
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070059#else
Will Drewrye4da89d2012-04-17 14:48:57 -050060static inline void secure_computing_strict(int this_syscall) { return; }
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070061#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070063static inline long prctl_get_seccomp(void)
64{
65 return -EINVAL;
66}
67
Will Drewrye2cfabdf2012-04-12 16:47:57 -050068static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3)
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070069{
70 return -EINVAL;
71}
72
Will Drewry932eceb2012-04-12 16:47:54 -050073static inline int seccomp_mode(struct seccomp *s)
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040074{
Kees Cook221272f2015-06-15 15:29:16 -070075 return SECCOMP_MODE_DISABLED;
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040076}
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#endif /* CONFIG_SECCOMP */
78
Will Drewrye2cfabdf2012-04-12 16:47:57 -050079#ifdef CONFIG_SECCOMP_FILTER
80extern void put_seccomp_filter(struct task_struct *tsk);
81extern void get_seccomp_filter(struct task_struct *tsk);
Will Drewrye2cfabdf2012-04-12 16:47:57 -050082#else /* CONFIG_SECCOMP_FILTER */
83static inline void put_seccomp_filter(struct task_struct *tsk)
84{
85 return;
86}
87static inline void get_seccomp_filter(struct task_struct *tsk)
88{
89 return;
90}
91#endif /* CONFIG_SECCOMP_FILTER */
Tycho Andersenf8e529e2015-10-27 09:23:59 +090092
93#if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE)
94extern long seccomp_get_filter(struct task_struct *task,
95 unsigned long filter_off, void __user *data);
96#else
97static inline long seccomp_get_filter(struct task_struct *task,
98 unsigned long n, void __user *data)
99{
100 return -EINVAL;
101}
102#endif /* CONFIG_SECCOMP_FILTER && CONFIG_CHECKPOINT_RESTORE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103#endif /* _LINUX_SECCOMP_H */