seccomp.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_SECCOMP_H
  3. #define _LINUX_SECCOMP_H
  4. #include <uapi/linux/seccomp.h>
  5. #define SECCOMP_FILTER_FLAG_MASK (SECCOMP_FILTER_FLAG_TSYNC | \
  6. SECCOMP_FILTER_FLAG_LOG | \
  7. SECCOMP_FILTER_FLAG_SPEC_ALLOW | \
  8. SECCOMP_FILTER_FLAG_NEW_LISTENER | \
  9. SECCOMP_FILTER_FLAG_TSYNC_ESRCH | \
  10. SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV)
  11. /* sizeof() the first published struct seccomp_notif_addfd */
  12. #define SECCOMP_NOTIFY_ADDFD_SIZE_VER0 24
  13. #define SECCOMP_NOTIFY_ADDFD_SIZE_LATEST SECCOMP_NOTIFY_ADDFD_SIZE_VER0
  14. #ifdef CONFIG_SECCOMP
  15. #include <linux/thread_info.h>
  16. #include <linux/atomic.h>
  17. #include <asm/seccomp.h>
  18. struct seccomp_filter;
  19. /**
  20. * struct seccomp - the state of a seccomp'ed process
  21. *
  22. * @mode: indicates one of the valid values above for controlled
  23. * system calls available to a process.
  24. * @filter: must always point to a valid seccomp-filter or NULL as it is
  25. * accessed without locking during system call entry.
  26. *
  27. * @filter must only be accessed from the context of current as there
  28. * is no read locking.
  29. */
  30. struct seccomp {
  31. int mode;
  32. atomic_t filter_count;
  33. struct seccomp_filter *filter;
  34. };
  35. #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
  36. extern int __secure_computing(const struct seccomp_data *sd);
  37. static inline int secure_computing(void)
  38. {
  39. if (unlikely(test_syscall_work(SECCOMP)))
  40. return __secure_computing(NULL);
  41. return 0;
  42. }
  43. #else
  44. extern void secure_computing_strict(int this_syscall);
  45. #endif
  46. extern long prctl_get_seccomp(void);
  47. extern long prctl_set_seccomp(unsigned long, void __user *);
  48. static inline int seccomp_mode(struct seccomp *s)
  49. {
  50. return s->mode;
  51. }
  52. #else /* CONFIG_SECCOMP */
  53. #include <linux/errno.h>
  54. struct seccomp { };
  55. struct seccomp_filter { };
  56. struct seccomp_data;
  57. #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
  58. static inline int secure_computing(void) { return 0; }
  59. static inline int __secure_computing(const struct seccomp_data *sd) { return 0; }
  60. #else
  61. static inline void secure_computing_strict(int this_syscall) { return; }
  62. #endif
  63. static inline long prctl_get_seccomp(void)
  64. {
  65. return -EINVAL;
  66. }
  67. static inline long prctl_set_seccomp(unsigned long arg2, char __user *arg3)
  68. {
  69. return -EINVAL;
  70. }
  71. static inline int seccomp_mode(struct seccomp *s)
  72. {
  73. return SECCOMP_MODE_DISABLED;
  74. }
  75. #endif /* CONFIG_SECCOMP */
  76. #ifdef CONFIG_SECCOMP_FILTER
  77. extern void seccomp_filter_release(struct task_struct *tsk);
  78. extern void get_seccomp_filter(struct task_struct *tsk);
  79. #else /* CONFIG_SECCOMP_FILTER */
  80. static inline void seccomp_filter_release(struct task_struct *tsk)
  81. {
  82. return;
  83. }
  84. static inline void get_seccomp_filter(struct task_struct *tsk)
  85. {
  86. return;
  87. }
  88. #endif /* CONFIG_SECCOMP_FILTER */
  89. #if defined(CONFIG_SECCOMP_FILTER) && defined(CONFIG_CHECKPOINT_RESTORE)
  90. extern long seccomp_get_filter(struct task_struct *task,
  91. unsigned long filter_off, void __user *data);
  92. extern long seccomp_get_metadata(struct task_struct *task,
  93. unsigned long filter_off, void __user *data);
  94. #else
  95. static inline long seccomp_get_filter(struct task_struct *task,
  96. unsigned long n, void __user *data)
  97. {
  98. return -EINVAL;
  99. }
  100. static inline long seccomp_get_metadata(struct task_struct *task,
  101. unsigned long filter_off,
  102. void __user *data)
  103. {
  104. return -EINVAL;
  105. }
  106. #endif /* CONFIG_SECCOMP_FILTER && CONFIG_CHECKPOINT_RESTORE */
  107. #ifdef CONFIG_SECCOMP_CACHE_DEBUG
  108. struct seq_file;
  109. int proc_pid_seccomp_cache(struct seq_file *m, struct pid_namespace *ns,
  110. struct pid *pid, struct task_struct *task);
  111. #endif
  112. #endif /* _LINUX_SECCOMP_H */