capability.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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://linux.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.6/
  11. */
  12. #ifndef _LINUX_CAPABILITY_H
  13. #define _LINUX_CAPABILITY_H
  14. #include <linux/types.h>
  15. #include <linux/compiler.h>
  16. struct task_struct;
  17. /* User-level do most of the mapping between kernel and user
  18. capabilities based on the version tag given by the kernel. The
  19. kernel might be somewhat backwards compatible, but don't bet on
  20. it. */
  21. /* XXX - Note, cap_t, is defined by POSIX to be an "opaque" pointer to
  22. a set of three capability sets. The transposition of 3*the
  23. following structure to such a composite is better handled in a user
  24. library since the draft standard requires the use of malloc/free
  25. etc.. */
  26. #define _LINUX_CAPABILITY_VERSION 0x19980330
  27. typedef struct __user_cap_header_struct {
  28. __u32 version;
  29. int pid;
  30. } __user *cap_user_header_t;
  31. typedef struct __user_cap_data_struct {
  32. __u32 effective;
  33. __u32 permitted;
  34. __u32 inheritable;
  35. } __user *cap_user_data_t;
  36. #define XATTR_CAPS_SUFFIX "capability"
  37. #define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
  38. #define XATTR_CAPS_SZ (3*sizeof(__le32))
  39. #define VFS_CAP_REVISION_MASK 0xFF000000
  40. #define VFS_CAP_REVISION_1 0x01000000
  41. #define VFS_CAP_REVISION VFS_CAP_REVISION_1
  42. #define VFS_CAP_FLAGS_MASK ~VFS_CAP_REVISION_MASK
  43. #define VFS_CAP_FLAGS_EFFECTIVE 0x000001
  44. struct vfs_cap_data {
  45. __u32 magic_etc; /* Little endian */
  46. __u32 permitted; /* Little endian */
  47. __u32 inheritable; /* Little endian */
  48. };
  49. #ifdef __KERNEL__
  50. /* #define STRICT_CAP_T_TYPECHECKS */
  51. #ifdef STRICT_CAP_T_TYPECHECKS
  52. typedef struct kernel_cap_struct {
  53. __u32 cap;
  54. } kernel_cap_t;
  55. #else
  56. typedef __u32 kernel_cap_t;
  57. #endif
  58. #define _USER_CAP_HEADER_SIZE (2*sizeof(__u32))
  59. #define _KERNEL_CAP_T_SIZE (sizeof(kernel_cap_t))
  60. #endif
  61. /**
  62. ** POSIX-draft defined capabilities.
  63. **/
  64. /* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this
  65. overrides the restriction of changing file ownership and group
  66. ownership. */
  67. #define CAP_CHOWN 0
  68. /* Override all DAC access, including ACL execute access if
  69. [_POSIX_ACL] is defined. Excluding DAC access covered by
  70. CAP_LINUX_IMMUTABLE. */
  71. #define CAP_DAC_OVERRIDE 1
  72. /* Overrides all DAC restrictions regarding read and search on files
  73. and directories, including ACL restrictions if [_POSIX_ACL] is
  74. defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */
  75. #define CAP_DAC_READ_SEARCH 2
  76. /* Overrides all restrictions about allowed operations on files, where
  77. file owner ID must be equal to the user ID, except where CAP_FSETID
  78. is applicable. It doesn't override MAC and DAC restrictions. */
  79. #define CAP_FOWNER 3
  80. /* Overrides the following restrictions that the effective user ID
  81. shall match the file owner ID when setting the S_ISUID and S_ISGID
  82. bits on that file; that the effective group ID (or one of the
  83. supplementary group IDs) shall match the file owner ID when setting
  84. the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are
  85. cleared on successful return from chown(2) (not implemented). */
  86. #define CAP_FSETID 4
  87. /* Used to decide between falling back on the old suser() or fsuser(). */
  88. #define CAP_FS_MASK 0x1f
  89. /* Overrides the restriction that the real or effective user ID of a
  90. process sending a signal must match the real or effective user ID
  91. of the process receiving the signal. */
  92. #define CAP_KILL 5
  93. /* Allows setgid(2) manipulation */
  94. /* Allows setgroups(2) */
  95. /* Allows forged gids on socket credentials passing. */
  96. #define CAP_SETGID 6
  97. /* Allows set*uid(2) manipulation (including fsuid). */
  98. /* Allows forged pids on socket credentials passing. */
  99. #define CAP_SETUID 7
  100. /**
  101. ** Linux-specific capabilities
  102. **/
  103. /* Transfer any capability in your permitted set to any pid,
  104. remove any capability in your permitted set from any pid */
  105. #define CAP_SETPCAP 8
  106. /* Allow modification of S_IMMUTABLE and S_APPEND file attributes */
  107. #define CAP_LINUX_IMMUTABLE 9
  108. /* Allows binding to TCP/UDP sockets below 1024 */
  109. /* Allows binding to ATM VCIs below 32 */
  110. #define CAP_NET_BIND_SERVICE 10
  111. /* Allow broadcasting, listen to multicast */
  112. #define CAP_NET_BROADCAST 11
  113. /* Allow interface configuration */
  114. /* Allow administration of IP firewall, masquerading and accounting */
  115. /* Allow setting debug option on sockets */
  116. /* Allow modification of routing tables */
  117. /* Allow setting arbitrary process / process group ownership on
  118. sockets */
  119. /* Allow binding to any address for transparent proxying */
  120. /* Allow setting TOS (type of service) */
  121. /* Allow setting promiscuous mode */
  122. /* Allow clearing driver statistics */
  123. /* Allow multicasting */
  124. /* Allow read/write of device-specific registers */
  125. /* Allow activation of ATM control sockets */
  126. #define CAP_NET_ADMIN 12
  127. /* Allow use of RAW sockets */
  128. /* Allow use of PACKET sockets */
  129. #define CAP_NET_RAW 13
  130. /* Allow locking of shared memory segments */
  131. /* Allow mlock and mlockall (which doesn't really have anything to do
  132. with IPC) */
  133. #define CAP_IPC_LOCK 14
  134. /* Override IPC ownership checks */
  135. #define CAP_IPC_OWNER 15
  136. /* Insert and remove kernel modules - modify kernel without limit */
  137. /* Modify cap_bset */
  138. #define CAP_SYS_MODULE 16
  139. /* Allow ioperm/iopl access */
  140. /* Allow sending USB messages to any device via /proc/bus/usb */
  141. #define CAP_SYS_RAWIO 17
  142. /* Allow use of chroot() */
  143. #define CAP_SYS_CHROOT 18
  144. /* Allow ptrace() of any process */
  145. #define CAP_SYS_PTRACE 19
  146. /* Allow configuration of process accounting */
  147. #define CAP_SYS_PACCT 20
  148. /* Allow configuration of the secure attention key */
  149. /* Allow administration of the random device */
  150. /* Allow examination and configuration of disk quotas */
  151. /* Allow configuring the kernel's syslog (printk behaviour) */
  152. /* Allow setting the domainname */
  153. /* Allow setting the hostname */
  154. /* Allow calling bdflush() */
  155. /* Allow mount() and umount(), setting up new smb connection */
  156. /* Allow some autofs root ioctls */
  157. /* Allow nfsservctl */
  158. /* Allow VM86_REQUEST_IRQ */
  159. /* Allow to read/write pci config on alpha */
  160. /* Allow irix_prctl on mips (setstacksize) */
  161. /* Allow flushing all cache on m68k (sys_cacheflush) */
  162. /* Allow removing semaphores */
  163. /* Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores
  164. and shared memory */
  165. /* Allow locking/unlocking of shared memory segment */
  166. /* Allow turning swap on/off */
  167. /* Allow forged pids on socket credentials passing */
  168. /* Allow setting readahead and flushing buffers on block devices */
  169. /* Allow setting geometry in floppy driver */
  170. /* Allow turning DMA on/off in xd driver */
  171. /* Allow administration of md devices (mostly the above, but some
  172. extra ioctls) */
  173. /* Allow tuning the ide driver */
  174. /* Allow access to the nvram device */
  175. /* Allow administration of apm_bios, serial and bttv (TV) device */
  176. /* Allow manufacturer commands in isdn CAPI support driver */
  177. /* Allow reading non-standardized portions of pci configuration space */
  178. /* Allow DDI debug ioctl on sbpcd driver */
  179. /* Allow setting up serial ports */
  180. /* Allow sending raw qic-117 commands */
  181. /* Allow enabling/disabling tagged queuing on SCSI controllers and sending
  182. arbitrary SCSI commands */
  183. /* Allow setting encryption key on loopback filesystem */
  184. /* Allow setting zone reclaim policy */
  185. #define CAP_SYS_ADMIN 21
  186. /* Allow use of reboot() */
  187. #define CAP_SYS_BOOT 22
  188. /* Allow raising priority and setting priority on other (different
  189. UID) processes */
  190. /* Allow use of FIFO and round-robin (realtime) scheduling on own
  191. processes and setting the scheduling algorithm used by another
  192. process. */
  193. /* Allow setting cpu affinity on other processes */
  194. #define CAP_SYS_NICE 23
  195. /* Override resource limits. Set resource limits. */
  196. /* Override quota limits. */
  197. /* Override reserved space on ext2 filesystem */
  198. /* Modify data journaling mode on ext3 filesystem (uses journaling
  199. resources) */
  200. /* NOTE: ext2 honors fsuid when checking for resource overrides, so
  201. you can override using fsuid too */
  202. /* Override size restrictions on IPC message queues */
  203. /* Allow more than 64hz interrupts from the real-time clock */
  204. /* Override max number of consoles on console allocation */
  205. /* Override max number of keymaps */
  206. #define CAP_SYS_RESOURCE 24
  207. /* Allow manipulation of system clock */
  208. /* Allow irix_stime on mips */
  209. /* Allow setting the real-time clock */
  210. #define CAP_SYS_TIME 25
  211. /* Allow configuration of tty devices */
  212. /* Allow vhangup() of tty */
  213. #define CAP_SYS_TTY_CONFIG 26
  214. /* Allow the privileged aspects of mknod() */
  215. #define CAP_MKNOD 27
  216. /* Allow taking of leases on files */
  217. #define CAP_LEASE 28
  218. #define CAP_AUDIT_WRITE 29
  219. #define CAP_AUDIT_CONTROL 30
  220. #define CAP_SETFCAP 31
  221. #ifdef __KERNEL__
  222. /*
  223. * Internal kernel functions only
  224. */
  225. #ifdef STRICT_CAP_T_TYPECHECKS
  226. #define to_cap_t(x) { x }
  227. #define cap_t(x) (x).cap
  228. #else
  229. #define to_cap_t(x) (x)
  230. #define cap_t(x) (x)
  231. #endif
  232. #define CAP_EMPTY_SET to_cap_t(0)
  233. #define CAP_FULL_SET to_cap_t(~0)
  234. #define CAP_INIT_EFF_SET to_cap_t(~0 & ~CAP_TO_MASK(CAP_SETPCAP))
  235. #define CAP_INIT_INH_SET to_cap_t(0)
  236. #define CAP_TO_MASK(x) (1 << (x))
  237. #define cap_raise(c, flag) (cap_t(c) |= CAP_TO_MASK(flag))
  238. #define cap_lower(c, flag) (cap_t(c) &= ~CAP_TO_MASK(flag))
  239. #define cap_raised(c, flag) (cap_t(c) & CAP_TO_MASK(flag))
  240. static inline kernel_cap_t cap_combine(kernel_cap_t a, kernel_cap_t b)
  241. {
  242. kernel_cap_t dest;
  243. cap_t(dest) = cap_t(a) | cap_t(b);
  244. return dest;
  245. }
  246. static inline kernel_cap_t cap_intersect(kernel_cap_t a, kernel_cap_t b)
  247. {
  248. kernel_cap_t dest;
  249. cap_t(dest) = cap_t(a) & cap_t(b);
  250. return dest;
  251. }
  252. static inline kernel_cap_t cap_drop(kernel_cap_t a, kernel_cap_t drop)
  253. {
  254. kernel_cap_t dest;
  255. cap_t(dest) = cap_t(a) & ~cap_t(drop);
  256. return dest;
  257. }
  258. static inline kernel_cap_t cap_invert(kernel_cap_t c)
  259. {
  260. kernel_cap_t dest;
  261. cap_t(dest) = ~cap_t(c);
  262. return dest;
  263. }
  264. #define cap_isclear(c) (!cap_t(c))
  265. #define cap_issubset(a,set) (!(cap_t(a) & ~cap_t(set)))
  266. #define cap_clear(c) do { cap_t(c) = 0; } while(0)
  267. #define cap_set_full(c) do { cap_t(c) = ~0; } while(0)
  268. #define cap_mask(c,mask) do { cap_t(c) &= cap_t(mask); } while(0)
  269. #define cap_is_fs_cap(c) (CAP_TO_MASK(c) & CAP_FS_MASK)
  270. int capable(int cap);
  271. int __capable(struct task_struct *t, int cap);
  272. #endif /* __KERNEL__ */
  273. #endif /* !_LINUX_CAPABILITY_H */