seccomp.h 3.3 KB

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