capability.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * This is <linux/capability.h>
  4. *
  5. * Andrew G. Morgan <morgan@kernel.org>
  6. * Alexander Kjeldaas <astor@guardian.no>
  7. * with help from Aleph1, Roland Buresund and Andrew Main.
  8. *
  9. * See here for the libcap library ("POSIX draft" compliance):
  10. *
  11. * ftp://www.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.6/
  12. */
  13. #ifndef _LINUX_CAPABILITY_H
  14. #define _LINUX_CAPABILITY_H
  15. #include <linux/types.h>
  16. /* User-level do most of the mapping between kernel and user
  17. capabilities based on the version tag given by the kernel. The
  18. kernel might be somewhat backwards compatible, but don't bet on
  19. it. */
  20. /* Note, cap_t, is defined by POSIX (draft) to be an "opaque" pointer to
  21. a set of three capability sets. The transposition of 3*the
  22. following structure to such a composite is better handled in a user
  23. library since the draft standard requires the use of malloc/free
  24. etc.. */
  25. #define _LINUX_CAPABILITY_VERSION_1 0x19980330
  26. #define _LINUX_CAPABILITY_U32S_1 1
  27. #define _LINUX_CAPABILITY_VERSION_2 0x20071026 /* deprecated - use v3 */
  28. #define _LINUX_CAPABILITY_U32S_2 2
  29. #define _LINUX_CAPABILITY_VERSION_3 0x20080522
  30. #define _LINUX_CAPABILITY_U32S_3 2
  31. typedef struct __user_cap_header_struct {
  32. __u32 version;
  33. int pid;
  34. } *cap_user_header_t;
  35. struct __user_cap_data_struct {
  36. __u32 effective;
  37. __u32 permitted;
  38. __u32 inheritable;
  39. };
  40. typedef struct __user_cap_data_struct *cap_user_data_t;
  41. #define VFS_CAP_REVISION_MASK 0xFF000000
  42. #define VFS_CAP_REVISION_SHIFT 24
  43. #define VFS_CAP_FLAGS_MASK ~VFS_CAP_REVISION_MASK
  44. #define VFS_CAP_FLAGS_EFFECTIVE 0x000001
  45. #define VFS_CAP_REVISION_1 0x01000000
  46. #define VFS_CAP_U32_1 1
  47. #define XATTR_CAPS_SZ_1 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_1))
  48. #define VFS_CAP_REVISION_2 0x02000000
  49. #define VFS_CAP_U32_2 2
  50. #define XATTR_CAPS_SZ_2 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_2))
  51. #define VFS_CAP_REVISION_3 0x03000000
  52. #define VFS_CAP_U32_3 2
  53. #define XATTR_CAPS_SZ_3 (sizeof(__le32)*(2 + 2*VFS_CAP_U32_3))
  54. #define XATTR_CAPS_SZ XATTR_CAPS_SZ_3
  55. #define VFS_CAP_U32 VFS_CAP_U32_3
  56. #define VFS_CAP_REVISION VFS_CAP_REVISION_3
  57. struct vfs_cap_data {
  58. __le32 magic_etc; /* Little endian */
  59. struct {
  60. __le32 permitted; /* Little endian */
  61. __le32 inheritable; /* Little endian */
  62. } data[VFS_CAP_U32];
  63. };
  64. /*
  65. * same as vfs_cap_data but with a rootid at the end
  66. */
  67. struct vfs_ns_cap_data {
  68. __le32 magic_etc;
  69. struct {
  70. __le32 permitted; /* Little endian */
  71. __le32 inheritable; /* Little endian */
  72. } data[VFS_CAP_U32];
  73. __le32 rootid;
  74. };
  75. /*
  76. * Backwardly compatible definition for source code - trapped in a
  77. * 32-bit world. If you find you need this, please consider using
  78. * libcap to untrap yourself...
  79. */
  80. #define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_1
  81. #define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_1
  82. /**
  83. ** POSIX-draft defined capabilities.
  84. **/
  85. /* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this
  86. overrides the restriction of changing file ownership and group
  87. ownership. */
  88. #define CAP_CHOWN 0
  89. /* Override all DAC access, including ACL execute access if
  90. [_POSIX_ACL] is defined. Excluding DAC access covered by
  91. CAP_LINUX_IMMUTABLE. */
  92. #define CAP_DAC_OVERRIDE 1
  93. /* Overrides all DAC restrictions regarding read and search on files
  94. and directories, including ACL restrictions if [_POSIX_ACL] is
  95. defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */
  96. #define CAP_DAC_READ_SEARCH 2
  97. /* Overrides all restrictions about allowed operations on files, where
  98. file owner ID must be equal to the user ID, except where CAP_FSETID
  99. is applicable. It doesn't override MAC and DAC restrictions. */
  100. #define CAP_FOWNER 3
  101. /* Overrides the following restrictions that the effective user ID
  102. shall match the file owner ID when setting the S_ISUID and S_ISGID
  103. bits on that file; that the effective group ID (or one of the
  104. supplementary group IDs) shall match the file owner ID when setting
  105. the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are
  106. cleared on successful return from chown(2) (not implemented). */
  107. #define CAP_FSETID 4
  108. /* Overrides the restriction that the real or effective user ID of a
  109. process sending a signal must match the real or effective user ID
  110. of the process receiving the signal. */
  111. #define CAP_KILL 5
  112. /* Allows setgid(2) manipulation */
  113. /* Allows setgroups(2) */
  114. /* Allows forged gids on socket credentials passing. */
  115. #define CAP_SETGID 6
  116. /* Allows set*uid(2) manipulation (including fsuid). */
  117. /* Allows forged pids on socket credentials passing. */
  118. #define CAP_SETUID 7
  119. /**
  120. ** Linux-specific capabilities
  121. **/
  122. /* Without VFS support for capabilities:
  123. * Transfer any capability in your permitted set to any pid,
  124. * remove any capability in your permitted set from any pid
  125. * With VFS support for capabilities (neither of above, but)
  126. * Add any capability from current's capability bounding set
  127. * to the current process' inheritable set
  128. * Allow taking bits out of capability bounding set
  129. * Allow modification of the securebits for a process
  130. */
  131. #define CAP_SETPCAP 8
  132. /* Allow modification of S_IMMUTABLE and S_APPEND file attributes */
  133. #define CAP_LINUX_IMMUTABLE 9
  134. /* Allows binding to TCP/UDP sockets below 1024 */
  135. /* Allows binding to ATM VCIs below 32 */
  136. #define CAP_NET_BIND_SERVICE 10
  137. /* Allow broadcasting, listen to multicast */
  138. #define CAP_NET_BROADCAST 11
  139. /* Allow interface configuration */
  140. /* Allow administration of IP firewall, masquerading and accounting */
  141. /* Allow setting debug option on sockets */
  142. /* Allow modification of routing tables */
  143. /* Allow setting arbitrary process / process group ownership on
  144. sockets */
  145. /* Allow binding to any address for transparent proxying (also via NET_RAW) */
  146. /* Allow setting TOS (type of service) */
  147. /* Allow setting promiscuous mode */
  148. /* Allow clearing driver statistics */
  149. /* Allow multicasting */
  150. /* Allow read/write of device-specific registers */
  151. /* Allow activation of ATM control sockets */
  152. #define CAP_NET_ADMIN 12
  153. /* Allow use of RAW sockets */
  154. /* Allow use of PACKET sockets */
  155. /* Allow binding to any address for transparent proxying (also via NET_ADMIN) */
  156. #define CAP_NET_RAW 13
  157. /* Allow locking of shared memory segments */
  158. /* Allow mlock and mlockall (which doesn't really have anything to do
  159. with IPC) */
  160. #define CAP_IPC_LOCK 14
  161. /* Override IPC ownership checks */
  162. #define CAP_IPC_OWNER 15
  163. /* Insert and remove kernel modules - modify kernel without limit */
  164. #define CAP_SYS_MODULE 16
  165. /* Allow ioperm/iopl access */
  166. /* Allow sending USB messages to any device via /dev/bus/usb */
  167. #define CAP_SYS_RAWIO 17
  168. /* Allow use of chroot() */
  169. #define CAP_SYS_CHROOT 18
  170. /* Allow ptrace() of any process */
  171. #define CAP_SYS_PTRACE 19
  172. /* Allow configuration of process accounting */
  173. #define CAP_SYS_PACCT 20
  174. /* Allow configuration of the secure attention key */
  175. /* Allow administration of the random device */
  176. /* Allow examination and configuration of disk quotas */
  177. /* Allow setting the domainname */
  178. /* Allow setting the hostname */
  179. /* Allow mount() and umount(), setting up new smb connection */
  180. /* Allow some autofs root ioctls */
  181. /* Allow nfsservctl */
  182. /* Allow VM86_REQUEST_IRQ */
  183. /* Allow to read/write pci config on alpha */
  184. /* Allow irix_prctl on mips (setstacksize) */
  185. /* Allow flushing all cache on m68k (sys_cacheflush) */
  186. /* Allow removing semaphores */
  187. /* Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores
  188. and shared memory */
  189. /* Allow locking/unlocking of shared memory segment */
  190. /* Allow turning swap on/off */
  191. /* Allow forged pids on socket credentials passing */
  192. /* Allow setting readahead and flushing buffers on block devices */
  193. /* Allow setting geometry in floppy driver */
  194. /* Allow turning DMA on/off in xd driver */
  195. /* Allow administration of md devices (mostly the above, but some
  196. extra ioctls) */
  197. /* Allow tuning the ide driver */
  198. /* Allow access to the nvram device */
  199. /* Allow administration of apm_bios, serial and bttv (TV) device */
  200. /* Allow manufacturer commands in isdn CAPI support driver */
  201. /* Allow reading non-standardized portions of pci configuration space */
  202. /* Allow DDI debug ioctl on sbpcd driver */
  203. /* Allow setting up serial ports */
  204. /* Allow sending raw qic-117 commands */
  205. /* Allow enabling/disabling tagged queuing on SCSI controllers and sending
  206. arbitrary SCSI commands */
  207. /* Allow setting encryption key on loopback filesystem */
  208. /* Allow setting zone reclaim policy */
  209. /* Allow everything under CAP_BPF and CAP_PERFMON for backward compatibility */
  210. #define CAP_SYS_ADMIN 21
  211. /* Allow use of reboot() */
  212. #define CAP_SYS_BOOT 22
  213. /* Allow raising priority and setting priority on other (different
  214. UID) processes */
  215. /* Allow use of FIFO and round-robin (realtime) scheduling on own
  216. processes and setting the scheduling algorithm used by another
  217. process. */
  218. /* Allow setting cpu affinity on other processes */
  219. /* Allow setting realtime ioprio class */
  220. /* Allow setting ioprio class on other processes */
  221. #define CAP_SYS_NICE 23
  222. /* Override resource limits. Set resource limits. */
  223. /* Override quota limits. */
  224. /* Override reserved space on ext2 filesystem */
  225. /* Modify data journaling mode on ext3 filesystem (uses journaling
  226. resources) */
  227. /* NOTE: ext2 honors fsuid when checking for resource overrides, so
  228. you can override using fsuid too */
  229. /* Override size restrictions on IPC message queues */
  230. /* Allow more than 64hz interrupts from the real-time clock */
  231. /* Override max number of consoles on console allocation */
  232. /* Override max number of keymaps */
  233. /* Control memory reclaim behavior */
  234. #define CAP_SYS_RESOURCE 24
  235. /* Allow manipulation of system clock */
  236. /* Allow irix_stime on mips */
  237. /* Allow setting the real-time clock */
  238. #define CAP_SYS_TIME 25
  239. /* Allow configuration of tty devices */
  240. /* Allow vhangup() of tty */
  241. #define CAP_SYS_TTY_CONFIG 26
  242. /* Allow the privileged aspects of mknod() */
  243. #define CAP_MKNOD 27
  244. /* Allow taking of leases on files */
  245. #define CAP_LEASE 28
  246. /* Allow writing the audit log via unicast netlink socket */
  247. #define CAP_AUDIT_WRITE 29
  248. /* Allow configuration of audit via unicast netlink socket */
  249. #define CAP_AUDIT_CONTROL 30
  250. /* Set or remove capabilities on files.
  251. Map uid=0 into a child user namespace. */
  252. #define CAP_SETFCAP 31
  253. /* Override MAC access.
  254. The base kernel enforces no MAC policy.
  255. An LSM may enforce a MAC policy, and if it does and it chooses
  256. to implement capability based overrides of that policy, this is
  257. the capability it should use to do so. */
  258. #define CAP_MAC_OVERRIDE 32
  259. /* Allow MAC configuration or state changes.
  260. The base kernel requires no MAC configuration.
  261. An LSM may enforce a MAC policy, and if it does and it chooses
  262. to implement capability based checks on modifications to that
  263. policy or the data required to maintain it, this is the
  264. capability it should use to do so. */
  265. #define CAP_MAC_ADMIN 33
  266. /* Allow configuring the kernel's syslog (printk behaviour) */
  267. #define CAP_SYSLOG 34
  268. /* Allow triggering something that will wake the system */
  269. #define CAP_WAKE_ALARM 35
  270. /* Allow preventing system suspends */
  271. #define CAP_BLOCK_SUSPEND 36
  272. /* Allow reading the audit log via multicast netlink socket */
  273. #define CAP_AUDIT_READ 37
  274. /*
  275. * Allow system performance and observability privileged operations
  276. * using perf_events, i915_perf and other kernel subsystems
  277. */
  278. #define CAP_PERFMON 38
  279. /*
  280. * CAP_BPF allows the following BPF operations:
  281. * - Creating all types of BPF maps
  282. * - Advanced verifier features
  283. * - Indirect variable access
  284. * - Bounded loops
  285. * - BPF to BPF function calls
  286. * - Scalar precision tracking
  287. * - Larger complexity limits
  288. * - Dead code elimination
  289. * - And potentially other features
  290. * - Loading BPF Type Format (BTF) data
  291. * - Retrieve xlated and JITed code of BPF programs
  292. * - Use bpf_spin_lock() helper
  293. *
  294. * CAP_PERFMON relaxes the verifier checks further:
  295. * - BPF progs can use of pointer-to-integer conversions
  296. * - speculation attack hardening measures are bypassed
  297. * - bpf_probe_read to read arbitrary kernel memory is allowed
  298. * - bpf_trace_printk to print kernel memory is allowed
  299. *
  300. * CAP_SYS_ADMIN is required to use bpf_probe_write_user.
  301. *
  302. * CAP_SYS_ADMIN is required to iterate system wide loaded
  303. * programs, maps, links, BTFs and convert their IDs to file descriptors.
  304. *
  305. * CAP_PERFMON and CAP_BPF are required to load tracing programs.
  306. * CAP_NET_ADMIN and CAP_BPF are required to load networking programs.
  307. */
  308. #define CAP_BPF 39
  309. /* Allow checkpoint/restore related operations */
  310. /* Allow PID selection during clone3() */
  311. /* Allow writing to ns_last_pid */
  312. #define CAP_CHECKPOINT_RESTORE 40
  313. #define CAP_LAST_CAP CAP_CHECKPOINT_RESTORE
  314. #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
  315. /*
  316. * Bit location of each capability (used by user-space library and kernel)
  317. */
  318. #define CAP_TO_INDEX(x) ((x) >> 5) /* 1 << 5 == bits in __u32 */
  319. #define CAP_TO_MASK(x) (1U << ((x) & 31)) /* mask for indexed __u32 */
  320. #endif /* _LINUX_CAPABILITY_H */