1 .\" Copyright (c) 2002 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" 6 Aug 2002 - Initial Creation
26 .\" Modified 2003-05-23, Michael Kerrisk, <mtk.manpages@gmail.com>
27 .\" Modified 2004-05-27, Michael Kerrisk, <mtk.manpages@gmail.com>
28 .\" 2004-12-08, mtk Added O_NOATIME for CAP_FOWNER
29 .\" 2005-08-16, mtk, Added CAP_AUDIT_CONTROL and CAP_AUDIT_WRITE
30 .\" 2008-07-15, Serge Hallyn <serue@us.bbm.com>
31 .\" Document file capabilities, per-process capability
32 .\" bounding set, changed semantics for CAP_SETPCAP,
33 .\" and other changes in 2.6.2[45].
34 .\" Add CAP_MAC_ADMIN, CAP_MAC_OVERRIDE, CAP_SETFCAP.
36 .\" Add text describing circumstances in which CAP_SETPCAP
37 .\" (theoretically) permits a thread to change the
38 .\" capability sets of another thread.
39 .\" Add section describing rules for programmatically
40 .\" adjusting thread capability sets.
41 .\" Describe rationale for capability bounding set.
42 .\" Document "securebits" flags.
43 .\" Add text noting that if we set the effective flag for one file
44 .\" capability, then we must also set the effective flag for all
45 .\" other capabilities where the permitted or inheritable bit is set.
46 .\" 2011-09-07, mtk/Serge hallyn: Add CAP_SYSLOG
48 .TH CAPABILITIES 7 2013-03-11 "Linux" "Linux Programmer's Manual"
50 capabilities \- overview of Linux capabilities
52 For the purpose of performing permission checks,
53 traditional UNIX implementations distinguish two categories of processes:
55 processes (whose effective user ID is 0, referred to as superuser or root),
58 processes (whose effective UID is nonzero).
59 Privileged processes bypass all kernel permission checks,
60 while unprivileged processes are subject to full permission
61 checking based on the process's credentials
62 (usually: effective UID, effective GID, and supplementary group list).
64 Starting with kernel 2.2, Linux divides the privileges traditionally
65 associated with superuser into distinct units, known as
67 which can be independently enabled and disabled.
68 Capabilities are a per-thread attribute.
71 The following list shows the capabilities implemented on Linux,
72 and the operations or behaviors that each capability permits:
74 .BR CAP_AUDIT_CONTROL " (since Linux 2.6.11)"
75 Enable and disable kernel auditing; change auditing filter rules;
76 retrieve auditing status and filtering rules.
78 .BR CAP_AUDIT_WRITE " (since Linux 2.6.11)"
79 Write records to kernel auditing log.
81 .BR CAP_BLOCK_SUSPEND " (since Linux 3.5)"
82 Employ features that can block system suspend
85 .IR /proc/sys/wake_lock ).
88 Make arbitrary changes to file UIDs and GIDs (see
92 Bypass file read, write, and execute permission checks.
93 (DAC is an abbreviation of "discretionary access control".)
95 .B CAP_DAC_READ_SEARCH
96 Bypass file read permission checks and
97 directory read and execute permission checks.
103 Bypass permission checks on operations that normally
104 require the file system UID of the process to match the UID of
108 excluding those operations covered by
111 .BR CAP_DAC_READ_SEARCH ;
113 set extended file attributes (see
117 set Access Control Lists (ACLs) on arbitrary files;
119 ignore directory sticky bit on file deletion;
123 for arbitrary files in
131 Don't clear set-user-ID and set-group-ID permission
132 bits when a file is modified;
133 set the set-group-ID bit for a file whose GID does not match
134 the file system or any of the supplementary GIDs of the calling process.
137 .\" FIXME As at Linux 3.2, there are some strange uses of this capability
138 .\" in other places; they probably should be replaced with something else.
146 Bypass permission checks for operations on System V IPC objects.
149 Bypass permission checks for sending signals (see
151 This includes use of the
155 .\" FIXME CAP_KILL also has an effect for threads + setting child
156 .\" termination signal to other than SIGCHLD: without this
157 .\" capability, the termination signal reverts to SIGCHLD
158 .\" if the child does an exec(). What is the rationale
161 .BR CAP_LEASE " (since Linux 2.4)"
162 Establish leases on arbitrary files (see
165 .B CAP_LINUX_IMMUTABLE
170 .\" These attributes are now available on ext2, ext3, Reiserfs, XFS, JFS
174 .BR CAP_MAC_ADMIN " (since Linux 2.6.25)"
175 Override Mandatory Access Control (MAC).
176 Implemented for the Smack Linux Security Module (LSM).
178 .BR CAP_MAC_OVERRIDE " (since Linux 2.6.25)"
179 Allow MAC configuration or state changes.
180 Implemented for the Smack LSM.
182 .BR CAP_MKNOD " (since Linux 2.4)"
183 Create special files using
187 Perform various network-related operations:
191 interface configuration;
193 administration of IP firewall, masquerading, and accounting
195 modify routing tables;
197 bind to any address for transparent proxying;
199 set type-of-service (TOS)
201 clear driver statistics;
203 set promiscuous mode;
205 enabling multicasting;
209 to set the following socket options:
213 (for a priority outside the range 0 to 6),
220 .B CAP_NET_BIND_SERVICE
221 Bind a socket to Internet domain privileged ports
222 (port numbers less than 1024).
225 (Unused) Make socket broadcasts, and listen to multicasts.
231 use RAW and PACKET sockets;
233 bind to any address for transparent proxying.
236 .\" Also various IP options and setsockopt(SO_BINDTODEVICE)
239 Make arbitrary manipulations of process GIDs and supplementary GID list;
240 forge GID when passing socket credentials via UNIX domain sockets.
242 .BR CAP_SETFCAP " (since Linux 2.6.24)"
243 Set file capabilities.
246 If file capabilities are not supported:
247 grant or remove any capability in the
248 caller's permitted capability set to or from any other process.
251 is not available when the kernel is configured to support
252 file capabilities, since
254 has entirely different semantics for such kernels.)
256 If file capabilities are supported:
257 add any capability from the calling thread's bounding set
258 to its inheritable set;
259 drop capabilities from the bounding set (via
261 .BR PR_CAPBSET_DROP );
267 Make arbitrary manipulations of process UIDs
272 make forged UID when passing socket credentials via UNIX domain sockets.
273 .\" FIXME CAP_SETUID also an effect in exec(); document this.
279 Perform a range of system administration operations including:
287 .BR setdomainname (2);
291 operations (since Linux 2.6.37,
293 should be used to permit such operations);
304 operations on arbitrary System V IPC objects;
306 perform operations on
310 Extended Attributes (see
314 .BR lookup_dcookie (2);
320 and (before Linux 2.6.25)
322 I/O scheduling classes;
324 forge UID when passing socket credentials;
327 .IR /proc/sys/fs/file-max ,
328 the system-wide limit on the number of open files,
329 in system calls that open files (e.g.,
337 flags that create new namespaces with
343 .BR perf_event_open (2);
353 .BR fanotify_init (2);
370 to insert characters into the input queue of a terminal other than
371 the caller's controlling terminal.
381 perform various privileged block-device
385 perform various privileged file-system
389 perform administrative operations on many device drivers.
404 Load and unload kernel modules
408 .BR delete_module (2));
409 in kernels before 2.6.25:
410 drop capabilities from the system-wide capability bounding set.
416 Raise process nice value
419 and change the nice value for arbitrary processes;
421 set real-time scheduling policies for calling process,
422 and set scheduling policies and priorities for arbitrary processes
423 .RB ( sched_setscheduler (2),
424 .BR sched_setparam (2));
426 set CPU affinity for arbitrary processes
427 .RB ( sched_setaffinity (2));
429 set I/O scheduling class and priority for arbitrary processes
430 .RB ( ioprio_set (2));
433 .BR migrate_pages (2)
434 to arbitrary processes and allow processes
435 to be migrated to arbitrary nodes;
436 .\" FIXME CAP_SYS_NICE also has the following effect for
437 .\" migrate_pages(2):
438 .\" do_migrate_pages(mm, &old, &new,
439 .\" capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
443 to arbitrary processes;
459 Trace arbitrary processes using
462 .BR get_robust_list (2)
463 to arbitrary processes;
464 inspect processes using
471 Perform I/O port operations
484 open devices for accessing x86 model-specific registers (MSRs, see
488 .IR /proc/sys/vm/mmap_min_addr ;
490 create memory mappings at addresses below the value specified by
491 .IR /proc/sys/vm/mmap_min_addr ;
501 perform various SCSI device commands;
503 perform certain operations on
509 perform a range of device-specific operations on other devices.
517 Use reserved space on ext2 file systems;
521 calls controlling ext3 journaling;
523 override disk quota limits;
525 increase resource limits (see
532 override maximum number of consoles on console allocation;
534 override maximum number of keymaps;
536 allow more than 64hz interrupts from the real-time clock;
540 limit for a System V message queue above the limit in
541 .I /proc/sys/kernel/msgmnb
548 .I /proc/sys/fs/pipe-size-max
549 limit when setting the capacity of a pipe using the
556 to increase the capacity of a pipe above the limit specified by
557 .IR /proc/sys/fs/pipe-max-size ;
560 .I /proc/sys/fs/mqueue/queues_max
561 limit when creating POSIX message queues (see
562 .BR mq_overview (7));
569 .IR /proc/PID/oom_score_adj
570 to a value lower than the value last set by a process with
571 .BR CAP_SYS_RESOURCE .
577 .RB ( settimeofday (2),
580 set real-time (hardware) clock.
582 .B CAP_SYS_TTY_CONFIG
585 employ various privileged
587 operations on virtual terminals.
589 .BR CAP_SYSLOG " (since Linux 2.6.37)"
596 for information on which operations require privilege.
598 View kernel addresses exposed via
600 and other interfaces when
601 .IR /proc/sys/kernel/kptr_restrict
603 (See the discussion of the
608 .BR CAP_WAKE_ALARM " (since Linux 3.0)"
609 Trigger something that will wake up the system (set
610 .B CLOCK_REALTIME_ALARM
612 .B CLOCK_BOOTTIME_ALARM
615 .SS Past and current implementation
616 A full implementation of capabilities requires that:
618 For all privileged operations,
619 the kernel must check whether the thread has the required
620 capability in its effective set.
622 The kernel must provide system calls allowing a thread's capability sets to
623 be changed and retrieved.
625 The file system must support attaching capabilities to an executable file,
626 so that a process gains those capabilities when the file is executed.
628 Before kernel 2.6.24, only the first two of these requirements are met;
629 since kernel 2.6.24, all three requirements are met.
631 .SS Thread capability sets
632 Each thread has three capability sets containing zero or more
633 of the above capabilities:
636 This is a limiting superset for the effective
637 capabilities that the thread may assume.
638 It is also a limiting superset for the capabilities that
639 may be added to the inheritable set by a thread that does not have the
641 capability in its effective set.
643 If a thread drops a capability from its permitted set,
644 it can never reacquire that capability (unless it
646 either a set-user-ID-root program, or
647 a program whose associated file capabilities grant that capability).
650 This is a set of capabilities preserved across an
652 It provides a mechanism for a process to assign capabilities
653 to the permitted set of the new program during an
657 This is the set of capabilities used by the kernel to
658 perform permission checks for the thread.
662 inherits copies of its parent's capability sets.
663 See below for a discussion of the treatment of capabilities during
668 a thread may manipulate its own capability sets (see below).
670 .SS File capabilities
671 Since kernel 2.6.24, the kernel supports
672 associating capability sets with an executable file using
674 The file capability sets are stored in an extended attribute (see
677 .IR "security.capability" .
678 Writing to this extended attribute requires the
681 The file capability sets,
682 in conjunction with the capability sets of the thread,
683 determine the capabilities of a thread after an
686 The three file capability sets are:
688 .IR Permitted " (formerly known as " forced ):
689 These capabilities are automatically permitted to the thread,
690 regardless of the thread's inheritable capabilities.
692 .IR Inheritable " (formerly known as " allowed ):
693 This set is ANDed with the thread's inheritable set to determine which
694 inheritable capabilities are enabled in the permitted set of
699 This is not a set, but rather just a single bit.
700 If this bit is set, then during an
702 all of the new permitted capabilities for the thread are
703 also raised in the effective set.
704 If this bit is not set, then after an
706 none of the new permitted capabilities is in the new effective set.
708 Enabling the file effective capability bit implies
709 that any file permitted or inheritable capability that causes a
710 thread to acquire the corresponding permitted capability during an
712 (see the transformation rules described below) will also acquire that
713 capability in its effective set.
714 Therefore, when assigning capabilities to a file
716 .BR cap_set_file (3),
718 if we specify the effective flag as being enabled for any capability,
719 then the effective flag must also be specified as enabled
720 for all other capabilities for which the corresponding permitted or
721 inheritable flags is enabled.
723 .SS Transformation of capabilities during execve()
727 the kernel calculates the new capabilities of
728 the process using the following algorithm:
732 P'(permitted) = (P(inheritable) & F(inheritable)) |
733 (F(permitted) & cap_bset)
735 P'(effective) = F(effective) ? P'(permitted) : 0
737 P'(inheritable) = P(inheritable) [i.e., unchanged]
744 denotes the value of a thread capability set before the
747 denotes the value of a capability set after the
750 denotes a file capability set
752 is the value of the capability bounding set (described below).
755 .SS Capabilities and execution of programs by root
756 In order to provide an all-powerful
758 using capability sets, during an
761 If a set-user-ID-root program is being executed,
762 or the real user ID of the process is 0 (root)
763 then the file inheritable and permitted sets are defined to be all ones
764 (i.e., all capabilities enabled).
766 If a set-user-ID-root program is being executed,
767 then the file effective bit is defined to be one (enabled).
769 The upshot of the above rules,
770 combined with the capabilities transformations described above,
771 is that when a process
773 a set-user-ID-root program, or when a process with an effective UID of 0
776 it gains all capabilities in its permitted and effective capability sets,
777 except those masked out by the capability bounding set.
778 .\" If a process with real UID 0, and nonzero effective UID does an
779 .\" exec(), then it gets all capabilities in its
780 .\" permitted set, and no effective capabilities
781 This provides semantics that are the same as those provided by
782 traditional UNIX systems.
783 .SS Capability bounding set
784 The capability bounding set is a security mechanism that can be used
785 to limit the capabilities that can be gained during an
787 The bounding set is used in the following ways:
791 the capability bounding set is ANDed with the file permitted
792 capability set, and the result of this operation is assigned to the
793 thread's permitted capability set.
794 The capability bounding set thus places a limit on the permitted
795 capabilities that may be granted by an executable file.
798 The capability bounding set acts as a limiting superset for
799 the capabilities that a thread can add to its inheritable set using
801 This means that if a capability is not in the bounding set,
802 then a thread can't add this capability to its
803 inheritable set, even if it was in its permitted capabilities,
804 and thereby cannot have this capability preserved in its
805 permitted set when it
807 a file that has the capability in its inheritable set.
809 Note that the bounding set masks the file permitted capabilities,
810 but not the inherited capabilities.
811 If a thread maintains a capability in its inherited set
812 that is not in its bounding set,
813 then it can still gain that capability in its permitted set
814 by executing a file that has the capability in its inherited set.
816 Depending on the kernel version, the capability bounding set is either
817 a system-wide attribute, or a per-process attribute.
819 .B "Capability bounding set prior to Linux 2.6.25"
821 In kernels before 2.6.25, the capability bounding set is a system-wide
822 attribute that affects all threads on the system.
823 The bounding set is accessible via the file
824 .IR /proc/sys/kernel/cap-bound .
825 (Confusingly, this bit mask parameter is expressed as a
826 signed decimal number in
827 .IR /proc/sys/kernel/cap-bound .)
831 process may set capabilities in the capability bounding set;
832 other than that, the superuser (more precisely: programs with the
834 capability) may only clear capabilities from this set.
836 On a standard system the capability bounding set always masks out the
839 To remove this restriction (dangerous!), modify the definition of
842 .I include/linux/capability.h
843 and rebuild the kernel.
845 The system-wide capability bounding set feature was added
846 to Linux starting with kernel version 2.2.11.
849 .B "Capability bounding set from Linux 2.6.25 onward"
851 From Linux 2.6.25, the
852 .I "capability bounding set"
853 is a per-thread attribute.
854 (There is no longer a system-wide capability bounding set.)
856 The bounding set is inherited at
858 from the thread's parent, and is preserved across an
861 A thread may remove capabilities from its capability bounding set using the
864 operation, provided it has the
867 Once a capability has been dropped from the bounding set,
868 it cannot be restored to that set.
869 A thread can determine if a capability is in its bounding set using the
874 Removing capabilities from the bounding set is only supported if file
875 capabilities are compiled into the kernel.
876 In kernels before Linux 2.6.33,
877 file capabilities were an optional feature configurable via the
878 CONFIG_SECURITY_FILE_CAPABILITIES
880 Since Linux 2.6.33, the configuration option has been removed
881 and file capabilities are always part of the kernel.
882 When file capabilities are compiled into the kernel, the
884 process (the ancestor of all processes) begins with a full bounding set.
885 If file capabilities are not compiled into the kernel, then
887 begins with a full bounding set minus
889 because this capability has a different meaning when there are
890 no file capabilities.
892 Removing a capability from the bounding set does not remove it
893 from the thread's inherited set.
894 However it does prevent the capability from being added
895 back into the thread's inherited set in the future.
898 .SS Effect of user ID changes on capabilities
899 To preserve the traditional semantics for transitions between
900 0 and nonzero user IDs,
901 the kernel makes the following changes to a thread's capability
902 sets on changes to the thread's real, effective, saved set,
903 and file system user IDs (using
908 If one or more of the real, effective or saved set user IDs
909 was previously 0, and as a result of the UID changes all of these IDs
910 have a nonzero value,
911 then all capabilities are cleared from the permitted and effective
914 If the effective user ID is changed from 0 to nonzero,
915 then all capabilities are cleared from the effective set.
917 If the effective user ID is changed from nonzero to 0,
918 then the permitted set is copied to the effective set.
920 If the file system user ID is changed from 0 to nonzero (see
922 then the following capabilities are cleared from the effective set:
924 .BR CAP_DAC_OVERRIDE ,
925 .BR CAP_DAC_READ_SEARCH ,
928 .B CAP_LINUX_IMMUTABLE
929 (since Linux 2.2.30),
930 .BR CAP_MAC_OVERRIDE ,
933 (since Linux 2.2.30).
934 If the file system UID is changed from nonzero to 0,
935 then any of these capabilities that are enabled in the permitted set
936 are enabled in the effective set.
938 If a thread that has a 0 value for one or more of its user IDs wants
939 to prevent its permitted capability set being cleared when it resets
940 all of its user IDs to nonzero values, it can do so using the
945 .SS Programmatically adjusting capability sets
946 A thread can retrieve and change its capability sets using the
954 .BR cap_set_proc (3),
958 is preferred for this purpose.
959 The following rules govern changes to the thread capability sets:
961 If the caller does not have the
964 the new inheritable set must be a subset of the combination
965 of the existing inheritable and permitted sets.
967 (Since kernel 2.6.25)
968 The new inheritable set must be a subset of the combination of the
969 existing inheritable set and the capability bounding set.
971 The new permitted set must be a subset of the existing permitted set
972 (i.e., it is not possible to acquire permitted capabilities
973 that the thread does not currently have).
975 The new effective set must be a subset of the new permitted set.
976 .SS The securebits flags: establishing a capabilities-only environment
977 .\" For some background:
978 .\" see http://lwn.net/Articles/280279/ and
979 .\" http://article.gmane.org/gmane.linux.kernel.lsm/5476/
980 Starting with kernel 2.6.26,
981 and with a kernel in which file capabilities are enabled,
982 Linux implements a set of per-thread
984 flags that can be used to disable special handling of capabilities for UID 0
986 These flags are as follows:
989 Setting this flag allows a thread that has one or more 0 UIDs to retain
990 its capabilities when it switches all of its UIDs to a nonzero value.
991 If this flag is not set,
992 then such a UID switch causes the thread to lose all capabilities.
993 This flag is always cleared on an
995 (This flag provides the same functionality as the older
1000 .B SECBIT_NO_SETUID_FIXUP
1001 Setting this flag stops the kernel from adjusting capability sets when
1002 the threads's effective and file system UIDs are switched between
1003 zero and nonzero values.
1005 .IR "Effect of User ID Changes on Capabilities" .)
1008 If this bit is set, then the kernel does not grant capabilities
1009 when a set-user-ID-root program is executed, or when a process with
1010 an effective or real UID of 0 calls
1013 .IR "Capabilities and execution of programs by root" .)
1015 Each of the above "base" flags has a companion "locked" flag.
1016 Setting any of the "locked" flags is irreversible,
1017 and has the effect of preventing further changes to the
1018 corresponding "base" flag.
1019 The locked flags are:
1020 .BR SECBIT_KEEP_CAPS_LOCKED ,
1021 .BR SECBIT_NO_SETUID_FIXUP_LOCKED ,
1023 .BR SECBIT_NOROOT_LOCKED .
1027 flags can be modified and retrieved using the
1029 .B PR_SET_SECUREBITS
1031 .B PR_GET_SECUREBITS
1035 capability is required to modify the flags.
1039 flags are inherited by child processes.
1042 all of the flags are preserved, except
1044 which is always cleared.
1046 An application can use the following call to lock itself,
1047 and all of its descendants,
1048 into an environment where the only way of gaining capabilities
1049 is by executing a program with associated file capabilities:
1053 prctl(PR_SET_SECUREBITS,
1054 SECBIT_KEEP_CAPS_LOCKED |
1055 SECBIT_NO_SETUID_FIXUP |
1056 SECBIT_NO_SETUID_FIXUP_LOCKED |
1058 SECBIT_NOROOT_LOCKED);
1063 No standards govern capabilities, but the Linux capability implementation
1064 is based on the withdrawn POSIX.1e draft standard; see
1065 .UR http://wt.tuxomania.net\:/publications\:/posix.1e/
1068 Since kernel 2.5.27, capabilities are an optional kernel component,
1069 and can be enabled/disabled via the CONFIG_SECURITY_CAPABILITIES
1070 kernel configuration option.
1073 .I /proc/PID/task/TID/status
1074 file can be used to view the capability sets of a thread.
1077 file shows the capability sets of a process's main thread.
1078 Before Linux 3.8, nonexistent capabilities were shown as being
1079 enabled (1) in these sets.
1081 .\" 7b9a7ec565505699f503b4fcf61500dceb36e744
1082 all non-existent capabilities (above
1084 are shown as disabled (0).
1088 package provides a suite of routines for setting and
1089 getting capabilities that is more comfortable and less likely
1090 to change than the interface provided by
1094 This package also provides the
1101 .UR http://www.kernel.org\:/pub\:/linux\:/libs\:/security\:/linux-privs
1104 Before kernel 2.6.24, and since kernel 2.6.24 if
1105 file capabilities are not enabled, a thread with the
1107 capability can manipulate the capabilities of threads other than itself.
1108 However, this is only theoretically possible,
1109 since no thread ever has
1111 in either of these cases:
1113 In the pre-2.6.25 implementation the system-wide capability bounding set,
1114 .IR /proc/sys/kernel/cap-bound ,
1115 always masks out this capability, and this can not be changed
1116 without modifying the kernel source and rebuilding.
1118 If file capabilities are disabled in the current implementation, then
1120 starts out with this capability removed from its per-process bounding
1121 set, and that bounding set is inherited by all other processes
1122 created on the system.
1128 .BR cap_copy_ext (3),
1129 .BR cap_from_text (3),
1130 .BR cap_get_file (3),
1131 .BR cap_get_proc (3),
1136 .BR credentials (7),
1141 .I include/linux/capability.h
1142 in the Linux kernel source tree