seccomp.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef _LINUX_SECCOMP_H
  2. #define _LINUX_SECCOMP_H
  3. #include <linux/compiler.h>
  4. #include <linux/types.h>
  5. /* Valid values for seccomp.mode and prctl(PR_SET_SECCOMP, <mode>) */
  6. #define SECCOMP_MODE_DISABLED 0 /* seccomp is not in use. */
  7. #define SECCOMP_MODE_STRICT 1 /* uses hard-coded filter. */
  8. #define SECCOMP_MODE_FILTER 2 /* uses user-supplied filter. */
  9. /* Valid operations for seccomp syscall. */
  10. #define SECCOMP_SET_MODE_STRICT 0
  11. #define SECCOMP_SET_MODE_FILTER 1
  12. /* Valid flags for SECCOMP_SET_MODE_FILTER */
  13. #define SECCOMP_FILTER_FLAG_TSYNC 1
  14. /*
  15. * All BPF programs must return a 32-bit value.
  16. * The bottom 16-bits are for optional return data.
  17. * The upper 16-bits are ordered from least permissive values to most.
  18. *
  19. * The ordering ensures that a min_t() over composed return values always
  20. * selects the least permissive choice.
  21. */
  22. #define SECCOMP_RET_KILL 0x00000000U /* kill the task immediately */
  23. #define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */
  24. #define SECCOMP_RET_ERRNO 0x00050000U /* returns an errno */
  25. #define SECCOMP_RET_TRACE 0x7ff00000U /* pass to a tracer or disallow */
  26. #define SECCOMP_RET_ALLOW 0x7fff0000U /* allow */
  27. /* Masks for the return value sections. */
  28. #define SECCOMP_RET_ACTION 0x7fff0000U
  29. #define SECCOMP_RET_DATA 0x0000ffffU
  30. /**
  31. * struct seccomp_data - the format the BPF program executes over.
  32. * @nr: the system call number
  33. * @arch: indicates system call convention as an AUDIT_ARCH_* value
  34. * as defined in <linux/audit.h>.
  35. * @instruction_pointer: at the time of the system call.
  36. * @args: up to 6 system call arguments always stored as 64-bit values
  37. * regardless of the architecture.
  38. */
  39. struct seccomp_data {
  40. int nr;
  41. __u32 arch;
  42. __u64 instruction_pointer;
  43. __u64 args[6];
  44. };
  45. #ifdef __KERNEL__
  46. #define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC)
  47. #ifdef CONFIG_SECCOMP
  48. #include <linux/thread_info.h>
  49. #include <asm/seccomp.h>
  50. struct seccomp_filter;
  51. /**
  52. * struct seccomp - the state of a seccomp'ed process
  53. *
  54. * @mode: indicates one of the valid values above for controlled
  55. * system calls available to a process.
  56. * @filter: must always point to a valid seccomp-filter or NULL as it is
  57. * accessed without locking during system call entry.
  58. *
  59. * @filter must only be accessed from the context of current as there
  60. * is no read locking.
  61. */
  62. struct seccomp {
  63. int mode;
  64. struct seccomp_filter *filter;
  65. };
  66. extern int __secure_computing(int);
  67. static inline int secure_computing(int this_syscall)
  68. {
  69. if (unlikely(test_thread_flag(TIF_SECCOMP)))
  70. return __secure_computing(this_syscall);
  71. return 0;
  72. }
  73. /* A wrapper for architectures supporting only SECCOMP_MODE_STRICT. */
  74. static inline void secure_computing_strict(int this_syscall)
  75. {
  76. BUG_ON(secure_computing(this_syscall) != 0);
  77. }
  78. extern long prctl_get_seccomp(void);
  79. extern long prctl_set_seccomp(unsigned long, char __user *);
  80. static inline int seccomp_mode(struct seccomp *s)
  81. {
  82. return s->mode;
  83. }
  84. #else /* CONFIG_SECCOMP */
  85. #include <linux/errno.h>
  86. struct seccomp { };
  87. struct seccomp_filter { };
  88. static inline int secure_computing(int this_syscall) { return 0; }
  89. static inline void secure_computing_strict(int this_syscall) { return; }
  90. static inline long prctl_get_seccomp(void)
  91. {
  92. return -EINVAL;
  93. }
  94. static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3)
  95. {
  96. return -EINVAL;
  97. }
  98. static inline int seccomp_mode(struct seccomp *s)
  99. {
  100. return 0;
  101. }
  102. #endif /* CONFIG_SECCOMP */
  103. #ifdef CONFIG_SECCOMP_FILTER
  104. extern void put_seccomp_filter(struct task_struct *tsk);
  105. extern void get_seccomp_filter(struct task_struct *tsk);
  106. extern u32 seccomp_bpf_load(int off);
  107. #else /* CONFIG_SECCOMP_FILTER */
  108. static inline void put_seccomp_filter(struct task_struct *tsk)
  109. {
  110. return;
  111. }
  112. static inline void get_seccomp_filter(struct task_struct *tsk)
  113. {
  114. return;
  115. }
  116. #endif /* CONFIG_SECCOMP_FILTER */
  117. #endif /* __KERNEL__ */
  118. #endif /* _LINUX_SECCOMP_H */