seccomp.h 3.1 KB

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