|CAPABILITIES(7)||Linux Programmer's Manual||CAPABILITIES(7)|
NAME¶capabilities - overview of Linux capabilities
DESCRIPTION¶For the purpose of performing permission checks, traditional UNIX implementations distinguish two categories of processes: privileged processes (whose effective user ID is 0, referred to as superuser or root), and unprivileged processes (whose effective UID is nonzero). Privileged processes bypass all kernel permission checks, while unprivileged processes are subject to full permission checking based on the process's credentials (usually: effective UID, effective GID, and supplementary group list).
Capabilities list¶The following list shows the capabilities implemented on Linux, and the operations or behaviors that each capability permits:
- CAP_AUDIT_CONTROL (since Linux 2.6.11)
- Enable and disable kernel auditing; change auditing filter rules; retrieve auditing status and filtering rules.
- CAP_AUDIT_READ (since Linux 3.16)
- Allow reading the audit log via a multicast netlink socket.
- CAP_AUDIT_WRITE (since Linux 2.6.11)
- Write records to kernel auditing log.
- CAP_BLOCK_SUSPEND (since Linux 3.5)
- Employ features that can block system suspend (epoll(7) EPOLLWAKEUP, /proc/sys/wake_lock).
- Make arbitrary changes to file UIDs and GIDs (see chown(2)).
- Bypass file read, write, and execute permission checks. (DAC is an abbreviation of "discretionary access control".)
- Bypass file read permission checks and directory read and execute permission checks;
- Invoke open_by_handle_at(2).
- Bypass permission checks on operations that normally require the filesystem UID of the process to match the UID of the file (e.g., chmod(2), utime(2)), excluding those operations covered by CAP_DAC_OVERRIDE and CAP_DAC_READ_SEARCH;
- set extended file attributes (see chattr(1)) on arbitrary files;
- set Access Control Lists (ACLs) on arbitrary files;
- ignore directory sticky bit on file deletion;
- Don't clear set-user-ID and set-group-ID permission bits when a file is modified; set the set-group-ID bit for a file whose GID does not match the filesystem or any of the supplementary GIDs of the calling process.
- Bypass permission checks for operations on System V IPC objects.
- Bypass permission checks for sending signals (see kill(2)). This includes use of the ioctl(2) KDSIGACCEPT operation.
- CAP_LEASE (since Linux 2.4)
- Establish leases on arbitrary files (see fcntl(2)).
- Set the FS_APPEND_FL and FS_IMMUTABLE_FL i-node flags (see chattr(1)).
- CAP_MAC_ADMIN (since Linux 2.6.25)
- Override Mandatory Access Control (MAC). Implemented for the Smack Linux Security Module (LSM).
- CAP_MAC_OVERRIDE (since Linux 2.6.25)
- Allow MAC configuration or state changes. Implemented for the Smack LSM.
- CAP_MKNOD (since Linux 2.4)
- Create special files using mknod(2).
- Perform various network-related operations:
- interface configuration;
- administration of IP firewall, masquerading, and accounting;
- modify routing tables;
- bind to any address for transparent proxying;
- set type-of-service (TOS)
- clear driver statistics;
- set promiscuous mode;
- enabling multicasting;
- use setsockopt(2) to set the following socket options: SO_DEBUG, SO_MARK, SO_PRIORITY (for a priority outside the range 0 to 6), SO_RCVBUFFORCE, and SO_SNDBUFFORCE.
- Bind a socket to Internet domain privileged ports (port numbers less than 1024).
- (Unused) Make socket broadcasts, and listen to multicasts.
- use RAW and PACKET sockets;
- bind to any address for transparent proxying.
- Make arbitrary manipulations of process GIDs and supplementary GID list; forge GID when passing socket credentials via UNIX domain sockets; write a group ID mapping in a user namespace (see user_namespaces(7)).
- CAP_SETFCAP (since Linux 2.6.24)
- Set file capabilities.
- If file capabilities are not supported: grant or remove any
capability in the caller's permitted capability set to or from any other
process. (This property of CAP_SETPCAP is not available when the
kernel is configured to support file capabilities, since
CAP_SETPCAP has entirely different semantics for such kernels.)
- Make arbitrary manipulations of process UIDs (setuid(2), setreuid(2), setresuid(2), setfsuid(2)); forge UID when passing socket credentials via UNIX domain sockets; write a user ID mapping in a user namespace (see user_namespaces(7)).
- Perform a range of system administration operations including: quotactl(2), mount(2), umount(2), swapon(2), swapoff(2), sethostname(2), and setdomainname(2);
- perform privileged syslog(2) operations (since Linux 2.6.37, CAP_SYSLOG should be used to permit such operations);
- perform VM86_REQUEST_IRQ vm86(2) command;
- perform IPC_SET and IPC_RMID operations on arbitrary System V IPC objects;
- override RLIMIT_NPROC resource limit;
- perform operations on trusted and security Extended Attributes (see attr(5));
- use lookup_dcookie(2);
- use ioprio_set(2) to assign IOPRIO_CLASS_RT and (before Linux 2.6.25) IOPRIO_CLASS_IDLE I/O scheduling classes;
- forge UID when passing socket credentials;
- exceed /proc/sys/fs/file-max, the system-wide limit on the number of open files, in system calls that open files (e.g., accept(2), execve(2), open(2), pipe(2));
- employ CLONE_* flags that create new namespaces with clone(2) and unshare(2) (but, since Linux 3.8, creating user namespaces does not require any capability);
- call perf_event_open(2);
- access privileged perf event information;
- call setns(2) (requires CAP_SYS_ADMIN in the target namespace);
- call fanotify_init(2);
- perform KEYCTL_CHOWN and KEYCTL_SETPERM keyctl(2) operations;
- perform madvise(2) MADV_HWPOISON operation;
- employ the TIOCSTI ioctl(2) to insert characters into the input queue of a terminal other than the caller's controlling terminal;
- employ the obsolete nfsservctl(2) system call;
- employ the obsolete bdflush(2) system call;
- perform various privileged block-device ioctl(2) operations;
- perform various privileged filesystem ioctl(2) operations;
- perform administrative operations on many device drivers.
- Use chroot(2).
- Load and unload kernel modules (see init_module(2) and delete_module(2)); in kernels before 2.6.25: drop capabilities from the system-wide capability bounding set.
- Raise process nice value (nice(2), setpriority(2)) and change the nice value for arbitrary processes;
- set real-time scheduling policies for calling process, and set scheduling policies and priorities for arbitrary processes (sched_setscheduler(2), sched_setparam(2), shed_setattr(2));
- set CPU affinity for arbitrary processes (sched_setaffinity(2));
- set I/O scheduling class and priority for arbitrary processes (ioprio_set(2));
- apply migrate_pages(2) to arbitrary processes and allow processes to be migrated to arbitrary nodes;
- apply move_pages(2) to arbitrary processes;
- Use acct(2).
- Trace arbitrary processes using ptrace(2);
- apply get_robust_list(2) to arbitrary processes;
- transfer data to or from the memory of arbitrary processes using process_vm_readv(2) and process_vm_writev(2).
- inspect processes using kcmp(2).
- access /proc/kcore;
- employ the FIBMAP ioctl(2) operation;
- open devices for accessing x86 model-specific registers (MSRs, see msr(4))
- update /proc/sys/vm/mmap_min_addr;
- create memory mappings at addresses below the value specified by /proc/sys/vm/mmap_min_addr;
- map files in /proc/bus/pci;
- open /dev/mem and /dev/kmem;
- perform various SCSI device commands;
- perform a range of device-specific operations on other devices.
- Use reserved space on ext2 filesystems;
- make ioctl(2) calls controlling ext3 journaling;
- override disk quota limits;
- increase resource limits (see setrlimit(2));
- override RLIMIT_NPROC resource limit;
- override maximum number of consoles on console allocation;
- override maximum number of keymaps;
- allow more than 64hz interrupts from the real-time clock;
- raise msg_qbytes limit for a System V message queue above the limit in /proc/sys/kernel/msgmnb (see msgop(2) and msgctl(2));
- override the /proc/sys/fs/pipe-size-max limit when setting the capacity of a pipe using the F_SETPIPE_SZ fcntl(2) command.
- use F_SETPIPE_SZ to increase the capacity of a pipe above the limit specified by /proc/sys/fs/pipe-max-size;
- override /proc/sys/fs/mqueue/queues_max limit when creating POSIX message queues (see mq_overview(7));
- employ prctl(2) PR_SET_MM operation;
- set /proc/PID/oom_score_adj to a value lower than the value last set by a process with CAP_SYS_RESOURCE.
- Set system clock (settimeofday(2), stime(2), adjtimex(2)); set real-time (hardware) clock.
- Use vhangup(2); employ various privileged ioctl(2) operations on virtual terminals.
- CAP_SYSLOG (since Linux 2.6.37)
- Perform privileged syslog(2) operations. See syslog(2) for information on which operations require privilege.
- View kernel addresses exposed via /proc and other interfaces when /proc/sys/kernel/kptr_restrict has the value 1. (See the discussion of the kptr_restrict in proc(5).)
- CAP_WAKE_ALARM (since Linux 3.0)
- Trigger something that will wake up the system (set CLOCK_REALTIME_ALARM and CLOCK_BOOTTIME_ALARM timers).
Past and current implementation¶A full implementation of capabilities requires that:
- For all privileged operations, the kernel must check whether the thread has the required capability in its effective set.
- The kernel must provide system calls allowing a thread's capability sets to be changed and retrieved.
- The filesystem must support attaching capabilities to an executable file, so that a process gains those capabilities when the file is executed.
Thread capability sets¶Each thread has three capability sets containing zero or more of the above capabilities:
- This is a limiting superset for the effective capabilities
that the thread may assume. It is also a limiting superset for the
capabilities that may be added to the inheritable set by a thread that
does not have the CAP_SETPCAP capability in its effective set.
- This is a set of capabilities preserved across an execve(2). It provides a mechanism for a process to assign capabilities to the permitted set of the new program during an execve(2).
- This is the set of capabilities used by the kernel to perform permission checks for the thread.
File capabilities¶Since kernel 2.6.24, the kernel supports associating capability sets with an executable file using setcap(8). The file capability sets are stored in an extended attribute (see setxattr(2)) named security.capability. Writing to this extended attribute requires the CAP_SETFCAP capability. The file capability sets, in conjunction with the capability sets of the thread, determine the capabilities of a thread after an execve(2).
- Permitted (formerly known as forced):
- These capabilities are automatically permitted to the thread, regardless of the thread's inheritable capabilities.
- Inheritable (formerly known as allowed):
- This set is ANDed with the thread's inheritable set to determine which inheritable capabilities are enabled in the permitted set of the thread after the execve(2).
- This is not a set, but rather just a single bit. If this
bit is set, then during an execve(2) all of the new permitted
capabilities for the thread are also raised in the effective set. If this
bit is not set, then after an execve(2), none of the new permitted
capabilities is in the new effective set.
Transformation of capabilities during execve()¶During an execve(2), the kernel calculates the new capabilities of the process using the following algorithm:
P'(permitted) = (P(inheritable) & F(inheritable)) | (F(permitted) & cap_bset) P'(effective) = F(effective) ? P'(permitted) : 0 P'(inheritable) = P(inheritable) [i.e., unchanged]
- denotes the value of a thread capability set before the execve(2)
- denotes the value of a capability set after the execve(2)
- denotes a file capability set
- is the value of the capability bounding set (described below).
Capabilities and execution of programs by root¶In order to provide an all-powerful root using capability sets, during an execve(2):
- If a set-user-ID-root program is being executed, or the real user ID of the process is 0 (root) then the file inheritable and permitted sets are defined to be all ones (i.e., all capabilities enabled).
- If a set-user-ID-root program is being executed, then the file effective bit is defined to be one (enabled).
Capability bounding set¶The capability bounding set is a security mechanism that can be used to limit the capabilities that can be gained during an execve(2). The bounding set is used in the following ways:
- During an execve(2), the capability bounding set is ANDed with the file permitted capability set, and the result of this operation is assigned to the thread's permitted capability set. The capability bounding set thus places a limit on the permitted capabilities that may be granted by an executable file.
- (Since Linux 2.6.25) The capability bounding set acts as a limiting superset for the capabilities that a thread can add to its inheritable set using capset(2). This means that if a capability is not in the bounding set, then a thread can't add this capability to its inheritable set, even if it was in its permitted capabilities, and thereby cannot have this capability preserved in its permitted set when it execve(2)s a file that has the capability in its inheritable set.
Effect of user ID changes on capabilities¶To preserve the traditional semantics for transitions between 0 and nonzero user IDs, the kernel makes the following changes to a thread's capability sets on changes to the thread's real, effective, saved set, and filesystem user IDs (using setuid(2), setresuid(2), or similar):
- If one or more of the real, effective or saved set user IDs was previously 0, and as a result of the UID changes all of these IDs have a nonzero value, then all capabilities are cleared from the permitted and effective capability sets.
- If the effective user ID is changed from 0 to nonzero, then all capabilities are cleared from the effective set.
- If the effective user ID is changed from nonzero to 0, then the permitted set is copied to the effective set.
- If the filesystem user ID is changed from 0 to nonzero (see setfsuid(2)), then the following capabilities are cleared from the effective set: CAP_CHOWN, CAP_DAC_OVERRIDE, CAP_DAC_READ_SEARCH, CAP_FOWNER, CAP_FSETID, CAP_LINUX_IMMUTABLE (since Linux 2.6.30), CAP_MAC_OVERRIDE, and CAP_MKNOD (since Linux 2.6.30). If the filesystem UID is changed from nonzero to 0, then any of these capabilities that are enabled in the permitted set are enabled in the effective set.
Programmatically adjusting capability sets¶A thread can retrieve and change its capability sets using the capget(2) and capset(2) system calls. However, the use of cap_get_proc(3) and cap_set_proc(3), both provided in the libcap package, is preferred for this purpose. The following rules govern changes to the thread capability sets:
- If the caller does not have the CAP_SETPCAP capability, the new inheritable set must be a subset of the combination of the existing inheritable and permitted sets.
- (Since Linux 2.6.25) The new inheritable set must be a subset of the combination of the existing inheritable set and the capability bounding set.
- The new permitted set must be a subset of the existing permitted set (i.e., it is not possible to acquire permitted capabilities that the thread does not currently have).
- The new effective set must be a subset of the new permitted set.
The securebits flags: establishing a capabilities-only environment¶Starting with kernel 2.6.26, and with a kernel in which file capabilities are enabled, Linux implements a set of per-thread securebits flags that can be used to disable special handling of capabilities for UID 0 (root). These flags are as follows:
- Setting this flag allows a thread that has one or more 0 UIDs to retain its capabilities when it switches all of its UIDs to a nonzero value. If this flag is not set, then such a UID switch causes the thread to lose all capabilities. This flag is always cleared on an execve(2). (This flag provides the same functionality as the older prctl(2) PR_SET_KEEPCAPS operation.)
- Setting this flag stops the kernel from adjusting capability sets when the threads's effective and filesystem UIDs are switched between zero and nonzero values. (See the subsection Effect of User ID Changes on Capabilities.)
- If this bit is set, then the kernel does not grant capabilities when a set-user-ID-root program is executed, or when a process with an effective or real UID of 0 calls execve(2). (See the subsection Capabilities and execution of programs by root.)
prctl(PR_SET_SECUREBITS, SECBIT_KEEP_CAPS_LOCKED | SECBIT_NO_SETUID_FIXUP | SECBIT_NO_SETUID_FIXUP_LOCKED | SECBIT_NOROOT | SECBIT_NOROOT_LOCKED);
Interaction with user namespaces¶For a discussion of the interaction of capabilities and user namespaces, see user_namespaces(7).
CONFORMING TO¶No standards govern capabilities, but the Linux capability implementation is based on the withdrawn POSIX.1e draft standard; see http://wt.tuxomania.net/publications/posix.1e/
NOTES¶Since kernel 2.5.27, capabilities are an optional kernel component, and can be enabled/disabled via the CONFIG_SECURITY_CAPABILITIES kernel configuration option.
- In the pre-2.6.25 implementation the system-wide capability bounding set, /proc/sys/kernel/cap-bound, always masks out this capability, and this can not be changed without modifying the kernel source and rebuilding.
- If file capabilities are disabled in the current implementation, then init starts out with this capability removed from its per-process bounding set, and that bounding set is inherited by all other processes created on the system.
SEE ALSO¶capsh(1), capget(2), prctl(2), setfsuid(2), cap_clear(3), cap_copy_ext(3), cap_from_text(3), cap_get_file(3), cap_get_proc(3), cap_init(3), capgetp(3), capsetp(3), libcap(3), credentials(7), user_namespaces(7), pthreads(7), getcap(8), setcap(8) include/linux/capability.h in the Linux kernel source tree
COLOPHON¶This page is part of release 3.74 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at http://www.kernel.org/doc/man-pages/.