Man page of CAPABILITIES
Section: Linux Programmer's Manual (7)
Return to Main Contents
capabilities - overview of Linux capabilities
For the purpose of performing permission checks,
traditional Unix implementations distinguish two categories of processes:
processes (whose effective user ID is 0, referred to as superuser or root),
processes (whose effective UID is non-zero).
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).
Starting with kernel 2.2, Linux divides the privileges traditionally
associated with superuser into distinct units, known as
which can be independently enabled and disabled.
Capabilities are a per-thread attribute.
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_WRITE (since Linux 2.6.11)
Write records to kernel auditing log.
Make arbitrary changes to file UIDs and GIDs (see
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.
Bypass permission checks on operations that normally
require the file system UID of the process to match the UID of
the file (e.g.,
excluding those operations covered by
set extended file attributes (see
on arbitrary files;
set Access Control Lists (ACLs) on arbitrary files;
ignore directory sticky bit on file deletion;
for arbitrary files in
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 file system 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
This includes use of the
- CAP_LEASE (since Linux 2.4)
Establish leases on arbitrary files (see
i-node flags (see
- 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
Perform various network-related operations
(e.g., setting privileged socket options,
enabling multicasting, interface configuration,
modifying routing tables).
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.
Make arbitrary manipulations of process GIDs and supplementary GID list;
forge GID when passing socket credentials via Unix domain sockets.
- 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
is not available when the kernel is configured to support
file capabilities, since
has entirely different semantics for such kernels.)
If file capabilities are supported:
add any capability from the calling thread's bounding set
to its inheritable set;
drop capabilities from the bounding set (via
make changes to the
Make arbitrary manipulations of process UIDs
make forged UID when passing socket credentials via Unix domain sockets.
Perform a range of system administration operations including:
operations on arbitrary System V IPC objects;
perform operations on
Extended Attributes (see
and (before Linux 2.6.25)
I/O scheduling classes;
forge UID when passing socket credentials;
the system-wide limit on the number of open files,
in system calls that open files (e.g.,
Load and unload kernel modules
in kernels before 2.6.25:
drop capabilities from the system-wide capability bounding set.
Raise process nice value
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
set CPU affinity for arbitrary processes
set I/O scheduling class and priority for arbitrary processes
to arbitrary processes and allow processes
to be migrated to arbitrary nodes;
to arbitrary processes;
Trace arbitrary processes using
Perform I/O port operations
Use reserved space on ext2 file systems;
calls controlling ext3 journaling;
override disk quota limits;
increase resource limits (see
limit for a System V message queue above the limit in
Set system clock
set real-time (hardware) clock.
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 file system must support attaching capabilities to an executable file,
so that a process gains those capabilities when the file is executed.
Before kernel 2.6.24, only the first two of these requirements are met;
since kernel 2.6.24, all three requirements are met.
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
capability in its effective set.
If a thread drops a capability from its permitted set,
it can never re-acquire that capability (unless it
either a set-user-ID-root program, or
a program whose associated file capabilities grant that capability).
This is a set of capabilities preserved across an
It provides a mechanism for a process to assign capabilities
to the permitted set of the new program during an
This is the set of capabilities used by the kernel to
perform permission checks for the thread.
A child created via
inherits copies of its parent's capability sets.
See below for a discussion of the treatment of capabilities during
a thread may manipulate its own capability sets (see below).
Since kernel 2.6.24, the kernel supports
associating capability sets with an executable file using
The file capability sets are stored in an extended attribute (see
Writing to this extended attribute requires the
The file capability sets,
in conjunction with the capability sets of the thread,
determine the capabilities of a thread after an
The three file capability sets are:
- 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
This is not a set, but rather just a single bit.
If this bit is set, then during an
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
none of the new permitted capabilities is in the new effective set.
Enabling the file effective capability bit implies
that any file permitted or inheritable capability that causes a
thread to acquire the corresponding permitted capability during an
(see the transformation rules described below) will also acquire that
capability in its effective set.
Therefore, when assigning capabilities to a file
if we specify the effective flag as being enabled for any capability,
then the effective flag must also be specified as enabled
for all other capabilities for which the corresponding permitted or
inheritable flags is enabled.
Transformation of Capabilities During execve()
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
denotes the value of a capability set after the
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
using capability sets, during an
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).
The upshot of the above rules,
combined with the capabilities transformations described above,
is that when a process
a set-user-ID-root program, or when a process with an effective UID of 0
it gains all capabilities in its permitted and effective capability sets,
except those masked out by the capability bounding set.
This provides semantics that are the same as those provided by
traditional Unix systems.
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
The bounding set is used in the following ways:
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
This means that if the capability is not in the bounding set,
then a thread can't add one of its permitted capabilities to its
inheritable set and thereby have that capability preserved in its
permitted set when it
a file that has the capability in its inheritable set.
Note that the bounding set masks the file permitted capabilities,
but not the inherited capabilities.
If a thread maintains a capability in its inherited set
that is not in its bounding set,
then it can still gain that capability in its permitted set
by executing a file that has the capability in its inherited set.
Depending on the kernel version, the capability bounding set is either
a system-wide attribute, or a per-process attribute.
Capability bounding set prior to Linux 2.6.25
In kernels before 2.6.25, the capability bounding set is a system-wide
attribute that affects all threads on the system.
The bounding set is accessible via the file
(Confusingly, this bit mask parameter is expressed as a
signed decimal number in
process may set capabilities in the capability bounding set;
other than that, the superuser (more precisely: programs with the
capability) may only clear capabilities from this set.
On a standard system the capability bounding set always masks out the
To remove this restriction (dangerous!), modify the definition of
and rebuild the kernel.
The system-wide capability bounding set feature was added
to Linux starting with kernel version 2.2.11.
Capability bounding set from Linux 2.6.25 onwards
From Linux 2.6.25, the
capability bounding set
is a per-thread attribute.
(There is no longer a system-wide capability bounding set.)
The bounding set is inherited at
from the thread's parent, and is preserved across an
A thread may remove capabilities from its capability bounding set using the
operation, provided it has the
Once a capability has been dropped from the bounding set,
it cannot be restored to that set.
A thread can determine if a capability is in its bounding set using the
Removing capabilities from the bounding set is only supported if file
capabilities are compiled into the kernel
In that case, the
process (the ancestor of all processes) begins with a full bounding set.
If file capabilities are not compiled into the kernel, then
begins with a full bounding set minus
because this capability has a different meaning when there are
no file capabilities.
Removing a capability from the bounding set does not remove it
from the thread's inherited set.
However it does prevent the capability from being added
back into the thread's inherited set in the future.
Effect of User ID Changes on Capabilities
To preserve the traditional semantics for transitions between
0 and non-zero 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 file system user IDs (using
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 non-zero value,
then all capabilities are cleared from the permitted and effective
If the effective user ID is changed from 0 to non-zero,
then all capabilities are cleared from the effective set.
If the effective user ID is changed from non-zero to 0,
then the permitted set is copied to the effective set.
If the file system user ID is changed from 0 to non-zero (see
then the following capabilities are cleared from the effective set:
If the file system UID is changed from non-zero to 0,
then any of these capabilities that are enabled in the permitted set
are enabled in the effective set.
If a thread that has a 0 value for one or more of its user IDs wants
to prevent its permitted capability set being cleared when it resets
all of its user IDs to non-zero values, it can do so using the
Programmatically adjusting capability sets
A thread can retrieve and change its capability sets using the
However, the use of
both provided in the
is preferred for this purpose.
The following rules govern changes to the thread capability sets:
If the caller does not have the
the new inheritable set must be a subset of the combination
of the existing inheritable and permitted sets.
(Since kernel 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
flags that can be used to disable special handling of capabilities for UID 0
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 non-zero 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
(This flag provides the same functionality as the older
Setting this flag stops the kernel from adjusting capability sets when
the threads's effective and file system UIDs are switched between
zero and non-zero 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
(See the subsection
Capabilities and execution of programs by root.)
Each of the above "base" flags has a companion "locked" flag.
Setting any of the "locked" flags is irreversible,
and has the effect of preventing further changes to the
corresponding "base" flag.
The locked flags are:
flags can be modified and retrieved using the
capability is required to modify the flags.
flags are inherited by child processes.
all of the flags are preserved, except
which is always cleared.
An application can use the following call to lock itself,
and all of its descendants,
into an environment where the only way of gaining capabilities
is by executing a program with associated file capabilities:
1 << SECURE_KEEP_CAPS_LOCKED |
1 << SECURE_NO_SETUID_FIXUP |
1 << SECURE_NO_SETUID_FIXUP_LOCKED |
1 << SECURE_NOROOT |
1 << SECURE_NOROOT_LOCKED);
No standards govern capabilities, but the Linux capability implementation
is based on the withdrawn POSIX.1e draft standard; see
Since kernel 2.5.27, capabilities are an optional kernel component,
and can be enabled/disabled via the CONFIG_SECURITY_CAPABILITIES
kernel configuration option.
file can be used to view the capability sets of a thread.
file shows the capability sets of a process's main thread.
package provides a suite of routines for setting and
getting capabilities that is more comfortable and less likely
to change than the interface provided by
This package also provides the
It can be found at
Before kernel 2.6.24, and since kernel 2.6.24 if
file capabilities are not enabled, a thread with the
capability can manipulate the capabilities of threads other than itself.
However, this is only theoretically possible,
since no thread ever has
in either of these cases:
In the pre-2.6.25 implementation the system-wide capability bounding set,
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
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.
in the kernel source
This page is part of release 3.22 of the Linux
A description of the project,
and information about reporting bugs,
can be found at
- Capabilities List
- Past and Current Implementation
- Thread Capability Sets
- File Capabilities
- Transformation of Capabilities During execve()
- Capabilities and execution of programs by root
- Capability bounding set
- Effect of User ID Changes on Capabilities
- Programmatically adjusting capability sets
- The securebits flags: establishing a capabilities-only environment
- CONFORMING TO
- SEE ALSO
This document was created by
using the manual pages.
Time: 04:16:59 GMT, September 24, 2010