logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

seccomp.h (5990B)


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