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