blob: 682237d68052cd292801aef1fa8869def55563f0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_SECCOMP_H
2#define _LINUX_SECCOMP_H
3
Will Drewry980e9202012-02-09 11:50:58 -06004#include <linux/compiler.h>
5#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
Will Drewry980e9202012-02-09 11:50:58 -06007
8/* Valid values for seccomp.mode and prctl(PR_SET_SECCOMP, <mode>) */
9#define SECCOMP_MODE_DISABLED 0 /* seccomp is not in use. */
10#define SECCOMP_MODE_STRICT 1 /* uses hard-coded filter. */
11#define SECCOMP_MODE_FILTER 2 /* uses user-supplied filter. */
12
Kees Cook95de3e52014-06-25 16:08:24 -070013/* Valid operations for seccomp syscall. */
14#define SECCOMP_SET_MODE_STRICT 0
15#define SECCOMP_SET_MODE_FILTER 1
16
Kees Cookd32af362014-06-05 00:23:17 -070017/* Valid flags for SECCOMP_SET_MODE_FILTER */
18#define SECCOMP_FILTER_FLAG_TSYNC 1
19
Will Drewry980e9202012-02-09 11:50:58 -060020/*
21 * All BPF programs must return a 32-bit value.
Will Drewry43ec8252012-02-15 20:45:54 -060022 * The bottom 16-bits are for optional return data.
Will Drewry980e9202012-02-09 11:50:58 -060023 * The upper 16-bits are ordered from least permissive values to most.
24 *
25 * The ordering ensures that a min_t() over composed return values always
26 * selects the least permissive choice.
27 */
28#define SECCOMP_RET_KILL 0x00000000U /* kill the task immediately */
Will Drewry69537022012-02-09 12:01:37 -060029#define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */
Will Drewry43ec8252012-02-15 20:45:54 -060030#define SECCOMP_RET_ERRNO 0x00050000U /* returns an errno */
Will Drewry4ca6e672012-02-09 12:08:39 -060031#define SECCOMP_RET_TRACE 0x7ff00000U /* pass to a tracer or disallow */
Will Drewry980e9202012-02-09 11:50:58 -060032#define SECCOMP_RET_ALLOW 0x7fff0000U /* allow */
33
34/* Masks for the return value sections. */
35#define SECCOMP_RET_ACTION 0x7fff0000U
36#define SECCOMP_RET_DATA 0x0000ffffU
37
38/**
39 * struct seccomp_data - the format the BPF program executes over.
40 * @nr: the system call number
41 * @arch: indicates system call convention as an AUDIT_ARCH_* value
42 * as defined in <linux/audit.h>.
43 * @instruction_pointer: at the time of the system call.
44 * @args: up to 6 system call arguments always stored as 64-bit values
45 * regardless of the architecture.
46 */
47struct seccomp_data {
48 int nr;
49 __u32 arch;
50 __u64 instruction_pointer;
51 __u64 args[6];
52};
53
54#ifdef __KERNEL__
Kees Cookd32af362014-06-05 00:23:17 -070055
56#define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC)
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#ifdef CONFIG_SECCOMP
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include <linux/thread_info.h>
61#include <asm/seccomp.h>
62
Will Drewry980e9202012-02-09 11:50:58 -060063struct seccomp_filter;
64/**
65 * struct seccomp - the state of a seccomp'ed process
66 *
67 * @mode: indicates one of the valid values above for controlled
68 * system calls available to a process.
Kees Cook880e1ab2014-06-27 15:18:48 -070069 * @filter: must always point to a valid seccomp-filter or NULL as it is
70 * accessed without locking during system call entry.
Will Drewry980e9202012-02-09 11:50:58 -060071 *
72 * @filter must only be accessed from the context of current as there
Kees Cook880e1ab2014-06-27 15:18:48 -070073 * is no read locking.
Will Drewry980e9202012-02-09 11:50:58 -060074 */
Will Drewry807936e2012-01-13 14:40:01 -060075struct seccomp {
76 int mode;
Will Drewry980e9202012-02-09 11:50:58 -060077 struct seccomp_filter *filter;
Will Drewry807936e2012-01-13 14:40:01 -060078};
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Will Drewry43ec8252012-02-15 20:45:54 -060080extern int __secure_computing(int);
81static inline int secure_computing(int this_syscall)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
83 if (unlikely(test_thread_flag(TIF_SECCOMP)))
Will Drewry43ec8252012-02-15 20:45:54 -060084 return __secure_computing(this_syscall);
85 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070088extern long prctl_get_seccomp(void);
Will Drewry980e9202012-02-09 11:50:58 -060089extern long prctl_set_seccomp(unsigned long, char __user *);
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -070090
Will Drewry807936e2012-01-13 14:40:01 -060091static inline int seccomp_mode(struct seccomp *s)
Andy Lutomirski5cec93c2011-06-05 13:50:24 -040092{
93 return s->mode;
94}
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#else /* CONFIG_SECCOMP */
97
Ralf Baechle42a17ad2009-04-18 11:30:56 +020098#include <linux/errno.h>
99
Will Drewry807936e2012-01-13 14:40:01 -0600100struct seccomp { };
Will Drewry980e9202012-02-09 11:50:58 -0600101struct seccomp_filter { };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Will Drewry980e9202012-02-09 11:50:58 -0600103#define secure_computing(x) 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -0700105static inline long prctl_get_seccomp(void)
106{
107 return -EINVAL;
108}
109
Will Drewry980e9202012-02-09 11:50:58 -0600110static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3)
Andrea Arcangeli1d9d02f2007-07-15 23:41:32 -0700111{
112 return -EINVAL;
113}
114
Will Drewry807936e2012-01-13 14:40:01 -0600115static inline int seccomp_mode(struct seccomp *s)
Andy Lutomirski5cec93c2011-06-05 13:50:24 -0400116{
117 return 0;
118}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#endif /* CONFIG_SECCOMP */
120
Will Drewry980e9202012-02-09 11:50:58 -0600121#ifdef CONFIG_SECCOMP_FILTER
122extern void put_seccomp_filter(struct task_struct *tsk);
123extern void get_seccomp_filter(struct task_struct *tsk);
124extern u32 seccomp_bpf_load(int off);
125#else /* CONFIG_SECCOMP_FILTER */
126static inline void put_seccomp_filter(struct task_struct *tsk)
127{
128 return;
129}
130static inline void get_seccomp_filter(struct task_struct *tsk)
131{
132 return;
133}
134#endif /* CONFIG_SECCOMP_FILTER */
135#endif /* __KERNEL__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#endif /* _LINUX_SECCOMP_H */