enum.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. // Copyright (c) 2013, Suryandaru Triandana <syndtr@gmail.com>
  2. // All rights reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style license that can be
  5. // found in the LICENSE file.
  6. package capability
  7. type CapType uint
  8. func (c CapType) String() string {
  9. switch c {
  10. case EFFECTIVE:
  11. return "effective"
  12. case PERMITTED:
  13. return "permitted"
  14. case INHERITABLE:
  15. return "inheritable"
  16. case BOUNDING:
  17. return "bounding"
  18. case CAPS:
  19. return "caps"
  20. case AMBIENT:
  21. return "ambient"
  22. }
  23. return "unknown"
  24. }
  25. const (
  26. EFFECTIVE CapType = 1 << iota
  27. PERMITTED
  28. INHERITABLE
  29. BOUNDING
  30. AMBIENT
  31. CAPS = EFFECTIVE | PERMITTED | INHERITABLE
  32. BOUNDS = BOUNDING
  33. AMBS = AMBIENT
  34. )
  35. //go:generate go run enumgen/gen.go
  36. type Cap int
  37. // POSIX-draft defined capabilities and Linux extensions.
  38. //
  39. // Defined in https://github.com/torvalds/linux/blob/master/include/uapi/linux/capability.h
  40. const (
  41. // In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this
  42. // overrides the restriction of changing file ownership and group
  43. // ownership.
  44. CAP_CHOWN = Cap(0)
  45. // Override all DAC access, including ACL execute access if
  46. // [_POSIX_ACL] is defined. Excluding DAC access covered by
  47. // CAP_LINUX_IMMUTABLE.
  48. CAP_DAC_OVERRIDE = Cap(1)
  49. // Overrides all DAC restrictions regarding read and search on files
  50. // and directories, including ACL restrictions if [_POSIX_ACL] is
  51. // defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE.
  52. CAP_DAC_READ_SEARCH = Cap(2)
  53. // Overrides all restrictions about allowed operations on files, where
  54. // file owner ID must be equal to the user ID, except where CAP_FSETID
  55. // is applicable. It doesn't override MAC and DAC restrictions.
  56. CAP_FOWNER = Cap(3)
  57. // Overrides the following restrictions that the effective user ID
  58. // shall match the file owner ID when setting the S_ISUID and S_ISGID
  59. // bits on that file; that the effective group ID (or one of the
  60. // supplementary group IDs) shall match the file owner ID when setting
  61. // the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are
  62. // cleared on successful return from chown(2) (not implemented).
  63. CAP_FSETID = Cap(4)
  64. // Overrides the restriction that the real or effective user ID of a
  65. // process sending a signal must match the real or effective user ID
  66. // of the process receiving the signal.
  67. CAP_KILL = Cap(5)
  68. // Allows setgid(2) manipulation
  69. // Allows setgroups(2)
  70. // Allows forged gids on socket credentials passing.
  71. CAP_SETGID = Cap(6)
  72. // Allows set*uid(2) manipulation (including fsuid).
  73. // Allows forged pids on socket credentials passing.
  74. CAP_SETUID = Cap(7)
  75. // Linux-specific capabilities
  76. // Without VFS support for capabilities:
  77. // Transfer any capability in your permitted set to any pid,
  78. // remove any capability in your permitted set from any pid
  79. // With VFS support for capabilities (neither of above, but)
  80. // Add any capability from current's capability bounding set
  81. // to the current process' inheritable set
  82. // Allow taking bits out of capability bounding set
  83. // Allow modification of the securebits for a process
  84. CAP_SETPCAP = Cap(8)
  85. // Allow modification of S_IMMUTABLE and S_APPEND file attributes
  86. CAP_LINUX_IMMUTABLE = Cap(9)
  87. // Allows binding to TCP/UDP sockets below 1024
  88. // Allows binding to ATM VCIs below 32
  89. CAP_NET_BIND_SERVICE = Cap(10)
  90. // Allow broadcasting, listen to multicast
  91. CAP_NET_BROADCAST = Cap(11)
  92. // Allow interface configuration
  93. // Allow administration of IP firewall, masquerading and accounting
  94. // Allow setting debug option on sockets
  95. // Allow modification of routing tables
  96. // Allow setting arbitrary process / process group ownership on
  97. // sockets
  98. // Allow binding to any address for transparent proxying (also via NET_RAW)
  99. // Allow setting TOS (type of service)
  100. // Allow setting promiscuous mode
  101. // Allow clearing driver statistics
  102. // Allow multicasting
  103. // Allow read/write of device-specific registers
  104. // Allow activation of ATM control sockets
  105. CAP_NET_ADMIN = Cap(12)
  106. // Allow use of RAW sockets
  107. // Allow use of PACKET sockets
  108. // Allow binding to any address for transparent proxying (also via NET_ADMIN)
  109. CAP_NET_RAW = Cap(13)
  110. // Allow locking of shared memory segments
  111. // Allow mlock and mlockall (which doesn't really have anything to do
  112. // with IPC)
  113. CAP_IPC_LOCK = Cap(14)
  114. // Override IPC ownership checks
  115. CAP_IPC_OWNER = Cap(15)
  116. // Insert and remove kernel modules - modify kernel without limit
  117. CAP_SYS_MODULE = Cap(16)
  118. // Allow ioperm/iopl access
  119. // Allow sending USB messages to any device via /proc/bus/usb
  120. CAP_SYS_RAWIO = Cap(17)
  121. // Allow use of chroot()
  122. CAP_SYS_CHROOT = Cap(18)
  123. // Allow ptrace() of any process
  124. CAP_SYS_PTRACE = Cap(19)
  125. // Allow configuration of process accounting
  126. CAP_SYS_PACCT = Cap(20)
  127. // Allow configuration of the secure attention key
  128. // Allow administration of the random device
  129. // Allow examination and configuration of disk quotas
  130. // Allow setting the domainname
  131. // Allow setting the hostname
  132. // Allow calling bdflush()
  133. // Allow mount() and umount(), setting up new smb connection
  134. // Allow some autofs root ioctls
  135. // Allow nfsservctl
  136. // Allow VM86_REQUEST_IRQ
  137. // Allow to read/write pci config on alpha
  138. // Allow irix_prctl on mips (setstacksize)
  139. // Allow flushing all cache on m68k (sys_cacheflush)
  140. // Allow removing semaphores
  141. // Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores
  142. // and shared memory
  143. // Allow locking/unlocking of shared memory segment
  144. // Allow turning swap on/off
  145. // Allow forged pids on socket credentials passing
  146. // Allow setting readahead and flushing buffers on block devices
  147. // Allow setting geometry in floppy driver
  148. // Allow turning DMA on/off in xd driver
  149. // Allow administration of md devices (mostly the above, but some
  150. // extra ioctls)
  151. // Allow tuning the ide driver
  152. // Allow access to the nvram device
  153. // Allow administration of apm_bios, serial and bttv (TV) device
  154. // Allow manufacturer commands in isdn CAPI support driver
  155. // Allow reading non-standardized portions of pci configuration space
  156. // Allow DDI debug ioctl on sbpcd driver
  157. // Allow setting up serial ports
  158. // Allow sending raw qic-117 commands
  159. // Allow enabling/disabling tagged queuing on SCSI controllers and sending
  160. // arbitrary SCSI commands
  161. // Allow setting encryption key on loopback filesystem
  162. // Allow setting zone reclaim policy
  163. // Allow everything under CAP_BPF and CAP_PERFMON for backward compatibility
  164. CAP_SYS_ADMIN = Cap(21)
  165. // Allow use of reboot()
  166. CAP_SYS_BOOT = Cap(22)
  167. // Allow raising priority and setting priority on other (different
  168. // UID) processes
  169. // Allow use of FIFO and round-robin (realtime) scheduling on own
  170. // processes and setting the scheduling algorithm used by another
  171. // process.
  172. // Allow setting cpu affinity on other processes
  173. CAP_SYS_NICE = Cap(23)
  174. // Override resource limits. Set resource limits.
  175. // Override quota limits.
  176. // Override reserved space on ext2 filesystem
  177. // Modify data journaling mode on ext3 filesystem (uses journaling
  178. // resources)
  179. // NOTE: ext2 honors fsuid when checking for resource overrides, so
  180. // you can override using fsuid too
  181. // Override size restrictions on IPC message queues
  182. // Allow more than 64hz interrupts from the real-time clock
  183. // Override max number of consoles on console allocation
  184. // Override max number of keymaps
  185. // Control memory reclaim behavior
  186. CAP_SYS_RESOURCE = Cap(24)
  187. // Allow manipulation of system clock
  188. // Allow irix_stime on mips
  189. // Allow setting the real-time clock
  190. CAP_SYS_TIME = Cap(25)
  191. // Allow configuration of tty devices
  192. // Allow vhangup() of tty
  193. CAP_SYS_TTY_CONFIG = Cap(26)
  194. // Allow the privileged aspects of mknod()
  195. CAP_MKNOD = Cap(27)
  196. // Allow taking of leases on files
  197. CAP_LEASE = Cap(28)
  198. CAP_AUDIT_WRITE = Cap(29)
  199. CAP_AUDIT_CONTROL = Cap(30)
  200. CAP_SETFCAP = Cap(31)
  201. // Override MAC access.
  202. // The base kernel enforces no MAC policy.
  203. // An LSM may enforce a MAC policy, and if it does and it chooses
  204. // to implement capability based overrides of that policy, this is
  205. // the capability it should use to do so.
  206. CAP_MAC_OVERRIDE = Cap(32)
  207. // Allow MAC configuration or state changes.
  208. // The base kernel requires no MAC configuration.
  209. // An LSM may enforce a MAC policy, and if it does and it chooses
  210. // to implement capability based checks on modifications to that
  211. // policy or the data required to maintain it, this is the
  212. // capability it should use to do so.
  213. CAP_MAC_ADMIN = Cap(33)
  214. // Allow configuring the kernel's syslog (printk behaviour)
  215. CAP_SYSLOG = Cap(34)
  216. // Allow triggering something that will wake the system
  217. CAP_WAKE_ALARM = Cap(35)
  218. // Allow preventing system suspends
  219. CAP_BLOCK_SUSPEND = Cap(36)
  220. // Allow reading the audit log via multicast netlink socket
  221. CAP_AUDIT_READ = Cap(37)
  222. // Allow system performance and observability privileged operations
  223. // using perf_events, i915_perf and other kernel subsystems
  224. CAP_PERFMON = Cap(38)
  225. // CAP_BPF allows the following BPF operations:
  226. // - Creating all types of BPF maps
  227. // - Advanced verifier features
  228. // - Indirect variable access
  229. // - Bounded loops
  230. // - BPF to BPF function calls
  231. // - Scalar precision tracking
  232. // - Larger complexity limits
  233. // - Dead code elimination
  234. // - And potentially other features
  235. // - Loading BPF Type Format (BTF) data
  236. // - Retrieve xlated and JITed code of BPF programs
  237. // - Use bpf_spin_lock() helper
  238. //
  239. // CAP_PERFMON relaxes the verifier checks further:
  240. // - BPF progs can use of pointer-to-integer conversions
  241. // - speculation attack hardening measures are bypassed
  242. // - bpf_probe_read to read arbitrary kernel memory is allowed
  243. // - bpf_trace_printk to print kernel memory is allowed
  244. //
  245. // CAP_SYS_ADMIN is required to use bpf_probe_write_user.
  246. //
  247. // CAP_SYS_ADMIN is required to iterate system wide loaded
  248. // programs, maps, links, BTFs and convert their IDs to file descriptors.
  249. //
  250. // CAP_PERFMON and CAP_BPF are required to load tracing programs.
  251. // CAP_NET_ADMIN and CAP_BPF are required to load networking programs.
  252. CAP_BPF = Cap(39)
  253. // Allow checkpoint/restore related operations.
  254. // Introduced in kernel 5.9
  255. CAP_CHECKPOINT_RESTORE = Cap(40)
  256. )
  257. var (
  258. // Highest valid capability of the running kernel.
  259. CAP_LAST_CAP = Cap(63)
  260. capUpperMask = ^uint32(0)
  261. )