blob: e5320f6c865439c0b8910afc17fcfd1598bcc4fb [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX_SECCOMP_H
3#define _LINUX_SECCOMP_H
4
David Howells607ca462012-10-13 10:46:48 +01005#include <uapi/linux/seccomp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
Kees Cook00a02d02018-05-03 14:56:12 -07007#define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC | \
8 SECCOMP_FILTER_FLAG_LOG | \
9 SECCOMP_FILTER_FLAG_SPEC_ALLOW)
Kees Cookc2e1f2e2014-06-05 00:23:17 -070010
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#ifdef CONFIG_SECCOMP
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/thread_info.h>
14#include <asm/seccomp.h>
15
Will Drewrye2cfabdf2012-04-12 16:47:57 -050016struct seccomp_filter;
17/**
18 * struct seccomp - the state of a seccomp'ed process
19 *
20 * @mode: indicates one of the valid values above for controlled
21 * system calls available to a process.
Kees Cookdbd952122014-06-27 15:18:48 -070022 * @filter: must always point to a valid seccomp-filter or NULL as it is
23 * accessed without locking during system call entry.
Will Drewrye2cfabdf2012-04-12 16:47:57 -050024 *
25 * @filter must only be accessed from the context of current as there
Kees Cookdbd952122014-06-27 15:18:48 -070026 * is no read locking.
Will Drewrye2cfabdf2012-04-12 16:47:57 -050027 */
Will Drewry932eceb2012-04-12 16:47:54 -050028struct seccomp {
29 int mode;
Will Drewrye2cfabdf2012-04-12 16:47:57 -050030 struct seccomp_filter *filter;
Will Drewry932eceb2012-04-12 16:47:54 -050031};
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070033#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
Andy Lutomirski2f275de2016-05-27 12:57:02 -070034extern int __secure_computing(const struct seccomp_data *sd);
35static inline int secure_computing(const struct seccomp_data *sd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
37 if (unlikely(test_thread_flag(TIF_SECCOMP)))
Andy Lutomirski2f275de2016-05-27 12:57:02 -070038 return __secure_computing(sd);
Will Drewryacf3b2c2012-04-12 16:47:59 -050039 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070041#else
42extern void secure_computing_strict(int this_syscall);
43#endif
Will Drewrye4da89d2012-04-17 14:48:57 -050044
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070045extern long prctl_get_seccomp(void);
Will Drewrye2cfabdf2012-04-12 16:47:57 -050046extern long prctl_set_seccomp(unsigned long, char __user *);
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070047
Will Drewry932eceb2012-04-12 16:47:54 -050048static inline int seccomp_mode(struct seccomp *s)
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040049{
50 return s->mode;
51}
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#else /* CONFIG_SECCOMP */
54
Ralf Baechle42a17ad2009-04-18 11:30:56 +020055#include <linux/errno.h>
56
Will Drewry932eceb2012-04-12 16:47:54 -050057struct seccomp { };
Will Drewrye2cfabdf2012-04-12 16:47:57 -050058struct seccomp_filter { };
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070060#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
Andy Lutomirski2f275de2016-05-27 12:57:02 -070061static inline int secure_computing(struct seccomp_data *sd) { return 0; }
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070062#else
Will Drewrye4da89d2012-04-17 14:48:57 -050063static inline void secure_computing_strict(int this_syscall) { return; }
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070064#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070066static inline long prctl_get_seccomp(void)
67{
68 return -EINVAL;
69}
70
Will Drewrye2cfabdf2012-04-12 16:47:57 -050071static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3)
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070072{
73 return -EINVAL;
74}
75
Will Drewry932eceb2012-04-12 16:47:54 -050076static inline int seccomp_mode(struct seccomp *s)
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040077{
Kees Cook221272f2015-06-15 15:29:16 -070078 return SECCOMP_MODE_DISABLED;
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040079}
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#endif /* CONFIG_SECCOMP */
81
Will Drewrye2cfabdf2012-04-12 16:47:57 -050082#ifdef CONFIG_SECCOMP_FILTER
83extern void put_seccomp_filter(struct task_struct *tsk);
84extern void get_seccomp_filter(struct task_struct *tsk);
Will Drewrye2cfabdf2012-04-12 16:47:57 -050085#else /* CONFIG_SECCOMP_FILTER */
86static inline void put_seccomp_filter(struct task_struct *tsk)
87{
88 return;
89}
90static inline void get_seccomp_filter(struct task_struct *tsk)
91{
92 return;
93}
94#endif /* CONFIG_SECCOMP_FILTER */
Tycho Andersenf8e529e2015-10-27 09:23:59 +090095
96#if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE)
97extern long seccomp_get_filter(struct task_struct *task,
98 unsigned long filter_off, void __user *data);
Tycho Andersen26500472017-10-11 09:39:21 -060099extern long seccomp_get_metadata(struct task_struct *task,
100 unsigned long filter_off, void __user *data);
Tycho Andersenf8e529e2015-10-27 09:23:59 +0900101#else
102static inline long seccomp_get_filter(struct task_struct *task,
103 unsigned long n, void __user *data)
104{
105 return -EINVAL;
106}
Tycho Andersen26500472017-10-11 09:39:21 -0600107static inline long seccomp_get_metadata(struct task_struct *task,
108 unsigned long filter_off,
109 void __user *data)
110{
111 return -EINVAL;
112}
Tycho Andersenf8e529e2015-10-27 09:23:59 +0900113#endif /* CONFIG_SECCOMP_FILTER && CONFIG_CHECKPOINT_RESTORE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#endif /* _LINUX_SECCOMP_H */