11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * This is <linux/capability.h> 31da177e4SLinus Torvalds * 4b5376771SSerge E. Hallyn * Andrew G. Morgan <[email protected]> 51da177e4SLinus Torvalds * Alexander Kjeldaas <[email protected]> 61da177e4SLinus Torvalds * with help from Aleph1, Roland Buresund and Andrew Main. 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * See here for the libcap library ("POSIX draft" compliance): 91da177e4SLinus Torvalds * 10b5376771SSerge E. Hallyn * ftp://linux.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.6/ 111da177e4SLinus Torvalds */ 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds #ifndef _LINUX_CAPABILITY_H 141da177e4SLinus Torvalds #define _LINUX_CAPABILITY_H 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #include <linux/types.h> 171da177e4SLinus Torvalds 18b7add02dSAndrew Morton struct task_struct; 19b7add02dSAndrew Morton 201da177e4SLinus Torvalds /* User-level do most of the mapping between kernel and user 211da177e4SLinus Torvalds capabilities based on the version tag given by the kernel. The 221da177e4SLinus Torvalds kernel might be somewhat backwards compatible, but don't bet on 231da177e4SLinus Torvalds it. */ 241da177e4SLinus Torvalds 25e338d263SAndrew Morgan /* Note, cap_t, is defined by POSIX (draft) to be an "opaque" pointer to 261da177e4SLinus Torvalds a set of three capability sets. The transposition of 3*the 271da177e4SLinus Torvalds following structure to such a composite is better handled in a user 281da177e4SLinus Torvalds library since the draft standard requires the use of malloc/free 291da177e4SLinus Torvalds etc.. */ 301da177e4SLinus Torvalds 31e338d263SAndrew Morgan #define _LINUX_CAPABILITY_VERSION_1 0x19980330 32e338d263SAndrew Morgan #define _LINUX_CAPABILITY_U32S_1 1 33e338d263SAndrew Morgan 34ca05a99aSAndrew G. Morgan #define _LINUX_CAPABILITY_VERSION_2 0x20071026 /* deprecated - use v3 */ 35e338d263SAndrew Morgan #define _LINUX_CAPABILITY_U32S_2 2 36e338d263SAndrew Morgan 37ca05a99aSAndrew G. Morgan #define _LINUX_CAPABILITY_VERSION_3 0x20080522 38ca05a99aSAndrew G. Morgan #define _LINUX_CAPABILITY_U32S_3 2 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds typedef struct __user_cap_header_struct { 411da177e4SLinus Torvalds __u32 version; 421da177e4SLinus Torvalds int pid; 431da177e4SLinus Torvalds } __user *cap_user_header_t; 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds typedef struct __user_cap_data_struct { 461da177e4SLinus Torvalds __u32 effective; 471da177e4SLinus Torvalds __u32 permitted; 481da177e4SLinus Torvalds __u32 inheritable; 491da177e4SLinus Torvalds } __user *cap_user_data_t; 501da177e4SLinus Torvalds 51e338d263SAndrew Morgan 52b5376771SSerge E. Hallyn #define XATTR_CAPS_SUFFIX "capability" 53b5376771SSerge E. Hallyn #define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX 541da177e4SLinus Torvalds 55b5376771SSerge E. Hallyn #define VFS_CAP_REVISION_MASK 0xFF000000 56851f7ff5SEric Paris #define VFS_CAP_REVISION_SHIFT 24 57b5376771SSerge E. Hallyn #define VFS_CAP_FLAGS_MASK ~VFS_CAP_REVISION_MASK 58b5376771SSerge E. Hallyn #define VFS_CAP_FLAGS_EFFECTIVE 0x000001 59b5376771SSerge E. Hallyn 60e338d263SAndrew Morgan #define VFS_CAP_REVISION_1 0x01000000 61e338d263SAndrew Morgan #define VFS_CAP_U32_1 1 62e338d263SAndrew Morgan #define XATTR_CAPS_SZ_1 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_1)) 63e338d263SAndrew Morgan 64e338d263SAndrew Morgan #define VFS_CAP_REVISION_2 0x02000000 65e338d263SAndrew Morgan #define VFS_CAP_U32_2 2 66e338d263SAndrew Morgan #define XATTR_CAPS_SZ_2 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_2)) 67e338d263SAndrew Morgan 68e338d263SAndrew Morgan #define XATTR_CAPS_SZ XATTR_CAPS_SZ_2 69e338d263SAndrew Morgan #define VFS_CAP_U32 VFS_CAP_U32_2 70e338d263SAndrew Morgan #define VFS_CAP_REVISION VFS_CAP_REVISION_2 71e338d263SAndrew Morgan 72b5376771SSerge E. Hallyn struct vfs_cap_data { 73e338d263SAndrew Morgan __le32 magic_etc; /* Little endian */ 748f6936f4SAndrew Morton struct { 75e338d263SAndrew Morgan __le32 permitted; /* Little endian */ 76e338d263SAndrew Morgan __le32 inheritable; /* Little endian */ 77e338d263SAndrew Morgan } data[VFS_CAP_U32]; 78b5376771SSerge E. Hallyn }; 79b5376771SSerge E. Hallyn 80ca05a99aSAndrew G. Morgan #ifndef __KERNEL__ 81ca05a99aSAndrew G. Morgan 82ca05a99aSAndrew G. Morgan /* 83ca05a99aSAndrew G. Morgan * Backwardly compatible definition for source code - trapped in a 84ca05a99aSAndrew G. Morgan * 32-bit world. If you find you need this, please consider using 85ca05a99aSAndrew G. Morgan * libcap to untrap yourself... 86ca05a99aSAndrew G. Morgan */ 87ca05a99aSAndrew G. Morgan #define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_1 88ca05a99aSAndrew G. Morgan #define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_1 89ca05a99aSAndrew G. Morgan 90ca05a99aSAndrew G. Morgan #else 91ca05a99aSAndrew G. Morgan 92ca05a99aSAndrew G. Morgan #define _KERNEL_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_3 93ca05a99aSAndrew G. Morgan #define _KERNEL_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_3 941da177e4SLinus Torvalds 959fa91d99SJaswinder Singh Rajput #ifdef CONFIG_SECURITY_FILE_CAPABILITIES 969fa91d99SJaswinder Singh Rajput extern int file_caps_enabled; 979fa91d99SJaswinder Singh Rajput #endif 989fa91d99SJaswinder Singh Rajput 991da177e4SLinus Torvalds typedef struct kernel_cap_struct { 100ca05a99aSAndrew G. Morgan __u32 cap[_KERNEL_CAPABILITY_U32S]; 1011da177e4SLinus Torvalds } kernel_cap_t; 1021da177e4SLinus Torvalds 103c0b00441SEric Paris /* exact same as vfs_cap_data but in cpu endian and always filled completely */ 104c0b00441SEric Paris struct cpu_vfs_cap_data { 105c0b00441SEric Paris __u32 magic_etc; 106c0b00441SEric Paris kernel_cap_t permitted; 107c0b00441SEric Paris kernel_cap_t inheritable; 108c0b00441SEric Paris }; 109c0b00441SEric Paris 110e338d263SAndrew Morgan #define _USER_CAP_HEADER_SIZE (sizeof(struct __user_cap_header_struct)) 1111da177e4SLinus Torvalds #define _KERNEL_CAP_T_SIZE (sizeof(kernel_cap_t)) 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds #endif 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds /** 1171da177e4SLinus Torvalds ** POSIX-draft defined capabilities. 1181da177e4SLinus Torvalds **/ 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds /* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this 1211da177e4SLinus Torvalds overrides the restriction of changing file ownership and group 1221da177e4SLinus Torvalds ownership. */ 1231da177e4SLinus Torvalds 1241da177e4SLinus Torvalds #define CAP_CHOWN 0 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds /* Override all DAC access, including ACL execute access if 1271da177e4SLinus Torvalds [_POSIX_ACL] is defined. Excluding DAC access covered by 1281da177e4SLinus Torvalds CAP_LINUX_IMMUTABLE. */ 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds #define CAP_DAC_OVERRIDE 1 1311da177e4SLinus Torvalds 1321da177e4SLinus Torvalds /* Overrides all DAC restrictions regarding read and search on files 1331da177e4SLinus Torvalds and directories, including ACL restrictions if [_POSIX_ACL] is 1341da177e4SLinus Torvalds defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */ 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds #define CAP_DAC_READ_SEARCH 2 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds /* Overrides all restrictions about allowed operations on files, where 1391da177e4SLinus Torvalds file owner ID must be equal to the user ID, except where CAP_FSETID 1401da177e4SLinus Torvalds is applicable. It doesn't override MAC and DAC restrictions. */ 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds #define CAP_FOWNER 3 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds /* Overrides the following restrictions that the effective user ID 1451da177e4SLinus Torvalds shall match the file owner ID when setting the S_ISUID and S_ISGID 1461da177e4SLinus Torvalds bits on that file; that the effective group ID (or one of the 1471da177e4SLinus Torvalds supplementary group IDs) shall match the file owner ID when setting 1481da177e4SLinus Torvalds the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are 1491da177e4SLinus Torvalds cleared on successful return from chown(2) (not implemented). */ 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds #define CAP_FSETID 4 1521da177e4SLinus Torvalds 1531da177e4SLinus Torvalds /* Overrides the restriction that the real or effective user ID of a 1541da177e4SLinus Torvalds process sending a signal must match the real or effective user ID 1551da177e4SLinus Torvalds of the process receiving the signal. */ 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds #define CAP_KILL 5 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds /* Allows setgid(2) manipulation */ 1601da177e4SLinus Torvalds /* Allows setgroups(2) */ 1611da177e4SLinus Torvalds /* Allows forged gids on socket credentials passing. */ 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds #define CAP_SETGID 6 1641da177e4SLinus Torvalds 1651da177e4SLinus Torvalds /* Allows set*uid(2) manipulation (including fsuid). */ 1661da177e4SLinus Torvalds /* Allows forged pids on socket credentials passing. */ 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds #define CAP_SETUID 7 1691da177e4SLinus Torvalds 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds /** 1721da177e4SLinus Torvalds ** Linux-specific capabilities 1731da177e4SLinus Torvalds **/ 1741da177e4SLinus Torvalds 175e338d263SAndrew Morgan /* Without VFS support for capabilities: 176e338d263SAndrew Morgan * Transfer any capability in your permitted set to any pid, 177e338d263SAndrew Morgan * remove any capability in your permitted set from any pid 178e338d263SAndrew Morgan * With VFS support for capabilities (neither of above, but) 1793b7391deSSerge E. Hallyn * Add any capability from current's capability bounding set 1803b7391deSSerge E. Hallyn * to the current process' inheritable set 1813b7391deSSerge E. Hallyn * Allow taking bits out of capability bounding set 1823898b1b4SAndrew G. Morgan * Allow modification of the securebits for a process 183e338d263SAndrew Morgan */ 1841da177e4SLinus Torvalds 1851da177e4SLinus Torvalds #define CAP_SETPCAP 8 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds /* Allow modification of S_IMMUTABLE and S_APPEND file attributes */ 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds #define CAP_LINUX_IMMUTABLE 9 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds /* Allows binding to TCP/UDP sockets below 1024 */ 1921da177e4SLinus Torvalds /* Allows binding to ATM VCIs below 32 */ 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds #define CAP_NET_BIND_SERVICE 10 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds /* Allow broadcasting, listen to multicast */ 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds #define CAP_NET_BROADCAST 11 1991da177e4SLinus Torvalds 2001da177e4SLinus Torvalds /* Allow interface configuration */ 2011da177e4SLinus Torvalds /* Allow administration of IP firewall, masquerading and accounting */ 2021da177e4SLinus Torvalds /* Allow setting debug option on sockets */ 2031da177e4SLinus Torvalds /* Allow modification of routing tables */ 2041da177e4SLinus Torvalds /* Allow setting arbitrary process / process group ownership on 2051da177e4SLinus Torvalds sockets */ 2061da177e4SLinus Torvalds /* Allow binding to any address for transparent proxying */ 2071da177e4SLinus Torvalds /* Allow setting TOS (type of service) */ 2081da177e4SLinus Torvalds /* Allow setting promiscuous mode */ 2091da177e4SLinus Torvalds /* Allow clearing driver statistics */ 2101da177e4SLinus Torvalds /* Allow multicasting */ 2111da177e4SLinus Torvalds /* Allow read/write of device-specific registers */ 2121da177e4SLinus Torvalds /* Allow activation of ATM control sockets */ 2131da177e4SLinus Torvalds 2141da177e4SLinus Torvalds #define CAP_NET_ADMIN 12 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds /* Allow use of RAW sockets */ 2171da177e4SLinus Torvalds /* Allow use of PACKET sockets */ 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds #define CAP_NET_RAW 13 2201da177e4SLinus Torvalds 2211da177e4SLinus Torvalds /* Allow locking of shared memory segments */ 2221da177e4SLinus Torvalds /* Allow mlock and mlockall (which doesn't really have anything to do 2231da177e4SLinus Torvalds with IPC) */ 2241da177e4SLinus Torvalds 2251da177e4SLinus Torvalds #define CAP_IPC_LOCK 14 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds /* Override IPC ownership checks */ 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds #define CAP_IPC_OWNER 15 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds /* Insert and remove kernel modules - modify kernel without limit */ 2321da177e4SLinus Torvalds #define CAP_SYS_MODULE 16 2331da177e4SLinus Torvalds 2341da177e4SLinus Torvalds /* Allow ioperm/iopl access */ 2351da177e4SLinus Torvalds /* Allow sending USB messages to any device via /proc/bus/usb */ 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds #define CAP_SYS_RAWIO 17 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds /* Allow use of chroot() */ 2401da177e4SLinus Torvalds 2411da177e4SLinus Torvalds #define CAP_SYS_CHROOT 18 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds /* Allow ptrace() of any process */ 2441da177e4SLinus Torvalds 2451da177e4SLinus Torvalds #define CAP_SYS_PTRACE 19 2461da177e4SLinus Torvalds 2471da177e4SLinus Torvalds /* Allow configuration of process accounting */ 2481da177e4SLinus Torvalds 2491da177e4SLinus Torvalds #define CAP_SYS_PACCT 20 2501da177e4SLinus Torvalds 2511da177e4SLinus Torvalds /* Allow configuration of the secure attention key */ 2521da177e4SLinus Torvalds /* Allow administration of the random device */ 2531da177e4SLinus Torvalds /* Allow examination and configuration of disk quotas */ 2541da177e4SLinus Torvalds /* Allow configuring the kernel's syslog (printk behaviour) */ 2551da177e4SLinus Torvalds /* Allow setting the domainname */ 2561da177e4SLinus Torvalds /* Allow setting the hostname */ 2571da177e4SLinus Torvalds /* Allow calling bdflush() */ 2581da177e4SLinus Torvalds /* Allow mount() and umount(), setting up new smb connection */ 2591da177e4SLinus Torvalds /* Allow some autofs root ioctls */ 2601da177e4SLinus Torvalds /* Allow nfsservctl */ 2611da177e4SLinus Torvalds /* Allow VM86_REQUEST_IRQ */ 2621da177e4SLinus Torvalds /* Allow to read/write pci config on alpha */ 2631da177e4SLinus Torvalds /* Allow irix_prctl on mips (setstacksize) */ 2641da177e4SLinus Torvalds /* Allow flushing all cache on m68k (sys_cacheflush) */ 2651da177e4SLinus Torvalds /* Allow removing semaphores */ 2661da177e4SLinus Torvalds /* Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores 2671da177e4SLinus Torvalds and shared memory */ 2681da177e4SLinus Torvalds /* Allow locking/unlocking of shared memory segment */ 2691da177e4SLinus Torvalds /* Allow turning swap on/off */ 2701da177e4SLinus Torvalds /* Allow forged pids on socket credentials passing */ 2711da177e4SLinus Torvalds /* Allow setting readahead and flushing buffers on block devices */ 2721da177e4SLinus Torvalds /* Allow setting geometry in floppy driver */ 2731da177e4SLinus Torvalds /* Allow turning DMA on/off in xd driver */ 2741da177e4SLinus Torvalds /* Allow administration of md devices (mostly the above, but some 2751da177e4SLinus Torvalds extra ioctls) */ 2761da177e4SLinus Torvalds /* Allow tuning the ide driver */ 2771da177e4SLinus Torvalds /* Allow access to the nvram device */ 2781da177e4SLinus Torvalds /* Allow administration of apm_bios, serial and bttv (TV) device */ 2791da177e4SLinus Torvalds /* Allow manufacturer commands in isdn CAPI support driver */ 2801da177e4SLinus Torvalds /* Allow reading non-standardized portions of pci configuration space */ 2811da177e4SLinus Torvalds /* Allow DDI debug ioctl on sbpcd driver */ 2821da177e4SLinus Torvalds /* Allow setting up serial ports */ 2831da177e4SLinus Torvalds /* Allow sending raw qic-117 commands */ 2841da177e4SLinus Torvalds /* Allow enabling/disabling tagged queuing on SCSI controllers and sending 2851da177e4SLinus Torvalds arbitrary SCSI commands */ 2861da177e4SLinus Torvalds /* Allow setting encryption key on loopback filesystem */ 287bce5f6baSMartin Hicks /* Allow setting zone reclaim policy */ 2881da177e4SLinus Torvalds 2891da177e4SLinus Torvalds #define CAP_SYS_ADMIN 21 2901da177e4SLinus Torvalds 2911da177e4SLinus Torvalds /* Allow use of reboot() */ 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds #define CAP_SYS_BOOT 22 2941da177e4SLinus Torvalds 2951da177e4SLinus Torvalds /* Allow raising priority and setting priority on other (different 2961da177e4SLinus Torvalds UID) processes */ 2971da177e4SLinus Torvalds /* Allow use of FIFO and round-robin (realtime) scheduling on own 2981da177e4SLinus Torvalds processes and setting the scheduling algorithm used by another 2991da177e4SLinus Torvalds process. */ 3001da177e4SLinus Torvalds /* Allow setting cpu affinity on other processes */ 3011da177e4SLinus Torvalds 3021da177e4SLinus Torvalds #define CAP_SYS_NICE 23 3031da177e4SLinus Torvalds 3041da177e4SLinus Torvalds /* Override resource limits. Set resource limits. */ 3051da177e4SLinus Torvalds /* Override quota limits. */ 3061da177e4SLinus Torvalds /* Override reserved space on ext2 filesystem */ 3071da177e4SLinus Torvalds /* Modify data journaling mode on ext3 filesystem (uses journaling 3081da177e4SLinus Torvalds resources) */ 3091da177e4SLinus Torvalds /* NOTE: ext2 honors fsuid when checking for resource overrides, so 3101da177e4SLinus Torvalds you can override using fsuid too */ 3111da177e4SLinus Torvalds /* Override size restrictions on IPC message queues */ 3121da177e4SLinus Torvalds /* Allow more than 64hz interrupts from the real-time clock */ 3131da177e4SLinus Torvalds /* Override max number of consoles on console allocation */ 3141da177e4SLinus Torvalds /* Override max number of keymaps */ 3151da177e4SLinus Torvalds 3161da177e4SLinus Torvalds #define CAP_SYS_RESOURCE 24 3171da177e4SLinus Torvalds 3181da177e4SLinus Torvalds /* Allow manipulation of system clock */ 3191da177e4SLinus Torvalds /* Allow irix_stime on mips */ 3201da177e4SLinus Torvalds /* Allow setting the real-time clock */ 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds #define CAP_SYS_TIME 25 3231da177e4SLinus Torvalds 3241da177e4SLinus Torvalds /* Allow configuration of tty devices */ 3251da177e4SLinus Torvalds /* Allow vhangup() of tty */ 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds #define CAP_SYS_TTY_CONFIG 26 3281da177e4SLinus Torvalds 3291da177e4SLinus Torvalds /* Allow the privileged aspects of mknod() */ 3301da177e4SLinus Torvalds 3311da177e4SLinus Torvalds #define CAP_MKNOD 27 3321da177e4SLinus Torvalds 3331da177e4SLinus Torvalds /* Allow taking of leases on files */ 3341da177e4SLinus Torvalds 3351da177e4SLinus Torvalds #define CAP_LEASE 28 3361da177e4SLinus Torvalds 3371da177e4SLinus Torvalds #define CAP_AUDIT_WRITE 29 3381da177e4SLinus Torvalds 3391da177e4SLinus Torvalds #define CAP_AUDIT_CONTROL 30 3401da177e4SLinus Torvalds 341b5376771SSerge E. Hallyn #define CAP_SETFCAP 31 342b5376771SSerge E. Hallyn 343e114e473SCasey Schaufler /* Override MAC access. 344e114e473SCasey Schaufler The base kernel enforces no MAC policy. 345e114e473SCasey Schaufler An LSM may enforce a MAC policy, and if it does and it chooses 346e114e473SCasey Schaufler to implement capability based overrides of that policy, this is 347e114e473SCasey Schaufler the capability it should use to do so. */ 348e114e473SCasey Schaufler 349e114e473SCasey Schaufler #define CAP_MAC_OVERRIDE 32 350e114e473SCasey Schaufler 351e114e473SCasey Schaufler /* Allow MAC configuration or state changes. 352e114e473SCasey Schaufler The base kernel requires no MAC configuration. 353e114e473SCasey Schaufler An LSM may enforce a MAC policy, and if it does and it chooses 354e114e473SCasey Schaufler to implement capability based checks on modifications to that 355e114e473SCasey Schaufler policy or the data required to maintain it, this is the 356e114e473SCasey Schaufler capability it should use to do so. */ 357e114e473SCasey Schaufler 358e114e473SCasey Schaufler #define CAP_MAC_ADMIN 33 359e114e473SCasey Schaufler 360e114e473SCasey Schaufler #define CAP_LAST_CAP CAP_MAC_ADMIN 3613b7391deSSerge E. Hallyn 3623b7391deSSerge E. Hallyn #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP) 3633b7391deSSerge E. Hallyn 364e338d263SAndrew Morgan /* 365e338d263SAndrew Morgan * Bit location of each capability (used by user-space library and kernel) 366e338d263SAndrew Morgan */ 367e338d263SAndrew Morgan 368e338d263SAndrew Morgan #define CAP_TO_INDEX(x) ((x) >> 5) /* 1 << 5 == bits in __u32 */ 369e338d263SAndrew Morgan #define CAP_TO_MASK(x) (1 << ((x) & 31)) /* mask for indexed __u32 */ 370e338d263SAndrew Morgan 3711da177e4SLinus Torvalds #ifdef __KERNEL__ 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvalds /* 3741da177e4SLinus Torvalds * Internal kernel functions only 3751da177e4SLinus Torvalds */ 3761da177e4SLinus Torvalds 377e338d263SAndrew Morgan #define CAP_FOR_EACH_U32(__capi) \ 378ca05a99aSAndrew G. Morgan for (__capi = 0; __capi < _KERNEL_CAPABILITY_U32S; ++__capi) 3791da177e4SLinus Torvalds 380e338d263SAndrew Morgan # define CAP_FS_MASK_B0 (CAP_TO_MASK(CAP_CHOWN) \ 381e338d263SAndrew Morgan | CAP_TO_MASK(CAP_DAC_OVERRIDE) \ 382e338d263SAndrew Morgan | CAP_TO_MASK(CAP_DAC_READ_SEARCH) \ 383e338d263SAndrew Morgan | CAP_TO_MASK(CAP_FOWNER) \ 384e338d263SAndrew Morgan | CAP_TO_MASK(CAP_FSETID)) 3851da177e4SLinus Torvalds 386e114e473SCasey Schaufler # define CAP_FS_MASK_B1 (CAP_TO_MASK(CAP_MAC_OVERRIDE)) 387e114e473SCasey Schaufler 388ca05a99aSAndrew G. Morgan #if _KERNEL_CAPABILITY_U32S != 2 389e338d263SAndrew Morgan # error Fix up hand-coded capability macro initializers 390e338d263SAndrew Morgan #else /* HAND-CODED capability initializers */ 3911da177e4SLinus Torvalds 39225f2ea9fSDavid Howells # define CAP_EMPTY_SET ((kernel_cap_t){{ 0, 0 }}) 39325f2ea9fSDavid Howells # define CAP_FULL_SET ((kernel_cap_t){{ ~0, ~0 }}) 39425f2ea9fSDavid Howells # define CAP_INIT_EFF_SET ((kernel_cap_t){{ ~CAP_TO_MASK(CAP_SETPCAP), ~0 }}) 39525f2ea9fSDavid Howells # define CAP_FS_SET ((kernel_cap_t){{ CAP_FS_MASK_B0, CAP_FS_MASK_B1 } }) 396*76a67ec6SJ. Bruce Fields # define CAP_NFSD_SET ((kernel_cap_t){{ CAP_FS_MASK_B0 \ 397*76a67ec6SJ. Bruce Fields | CAP_TO_MASK(CAP_SYS_RESOURCE) \ 398*76a67ec6SJ. Bruce Fields | CAP_TO_MASK(CAP_MKNOD), \ 39925f2ea9fSDavid Howells CAP_FS_MASK_B1 } }) 4001da177e4SLinus Torvalds 401ca05a99aSAndrew G. Morgan #endif /* _KERNEL_CAPABILITY_U32S != 2 */ 4021da177e4SLinus Torvalds 403e338d263SAndrew Morgan #define CAP_INIT_INH_SET CAP_EMPTY_SET 4041da177e4SLinus Torvalds 405e338d263SAndrew Morgan # define cap_clear(c) do { (c) = __cap_empty_set; } while (0) 406e338d263SAndrew Morgan # define cap_set_full(c) do { (c) = __cap_full_set; } while (0) 407e338d263SAndrew Morgan # define cap_set_init_eff(c) do { (c) = __cap_init_eff_set; } while (0) 4081da177e4SLinus Torvalds 409e338d263SAndrew Morgan #define cap_raise(c, flag) ((c).cap[CAP_TO_INDEX(flag)] |= CAP_TO_MASK(flag)) 410e338d263SAndrew Morgan #define cap_lower(c, flag) ((c).cap[CAP_TO_INDEX(flag)] &= ~CAP_TO_MASK(flag)) 411e338d263SAndrew Morgan #define cap_raised(c, flag) ((c).cap[CAP_TO_INDEX(flag)] & CAP_TO_MASK(flag)) 412e338d263SAndrew Morgan 413e338d263SAndrew Morgan #define CAP_BOP_ALL(c, a, b, OP) \ 414e338d263SAndrew Morgan do { \ 415e338d263SAndrew Morgan unsigned __capi; \ 416e338d263SAndrew Morgan CAP_FOR_EACH_U32(__capi) { \ 417e338d263SAndrew Morgan c.cap[__capi] = a.cap[__capi] OP b.cap[__capi]; \ 418e338d263SAndrew Morgan } \ 419e338d263SAndrew Morgan } while (0) 420e338d263SAndrew Morgan 421e338d263SAndrew Morgan #define CAP_UOP_ALL(c, a, OP) \ 422e338d263SAndrew Morgan do { \ 423e338d263SAndrew Morgan unsigned __capi; \ 424e338d263SAndrew Morgan CAP_FOR_EACH_U32(__capi) { \ 425e338d263SAndrew Morgan c.cap[__capi] = OP a.cap[__capi]; \ 426e338d263SAndrew Morgan } \ 427e338d263SAndrew Morgan } while (0) 428e338d263SAndrew Morgan 429e338d263SAndrew Morgan static inline kernel_cap_t cap_combine(const kernel_cap_t a, 430e338d263SAndrew Morgan const kernel_cap_t b) 4311da177e4SLinus Torvalds { 4321da177e4SLinus Torvalds kernel_cap_t dest; 433e338d263SAndrew Morgan CAP_BOP_ALL(dest, a, b, |); 4341da177e4SLinus Torvalds return dest; 4351da177e4SLinus Torvalds } 4361da177e4SLinus Torvalds 437e338d263SAndrew Morgan static inline kernel_cap_t cap_intersect(const kernel_cap_t a, 438e338d263SAndrew Morgan const kernel_cap_t b) 4391da177e4SLinus Torvalds { 4401da177e4SLinus Torvalds kernel_cap_t dest; 441e338d263SAndrew Morgan CAP_BOP_ALL(dest, a, b, &); 4421da177e4SLinus Torvalds return dest; 4431da177e4SLinus Torvalds } 4441da177e4SLinus Torvalds 445e338d263SAndrew Morgan static inline kernel_cap_t cap_drop(const kernel_cap_t a, 446e338d263SAndrew Morgan const kernel_cap_t drop) 4471da177e4SLinus Torvalds { 4481da177e4SLinus Torvalds kernel_cap_t dest; 449e338d263SAndrew Morgan CAP_BOP_ALL(dest, a, drop, &~); 4501da177e4SLinus Torvalds return dest; 4511da177e4SLinus Torvalds } 4521da177e4SLinus Torvalds 453e338d263SAndrew Morgan static inline kernel_cap_t cap_invert(const kernel_cap_t c) 4541da177e4SLinus Torvalds { 4551da177e4SLinus Torvalds kernel_cap_t dest; 456e338d263SAndrew Morgan CAP_UOP_ALL(dest, c, ~); 4571da177e4SLinus Torvalds return dest; 4581da177e4SLinus Torvalds } 4591da177e4SLinus Torvalds 460e338d263SAndrew Morgan static inline int cap_isclear(const kernel_cap_t a) 461e338d263SAndrew Morgan { 462e338d263SAndrew Morgan unsigned __capi; 463e338d263SAndrew Morgan CAP_FOR_EACH_U32(__capi) { 464e338d263SAndrew Morgan if (a.cap[__capi] != 0) 465e338d263SAndrew Morgan return 0; 466e338d263SAndrew Morgan } 467e338d263SAndrew Morgan return 1; 468e338d263SAndrew Morgan } 4691da177e4SLinus Torvalds 4709d36be76SEric Paris /* 4719d36be76SEric Paris * Check if "a" is a subset of "set". 4729d36be76SEric Paris * return 1 if ALL of the capabilities in "a" are also in "set" 4739d36be76SEric Paris * cap_issubset(0101, 1111) will return 1 4749d36be76SEric Paris * return 0 if ANY of the capabilities in "a" are not in "set" 4759d36be76SEric Paris * cap_issubset(1111, 0101) will return 0 4769d36be76SEric Paris */ 477e338d263SAndrew Morgan static inline int cap_issubset(const kernel_cap_t a, const kernel_cap_t set) 478e338d263SAndrew Morgan { 479e338d263SAndrew Morgan kernel_cap_t dest; 480e338d263SAndrew Morgan dest = cap_drop(a, set); 481e338d263SAndrew Morgan return cap_isclear(dest); 482e338d263SAndrew Morgan } 4831da177e4SLinus Torvalds 484e338d263SAndrew Morgan /* Used to decide between falling back on the old suser() or fsuser(). */ 485e338d263SAndrew Morgan 486e338d263SAndrew Morgan static inline int cap_is_fs_cap(int cap) 487e338d263SAndrew Morgan { 488e338d263SAndrew Morgan const kernel_cap_t __cap_fs_set = CAP_FS_SET; 489e338d263SAndrew Morgan return !!(CAP_TO_MASK(cap) & __cap_fs_set.cap[CAP_TO_INDEX(cap)]); 490e338d263SAndrew Morgan } 491e338d263SAndrew Morgan 492e338d263SAndrew Morgan static inline kernel_cap_t cap_drop_fs_set(const kernel_cap_t a) 493e338d263SAndrew Morgan { 494e338d263SAndrew Morgan const kernel_cap_t __cap_fs_set = CAP_FS_SET; 495e338d263SAndrew Morgan return cap_drop(a, __cap_fs_set); 496e338d263SAndrew Morgan } 497e338d263SAndrew Morgan 498e338d263SAndrew Morgan static inline kernel_cap_t cap_raise_fs_set(const kernel_cap_t a, 499e338d263SAndrew Morgan const kernel_cap_t permitted) 500e338d263SAndrew Morgan { 501e338d263SAndrew Morgan const kernel_cap_t __cap_fs_set = CAP_FS_SET; 502e338d263SAndrew Morgan return cap_combine(a, 503e338d263SAndrew Morgan cap_intersect(permitted, __cap_fs_set)); 504e338d263SAndrew Morgan } 505e338d263SAndrew Morgan 506e338d263SAndrew Morgan static inline kernel_cap_t cap_drop_nfsd_set(const kernel_cap_t a) 507e338d263SAndrew Morgan { 508e338d263SAndrew Morgan const kernel_cap_t __cap_fs_set = CAP_NFSD_SET; 509e338d263SAndrew Morgan return cap_drop(a, __cap_fs_set); 510e338d263SAndrew Morgan } 511e338d263SAndrew Morgan 512e338d263SAndrew Morgan static inline kernel_cap_t cap_raise_nfsd_set(const kernel_cap_t a, 513e338d263SAndrew Morgan const kernel_cap_t permitted) 514e338d263SAndrew Morgan { 515e338d263SAndrew Morgan const kernel_cap_t __cap_nfsd_set = CAP_NFSD_SET; 516e338d263SAndrew Morgan return cap_combine(a, 517e338d263SAndrew Morgan cap_intersect(permitted, __cap_nfsd_set)); 518e338d263SAndrew Morgan } 519e338d263SAndrew Morgan 520e338d263SAndrew Morgan extern const kernel_cap_t __cap_empty_set; 521e338d263SAndrew Morgan extern const kernel_cap_t __cap_full_set; 522e338d263SAndrew Morgan extern const kernel_cap_t __cap_init_eff_set; 5231da177e4SLinus Torvalds 5245cd9c58fSDavid Howells /** 5255cd9c58fSDavid Howells * has_capability - Determine if a task has a superior capability available 5265cd9c58fSDavid Howells * @t: The task in question 5275cd9c58fSDavid Howells * @cap: The capability to be tested for 5285cd9c58fSDavid Howells * 5295cd9c58fSDavid Howells * Return true if the specified task has the given superior capability 5305cd9c58fSDavid Howells * currently in effect, false if not. 5315cd9c58fSDavid Howells * 5325cd9c58fSDavid Howells * Note that this does not set PF_SUPERPRIV on the task. 5335cd9c58fSDavid Howells */ 5343699c53cSDavid Howells #define has_capability(t, cap) (security_real_capable((t), (cap)) == 0) 5353699c53cSDavid Howells 5363699c53cSDavid Howells /** 5373699c53cSDavid Howells * has_capability_noaudit - Determine if a task has a superior capability available (unaudited) 5383699c53cSDavid Howells * @t: The task in question 5393699c53cSDavid Howells * @cap: The capability to be tested for 5403699c53cSDavid Howells * 5413699c53cSDavid Howells * Return true if the specified task has the given superior capability 5423699c53cSDavid Howells * currently in effect, false if not, but don't write an audit message for the 5433699c53cSDavid Howells * check. 5443699c53cSDavid Howells * 5453699c53cSDavid Howells * Note that this does not set PF_SUPERPRIV on the task. 5463699c53cSDavid Howells */ 5473699c53cSDavid Howells #define has_capability_noaudit(t, cap) \ 5483699c53cSDavid Howells (security_real_capable_noaudit((t), (cap)) == 0) 5495cd9c58fSDavid Howells 5505cd9c58fSDavid Howells extern int capable(int cap); 551c59ede7bSRandy.Dunlap 552851f7ff5SEric Paris /* audit system wants to get cap info from files as well */ 553851f7ff5SEric Paris struct dentry; 554851f7ff5SEric Paris extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps); 555851f7ff5SEric Paris 5561da177e4SLinus Torvalds #endif /* __KERNEL__ */ 5571da177e4SLinus Torvalds 5581da177e4SLinus Torvalds #endif /* !_LINUX_CAPABILITY_H */ 559