capability.h 11 KB

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