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