1 #ifndef _LINUX_SECCOMP_H 2 #define _LINUX_SECCOMP_H 3 4 #include <linux/compiler.h> 5 #include <linux/types.h> 6 7 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 13 /* Valid operations for seccomp syscall. */ 14 #define SECCOMP_SET_MODE_STRICT 0 15 #define SECCOMP_SET_MODE_FILTER 1 16 17 /* Valid flags for SECCOMP_SET_MODE_FILTER */ 18 #define SECCOMP_FILTER_FLAG_TSYNC 1 19 20 /* 21 * All BPF programs must return a 32-bit value. 22 * The bottom 16-bits are for optional return data. 23 * 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 */ 29 #define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */ 30 #define SECCOMP_RET_ERRNO 0x00050000U /* returns an errno */ 31 #define SECCOMP_RET_TRACE 0x7ff00000U /* pass to a tracer or disallow */ 32 #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 */ 47 struct seccomp_data { 48 int nr; 49 __u32 arch; 50 __u64 instruction_pointer; 51 __u64 args[6]; 52 }; 53 54 #ifdef __KERNEL__ 55 56 #define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC) 57 58 #ifdef CONFIG_SECCOMP 59 60 #include <linux/thread_info.h> 61 #include <asm/seccomp.h> 62 63 struct 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. 69 * @filter: must always point to a valid seccomp-filter or NULL as it is 70 * accessed without locking during system call entry. 71 * 72 * @filter must only be accessed from the context of current as there 73 * is no read locking. 74 */ 75 struct seccomp { 76 int mode; 77 struct seccomp_filter *filter; 78 }; 79 80 extern int __secure_computing(int); secure_computing(int this_syscall)81static inline int secure_computing(int this_syscall) 82 { 83 if (unlikely(test_thread_flag(TIF_SECCOMP))) 84 return __secure_computing(this_syscall); 85 return 0; 86 } 87 88 /* A wrapper for architectures supporting only SECCOMP_MODE_STRICT. */ secure_computing_strict(int this_syscall)89static inline void secure_computing_strict(int this_syscall) 90 { 91 BUG_ON(secure_computing(this_syscall) != 0); 92 } 93 94 extern long prctl_get_seccomp(void); 95 extern long prctl_set_seccomp(unsigned long, char __user *); 96 seccomp_mode(struct seccomp * s)97static inline int seccomp_mode(struct seccomp *s) 98 { 99 return s->mode; 100 } 101 102 #else /* CONFIG_SECCOMP */ 103 104 #include <linux/errno.h> 105 106 struct seccomp { }; 107 struct seccomp_filter { }; 108 secure_computing(int this_syscall)109static inline int secure_computing(int this_syscall) { return 0; } secure_computing_strict(int this_syscall)110static inline void secure_computing_strict(int this_syscall) { return; } 111 prctl_get_seccomp(void)112static inline long prctl_get_seccomp(void) 113 { 114 return -EINVAL; 115 } 116 prctl_set_seccomp(unsigned long arg2,char __user * arg3)117static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3) 118 { 119 return -EINVAL; 120 } 121 seccomp_mode(struct seccomp * s)122static inline int seccomp_mode(struct seccomp *s) 123 { 124 return 0; 125 } 126 #endif /* CONFIG_SECCOMP */ 127 128 #ifdef CONFIG_SECCOMP_FILTER 129 extern void put_seccomp_filter(struct task_struct *tsk); 130 extern void get_seccomp_filter(struct task_struct *tsk); 131 extern u32 seccomp_bpf_load(int off); 132 #else /* CONFIG_SECCOMP_FILTER */ put_seccomp_filter(struct task_struct * tsk)133static inline void put_seccomp_filter(struct task_struct *tsk) 134 { 135 return; 136 } get_seccomp_filter(struct task_struct * tsk)137static inline void get_seccomp_filter(struct task_struct *tsk) 138 { 139 return; 140 } 141 #endif /* CONFIG_SECCOMP_FILTER */ 142 #endif /* __KERNEL__ */ 143 #endif /* _LINUX_SECCOMP_H */ 144