blob: 4192369b84181d9e6a5a8dc90cc29aea17228cb5 [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 | \
Tycho Andersen51891492020-03-04 11:05:17 -070010 SECCOMP_FILTER_FLAG_NEW_LISTENER | \
11 SECCOMP_FILTER_FLAG_TSYNC_ESRCH)
Kees Cookc2e1f2e2014-06-05 00:23:17 -070012
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#ifdef CONFIG_SECCOMP
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/thread_info.h>
16#include <asm/seccomp.h>
17
Will Drewrye2cfabdf2012-04-12 16:47:57 -050018struct seccomp_filter;
19/**
20 * struct seccomp - the state of a seccomp'ed process
21 *
22 * @mode: indicates one of the valid values above for controlled
23 * system calls available to a process.
Kees Cookdbd952122014-06-27 15:18:48 -070024 * @filter: must always point to a valid seccomp-filter or NULL as it is
25 * accessed without locking during system call entry.
Will Drewrye2cfabdf2012-04-12 16:47:57 -050026 *
27 * @filter must only be accessed from the context of current as there
Kees Cookdbd952122014-06-27 15:18:48 -070028 * is no read locking.
Will Drewrye2cfabdf2012-04-12 16:47:57 -050029 */
Will Drewry932eceb2012-04-12 16:47:54 -050030struct seccomp {
31 int mode;
Will Drewrye2cfabdf2012-04-12 16:47:57 -050032 struct seccomp_filter *filter;
Will Drewry932eceb2012-04-12 16:47:54 -050033};
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070035#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
Andy Lutomirski2f275de2016-05-27 12:57:02 -070036extern int __secure_computing(const struct seccomp_data *sd);
Christian Braunerfefad9e2019-09-24 08:44:20 +020037static inline int secure_computing(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
39 if (unlikely(test_thread_flag(TIF_SECCOMP)))
Christian Braunerfefad9e2019-09-24 08:44:20 +020040 return __secure_computing(NULL);
Will Drewryacf3b2c2012-04-12 16:47:59 -050041 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070043#else
44extern void secure_computing_strict(int this_syscall);
45#endif
Will Drewrye4da89d2012-04-17 14:48:57 -050046
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070047extern long prctl_get_seccomp(void);
Tycho Andersena5662e42018-12-09 11:24:12 -070048extern long prctl_set_seccomp(unsigned long, void __user *);
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070049
Will Drewry932eceb2012-04-12 16:47:54 -050050static inline int seccomp_mode(struct seccomp *s)
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040051{
52 return s->mode;
53}
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#else /* CONFIG_SECCOMP */
56
Ralf Baechle42a17ad2009-04-18 11:30:56 +020057#include <linux/errno.h>
58
Will Drewry932eceb2012-04-12 16:47:54 -050059struct seccomp { };
Will Drewrye2cfabdf2012-04-12 16:47:57 -050060struct seccomp_filter { };
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070062#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
Christian Braunerfefad9e2019-09-24 08:44:20 +020063static inline int secure_computing(void) { return 0; }
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070064#else
Will Drewrye4da89d2012-04-17 14:48:57 -050065static inline void secure_computing_strict(int this_syscall) { return; }
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070066#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070068static inline long prctl_get_seccomp(void)
69{
70 return -EINVAL;
71}
72
Will Drewrye2cfabdf2012-04-12 16:47:57 -050073static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3)
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070074{
75 return -EINVAL;
76}
77
Will Drewry932eceb2012-04-12 16:47:54 -050078static inline int seccomp_mode(struct seccomp *s)
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040079{
Kees Cook221272f2015-06-15 15:29:16 -070080 return SECCOMP_MODE_DISABLED;
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040081}
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#endif /* CONFIG_SECCOMP */
83
Will Drewrye2cfabdf2012-04-12 16:47:57 -050084#ifdef CONFIG_SECCOMP_FILTER
85extern void put_seccomp_filter(struct task_struct *tsk);
86extern void get_seccomp_filter(struct task_struct *tsk);
Will Drewrye2cfabdf2012-04-12 16:47:57 -050087#else /* CONFIG_SECCOMP_FILTER */
88static inline void put_seccomp_filter(struct task_struct *tsk)
89{
90 return;
91}
92static inline void get_seccomp_filter(struct task_struct *tsk)
93{
94 return;
95}
96#endif /* CONFIG_SECCOMP_FILTER */
Tycho Andersenf8e529e2015-10-27 09:23:59 +090097
98#if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE)
99extern long seccomp_get_filter(struct task_struct *task,
100 unsigned long filter_off, void __user *data);
Tycho Andersen26500472017-10-11 09:39:21 -0600101extern long seccomp_get_metadata(struct task_struct *task,
102 unsigned long filter_off, void __user *data);
Tycho Andersenf8e529e2015-10-27 09:23:59 +0900103#else
104static inline long seccomp_get_filter(struct task_struct *task,
105 unsigned long n, void __user *data)
106{
107 return -EINVAL;
108}
Tycho Andersen26500472017-10-11 09:39:21 -0600109static inline long seccomp_get_metadata(struct task_struct *task,
110 unsigned long filter_off,
111 void __user *data)
112{
113 return -EINVAL;
114}
Tycho Andersenf8e529e2015-10-27 09:23:59 +0900115#endif /* CONFIG_SECCOMP_FILTER && CONFIG_CHECKPOINT_RESTORE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#endif /* _LINUX_SECCOMP_H */