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
46 .TH CAPABILITIES 7 2012-12-22 "Linux" "Linux Programmer's Manual"
48 capabilities \- overview of Linux capabilities
50 For the purpose of performing permission checks,
51 traditional UNIX implementations distinguish two categories of processes:
53 processes (whose effective user ID is 0, referred to as superuser or root),
56 processes (whose effective UID is nonzero).
57 Privileged processes bypass all kernel permission checks,
58 while unprivileged processes are subject to full permission
59 checking based on the process's credentials
60 (usually: effective UID, effective GID, and supplementary group list).
62 Starting with kernel 2.2, Linux divides the privileges traditionally
63 associated with superuser into distinct units, known as
65 which can be independently enabled and disabled.
66 Capabilities are a per-thread attribute.
69 The following list shows the capabilities implemented on Linux,
70 and the operations or behaviors that each capability permits:
72 .BR CAP_AUDIT_CONTROL " (since Linux 2.6.11)"
73 Enable and disable kernel auditing; change auditing filter rules;
74 retrieve auditing status and filtering rules.
76 .BR CAP_AUDIT_WRITE " (since Linux 2.6.11)"
77 Write records to kernel auditing log.
79 .BR CAP_BLOCK_SUSPEND " (since Linux 3.5)"
80 Employ features that can block system suspend
83 .IR /proc/sys/wake_lock ).
86 Make arbitrary changes to file UIDs and GIDs (see
90 Bypass file read, write, and execute permission checks.
91 (DAC is an abbreviation of "discretionary access control".)
93 .B CAP_DAC_READ_SEARCH
94 Bypass file read permission checks and
95 directory read and execute permission checks.
101 Bypass permission checks on operations that normally
102 require the file system UID of the process to match the UID of
106 excluding those operations covered by
109 .BR CAP_DAC_READ_SEARCH ;
111 set extended file attributes (see
115 set Access Control Lists (ACLs) on arbitrary files;
117 ignore directory sticky bit on file deletion;
121 for arbitrary files in
129 Don't clear set-user-ID and set-group-ID permission
130 bits when a file is modified;
131 set the set-group-ID bit for a file whose GID does not match
132 the file system or any of the supplementary GIDs of the calling process.
135 .\" FIXME As at Linux 3.2, there are some strange uses of this capability
136 .\" in other places; they probably should be replaced with something else.
144 Bypass permission checks for operations on System V IPC objects.
147 Bypass permission checks for sending signals (see
149 This includes use of the
153 .\" FIXME CAP_KILL also has an effect for threads + setting child
154 .\" termination signal to other than SIGCHLD: without this
155 .\" capability, the termination signal reverts to SIGCHLD
156 .\" if the child does an exec(). What is the rationale
159 .BR CAP_LEASE " (since Linux 2.4)"
160 Establish leases on arbitrary files (see
163 .B CAP_LINUX_IMMUTABLE
168 .\" These attributes are now available on ext2, ext3, Reiserfs, XFS, JFS
172 .BR CAP_MAC_ADMIN " (since Linux 2.6.25)"
173 Override Mandatory Access Control (MAC).
174 Implemented for the Smack Linux Security Module (LSM).
176 .BR CAP_MAC_OVERRIDE " (since Linux 2.6.25)"
177 Allow MAC configuration or state changes.
178 Implemented for the Smack LSM.
180 .BR CAP_MKNOD " (since Linux 2.4)"
181 Create special files using
185 Perform various network-related operations:
189 interface configuration;
191 administration of IP firewall, masquerading, and accounting
193 modify routing tables;
195 bind to any address for transparent proxying;
197 set type-of-service (TOS)
199 clear driver statistics;
201 set promiscuous mode;
203 enabling multicasting;
207 to set the following socket options:
211 (for a priority outside the range 0 to 6),
218 .B CAP_NET_BIND_SERVICE
219 Bind a socket to Internet domain privileged ports
220 (port numbers less than 1024).
223 (Unused) Make socket broadcasts, and listen to multicasts.
229 use RAW and PACKET sockets;
231 bind to any address for transparent proxying.
234 .\" Also various IP options and setsockopt(SO_BINDTODEVICE)
237 Make arbitrary manipulations of process GIDs and supplementary GID list;
238 forge GID when passing socket credentials via UNIX domain sockets.
240 .BR CAP_SETFCAP " (since Linux 2.6.24)"
241 Set file capabilities.
244 If file capabilities are not supported:
245 grant or remove any capability in the
246 caller's permitted capability set to or from any other process.
249 is not available when the kernel is configured to support
250 file capabilities, since
252 has entirely different semantics for such kernels.)
254 If file capabilities are supported:
255 add any capability from the calling thread's bounding set
256 to its inheritable set;
257 drop capabilities from the bounding set (via
259 .BR PR_CAPBSET_DROP );
265 Make arbitrary manipulations of process UIDs
270 make forged UID when passing socket credentials via UNIX domain sockets.
271 .\" FIXME CAP_SETUID also an effect in exec(); document this.
277 Perform a range of system administration operations including:
285 .BR setdomainname (2);
289 operations (since Linux 2.6.37,
291 should be used to permit such operations);
302 operations on arbitrary System V IPC objects;
304 perform operations on
308 Extended Attributes (see
312 .BR lookup_dcookie (2);
318 and (before Linux 2.6.25)
320 I/O scheduling classes;
322 forge UID when passing socket credentials;
325 .IR /proc/sys/fs/file-max ,
326 the system-wide limit on the number of open files,
327 in system calls that open files (e.g.,
335 flags that create new namespaces with
341 .BR perf_event_open (2);
351 .BR fanotify_init (2);
368 to insert characters into the input queue of a terminal other than
369 the caller's controlling terminal.
379 perform various privileged block-device
383 perform various privileged file-system
387 perform administrative operations on many device drivers.
402 Load and unload kernel modules
406 .BR delete_module (2));
407 in kernels before 2.6.25:
408 drop capabilities from the system-wide capability bounding set.
414 Raise process nice value
417 and change the nice value for arbitrary processes;
419 set real-time scheduling policies for calling process,
420 and set scheduling policies and priorities for arbitrary processes
421 .RB ( sched_setscheduler (2),
422 .BR sched_setparam (2));
424 set CPU affinity for arbitrary processes
425 .RB ( sched_setaffinity (2));
427 set I/O scheduling class and priority for arbitrary processes
428 .RB ( ioprio_set (2));
431 .BR migrate_pages (2)
432 to arbitrary processes and allow processes
433 to be migrated to arbitrary nodes;
434 .\" FIXME CAP_SYS_NICE also has the following effect for
435 .\" migrate_pages(2):
436 .\" do_migrate_pages(mm, &old, &new,
437 .\" capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
441 to arbitrary processes;
457 Trace arbitrary processes using
460 .BR get_robust_list (2)
461 to arbitrary processes;
462 inspect processes using
466 Perform I/O port operations
481 Use reserved space on ext2 file systems;
485 calls controlling ext3 journaling;
487 override disk quota limits;
489 increase resource limits (see
496 override maximum number of consoles on console allocation;
498 override maximum number of keymaps;
500 allow more than 64hz interrupts from the real-time clock;
504 limit for a System V message queue above the limit in
505 .I /proc/sys/kernel/msgmnb
512 .I /proc/sys/fs/pipe-size-max
513 limit when setting the capacity of a pipe using the
520 to increase the capacity of a pipe above the limit specified by
521 .IR /proc/sys/fs/pipe-max-size ;
524 .I /proc/sys/fs/mqueue/queues_max
525 limit when creating POSIX message queues (see
526 .BR mq_overview (7));
537 .RB ( settimeofday (2),
540 set real-time (hardware) clock.
542 .B CAP_SYS_TTY_CONFIG
545 employ various privileged
547 operations on virtual terminals.
549 .BR CAP_SYSLOG " (since Linux 2.6.37)"
556 for information on which operations require privilege.
558 View kernel addresses exposed via
560 and other interfaces when
561 .IR /proc/sys/kernel/kptr_restrict
563 (See the discussion of the
568 .BR CAP_WAKE_ALARM " (since Linux 3.0)"
569 Trigger something that will wake up the system (set
570 .B CLOCK_REALTIME_ALARM
572 .B CLOCK_BOOTTIME_ALARM
575 .SS Past and current implementation
576 A full implementation of capabilities requires that:
578 For all privileged operations,
579 the kernel must check whether the thread has the required
580 capability in its effective set.
582 The kernel must provide system calls allowing a thread's capability sets to
583 be changed and retrieved.
585 The file system must support attaching capabilities to an executable file,
586 so that a process gains those capabilities when the file is executed.
588 Before kernel 2.6.24, only the first two of these requirements are met;
589 since kernel 2.6.24, all three requirements are met.
591 .SS Thread capability sets
592 Each thread has three capability sets containing zero or more
593 of the above capabilities:
596 This is a limiting superset for the effective
597 capabilities that the thread may assume.
598 It is also a limiting superset for the capabilities that
599 may be added to the inheritable set by a thread that does not have the
601 capability in its effective set.
603 If a thread drops a capability from its permitted set,
604 it can never reacquire that capability (unless it
606 either a set-user-ID-root program, or
607 a program whose associated file capabilities grant that capability).
610 This is a set of capabilities preserved across an
612 It provides a mechanism for a process to assign capabilities
613 to the permitted set of the new program during an
617 This is the set of capabilities used by the kernel to
618 perform permission checks for the thread.
622 inherits copies of its parent's capability sets.
623 See below for a discussion of the treatment of capabilities during
628 a thread may manipulate its own capability sets (see below).
630 .SS File capabilities
631 Since kernel 2.6.24, the kernel supports
632 associating capability sets with an executable file using
634 The file capability sets are stored in an extended attribute (see
637 .IR "security.capability" .
638 Writing to this extended attribute requires the
641 The file capability sets,
642 in conjunction with the capability sets of the thread,
643 determine the capabilities of a thread after an
646 The three file capability sets are:
648 .IR Permitted " (formerly known as " forced ):
649 These capabilities are automatically permitted to the thread,
650 regardless of the thread's inheritable capabilities.
652 .IR Inheritable " (formerly known as " allowed ):
653 This set is ANDed with the thread's inheritable set to determine which
654 inheritable capabilities are enabled in the permitted set of
659 This is not a set, but rather just a single bit.
660 If this bit is set, then during an
662 all of the new permitted capabilities for the thread are
663 also raised in the effective set.
664 If this bit is not set, then after an
666 none of the new permitted capabilities is in the new effective set.
668 Enabling the file effective capability bit implies
669 that any file permitted or inheritable capability that causes a
670 thread to acquire the corresponding permitted capability during an
672 (see the transformation rules described below) will also acquire that
673 capability in its effective set.
674 Therefore, when assigning capabilities to a file
676 .BR cap_set_file (3),
678 if we specify the effective flag as being enabled for any capability,
679 then the effective flag must also be specified as enabled
680 for all other capabilities for which the corresponding permitted or
681 inheritable flags is enabled.
683 .SS Transformation of capabilities during execve()
687 the kernel calculates the new capabilities of
688 the process using the following algorithm:
692 P'(permitted) = (P(inheritable) & F(inheritable)) |
693 (F(permitted) & cap_bset)
695 P'(effective) = F(effective) ? P'(permitted) : 0
697 P'(inheritable) = P(inheritable) [i.e., unchanged]
704 denotes the value of a thread capability set before the
707 denotes the value of a capability set after the
710 denotes a file capability set
712 is the value of the capability bounding set (described below).
715 .SS Capabilities and execution of programs by root
716 In order to provide an all-powerful
718 using capability sets, during an
721 If a set-user-ID-root program is being executed,
722 or the real user ID of the process is 0 (root)
723 then the file inheritable and permitted sets are defined to be all ones
724 (i.e., all capabilities enabled).
726 If a set-user-ID-root program is being executed,
727 then the file effective bit is defined to be one (enabled).
729 The upshot of the above rules,
730 combined with the capabilities transformations described above,
731 is that when a process
733 a set-user-ID-root program, or when a process with an effective UID of 0
736 it gains all capabilities in its permitted and effective capability sets,
737 except those masked out by the capability bounding set.
738 .\" If a process with real UID 0, and nonzero effective UID does an
739 .\" exec(), then it gets all capabilities in its
740 .\" permitted set, and no effective capabilities
741 This provides semantics that are the same as those provided by
742 traditional UNIX systems.
743 .SS Capability bounding set
744 The capability bounding set is a security mechanism that can be used
745 to limit the capabilities that can be gained during an
747 The bounding set is used in the following ways:
751 the capability bounding set is ANDed with the file permitted
752 capability set, and the result of this operation is assigned to the
753 thread's permitted capability set.
754 The capability bounding set thus places a limit on the permitted
755 capabilities that may be granted by an executable file.
758 The capability bounding set acts as a limiting superset for
759 the capabilities that a thread can add to its inheritable set using
761 This means that if a capability is not in the bounding set,
762 then a thread can't add this capability to its
763 inheritable set, even if it was in its permitted capabilities,
764 and thereby cannot have this capability preserved in its
765 permitted set when it
767 a file that has the capability in its inheritable set.
769 Note that the bounding set masks the file permitted capabilities,
770 but not the inherited capabilities.
771 If a thread maintains a capability in its inherited set
772 that is not in its bounding set,
773 then it can still gain that capability in its permitted set
774 by executing a file that has the capability in its inherited set.
776 Depending on the kernel version, the capability bounding set is either
777 a system-wide attribute, or a per-process attribute.
779 .B "Capability bounding set prior to Linux 2.6.25"
781 In kernels before 2.6.25, the capability bounding set is a system-wide
782 attribute that affects all threads on the system.
783 The bounding set is accessible via the file
784 .IR /proc/sys/kernel/cap-bound .
785 (Confusingly, this bit mask parameter is expressed as a
786 signed decimal number in
787 .IR /proc/sys/kernel/cap-bound .)
791 process may set capabilities in the capability bounding set;
792 other than that, the superuser (more precisely: programs with the
794 capability) may only clear capabilities from this set.
796 On a standard system the capability bounding set always masks out the
799 To remove this restriction (dangerous!), modify the definition of
802 .I include/linux/capability.h
803 and rebuild the kernel.
805 The system-wide capability bounding set feature was added
806 to Linux starting with kernel version 2.2.11.
809 .B "Capability bounding set from Linux 2.6.25 onward"
811 From Linux 2.6.25, the
812 .I "capability bounding set"
813 is a per-thread attribute.
814 (There is no longer a system-wide capability bounding set.)
816 The bounding set is inherited at
818 from the thread's parent, and is preserved across an
821 A thread may remove capabilities from its capability bounding set using the
824 operation, provided it has the
827 Once a capability has been dropped from the bounding set,
828 it cannot be restored to that set.
829 A thread can determine if a capability is in its bounding set using the
834 Removing capabilities from the bounding set is only supported if file
835 capabilities are compiled into the kernel.
836 In kernels before Linux 2.6.33,
837 file capabilities were an optional feature configurable via the
838 CONFIG_SECURITY_FILE_CAPABILITIES
840 Since Linux 2.6.33, the configuration option has been removed
841 and file capabilities are always part of the kernel.
842 When file capabilities are compiled into the kernel, the
844 process (the ancestor of all processes) begins with a full bounding set.
845 If file capabilities are not compiled into the kernel, then
847 begins with a full bounding set minus
849 because this capability has a different meaning when there are
850 no file capabilities.
852 Removing a capability from the bounding set does not remove it
853 from the thread's inherited set.
854 However it does prevent the capability from being added
855 back into the thread's inherited set in the future.
858 .SS Effect of user ID changes on capabilities
859 To preserve the traditional semantics for transitions between
860 0 and nonzero user IDs,
861 the kernel makes the following changes to a thread's capability
862 sets on changes to the thread's real, effective, saved set,
863 and file system user IDs (using
868 If one or more of the real, effective or saved set user IDs
869 was previously 0, and as a result of the UID changes all of these IDs
870 have a nonzero value,
871 then all capabilities are cleared from the permitted and effective
874 If the effective user ID is changed from 0 to nonzero,
875 then all capabilities are cleared from the effective set.
877 If the effective user ID is changed from nonzero to 0,
878 then the permitted set is copied to the effective set.
880 If the file system user ID is changed from 0 to nonzero (see
882 then the following capabilities are cleared from the effective set:
884 .BR CAP_DAC_OVERRIDE ,
885 .BR CAP_DAC_READ_SEARCH ,
888 .B CAP_LINUX_IMMUTABLE
889 (since Linux 2.2.30),
890 .BR CAP_MAC_OVERRIDE ,
893 (since Linux 2.2.30).
894 If the file system UID is changed from nonzero to 0,
895 then any of these capabilities that are enabled in the permitted set
896 are enabled in the effective set.
898 If a thread that has a 0 value for one or more of its user IDs wants
899 to prevent its permitted capability set being cleared when it resets
900 all of its user IDs to nonzero values, it can do so using the
905 .SS Programmatically adjusting capability sets
906 A thread can retrieve and change its capability sets using the
914 .BR cap_set_proc (3),
918 is preferred for this purpose.
919 The following rules govern changes to the thread capability sets:
921 If the caller does not have the
924 the new inheritable set must be a subset of the combination
925 of the existing inheritable and permitted sets.
927 (Since kernel 2.6.25)
928 The new inheritable set must be a subset of the combination of the
929 existing inheritable set and the capability bounding set.
931 The new permitted set must be a subset of the existing permitted set
932 (i.e., it is not possible to acquire permitted capabilities
933 that the thread does not currently have).
935 The new effective set must be a subset of the new permitted set.
936 .SS The """securebits"" flags: establishing a capabilities-only environment
937 .\" For some background:
938 .\" see http://lwn.net/Articles/280279/ and
939 .\" http://article.gmane.org/gmane.linux.kernel.lsm/5476/
940 Starting with kernel 2.6.26,
941 and with a kernel in which file capabilities are enabled,
942 Linux implements a set of per-thread
944 flags that can be used to disable special handling of capabilities for UID 0
946 These flags are as follows:
949 Setting this flag allows a thread that has one or more 0 UIDs to retain
950 its capabilities when it switches all of its UIDs to a nonzero value.
951 If this flag is not set,
952 then such a UID switch causes the thread to lose all capabilities.
953 This flag is always cleared on an
955 (This flag provides the same functionality as the older
960 .B SECBIT_NO_SETUID_FIXUP
961 Setting this flag stops the kernel from adjusting capability sets when
962 the threads's effective and file system UIDs are switched between
963 zero and nonzero values.
965 .IR "Effect of User ID Changes on Capabilities" .)
968 If this bit is set, then the kernel does not grant capabilities
969 when a set-user-ID-root program is executed, or when a process with
970 an effective or real UID of 0 calls
973 .IR "Capabilities and execution of programs by root" .)
975 Each of the above "base" flags has a companion "locked" flag.
976 Setting any of the "locked" flags is irreversible,
977 and has the effect of preventing further changes to the
978 corresponding "base" flag.
979 The locked flags are:
980 .BR SECBIT_KEEP_CAPS_LOCKED ,
981 .BR SECBIT_NO_SETUID_FIXUP_LOCKED ,
983 .BR SECBIT_NOROOT_LOCKED .
987 flags can be modified and retrieved using the
995 capability is required to modify the flags.
999 flags are inherited by child processes.
1002 all of the flags are preserved, except
1004 which is always cleared.
1006 An application can use the following call to lock itself,
1007 and all of its descendants,
1008 into an environment where the only way of gaining capabilities
1009 is by executing a program with associated file capabilities:
1013 prctl(PR_SET_SECUREBITS,
1014 SECBIT_KEEP_CAPS_LOCKED |
1015 SECBIT_NO_SETUID_FIXUP |
1016 SECBIT_NO_SETUID_FIXUP_LOCKED |
1018 SECBIT_NOROOT_LOCKED);
1023 No standards govern capabilities, but the Linux capability implementation
1024 is based on the withdrawn POSIX.1e draft standard; see
1025 .UR http://wt.tuxomania.net\:/publications\:/posix.1e/
1028 Since kernel 2.5.27, capabilities are an optional kernel component,
1029 and can be enabled/disabled via the CONFIG_SECURITY_CAPABILITIES
1030 kernel configuration option.
1033 .I /proc/PID/task/TID/status
1034 file can be used to view the capability sets of a thread.
1037 file shows the capability sets of a process's main thread.
1041 package provides a suite of routines for setting and
1042 getting capabilities that is more comfortable and less likely
1043 to change than the interface provided by
1047 This package also provides the
1054 .UR http://www.kernel.org\:/pub\:/linux\:/libs\:/security\:/linux-privs
1057 Before kernel 2.6.24, and since kernel 2.6.24 if
1058 file capabilities are not enabled, a thread with the
1060 capability can manipulate the capabilities of threads other than itself.
1061 However, this is only theoretically possible,
1062 since no thread ever has
1064 in either of these cases:
1066 In the pre-2.6.25 implementation the system-wide capability bounding set,
1067 .IR /proc/sys/kernel/cap-bound ,
1068 always masks out this capability, and this can not be changed
1069 without modifying the kernel source and rebuilding.
1071 If file capabilities are disabled in the current implementation, then
1073 starts out with this capability removed from its per-process bounding
1074 set, and that bounding set is inherited by all other processes
1075 created on the system.
1081 .BR cap_copy_ext (3),
1082 .BR cap_from_text (3),
1083 .BR cap_get_file (3),
1084 .BR cap_get_proc (3),
1089 .BR credentials (7),
1094 .I include/linux/capability.h
1095 in the Linux kernel source tree