blob: 5d586a45a319f20cc1c91412428e81beb0517e60 [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
Will Drewryacf3b2c2012-04-12 16:47:59 -050030extern int __secure_computing(int);
31static inline int secure_computing(int this_syscall)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
33 if (unlikely(test_thread_flag(TIF_SECCOMP)))
Will Drewryacf3b2c2012-04-12 16:47:59 -050034 return __secure_computing(this_syscall);
35 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036}
37
Will Drewrye4da89d2012-04-17 14:48:57 -050038/* A wrapper for architectures supporting only SECCOMP_MODE_STRICT. */
39static inline void secure_computing_strict(int this_syscall)
40{
41 BUG_ON(secure_computing(this_syscall) != 0);
42}
43
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070044extern long prctl_get_seccomp(void);
Will Drewrye2cfabdf2012-04-12 16:47:57 -050045extern long prctl_set_seccomp(unsigned long, char __user *);
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070046
Will Drewry932eceb2012-04-12 16:47:54 -050047static inline int seccomp_mode(struct seccomp *s)
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040048{
49 return s->mode;
50}
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#else /* CONFIG_SECCOMP */
53
Ralf Baechle42a17ad2009-04-18 11:30:56 +020054#include <linux/errno.h>
55
Will Drewry932eceb2012-04-12 16:47:54 -050056struct seccomp { };
Will Drewrye2cfabdf2012-04-12 16:47:57 -050057struct seccomp_filter { };
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Stephen Rothwellb1fa6502012-04-17 12:08:48 +100059static inline int secure_computing(int this_syscall) { return 0; }
Will Drewrye4da89d2012-04-17 14:48:57 -050060static inline void secure_computing_strict(int this_syscall) { return; }
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070062static inline long prctl_get_seccomp(void)
63{
64 return -EINVAL;
65}
66
Will Drewrye2cfabdf2012-04-12 16:47:57 -050067static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3)
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070068{
69 return -EINVAL;
70}
71
Will Drewry932eceb2012-04-12 16:47:54 -050072static inline int seccomp_mode(struct seccomp *s)
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040073{
74 return 0;
75}
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#endif /* CONFIG_SECCOMP */
77
Will Drewrye2cfabdf2012-04-12 16:47:57 -050078#ifdef CONFIG_SECCOMP_FILTER
79extern void put_seccomp_filter(struct task_struct *tsk);
80extern void get_seccomp_filter(struct task_struct *tsk);
Will Drewrye2cfabdf2012-04-12 16:47:57 -050081#else /* CONFIG_SECCOMP_FILTER */
82static inline void put_seccomp_filter(struct task_struct *tsk)
83{
84 return;
85}
86static inline void get_seccomp_filter(struct task_struct *tsk)
87{
88 return;
89}
90#endif /* CONFIG_SECCOMP_FILTER */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#endif /* _LINUX_SECCOMP_H */