blob: 10f25f7e4304cc0330851a01ecd10353a4ad2ef6 [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
Tyler Hickse66a3992017-08-11 04:33:56 +00007#define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC | \
8 SECCOMP_FILTER_FLAG_LOG)
Kees Cookc2e1f2e2014-06-05 00:23:17 -07009
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#ifdef CONFIG_SECCOMP
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/thread_info.h>
13#include <asm/seccomp.h>
14
Will Drewrye2cfabdf2012-04-12 16:47:57 -050015struct seccomp_filter;
16/**
17 * struct seccomp - the state of a seccomp'ed process
18 *
19 * @mode: indicates one of the valid values above for controlled
20 * system calls available to a process.
Kees Cookdbd952122014-06-27 15:18:48 -070021 * @filter: must always point to a valid seccomp-filter or NULL as it is
22 * accessed without locking during system call entry.
Will Drewrye2cfabdf2012-04-12 16:47:57 -050023 *
24 * @filter must only be accessed from the context of current as there
Kees Cookdbd952122014-06-27 15:18:48 -070025 * is no read locking.
Will Drewrye2cfabdf2012-04-12 16:47:57 -050026 */
Will Drewry932eceb2012-04-12 16:47:54 -050027struct seccomp {
28 int mode;
Will Drewrye2cfabdf2012-04-12 16:47:57 -050029 struct seccomp_filter *filter;
Will Drewry932eceb2012-04-12 16:47:54 -050030};
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070032#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
Andy Lutomirski2f275de2016-05-27 12:57:02 -070033extern int __secure_computing(const struct seccomp_data *sd);
34static inline int secure_computing(const struct seccomp_data *sd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
36 if (unlikely(test_thread_flag(TIF_SECCOMP)))
Andy Lutomirski2f275de2016-05-27 12:57:02 -070037 return __secure_computing(sd);
Will Drewryacf3b2c2012-04-12 16:47:59 -050038 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039}
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070040#else
41extern void secure_computing_strict(int this_syscall);
42#endif
Will Drewrye4da89d2012-04-17 14:48:57 -050043
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
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070059#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
Andy Lutomirski2f275de2016-05-27 12:57:02 -070060static inline int secure_computing(struct seccomp_data *sd) { return 0; }
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070061#else
Will Drewrye4da89d2012-04-17 14:48:57 -050062static inline void secure_computing_strict(int this_syscall) { return; }
Andy Lutomirskia4412fc2014-07-21 18:49:14 -070063#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070065static inline long prctl_get_seccomp(void)
66{
67 return -EINVAL;
68}
69
Will Drewrye2cfabdf2012-04-12 16:47:57 -050070static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3)
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070071{
72 return -EINVAL;
73}
74
Will Drewry932eceb2012-04-12 16:47:54 -050075static inline int seccomp_mode(struct seccomp *s)
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040076{
Kees Cook221272f2015-06-15 15:29:16 -070077 return SECCOMP_MODE_DISABLED;
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040078}
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#endif /* CONFIG_SECCOMP */
80
Will Drewrye2cfabdf2012-04-12 16:47:57 -050081#ifdef CONFIG_SECCOMP_FILTER
82extern void put_seccomp_filter(struct task_struct *tsk);
83extern void get_seccomp_filter(struct task_struct *tsk);
Will Drewrye2cfabdf2012-04-12 16:47:57 -050084#else /* CONFIG_SECCOMP_FILTER */
85static inline void put_seccomp_filter(struct task_struct *tsk)
86{
87 return;
88}
89static inline void get_seccomp_filter(struct task_struct *tsk)
90{
91 return;
92}
93#endif /* CONFIG_SECCOMP_FILTER */
Tycho Andersenf8e529e2015-10-27 09:23:59 +090094
95#if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE)
96extern long seccomp_get_filter(struct task_struct *task,
97 unsigned long filter_off, void __user *data);
98#else
99static inline long seccomp_get_filter(struct task_struct *task,
100 unsigned long n, void __user *data)
101{
102 return -EINVAL;
103}
104#endif /* CONFIG_SECCOMP_FILTER && CONFIG_CHECKPOINT_RESTORE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#endif /* _LINUX_SECCOMP_H */