seccomp.h 3.2 KB

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