seccomp.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _UAPI_LINUX_SECCOMP_H
  3. #define _UAPI_LINUX_SECCOMP_H
  4. #include <linux/compiler.h>
  5. #include <linux/types.h>
  6. /* Valid values for seccomp.mode and prctl(PR_SET_SECCOMP, <mode>) */
  7. #define SECCOMP_MODE_DISABLED 0 /* seccomp is not in use. */
  8. #define SECCOMP_MODE_STRICT 1 /* uses hard-coded filter. */
  9. #define SECCOMP_MODE_FILTER 2 /* uses user-supplied filter. */
  10. /* Valid operations for seccomp syscall. */
  11. #define SECCOMP_SET_MODE_STRICT 0
  12. #define SECCOMP_SET_MODE_FILTER 1
  13. #define SECCOMP_GET_ACTION_AVAIL 2
  14. #define SECCOMP_GET_NOTIF_SIZES 3
  15. /* Valid flags for SECCOMP_SET_MODE_FILTER */
  16. #define SECCOMP_FILTER_FLAG_TSYNC (1UL << 0)
  17. #define SECCOMP_FILTER_FLAG_LOG (1UL << 1)
  18. #define SECCOMP_FILTER_FLAG_SPEC_ALLOW (1UL << 2)
  19. #define SECCOMP_FILTER_FLAG_NEW_LISTENER (1UL << 3)
  20. #define SECCOMP_FILTER_FLAG_TSYNC_ESRCH (1UL << 4)
  21. /* Received notifications wait in killable state (only respond to fatal signals) */
  22. #define SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV (1UL << 5)
  23. /*
  24. * All BPF programs must return a 32-bit value.
  25. * The bottom 16-bits are for optional return data.
  26. * The upper 16-bits are ordered from least permissive values to most,
  27. * as a signed value (so 0x8000000 is negative).
  28. *
  29. * The ordering ensures that a min_t() over composed return values always
  30. * selects the least permissive choice.
  31. */
  32. #define SECCOMP_RET_KILL_PROCESS 0x80000000U /* kill the process */
  33. #define SECCOMP_RET_KILL_THREAD 0x00000000U /* kill the thread */
  34. #define SECCOMP_RET_KILL SECCOMP_RET_KILL_THREAD
  35. #define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */
  36. #define SECCOMP_RET_ERRNO 0x00050000U /* returns an errno */
  37. #define SECCOMP_RET_USER_NOTIF 0x7fc00000U /* notifies userspace */
  38. #define SECCOMP_RET_TRACE 0x7ff00000U /* pass to a tracer or disallow */
  39. #define SECCOMP_RET_LOG 0x7ffc0000U /* allow after logging */
  40. #define SECCOMP_RET_ALLOW 0x7fff0000U /* allow */
  41. /* Masks for the return value sections. */
  42. #define SECCOMP_RET_ACTION_FULL 0xffff0000U
  43. #define SECCOMP_RET_ACTION 0x7fff0000U
  44. #define SECCOMP_RET_DATA 0x0000ffffU
  45. /**
  46. * struct seccomp_data - the format the BPF program executes over.
  47. * @nr: the system call number
  48. * @arch: indicates system call convention as an AUDIT_ARCH_* value
  49. * as defined in <linux/audit.h>.
  50. * @instruction_pointer: at the time of the system call.
  51. * @args: up to 6 system call arguments always stored as 64-bit values
  52. * regardless of the architecture.
  53. */
  54. struct seccomp_data {
  55. int nr;
  56. __u32 arch;
  57. __u64 instruction_pointer;
  58. __u64 args[6];
  59. };
  60. struct seccomp_notif_sizes {
  61. __u16 seccomp_notif;
  62. __u16 seccomp_notif_resp;
  63. __u16 seccomp_data;
  64. };
  65. struct seccomp_notif {
  66. __u64 id;
  67. __u32 pid;
  68. __u32 flags;
  69. struct seccomp_data data;
  70. };
  71. /*
  72. * Valid flags for struct seccomp_notif_resp
  73. *
  74. * Note, the SECCOMP_USER_NOTIF_FLAG_CONTINUE flag must be used with caution!
  75. * If set by the process supervising the syscalls of another process the
  76. * syscall will continue. This is problematic because of an inherent TOCTOU.
  77. * An attacker can exploit the time while the supervised process is waiting on
  78. * a response from the supervising process to rewrite syscall arguments which
  79. * are passed as pointers of the intercepted syscall.
  80. * It should be absolutely clear that this means that the seccomp notifier
  81. * _cannot_ be used to implement a security policy! It should only ever be used
  82. * in scenarios where a more privileged process supervises the syscalls of a
  83. * lesser privileged process to get around kernel-enforced security
  84. * restrictions when the privileged process deems this safe. In other words,
  85. * in order to continue a syscall the supervising process should be sure that
  86. * another security mechanism or the kernel itself will sufficiently block
  87. * syscalls if arguments are rewritten to something unsafe.
  88. *
  89. * Similar precautions should be applied when stacking SECCOMP_RET_USER_NOTIF
  90. * or SECCOMP_RET_TRACE. For SECCOMP_RET_USER_NOTIF filters acting on the
  91. * same syscall, the most recently added filter takes precedence. This means
  92. * that the new SECCOMP_RET_USER_NOTIF filter can override any
  93. * SECCOMP_IOCTL_NOTIF_SEND from earlier filters, essentially allowing all
  94. * such filtered syscalls to be executed by sending the response
  95. * SECCOMP_USER_NOTIF_FLAG_CONTINUE. Note that SECCOMP_RET_TRACE can equally
  96. * be overriden by SECCOMP_USER_NOTIF_FLAG_CONTINUE.
  97. */
  98. #define SECCOMP_USER_NOTIF_FLAG_CONTINUE (1UL << 0)
  99. struct seccomp_notif_resp {
  100. __u64 id;
  101. __s64 val;
  102. __s32 error;
  103. __u32 flags;
  104. };
  105. #define SECCOMP_USER_NOTIF_FD_SYNC_WAKE_UP (1UL << 0)
  106. /* valid flags for seccomp_notif_addfd */
  107. #define SECCOMP_ADDFD_FLAG_SETFD (1UL << 0) /* Specify remote fd */
  108. #define SECCOMP_ADDFD_FLAG_SEND (1UL << 1) /* Addfd and return it, atomically */
  109. /**
  110. * struct seccomp_notif_addfd
  111. * @id: The ID of the seccomp notification
  112. * @flags: SECCOMP_ADDFD_FLAG_*
  113. * @srcfd: The local fd number
  114. * @newfd: Optional remote FD number if SETFD option is set, otherwise 0.
  115. * @newfd_flags: The O_* flags the remote FD should have applied
  116. */
  117. struct seccomp_notif_addfd {
  118. __u64 id;
  119. __u32 flags;
  120. __u32 srcfd;
  121. __u32 newfd;
  122. __u32 newfd_flags;
  123. };
  124. #define SECCOMP_IOC_MAGIC '!'
  125. #define SECCOMP_IO(nr) _IO(SECCOMP_IOC_MAGIC, nr)
  126. #define SECCOMP_IOR(nr, type) _IOR(SECCOMP_IOC_MAGIC, nr, type)
  127. #define SECCOMP_IOW(nr, type) _IOW(SECCOMP_IOC_MAGIC, nr, type)
  128. #define SECCOMP_IOWR(nr, type) _IOWR(SECCOMP_IOC_MAGIC, nr, type)
  129. /* Flags for seccomp notification fd ioctl. */
  130. #define SECCOMP_IOCTL_NOTIF_RECV SECCOMP_IOWR(0, struct seccomp_notif)
  131. #define SECCOMP_IOCTL_NOTIF_SEND SECCOMP_IOWR(1, \
  132. struct seccomp_notif_resp)
  133. #define SECCOMP_IOCTL_NOTIF_ID_VALID SECCOMP_IOW(2, __u64)
  134. /* On success, the return value is the remote process's added fd number */
  135. #define SECCOMP_IOCTL_NOTIF_ADDFD SECCOMP_IOW(3, \
  136. struct seccomp_notif_addfd)
  137. #define SECCOMP_IOCTL_NOTIF_SET_FLAGS SECCOMP_IOW(4, __u64)
  138. #endif /* _UAPI_LINUX_SECCOMP_H */