capability.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /*
  2. * This is <linux/capability.h>
  3. *
  4. * Andrew G. Morgan <morgan@kernel.org>
  5. * Alexander Kjeldaas <astor@guardian.no>
  6. * with help from Aleph1, Roland Buresund and Andrew Main.
  7. *
  8. * See here for the libcap library ("POSIX draft" compliance):
  9. *
  10. * ftp://www.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.6/
  11. */
  12. #ifndef _UAPI_LINUX_CAPABILITY_H
  13. #define _UAPI_LINUX_CAPABILITY_H
  14. #include <linux/types.h>
  15. struct task_struct;
  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. } __user *cap_user_header_t;
  35. typedef struct __user_cap_data_struct {
  36. __u32 effective;
  37. __u32 permitted;
  38. __u32 inheritable;
  39. } __user *cap_user_data_t;
  40. #define VFS_CAP_REVISION_MASK 0xFF000000
  41. #define VFS_CAP_REVISION_SHIFT 24
  42. #define VFS_CAP_FLAGS_MASK ~VFS_CAP_REVISION_MASK
  43. #define VFS_CAP_FLAGS_EFFECTIVE 0x000001
  44. #define VFS_CAP_REVISION_1 0x01000000
  45. #define VFS_CAP_U32_1 1
  46. #define XATTR_CAPS_SZ_1 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_1))
  47. #define VFS_CAP_REVISION_2 0x02000000
  48. #define VFS_CAP_U32_2 2
  49. #define XATTR_CAPS_SZ_2 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_2))
  50. #define XATTR_CAPS_SZ XATTR_CAPS_SZ_2
  51. #define VFS_CAP_U32 VFS_CAP_U32_2
  52. #define VFS_CAP_REVISION VFS_CAP_REVISION_2
  53. struct vfs_cap_data {
  54. __le32 magic_etc; /* Little endian */
  55. struct {
  56. __le32 permitted; /* Little endian */
  57. __le32 inheritable; /* Little endian */
  58. } data[VFS_CAP_U32];
  59. };
  60. #ifndef __KERNEL__
  61. /*
  62. * Backwardly compatible definition for source code - trapped in a
  63. * 32-bit world. If you find you need this, please consider using
  64. * libcap to untrap yourself...
  65. */
  66. #define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_1
  67. #define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_1
  68. #endif
  69. /**
  70. ** POSIX-draft defined capabilities.
  71. **/
  72. /* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this
  73. overrides the restriction of changing file ownership and group
  74. ownership. */
  75. #define CAP_CHOWN 0
  76. /* Override all DAC access, including ACL execute access if
  77. [_POSIX_ACL] is defined. Excluding DAC access covered by
  78. CAP_LINUX_IMMUTABLE. */
  79. #define CAP_DAC_OVERRIDE 1
  80. /* Overrides all DAC restrictions regarding read and search on files
  81. and directories, including ACL restrictions if [_POSIX_ACL] is
  82. defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */
  83. #define CAP_DAC_READ_SEARCH 2
  84. /* Overrides all restrictions about allowed operations on files, where
  85. file owner ID must be equal to the user ID, except where CAP_FSETID
  86. is applicable. It doesn't override MAC and DAC restrictions. */
  87. #define CAP_FOWNER 3
  88. /* Overrides the following restrictions that the effective user ID
  89. shall match the file owner ID when setting the S_ISUID and S_ISGID
  90. bits on that file; that the effective group ID (or one of the
  91. supplementary group IDs) shall match the file owner ID when setting
  92. the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are
  93. cleared on successful return from chown(2) (not implemented). */
  94. #define CAP_FSETID 4
  95. /* Overrides the restriction that the real or effective user ID of a
  96. process sending a signal must match the real or effective user ID
  97. of the process receiving the signal. */
  98. #define CAP_KILL 5
  99. /* Allows setgid(2) manipulation */
  100. /* Allows setgroups(2) */
  101. /* Allows forged gids on socket credentials passing. */
  102. #define CAP_SETGID 6
  103. /* Allows set*uid(2) manipulation (including fsuid). */
  104. /* Allows forged pids on socket credentials passing. */
  105. #define CAP_SETUID 7
  106. /**
  107. ** Linux-specific capabilities
  108. **/
  109. /* Without VFS support for capabilities:
  110. * Transfer any capability in your permitted set to any pid,
  111. * remove any capability in your permitted set from any pid
  112. * With VFS support for capabilities (neither of above, but)
  113. * Add any capability from current's capability bounding set
  114. * to the current process' inheritable set
  115. * Allow taking bits out of capability bounding set
  116. * Allow modification of the securebits for a process
  117. */
  118. #define CAP_SETPCAP 8
  119. /* Allow modification of S_IMMUTABLE and S_APPEND file attributes */
  120. #define CAP_LINUX_IMMUTABLE 9
  121. /* Allows binding to TCP/UDP sockets below 1024 */
  122. /* Allows binding to ATM VCIs below 32 */
  123. #define CAP_NET_BIND_SERVICE 10
  124. /* Allow broadcasting, listen to multicast */
  125. #define CAP_NET_BROADCAST 11
  126. /* Allow interface configuration */
  127. /* Allow administration of IP firewall, masquerading and accounting */
  128. /* Allow setting debug option on sockets */
  129. /* Allow modification of routing tables */
  130. /* Allow setting arbitrary process / process group ownership on
  131. sockets */
  132. /* Allow binding to any address for transparent proxying (also via NET_RAW) */
  133. /* Allow setting TOS (type of service) */
  134. /* Allow setting promiscuous mode */
  135. /* Allow clearing driver statistics */
  136. /* Allow multicasting */
  137. /* Allow read/write of device-specific registers */
  138. /* Allow activation of ATM control sockets */
  139. #define CAP_NET_ADMIN 12
  140. /* Allow use of RAW sockets */
  141. /* Allow use of PACKET sockets */
  142. /* Allow binding to any address for transparent proxying (also via NET_ADMIN) */
  143. #define CAP_NET_RAW 13
  144. /* Allow locking of shared memory segments */
  145. /* Allow mlock and mlockall (which doesn't really have anything to do
  146. with IPC) */
  147. #define CAP_IPC_LOCK 14
  148. /* Override IPC ownership checks */
  149. #define CAP_IPC_OWNER 15
  150. /* Insert and remove kernel modules - modify kernel without limit */
  151. #define CAP_SYS_MODULE 16
  152. /* Allow ioperm/iopl access */
  153. /* Allow sending USB messages to any device via /proc/bus/usb */
  154. #define CAP_SYS_RAWIO 17
  155. /* Allow use of chroot() */
  156. #define CAP_SYS_CHROOT 18
  157. /* Allow ptrace() of any process */
  158. #define CAP_SYS_PTRACE 19
  159. /* Allow configuration of process accounting */
  160. #define CAP_SYS_PACCT 20
  161. /* Allow configuration of the secure attention key */
  162. /* Allow administration of the random device */
  163. /* Allow examination and configuration of disk quotas */
  164. /* Allow setting the domainname */
  165. /* Allow setting the hostname */
  166. /* Allow calling bdflush() */
  167. /* Allow mount() and umount(), setting up new smb connection */
  168. /* Allow some autofs root ioctls */
  169. /* Allow nfsservctl */
  170. /* Allow VM86_REQUEST_IRQ */
  171. /* Allow to read/write pci config on alpha */
  172. /* Allow irix_prctl on mips (setstacksize) */
  173. /* Allow flushing all cache on m68k (sys_cacheflush) */
  174. /* Allow removing semaphores */
  175. /* Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores
  176. and shared memory */
  177. /* Allow locking/unlocking of shared memory segment */
  178. /* Allow turning swap on/off */
  179. /* Allow forged pids on socket credentials passing */
  180. /* Allow setting readahead and flushing buffers on block devices */
  181. /* Allow setting geometry in floppy driver */
  182. /* Allow turning DMA on/off in xd driver */
  183. /* Allow administration of md devices (mostly the above, but some
  184. extra ioctls) */
  185. /* Allow tuning the ide driver */
  186. /* Allow access to the nvram device */
  187. /* Allow administration of apm_bios, serial and bttv (TV) device */
  188. /* Allow manufacturer commands in isdn CAPI support driver */
  189. /* Allow reading non-standardized portions of pci configuration space */
  190. /* Allow DDI debug ioctl on sbpcd driver */
  191. /* Allow setting up serial ports */
  192. /* Allow sending raw qic-117 commands */
  193. /* Allow enabling/disabling tagged queuing on SCSI controllers and sending
  194. arbitrary SCSI commands */
  195. /* Allow setting encryption key on loopback filesystem */
  196. /* Allow setting zone reclaim policy */
  197. #define CAP_SYS_ADMIN 21
  198. /* Allow use of reboot() */
  199. #define CAP_SYS_BOOT 22
  200. /* Allow raising priority and setting priority on other (different
  201. UID) processes */
  202. /* Allow use of FIFO and round-robin (realtime) scheduling on own
  203. processes and setting the scheduling algorithm used by another
  204. process. */
  205. /* Allow setting cpu affinity on other processes */
  206. #define CAP_SYS_NICE 23
  207. /* Override resource limits. Set resource limits. */
  208. /* Override quota limits. */
  209. /* Override reserved space on ext2 filesystem */
  210. /* Modify data journaling mode on ext3 filesystem (uses journaling
  211. resources) */
  212. /* NOTE: ext2 honors fsuid when checking for resource overrides, so
  213. you can override using fsuid too */
  214. /* Override size restrictions on IPC message queues */
  215. /* Allow more than 64hz interrupts from the real-time clock */
  216. /* Override max number of consoles on console allocation */
  217. /* Override max number of keymaps */
  218. #define CAP_SYS_RESOURCE 24
  219. /* Allow manipulation of system clock */
  220. /* Allow irix_stime on mips */
  221. /* Allow setting the real-time clock */
  222. #define CAP_SYS_TIME 25
  223. /* Allow configuration of tty devices */
  224. /* Allow vhangup() of tty */
  225. #define CAP_SYS_TTY_CONFIG 26
  226. /* Allow the privileged aspects of mknod() */
  227. #define CAP_MKNOD 27
  228. /* Allow taking of leases on files */
  229. #define CAP_LEASE 28
  230. /* Allow writing the audit log via unicast netlink socket */
  231. #define CAP_AUDIT_WRITE 29
  232. /* Allow configuration of audit via unicast netlink socket */
  233. #define CAP_AUDIT_CONTROL 30
  234. #define CAP_SETFCAP 31
  235. /* Override MAC access.
  236. The base kernel enforces no MAC policy.
  237. An LSM may enforce a MAC policy, and if it does and it chooses
  238. to implement capability based overrides of that policy, this is
  239. the capability it should use to do so. */
  240. #define CAP_MAC_OVERRIDE 32
  241. /* Allow MAC configuration or state changes.
  242. The base kernel requires no MAC configuration.
  243. An LSM may enforce a MAC policy, and if it does and it chooses
  244. to implement capability based checks on modifications to that
  245. policy or the data required to maintain it, this is the
  246. capability it should use to do so. */
  247. #define CAP_MAC_ADMIN 33
  248. /* Allow configuring the kernel's syslog (printk behaviour) */
  249. #define CAP_SYSLOG 34
  250. /* Allow triggering something that will wake the system */
  251. #define CAP_WAKE_ALARM 35
  252. /* Allow preventing system suspends */
  253. #define CAP_BLOCK_SUSPEND 36
  254. /* Allow reading the audit log via multicast netlink socket */
  255. #define CAP_AUDIT_READ 37
  256. #define CAP_LAST_CAP CAP_AUDIT_READ
  257. #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
  258. /*
  259. * Bit location of each capability (used by user-space library and kernel)
  260. */
  261. #define CAP_TO_INDEX(x) ((x) >> 5) /* 1 << 5 == bits in __u32 */
  262. #define CAP_TO_MASK(x) (1 << ((x) & 31)) /* mask for indexed __u32 */
  263. #endif /* _UAPI_LINUX_CAPABILITY_H */