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 * https://git.kernel.org/pub/scm/libs/libcap/libcap.git/refs/ 11 * http://www.kernel.org/pub/linux/libs/security/linux-privs/ 12 */ 13 14 #ifndef _UAPI_LINUX_CAPABILITY_H 15 #define _UAPI_LINUX_CAPABILITY_H 16 17 #include <stdint.h> 18 #define __u32 uint32_t 19 #define __le32 __u32 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 /* Note, cap_t, is defined by POSIX (draft) 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_1 0x19980330 33 #define _LINUX_CAPABILITY_U32S_1 1 34 35 #define _LINUX_CAPABILITY_VERSION_2 0x20071026 /* deprecated - use v3 */ 36 #define _LINUX_CAPABILITY_U32S_2 2 37 38 #define _LINUX_CAPABILITY_VERSION_3 0x20080522 39 #define _LINUX_CAPABILITY_U32S_3 2 40 41 typedef struct __user_cap_header_struct { 42 __u32 version; 43 int pid; 44 } *cap_user_header_t; 45 46 typedef struct __user_cap_data_struct { 47 __u32 effective; 48 __u32 permitted; 49 __u32 inheritable; 50 } *cap_user_data_t; 51 52 53 #define VFS_CAP_REVISION_MASK 0xFF000000 54 #define VFS_CAP_REVISION_SHIFT 24 55 #define VFS_CAP_FLAGS_MASK ~VFS_CAP_REVISION_MASK 56 #define VFS_CAP_FLAGS_EFFECTIVE 0x000001 57 58 #define VFS_CAP_REVISION_1 0x01000000 59 #define VFS_CAP_U32_1 1 60 #define XATTR_CAPS_SZ_1 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_1)) 61 62 #define VFS_CAP_REVISION_2 0x02000000 63 #define VFS_CAP_U32_2 2 64 #define XATTR_CAPS_SZ_2 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_2)) 65 66 #define VFS_CAP_REVISION_3 0x03000000 67 #define VFS_CAP_U32_3 VFS_CAP_U32_2 68 #define XATTR_CAPS_SZ_3 (sizeof(__le32)+XATTR_CAPS_SZ_2) 69 70 /* 71 * Kernel capabilities default to v2. The v3 VFS caps are only used, 72 * at present, for namespace specific filesystem capabilities. 73 */ 74 #define XATTR_CAPS_SZ XATTR_CAPS_SZ_2 75 #define VFS_CAP_U32 VFS_CAP_U32_2 76 #define VFS_CAP_REVISION VFS_CAP_REVISION_2 77 78 #define _VFS_CAP_DATA_HEAD \ 79 __le32 magic_etc; /* Little endian */ \ 80 struct { \ 81 __le32 permitted; /* Little endian */ \ 82 __le32 inheritable; /* Little endian */ \ 83 } data[VFS_CAP_U32] 84 85 struct vfs_cap_data { 86 _VFS_CAP_DATA_HEAD; 87 }; 88 89 struct vfs_ns_cap_data { 90 _VFS_CAP_DATA_HEAD; 91 __le32 rootid; 92 }; 93 94 #ifndef __KERNEL__ 95 96 /* 97 * Backwardly compatible definition for source code - trapped in a 98 * 32-bit world. If you find you need this, please consider using 99 * libcap to untrap yourself... 100 */ 101 #define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_1 102 #define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_1 103 104 #endif 105 106 107 /** 108 ** POSIX-draft defined capabilities. 109 **/ 110 111 /* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this 112 overrides the restriction of changing file ownership and group 113 ownership. */ 114 115 #define CAP_CHOWN 0 116 117 /* Override all DAC access, including ACL execute access if 118 [_POSIX_ACL] is defined. Excluding DAC access covered by 119 CAP_LINUX_IMMUTABLE. */ 120 121 #define CAP_DAC_OVERRIDE 1 122 123 /* Overrides all DAC restrictions regarding read and search on files 124 and directories, including ACL restrictions if [_POSIX_ACL] is 125 defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */ 126 127 #define CAP_DAC_READ_SEARCH 2 128 129 /* Overrides all restrictions about allowed operations on files, where 130 file owner ID must be equal to the user ID, except where CAP_FSETID 131 is applicable. It doesn't override MAC and DAC restrictions. */ 132 133 #define CAP_FOWNER 3 134 135 /* Overrides the following restrictions that the effective user ID 136 shall match the file owner ID when setting the S_ISUID and S_ISGID 137 bits on that file; that the effective group ID (or one of the 138 supplementary group IDs) shall match the file owner ID when setting 139 the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are 140 cleared on successful return from chown(2) (not implemented). */ 141 142 #define CAP_FSETID 4 143 144 /* Overrides the restriction that the real or effective user ID of a 145 process sending a signal must match the real or effective user ID 146 of the process receiving the signal. */ 147 148 #define CAP_KILL 5 149 150 /* Allows setgid(2) manipulation */ 151 /* Allows setgroups(2) */ 152 /* Allows forged gids on socket credentials passing. */ 153 154 #define CAP_SETGID 6 155 156 /* Allows set*uid(2) manipulation (including fsuid). */ 157 /* Allows forged pids on socket credentials passing. */ 158 159 #define CAP_SETUID 7 160 161 162 /** 163 ** Linux-specific capabilities 164 **/ 165 166 /* Without VFS support for capabilities: 167 * Transfer any capability in your permitted set to any pid, 168 * remove any capability in your permitted set from any pid 169 * With VFS support for capabilities (neither of above, but) 170 * Add any capability from current's capability bounding set 171 * to the current process' inheritable set 172 * Allow taking bits out of capability bounding set 173 * Allow modification of the securebits for a process 174 */ 175 176 #define CAP_SETPCAP 8 177 178 /* Allow modification of S_IMMUTABLE and S_APPEND file attributes */ 179 180 #define CAP_LINUX_IMMUTABLE 9 181 182 /* Allows binding to TCP/UDP sockets below 1024 */ 183 /* Allows binding to ATM VCIs below 32 */ 184 185 #define CAP_NET_BIND_SERVICE 10 186 187 /* Allow broadcasting, listen to multicast */ 188 189 #define CAP_NET_BROADCAST 11 190 191 /* Allow interface configuration */ 192 /* Allow administration of IP firewall, masquerading and accounting */ 193 /* Allow setting debug option on sockets */ 194 /* Allow modification of routing tables */ 195 /* Allow setting arbitrary process / process group ownership on 196 sockets */ 197 /* Allow binding to any address for transparent proxying (also via NET_RAW) */ 198 /* Allow setting TOS (type of service) */ 199 /* Allow setting promiscuous mode */ 200 /* Allow clearing driver statistics */ 201 /* Allow multicasting */ 202 /* Allow read/write of device-specific registers */ 203 /* Allow activation of ATM control sockets */ 204 205 #define CAP_NET_ADMIN 12 206 207 /* Allow use of RAW sockets */ 208 /* Allow use of PACKET sockets */ 209 /* Allow binding to any address for transparent proxying (also via NET_ADMIN) */ 210 211 #define CAP_NET_RAW 13 212 213 /* Allow locking of shared memory segments */ 214 /* Allow mlock and mlockall (which doesn't really have anything to do 215 with IPC) */ 216 217 #define CAP_IPC_LOCK 14 218 219 /* Override IPC ownership checks */ 220 221 #define CAP_IPC_OWNER 15 222 223 /* Insert and remove kernel modules - modify kernel without limit */ 224 #define CAP_SYS_MODULE 16 225 226 /* Allow ioperm/iopl access */ 227 /* Allow sending USB messages to any device via /dev/bus/usb */ 228 229 #define CAP_SYS_RAWIO 17 230 231 /* Allow use of chroot() */ 232 233 #define CAP_SYS_CHROOT 18 234 235 /* Allow ptrace() of any process */ 236 237 #define CAP_SYS_PTRACE 19 238 239 /* Allow configuration of process accounting */ 240 241 #define CAP_SYS_PACCT 20 242 243 /* Allow configuration of the secure attention key */ 244 /* Allow administration of the random device */ 245 /* Allow examination and configuration of disk quotas */ 246 /* Allow setting the domainname */ 247 /* Allow setting the hostname */ 248 /* Allow calling bdflush() */ 249 /* Allow mount() and umount(), setting up new smb connection */ 250 /* Allow some autofs root ioctls */ 251 /* Allow nfsservctl */ 252 /* Allow VM86_REQUEST_IRQ */ 253 /* Allow to read/write pci config on alpha */ 254 /* Allow irix_prctl on mips (setstacksize) */ 255 /* Allow flushing all cache on m68k (sys_cacheflush) */ 256 /* Allow removing semaphores */ 257 /* Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores 258 and shared memory */ 259 /* Allow locking/unlocking of shared memory segment */ 260 /* Allow turning swap on/off */ 261 /* Allow forged pids on socket credentials passing */ 262 /* Allow setting readahead and flushing buffers on block devices */ 263 /* Allow setting geometry in floppy driver */ 264 /* Allow turning DMA on/off in xd driver */ 265 /* Allow administration of md devices (mostly the above, but some 266 extra ioctls) */ 267 /* Allow tuning the ide driver */ 268 /* Allow access to the nvram device */ 269 /* Allow administration of apm_bios, serial and bttv (TV) device */ 270 /* Allow manufacturer commands in isdn CAPI support driver */ 271 /* Allow reading non-standardized portions of pci configuration space */ 272 /* Allow DDI debug ioctl on sbpcd driver */ 273 /* Allow setting up serial ports */ 274 /* Allow sending raw qic-117 commands */ 275 /* Allow enabling/disabling tagged queuing on SCSI controllers and sending 276 arbitrary SCSI commands */ 277 /* Allow setting encryption key on loopback filesystem */ 278 /* Allow setting zone reclaim policy */ 279 280 #define CAP_SYS_ADMIN 21 281 282 /* Allow use of reboot() */ 283 284 #define CAP_SYS_BOOT 22 285 286 /* Allow raising priority and setting priority on other (different 287 UID) processes */ 288 /* Allow use of FIFO and round-robin (realtime) scheduling on own 289 processes and setting the scheduling algorithm used by another 290 process. */ 291 /* Allow setting cpu affinity on other processes */ 292 293 #define CAP_SYS_NICE 23 294 295 /* Override resource limits. Set resource limits. */ 296 /* Override quota limits. */ 297 /* Override reserved space on ext2 filesystem */ 298 /* Modify data journaling mode on ext3 filesystem (uses journaling 299 resources) */ 300 /* NOTE: ext2 honors fsuid when checking for resource overrides, so 301 you can override using fsuid too */ 302 /* Override size restrictions on IPC message queues */ 303 /* Allow more than 64hz interrupts from the real-time clock */ 304 /* Override max number of consoles on console allocation */ 305 /* Override max number of keymaps */ 306 307 #define CAP_SYS_RESOURCE 24 308 309 /* Allow manipulation of system clock */ 310 /* Allow irix_stime on mips */ 311 /* Allow setting the real-time clock */ 312 313 #define CAP_SYS_TIME 25 314 315 /* Allow configuration of tty devices */ 316 /* Allow vhangup() of tty */ 317 318 #define CAP_SYS_TTY_CONFIG 26 319 320 /* Allow the privileged aspects of mknod() */ 321 322 #define CAP_MKNOD 27 323 324 /* Allow taking of leases on files */ 325 326 #define CAP_LEASE 28 327 328 /* Allow writing the audit log via unicast netlink socket */ 329 330 #define CAP_AUDIT_WRITE 29 331 332 /* Allow configuration of audit via unicast netlink socket */ 333 334 #define CAP_AUDIT_CONTROL 30 335 336 /* Set capabilities on files. */ 337 338 #define CAP_SETFCAP 31 339 340 /* Override MAC access. 341 The base kernel enforces no MAC policy. 342 An LSM may enforce a MAC policy, and if it does and it chooses 343 to implement capability based overrides of that policy, this is 344 the capability it should use to do so. */ 345 346 #define CAP_MAC_OVERRIDE 32 347 348 /* Allow MAC configuration or state changes. 349 The base kernel requires no MAC configuration. 350 An LSM may enforce a MAC policy, and if it does and it chooses 351 to implement capability based checks on modifications to that 352 policy or the data required to maintain it, this is the 353 capability it should use to do so. */ 354 355 #define CAP_MAC_ADMIN 33 356 357 /* Allow configuring the kernel's syslog (printk behaviour) */ 358 359 #define CAP_SYSLOG 34 360 361 /* Allow triggering something that will wake the system */ 362 363 #define CAP_WAKE_ALARM 35 364 365 /* Allow preventing system suspends */ 366 367 #define CAP_BLOCK_SUSPEND 36 368 369 /* Allow reading the audit log via multicast netlink socket */ 370 371 #define CAP_AUDIT_READ 37 372 373 /* Allow system performance and observability privileged operations using 374 * perf_events, i915_perf and other kernel subsystems. */ 375 376 #define CAP_PERFMON 38 377 378 /* 379 * CAP_BPF allows the following BPF operations: 380 * - Creating all types of BPF maps 381 * - Advanced verifier features 382 * - Indirect variable access 383 * - Bounded loops 384 * - BPF to BPF function calls 385 * - Scalar precision tracking 386 * - Larger complexity limits 387 * - Dead code elimination 388 * - And potentially other features 389 * - Loading BPF Type Format (BTF) data 390 * - Retrieve xlated and JITed code of BPF programs 391 * - Use bpf_spin_lock() helper 392 * 393 * CAP_PERFMON relaxes the verifier checks further: 394 * - BPF progs can use of pointer-to-integer conversions 395 * - speculation attack hardening measures are bypassed 396 * - bpf_probe_read to read arbitrary kernel memory is allowed 397 * - bpf_trace_printk to print kernel memory is allowed 398 * 399 * CAP_SYS_ADMIN is required to use bpf_probe_write_user. 400 * 401 * CAP_SYS_ADMIN is required to iterate system wide loaded 402 * programs, maps, links, BTFs and convert their IDs to file descriptors. 403 * 404 * CAP_PERFMON and CAP_BPF are required to load tracing programs. 405 * CAP_NET_ADMIN and CAP_BPF are required to load networking programs. 406 */ 407 408 #define CAP_BPF 39 409 410 /* Allow checkpoint/restore related operations */ 411 /* Allow PID selection during clone3() */ 412 /* Allow writing to ns_last_pid */ 413 414 #define CAP_CHECKPOINT_RESTORE 40 415 416 #define CAP_LAST_CAP CAP_CHECKPOINT_RESTORE 417 418 #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP) 419 420 /* 421 * Bit location of each capability (used by user-space library and kernel) 422 */ 423 424 #define CAP_TO_INDEX(x) ((x) >> 5) /* 1 << 5 == bits in __u32 */ 425 #define CAP_TO_MASK(x) (1u << ((x) & 31)) /* mask for indexed __u32 */ 426 427 #endif /* _UAPI_LINUX_CAPABILITY_H */ 428