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