blob: 84868d37b35d0c26219ed9a6e2182e7c91cb13b1 [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
Tycho Andersen6a21cc52018-12-09 11:24:13 -07007#define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC | \
8 SECCOMP_FILTER_FLAG_LOG | \
9 SECCOMP_FILTER_FLAG_SPEC_ALLOW | \
10 SECCOMP_FILTER_FLAG_NEW_LISTENER)
Kees Cookc2e1f2e2014-06-05 00:23:17 -070011
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#ifdef CONFIG_SECCOMP
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/thread_info.h>
15#include <asm/seccomp.h>
16
Will Drewrye2cfabdf2012-04-12 16:47:57 -050017struct seccomp_filter;
18/**
19 * struct seccomp - the state of a seccomp'ed process
20 *
21 * @mode: indicates one of the valid values above for controlled
22 * system calls available to a process.
Kees Cookdbd952122014-06-27 15:18:48 -070023 * @filter: must always point to a valid seccomp-filter or NULL as it is
24 * accessed without locking during system call entry.
Will Drewrye2cfabdf2012-04-12 16:47:57 -050025 *
26 * @filter must only be accessed from the context of current as there
Kees Cookdbd952122014-06-27 15:18:48 -070027 * is no read locking.
Will Drewrye2cfabdf2012-04-12 16:47:57 -050028 */
Will Drewry932eceb2012-04-12 16:47:54 -050029struct seccomp {
30 int mode;
Will Drewrye2cfabdf2012-04-12 16:47:57 -050031 struct seccomp_filter *filter;
Will Drewry932eceb2012-04-12 16:47:54 -050032};
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070034#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
Andy Lutomirski2f275de2016-05-27 12:57:02 -070035extern int __secure_computing(const struct seccomp_data *sd);
36static inline int secure_computing(const struct seccomp_data *sd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
38 if (unlikely(test_thread_flag(TIF_SECCOMP)))
Andy Lutomirski2f275de2016-05-27 12:57:02 -070039 return __secure_computing(sd);
Will Drewryacf3b2c2012-04-12 16:47:59 -050040 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070042#else
43extern void secure_computing_strict(int this_syscall);
44#endif
Will Drewrye4da89d2012-04-17 14:48:57 -050045
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070046extern long prctl_get_seccomp(void);
Tycho Andersena5662e42018-12-09 11:24:12 -070047extern long prctl_set_seccomp(unsigned long, void __user *);
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070048
Will Drewry932eceb2012-04-12 16:47:54 -050049static inline int seccomp_mode(struct seccomp *s)
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040050{
51 return s->mode;
52}
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#else /* CONFIG_SECCOMP */
55
Ralf Baechle42a17ad2009-04-18 11:30:56 +020056#include <linux/errno.h>
57
Will Drewry932eceb2012-04-12 16:47:54 -050058struct seccomp { };
Will Drewrye2cfabdf2012-04-12 16:47:57 -050059struct seccomp_filter { };
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070061#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
Andy Lutomirski2f275de2016-05-27 12:57:02 -070062static inline int secure_computing(struct seccomp_data *sd) { return 0; }
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070063#else
Will Drewrye4da89d2012-04-17 14:48:57 -050064static inline void secure_computing_strict(int this_syscall) { return; }
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070065#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070067static inline long prctl_get_seccomp(void)
68{
69 return -EINVAL;
70}
71
Will Drewrye2cfabdf2012-04-12 16:47:57 -050072static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3)
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070073{
74 return -EINVAL;
75}
76
Will Drewry932eceb2012-04-12 16:47:54 -050077static inline int seccomp_mode(struct seccomp *s)
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040078{
Kees Cook221272f2015-06-15 15:29:16 -070079 return SECCOMP_MODE_DISABLED;
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040080}
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#endif /* CONFIG_SECCOMP */
82
Will Drewrye2cfabdf2012-04-12 16:47:57 -050083#ifdef CONFIG_SECCOMP_FILTER
84extern void put_seccomp_filter(struct task_struct *tsk);
85extern void get_seccomp_filter(struct task_struct *tsk);
Will Drewrye2cfabdf2012-04-12 16:47:57 -050086#else /* CONFIG_SECCOMP_FILTER */
87static inline void put_seccomp_filter(struct task_struct *tsk)
88{
89 return;
90}
91static inline void get_seccomp_filter(struct task_struct *tsk)
92{
93 return;
94}
95#endif /* CONFIG_SECCOMP_FILTER */
Tycho Andersenf8e529e2015-10-27 09:23:59 +090096
97#if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE)
98extern long seccomp_get_filter(struct task_struct *task,
99 unsigned long filter_off, void __user *data);
Tycho Andersen26500472017-10-11 09:39:21 -0600100extern long seccomp_get_metadata(struct task_struct *task,
101 unsigned long filter_off, void __user *data);
Tycho Andersenf8e529e2015-10-27 09:23:59 +0900102#else
103static inline long seccomp_get_filter(struct task_struct *task,
104 unsigned long n, void __user *data)
105{
106 return -EINVAL;
107}
Tycho Andersen26500472017-10-11 09:39:21 -0600108static inline long seccomp_get_metadata(struct task_struct *task,
109 unsigned long filter_off,
110 void __user *data)
111{
112 return -EINVAL;
113}
Tycho Andersenf8e529e2015-10-27 09:23:59 +0900114#endif /* CONFIG_SECCOMP_FILTER && CONFIG_CHECKPOINT_RESTORE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#endif /* _LINUX_SECCOMP_H */