1 .\" Copyright (c) 2002 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" 6 Aug 2002 - Initial Creation
24 .\" Modified 2003-05-23, Michael Kerrisk, <mtk.manpages@gmail.com>
25 .\" Modified 2004-05-27, Michael Kerrisk, <mtk.manpages@gmail.com>
26 .\" 2004-12-08, mtk Added O_NOATIME for CAP_FOWNER
27 .\" 2005-08-16, mtk, Added CAP_AUDIT_CONTROL and CAP_AUDIT_WRITE
28 .\" 2008-07-15, Serge Hallyn <serue@us.bbm.com>
29 .\" Document file capabilities, per-process capability
30 .\" bounding set, changed semantics for CAP_SETPCAP,
31 .\" and other changes in 2.6.2[45].
32 .\" Add CAP_MAC_ADMIN, CAP_MAC_OVERRIDE, CAP_SETFCAP.
34 .\" Add text describing circumstances in which CAP_SETPCAP
35 .\" (theoretically) permits a thread to change the
36 .\" capability sets of another thread.
37 .\" Add section describing rules for programmatically
38 .\" adjusting thread capability sets.
39 .\" Describe rationale for capability bounding set.
40 .\" Document "securebits" flags.
41 .\" Add text noting that if we set the effective flag for one file
42 .\" capability, then we must also set the effective flag for all
43 .\" other capabilities where the permitted or inheritable bit is set.
44 .\" 2011-09-07, mtk/Serge hallyn: Add CAP_SYSLOG
45 .\" FIXME: Linux 3.0 added CAP_WAKE_ALARM
47 .TH CAPABILITIES 7 2011-10-04 "Linux" "Linux Programmer's Manual"
49 capabilities \- overview of Linux capabilities
51 For the purpose of performing permission checks,
52 traditional UNIX implementations distinguish two categories of processes:
54 processes (whose effective user ID is 0, referred to as superuser or root),
57 processes (whose effective UID is nonzero).
58 Privileged processes bypass all kernel permission checks,
59 while unprivileged processes are subject to full permission
60 checking based on the process's credentials
61 (usually: effective UID, effective GID, and supplementary group list).
63 Starting with kernel 2.2, Linux divides the privileges traditionally
64 associated with superuser into distinct units, known as
66 which can be independently enabled and disabled.
67 Capabilities are a per-thread attribute.
70 The following list shows the capabilities implemented on Linux,
71 and the operations or behaviors that each capability permits:
73 .BR CAP_AUDIT_CONTROL " (since Linux 2.6.11)"
74 Enable and disable kernel auditing; change auditing filter rules;
75 retrieve auditing status and filtering rules.
77 .BR CAP_AUDIT_WRITE " (since Linux 2.6.11)"
78 Write records to kernel auditing log.
81 Make arbitrary changes to file UIDs and GIDs (see
85 Bypass file read, write, and execute permission checks.
86 (DAC is an abbreviation of "discretionary access control".)
88 .B CAP_DAC_READ_SEARCH
89 Bypass file read permission checks and
90 directory read and execute permission checks.
96 Bypass permission checks on operations that normally
97 require the file system UID of the process to match the UID of
101 excluding those operations covered by
104 .BR CAP_DAC_READ_SEARCH ;
106 set extended file attributes (see
110 set Access Control Lists (ACLs) on arbitrary files;
112 ignore directory sticky bit on file deletion;
116 for arbitrary files in
124 Don't clear set-user-ID and set-group-ID permission
125 bits when a file is modified;
126 set the set-group-ID bit for a file whose GID does not match
127 the file system or any of the supplementary GIDs of the calling process.
137 Bypass permission checks for operations on System V IPC objects.
140 Bypass permission checks for sending signals (see
142 This includes use of the
146 .\" FIXME CAP_KILL also has an effect for threads + setting child
147 .\" termination signal to other than SIGCHLD: without this
148 .\" capability, the termination signal reverts to SIGCHLD
149 .\" if the child does an exec(). What is the rationale
152 .BR CAP_LEASE " (since Linux 2.4)"
153 Establish leases on arbitrary files (see
156 .B CAP_LINUX_IMMUTABLE
161 .\" These attributes are now available on ext2, ext3, Reiserfs, XFS, JFS
165 .BR CAP_MAC_ADMIN " (since Linux 2.6.25)"
166 Override Mandatory Access Control (MAC).
167 Implemented for the Smack Linux Security Module (LSM).
169 .BR CAP_MAC_OVERRIDE " (since Linux 2.6.25)"
170 Allow MAC configuration or state changes.
171 Implemented for the Smack LSM.
173 .BR CAP_MKNOD " (since Linux 2.4)"
174 Create special files using
178 Perform various network-related operations
179 (e.g., setting privileged socket options,
180 enabling multicasting, interface configuration,
181 modifying routing tables).
183 .B CAP_NET_BIND_SERVICE
184 Bind a socket to Internet domain privileged ports
185 (port numbers less than 1024).
188 (Unused) Make socket broadcasts, and listen to multicasts.
191 Use RAW and PACKET sockets.
192 .\" Also various IP options and setsockopt(SO_BINDTODEVICE)
195 Make arbitrary manipulations of process GIDs and supplementary GID list;
196 forge GID when passing socket credentials via UNIX domain sockets.
198 .BR CAP_SETFCAP " (since Linux 2.6.24)"
199 Set file capabilities.
202 If file capabilities are not supported:
203 grant or remove any capability in the
204 caller's permitted capability set to or from any other process.
207 is not available when the kernel is configured to support
208 file capabilities, since
210 has entirely different semantics for such kernels.)
212 If file capabilities are supported:
213 add any capability from the calling thread's bounding set
214 to its inheritable set;
215 drop capabilities from the bounding set (via
217 .BR PR_CAPBSET_DROP );
223 Make arbitrary manipulations of process UIDs
228 make forged UID when passing socket credentials via UNIX domain sockets.
229 .\" FIXME CAP_SETUID also an effect in exec(); document this.
235 Perform a range of system administration operations including:
243 .BR setdomainname (2);
247 operations (since Linux 2.6.37,
249 should be used to permit such operations);
255 operations on arbitrary System V IPC objects;
257 perform operations on
261 Extended Attributes (see
265 .BR lookup_dcookie (2);
271 and (before Linux 2.6.25)
273 I/O scheduling classes;
275 forge UID when passing socket credentials;
278 .IR /proc/sys/fs/file-max ,
279 the system-wide limit on the number of open files,
280 in system calls that open files (e.g.,
321 Load and unload kernel modules
325 .BR delete_module (2));
326 in kernels before 2.6.25:
327 drop capabilities from the system-wide capability bounding set.
333 Raise process nice value
336 and change the nice value for arbitrary processes;
338 set real-time scheduling policies for calling process,
339 and set scheduling policies and priorities for arbitrary processes
340 .RB ( sched_setscheduler (2),
341 .BR sched_setparam (2));
343 set CPU affinity for arbitrary processes
344 .RB ( sched_setaffinity (2));
346 set I/O scheduling class and priority for arbitrary processes
347 .RB ( ioprio_set (2));
350 .BR migrate_pages (2)
351 to arbitrary processes and allow processes
352 to be migrated to arbitrary nodes;
353 .\" FIXME CAP_SYS_NICE also has the following effect for
354 .\" migrate_pages(2):
355 .\" do_migrate_pages(mm, &old, &new,
356 .\" capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
360 to arbitrary processes;
376 Trace arbitrary processes using
379 .BR get_robust_list (2)
380 to arbitrary processes.
383 Perform I/O port operations
394 Use reserved space on ext2 file systems;
398 calls controlling ext3 journaling;
400 override disk quota limits;
402 increase resource limits (see
411 limit for a System V message queue above the limit in
412 .I /proc/sys/kernel/msgmnb
420 to increase the capacity of a pipe above the limit specified by
421 .IR /proc/sys/fs/pipe-max-size .
427 .RB ( settimeofday (2),
430 set real-time (hardware) clock.
432 .B CAP_SYS_TTY_CONFIG
436 .BR CAP_SYSLOG " (since Linux 2.6.37)"
442 for information on which operations require privilege.
444 .SS Past and Current Implementation
445 A full implementation of capabilities requires that:
447 For all privileged operations,
448 the kernel must check whether the thread has the required
449 capability in its effective set.
451 The kernel must provide system calls allowing a thread's capability sets to
452 be changed and retrieved.
454 The file system must support attaching capabilities to an executable file,
455 so that a process gains those capabilities when the file is executed.
457 Before kernel 2.6.24, only the first two of these requirements are met;
458 since kernel 2.6.24, all three requirements are met.
460 .SS Thread Capability Sets
461 Each thread has three capability sets containing zero or more
462 of the above capabilities:
465 This is a limiting superset for the effective
466 capabilities that the thread may assume.
467 It is also a limiting superset for the capabilities that
468 may be added to the inheritable set by a thread that does not have the
470 capability in its effective set.
472 If a thread drops a capability from its permitted set,
473 it can never reacquire that capability (unless it
475 either a set-user-ID-root program, or
476 a program whose associated file capabilities grant that capability).
479 This is a set of capabilities preserved across an
481 It provides a mechanism for a process to assign capabilities
482 to the permitted set of the new program during an
486 This is the set of capabilities used by the kernel to
487 perform permission checks for the thread.
491 inherits copies of its parent's capability sets.
492 See below for a discussion of the treatment of capabilities during
497 a thread may manipulate its own capability sets (see below).
499 .SS File Capabilities
500 Since kernel 2.6.24, the kernel supports
501 associating capability sets with an executable file using
503 The file capability sets are stored in an extended attribute (see
506 .IR "security.capability" .
507 Writing to this extended attribute requires the
510 The file capability sets,
511 in conjunction with the capability sets of the thread,
512 determine the capabilities of a thread after an
515 The three file capability sets are:
517 .IR Permitted " (formerly known as " forced ):
518 These capabilities are automatically permitted to the thread,
519 regardless of the thread's inheritable capabilities.
521 .IR Inheritable " (formerly known as " allowed ):
522 This set is ANDed with the thread's inheritable set to determine which
523 inheritable capabilities are enabled in the permitted set of
528 This is not a set, but rather just a single bit.
529 If this bit is set, then during an
531 all of the new permitted capabilities for the thread are
532 also raised in the effective set.
533 If this bit is not set, then after an
535 none of the new permitted capabilities is in the new effective set.
537 Enabling the file effective capability bit implies
538 that any file permitted or inheritable capability that causes a
539 thread to acquire the corresponding permitted capability during an
541 (see the transformation rules described below) will also acquire that
542 capability in its effective set.
543 Therefore, when assigning capabilities to a file
545 .BR cap_set_file (3),
547 if we specify the effective flag as being enabled for any capability,
548 then the effective flag must also be specified as enabled
549 for all other capabilities for which the corresponding permitted or
550 inheritable flags is enabled.
552 .SS Transformation of Capabilities During execve()
556 the kernel calculates the new capabilities of
557 the process using the following algorithm:
561 P'(permitted) = (P(inheritable) & F(inheritable)) |
562 (F(permitted) & cap_bset)
564 P'(effective) = F(effective) ? P'(permitted) : 0
566 P'(inheritable) = P(inheritable) [i.e., unchanged]
573 denotes the value of a thread capability set before the
576 denotes the value of a capability set after the
579 denotes a file capability set
581 is the value of the capability bounding set (described below).
584 .SS Capabilities and execution of programs by root
585 In order to provide an all-powerful
587 using capability sets, during an
590 If a set-user-ID-root program is being executed,
591 or the real user ID of the process is 0 (root)
592 then the file inheritable and permitted sets are defined to be all ones
593 (i.e., all capabilities enabled).
595 If a set-user-ID-root program is being executed,
596 then the file effective bit is defined to be one (enabled).
598 The upshot of the above rules,
599 combined with the capabilities transformations described above,
600 is that when a process
602 a set-user-ID-root program, or when a process with an effective UID of 0
605 it gains all capabilities in its permitted and effective capability sets,
606 except those masked out by the capability bounding set.
607 .\" If a process with real UID 0, and nonzero effective UID does an
608 .\" exec(), then it gets all capabilities in its
609 .\" permitted set, and no effective capabilities
610 This provides semantics that are the same as those provided by
611 traditional UNIX systems.
612 .SS Capability bounding set
613 The capability bounding set is a security mechanism that can be used
614 to limit the capabilities that can be gained during an
616 The bounding set is used in the following ways:
620 the capability bounding set is ANDed with the file permitted
621 capability set, and the result of this operation is assigned to the
622 thread's permitted capability set.
623 The capability bounding set thus places a limit on the permitted
624 capabilities that may be granted by an executable file.
627 The capability bounding set acts as a limiting superset for
628 the capabilities that a thread can add to its inheritable set using
630 This means that if a capability is not in the bounding set,
631 then a thread can't add this capability to its
632 inheritable set, even if it was in its permitted capabilities,
633 and thereby cannot have this capability preserved in its
634 permitted set when it
636 a file that has the capability in its inheritable set.
638 Note that the bounding set masks the file permitted capabilities,
639 but not the inherited capabilities.
640 If a thread maintains a capability in its inherited set
641 that is not in its bounding set,
642 then it can still gain that capability in its permitted set
643 by executing a file that has the capability in its inherited set.
645 Depending on the kernel version, the capability bounding set is either
646 a system-wide attribute, or a per-process attribute.
648 .B "Capability bounding set prior to Linux 2.6.25"
650 In kernels before 2.6.25, the capability bounding set is a system-wide
651 attribute that affects all threads on the system.
652 The bounding set is accessible via the file
653 .IR /proc/sys/kernel/cap-bound .
654 (Confusingly, this bit mask parameter is expressed as a
655 signed decimal number in
656 .IR /proc/sys/kernel/cap-bound .)
660 process may set capabilities in the capability bounding set;
661 other than that, the superuser (more precisely: programs with the
663 capability) may only clear capabilities from this set.
665 On a standard system the capability bounding set always masks out the
668 To remove this restriction (dangerous!), modify the definition of
671 .I include/linux/capability.h
672 and rebuild the kernel.
674 The system-wide capability bounding set feature was added
675 to Linux starting with kernel version 2.2.11.
678 .B "Capability bounding set from Linux 2.6.25 onward"
680 From Linux 2.6.25, the
681 .I "capability bounding set"
682 is a per-thread attribute.
683 (There is no longer a system-wide capability bounding set.)
685 The bounding set is inherited at
687 from the thread's parent, and is preserved across an
690 A thread may remove capabilities from its capability bounding set using the
693 operation, provided it has the
696 Once a capability has been dropped from the bounding set,
697 it cannot be restored to that set.
698 A thread can determine if a capability is in its bounding set using the
703 Removing capabilities from the bounding set is only supported if file
704 capabilities are compiled into the kernel.
705 In kernels before Linux 2.6.33,
706 file capabilities were an optional feature configurable via the
707 CONFIG_SECURITY_FILE_CAPABILITIES
709 Since Linux 2.6.33, the configuration option has been removed
710 and file capabilities are always part of the kernel.
711 When file capabilities are compiled into the kernel, the
713 process (the ancestor of all processes) begins with a full bounding set.
714 If file capabilities are not compiled into the kernel, then
716 begins with a full bounding set minus
718 because this capability has a different meaning when there are
719 no file capabilities.
721 Removing a capability from the bounding set does not remove it
722 from the thread's inherited set.
723 However it does prevent the capability from being added
724 back into the thread's inherited set in the future.
727 .SS Effect of User ID Changes on Capabilities
728 To preserve the traditional semantics for transitions between
729 0 and nonzero user IDs,
730 the kernel makes the following changes to a thread's capability
731 sets on changes to the thread's real, effective, saved set,
732 and file system user IDs (using
737 If one or more of the real, effective or saved set user IDs
738 was previously 0, and as a result of the UID changes all of these IDs
739 have a nonzero value,
740 then all capabilities are cleared from the permitted and effective
743 If the effective user ID is changed from 0 to nonzero,
744 then all capabilities are cleared from the effective set.
746 If the effective user ID is changed from nonzero to 0,
747 then the permitted set is copied to the effective set.
749 If the file system user ID is changed from 0 to nonzero (see
751 then the following capabilities are cleared from the effective set:
753 .BR CAP_DAC_OVERRIDE ,
754 .BR CAP_DAC_READ_SEARCH ,
757 .B CAP_LINUX_IMMUTABLE
758 (since Linux 2.2.30),
759 .BR CAP_MAC_OVERRIDE ,
762 (since Linux 2.2.30).
763 If the file system UID is changed from nonzero to 0,
764 then any of these capabilities that are enabled in the permitted set
765 are enabled in the effective set.
767 If a thread that has a 0 value for one or more of its user IDs wants
768 to prevent its permitted capability set being cleared when it resets
769 all of its user IDs to nonzero values, it can do so using the
774 .SS Programmatically adjusting capability sets
775 A thread can retrieve and change its capability sets using the
783 .BR cap_set_proc (3),
787 is preferred for this purpose.
788 The following rules govern changes to the thread capability sets:
790 If the caller does not have the
793 the new inheritable set must be a subset of the combination
794 of the existing inheritable and permitted sets.
796 (Since kernel 2.6.25)
797 The new inheritable set must be a subset of the combination of the
798 existing inheritable set and the capability bounding set.
800 The new permitted set must be a subset of the existing permitted set
801 (i.e., it is not possible to acquire permitted capabilities
802 that the thread does not currently have).
804 The new effective set must be a subset of the new permitted set.
805 .SS The """securebits"" flags: establishing a capabilities-only environment
806 .\" For some background:
807 .\" see http://lwn.net/Articles/280279/ and
808 .\" http://article.gmane.org/gmane.linux.kernel.lsm/5476/
809 Starting with kernel 2.6.26,
810 and with a kernel in which file capabilities are enabled,
811 Linux implements a set of per-thread
813 flags that can be used to disable special handling of capabilities for UID 0
815 These flags are as follows:
818 Setting this flag allows a thread that has one or more 0 UIDs to retain
819 its capabilities when it switches all of its UIDs to a nonzero value.
820 If this flag is not set,
821 then such a UID switch causes the thread to lose all capabilities.
822 This flag is always cleared on an
824 (This flag provides the same functionality as the older
829 .B SECBIT_NO_SETUID_FIXUP
830 Setting this flag stops the kernel from adjusting capability sets when
831 the threads's effective and file system UIDs are switched between
832 zero and nonzero values.
834 .IR "Effect of User ID Changes on Capabilities" .)
837 If this bit is set, then the kernel does not grant capabilities
838 when a set-user-ID-root program is executed, or when a process with
839 an effective or real UID of 0 calls
842 .IR "Capabilities and execution of programs by root" .)
844 Each of the above "base" flags has a companion "locked" flag.
845 Setting any of the "locked" flags is irreversible,
846 and has the effect of preventing further changes to the
847 corresponding "base" flag.
848 The locked flags are:
849 .BR SECBIT_KEEP_CAPS_LOCKED ,
850 .BR SECBIT_NO_SETUID_FIXUP_LOCKED ,
852 .BR SECBIT_NOROOT_LOCKED .
856 flags can be modified and retrieved using the
864 capability is required to modify the flags.
868 flags are inherited by child processes.
871 all of the flags are preserved, except
873 which is always cleared.
875 An application can use the following call to lock itself,
876 and all of its descendants,
877 into an environment where the only way of gaining capabilities
878 is by executing a program with associated file capabilities:
882 prctl(PR_SET_SECUREBITS,
883 SECBIT_KEEP_CAPS_LOCKED |
884 SECBIT_NO_SETUID_FIXUP |
885 SECBIT_NO_SETUID_FIXUP_LOCKED |
887 SECBIT_NOROOT_LOCKED);
892 No standards govern capabilities, but the Linux capability implementation
893 is based on the withdrawn POSIX.1e draft standard; see
894 .IR http://wt.xpilot.org/publications/posix.1e/ .
896 Since kernel 2.5.27, capabilities are an optional kernel component,
897 and can be enabled/disabled via the CONFIG_SECURITY_CAPABILITIES
898 kernel configuration option.
901 .I /proc/PID/task/TID/status
902 file can be used to view the capability sets of a thread.
905 file shows the capability sets of a process's main thread.
909 package provides a suite of routines for setting and
910 getting capabilities that is more comfortable and less likely
911 to change than the interface provided by
915 This package also provides the
922 .IR http://www.kernel.org/pub/linux/libs/security/linux-privs .
924 Before kernel 2.6.24, and since kernel 2.6.24 if
925 file capabilities are not enabled, a thread with the
927 capability can manipulate the capabilities of threads other than itself.
928 However, this is only theoretically possible,
929 since no thread ever has
931 in either of these cases:
933 In the pre-2.6.25 implementation the system-wide capability bounding set,
934 .IR /proc/sys/kernel/cap-bound ,
935 always masks out this capability, and this can not be changed
936 without modifying the kernel source and rebuilding.
938 If file capabilities are disabled in the current implementation, then
940 starts out with this capability removed from its per-process bounding
941 set, and that bounding set is inherited by all other processes
942 created on the system.
948 .BR cap_copy_ext (3),
949 .BR cap_from_text (3),
950 .BR cap_get_file (3),
951 .BR cap_get_proc (3),
960 .I include/linux/capability.h