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 2019-08-02 "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_READ " (since Linux 3.16)"
79 .\" commit a29b694aa1739f9d76538e34ae25524f9c549d59
80 .\" commit 3a101b8de0d39403b2c7e5c23fd0b005668acf48
81 Allow reading the audit log via a multicast netlink socket.
83 .BR CAP_AUDIT_WRITE " (since Linux 2.6.11)"
84 Write records to kernel auditing log.
85 .\" FIXME Add FAN_ENABLE_AUDIT
87 .BR CAP_BLOCK_SUSPEND " (since Linux 3.5)"
88 Employ features that can block system suspend
91 .IR /proc/sys/wake_lock ).
94 Make arbitrary changes to file UIDs and GIDs (see
98 Bypass file read, write, and execute permission checks.
99 (DAC is an abbreviation of "discretionary access control".)
101 .B CAP_DAC_READ_SEARCH
105 Bypass file read permission checks and
106 directory read and execute permission checks;
109 .BR open_by_handle_at (2);
114 flag to create a link to a file referred to by a file descriptor.
122 Bypass permission checks on operations that normally
123 require the filesystem UID of the process to match the UID of
127 excluding those operations covered by
130 .BR CAP_DAC_READ_SEARCH ;
133 .BR ioctl_iflags (2))
136 set Access Control Lists (ACLs) on arbitrary files;
138 ignore directory sticky bit on file deletion;
142 extended attributes on sticky directory owned by any user;
146 for arbitrary files in
157 Don't clear set-user-ID and set-group-ID mode
158 bits when a file is modified;
160 set the set-group-ID bit for a file whose GID does not match
161 the filesystem or any of the supplementary GIDs of the calling process.
166 .\" FIXME . As at Linux 3.2, there are some strange uses of this capability
167 .\" in other places; they probably should be replaced with something else.
175 Bypass permission checks for operations on System V IPC objects.
178 Bypass permission checks for sending signals (see
180 This includes use of the
184 .\" FIXME . CAP_KILL also has an effect for threads + setting child
185 .\" termination signal to other than SIGCHLD: without this
186 .\" capability, the termination signal reverts to SIGCHLD
187 .\" if the child does an exec(). What is the rationale
190 .BR CAP_LEASE " (since Linux 2.4)"
191 Establish leases on arbitrary files (see
194 .B CAP_LINUX_IMMUTABLE
200 .BR ioctl_iflags (2)).
202 .BR CAP_MAC_ADMIN " (since Linux 2.6.25)"
203 Allow MAC configuration or state changes.
204 Implemented for the Smack Linux Security Module (LSM).
206 .BR CAP_MAC_OVERRIDE " (since Linux 2.6.25)"
207 Override Mandatory Access Control (MAC).
208 Implemented for the Smack LSM.
210 .BR CAP_MKNOD " (since Linux 2.4)"
211 Create special files using
215 Perform various network-related operations:
219 interface configuration;
221 administration of IP firewall, masquerading, and accounting;
223 modify routing tables;
225 bind to any address for transparent proxying;
227 set type-of-service (TOS)
229 clear driver statistics;
231 set promiscuous mode;
233 enabling multicasting;
237 to set the following socket options:
241 (for a priority outside the range 0 to 6),
248 .B CAP_NET_BIND_SERVICE
249 Bind a socket to Internet domain privileged ports
250 (port numbers less than 1024).
253 (Unused) Make socket broadcasts, and listen to multicasts.
254 .\" FIXME Since Linux 4.2, there are use cases for netlink sockets
255 .\" commit 59324cf35aba5336b611074028777838a963d03b
261 Use RAW and PACKET sockets;
263 bind to any address for transparent proxying.
266 .\" Also various IP options and setsockopt(SO_BINDTODEVICE)
272 Make arbitrary manipulations of process GIDs and supplementary GID list;
274 forge GID when passing socket credentials via UNIX domain sockets;
276 write a group ID mapping in a user namespace (see
277 .BR user_namespaces (7)).
281 .BR CAP_SETFCAP " (since Linux 2.6.24)"
282 Set arbitrary capabilities on a file.
285 If file capabilities are supported (i.e., since Linux 2.6.24):
286 add any capability from the calling thread's bounding set
287 to its inheritable set;
288 drop capabilities from the bounding set (via
290 .BR PR_CAPBSET_DROP );
295 If file capabilities are not supported (i.e., kernels before Linux 2.6.24):
296 grant or remove any capability in the
297 caller's permitted capability set to or from any other process.
300 is not available when the kernel is configured to support
301 file capabilities, since
303 has entirely different semantics for such kernels.)
309 Make arbitrary manipulations of process UIDs
315 forge UID when passing socket credentials via UNIX domain sockets;
317 write a user ID mapping in a user namespace (see
318 .BR user_namespaces (7)).
321 .\" FIXME CAP_SETUID also an effect in exec(); document this.
325 this capability is overloaded; see
326 .IR "Notes to kernel developers" ,
332 Perform a range of system administration operations including:
341 .BR setdomainname (2);
345 operations (since Linux 2.6.37,
347 should be used to permit such operations);
358 operations on arbitrary System V IPC objects;
364 perform operations on
368 Extended Attributes (see
372 .BR lookup_dcookie (2);
378 and (before Linux 2.6.25)
380 I/O scheduling classes;
382 forge PID when passing socket credentials via UNIX domain sockets;
385 .IR /proc/sys/fs/file-max ,
386 the system-wide limit on the number of open files,
387 in system calls that open files (e.g.,
395 flags that create new namespaces with
399 (but, since Linux 3.8,
400 creating user namespaces does not require any capability);
403 .BR perf_event_open (2);
418 .BR fanotify_init (2);
438 to insert characters into the input queue of a terminal other than
439 the caller's controlling terminal;
449 perform various privileged block-device
453 perform various privileged filesystem
466 filter without first having to set the
470 modify allow/deny rules for device control groups;
474 .B PTRACE_SECCOMP_GET_FILTER
475 operation to dump tracee's seccomp filters;
480 operation to suspend the tracee's seccomp protections (i.e., the
481 .B PTRACE_O_SUSPEND_SECCOMP
484 perform administrative operations on many device drivers.
501 change mount namespaces using
510 Load and unload kernel modules
514 .BR delete_module (2));
516 in kernels before 2.6.25:
517 drop capabilities from the system-wide capability bounding set.
525 Raise process nice value
528 and change the nice value for arbitrary processes;
530 set real-time scheduling policies for calling process,
531 and set scheduling policies and priorities for arbitrary processes
532 .RB ( sched_setscheduler (2),
533 .BR sched_setparam (2),
534 .BR sched_setattr (2));
536 set CPU affinity for arbitrary processes
537 .RB ( sched_setaffinity (2));
539 set I/O scheduling class and priority for arbitrary processes
540 .RB ( ioprio_set (2));
543 .BR migrate_pages (2)
544 to arbitrary processes and allow processes
545 to be migrated to arbitrary nodes;
546 .\" FIXME CAP_SYS_NICE also has the following effect for
547 .\" migrate_pages(2):
548 .\" do_migrate_pages(mm, &old, &new,
549 .\" capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
555 to arbitrary processes;
574 Trace arbitrary processes using
578 .BR get_robust_list (2)
579 to arbitrary processes;
581 transfer data to or from the memory of arbitrary processes using
582 .BR process_vm_readv (2)
584 .BR process_vm_writev (2);
586 inspect processes using
595 Perform I/O port operations
608 open devices for accessing x86 model-specific registers (MSRs, see
612 .IR /proc/sys/vm/mmap_min_addr ;
614 create memory mappings at addresses below the value specified by
615 .IR /proc/sys/vm/mmap_min_addr ;
625 perform various SCSI device commands;
627 perform certain operations on
633 perform a range of device-specific operations on other devices.
641 Use reserved space on ext2 filesystems;
645 calls controlling ext3 journaling;
647 override disk quota limits;
649 increase resource limits (see
656 override maximum number of consoles on console allocation;
658 override maximum number of keymaps;
660 allow more than 64hz interrupts from the real-time clock;
664 limit for a System V message queue above the limit in
665 .I /proc/sys/kernel/msgmnb
673 resource limit on the number of "in-flight" file descriptors
674 to be bypassed when passing file descriptors to another process
675 via a UNIX domain socket (see
679 .I /proc/sys/fs/pipe-size-max
680 limit when setting the capacity of a pipe using the
687 to increase the capacity of a pipe above the limit specified by
688 .IR /proc/sys/fs/pipe-max-size ;
691 .I /proc/sys/fs/mqueue/queues_max
692 limit when creating POSIX message queues (see
693 .BR mq_overview (7));
701 .IR /proc/[pid]/oom_score_adj
702 to a value lower than the value last set by a process with
703 .BR CAP_SYS_RESOURCE .
709 .RB ( settimeofday (2),
712 set real-time (hardware) clock.
714 .B CAP_SYS_TTY_CONFIG
717 employ various privileged
719 operations on virtual terminals.
721 .BR CAP_SYSLOG " (since Linux 2.6.37)"
730 for information on which operations require privilege.
732 View kernel addresses exposed via
734 and other interfaces when
735 .IR /proc/sys/kernel/kptr_restrict
737 (See the discussion of the
744 .BR CAP_WAKE_ALARM " (since Linux 3.0)"
745 Trigger something that will wake up the system (set
746 .B CLOCK_REALTIME_ALARM
748 .B CLOCK_BOOTTIME_ALARM
751 .SS Past and current implementation
752 A full implementation of capabilities requires that:
754 For all privileged operations,
755 the kernel must check whether the thread has the required
756 capability in its effective set.
758 The kernel must provide system calls allowing a thread's capability sets to
759 be changed and retrieved.
761 The filesystem must support attaching capabilities to an executable file,
762 so that a process gains those capabilities when the file is executed.
764 Before kernel 2.6.24, only the first two of these requirements are met;
765 since kernel 2.6.24, all three requirements are met.
767 .SS Notes to kernel developers
768 When adding a new kernel feature that should be governed by a capability,
769 consider the following points.
771 The goal of capabilities is divide the power of superuser into pieces,
772 such that if a program that has one or more capabilities is compromised,
773 its power to do damage to the system would be less than the same program
774 running with root privilege.
776 You have the choice of either creating a new capability for your new feature,
777 or associating the feature with one of the existing capabilities.
778 In order to keep the set of capabilities to a manageable size,
779 the latter option is preferable,
780 unless there are compelling reasons to take the former option.
781 (There is also a technical limit:
782 the size of capability sets is currently limited to 64 bits.)
784 To determine which existing capability might best be associated
785 with your new feature, review the list of capabilities above in order
786 to find a "silo" into which your new feature best fits.
787 One approach to take is to determine if there are other features
788 requiring capabilities that will always be used along with the new feature.
789 If the new feature is useless without these other features,
790 you should use the same capability as the other features.
795 if you can possibly avoid it!
796 A vast proportion of existing capability checks are associated
797 with this capability (see the partial list above).
798 It can plausibly be called "the new root",
799 since on the one hand, it confers a wide range of powers,
800 and on the other hand,
801 its broad scope means that this is the capability
802 that is required by many privileged programs.
803 Don't make the problem worse.
804 The only new features that should be associated with
808 match existing uses in that silo.
810 If you have determined that it really is necessary to create
811 a new capability for your feature,
812 don't make or name it as a "single-use" capability.
813 Thus, for example, the addition of the highly specific
815 was probably a mistake.
816 Instead, try to identify and name your new capability as a broader
817 silo into which other related future use cases might fit.
819 .SS Thread capability sets
820 Each thread has the following capability sets containing zero or more
821 of the above capabilities:
824 This is a limiting superset for the effective
825 capabilities that the thread may assume.
826 It is also a limiting superset for the capabilities that
827 may be added to the inheritable set by a thread that does not have the
829 capability in its effective set.
831 If a thread drops a capability from its permitted set,
832 it can never reacquire that capability (unless it
834 either a set-user-ID-root program, or
835 a program whose associated file capabilities grant that capability).
838 This is a set of capabilities preserved across an
840 Inheritable capabilities remain inheritable when executing any program,
841 and inheritable capabilities are added to the permitted set when executing
842 a program that has the corresponding bits set in the file inheritable set.
844 Because inheritable capabilities are not generally preserved across
846 when running as a non-root user, applications that wish to run helper
847 programs with elevated capabilities should consider using
848 ambient capabilities, described below.
851 This is the set of capabilities used by the kernel to
852 perform permission checks for the thread.
854 .IR Bounding " (per-thread since Linux 2.6.25)"
855 The capability bounding set is a mechanism that can be used
856 to limit the capabilities that are gained during
859 Since Linux 2.6.25, this is a per-thread capability set.
860 In older kernels, the capability bounding set was a system wide attribute
861 shared by all threads on the system.
864 For more details on the capability bounding set, see below.
866 .IR Ambient " (since Linux 4.3)"
867 .\" commit 58319057b7847667f0c9585b9de0e8932b0fdb08
868 This is a set of capabilities that are preserved across an
870 of a program that is not privileged.
871 The ambient capability set obeys the invariant that no capability
872 can ever be ambient if it is not both permitted and inheritable.
874 The ambient capability set can be directly modified using
876 Ambient capabilities are automatically lowered if either of
877 the corresponding permitted or inheritable capabilities is lowered.
879 Executing a program that changes UID or GID due to the
880 set-user-ID or set-group-ID bits or executing a program that has
881 any file capabilities set will clear the ambient set.
882 Ambient capabilities are added to the permitted set and
883 assigned to the effective set when
886 If ambient capabilities cause a process's permitted and effective
887 capabilities to increase during an
889 this does not trigger the secure-execution mode described in
894 inherits copies of its parent's capability sets.
895 See below for a discussion of the treatment of capabilities during
900 a thread may manipulate its own capability sets (see below).
902 Since Linux 3.2, the file
903 .I /proc/sys/kernel/cap_last_cap
904 .\" commit 73efc0394e148d0e15583e13712637831f926720
905 exposes the numerical value of the highest capability
906 supported by the running kernel;
907 this can be used to determine the highest bit
908 that may be set in a capability set.
910 .SS File capabilities
911 Since kernel 2.6.24, the kernel supports
912 associating capability sets with an executable file using
914 The file capability sets are stored in an extended attribute (see
919 .IR "security.capability" .
920 Writing to this extended attribute requires the
923 The file capability sets,
924 in conjunction with the capability sets of the thread,
925 determine the capabilities of a thread after an
928 The three file capability sets are:
930 .IR Permitted " (formerly known as " forced ):
931 These capabilities are automatically permitted to the thread,
932 regardless of the thread's inheritable capabilities.
934 .IR Inheritable " (formerly known as " allowed ):
935 This set is ANDed with the thread's inheritable set to determine which
936 inheritable capabilities are enabled in the permitted set of
941 This is not a set, but rather just a single bit.
942 If this bit is set, then during an
944 all of the new permitted capabilities for the thread are
945 also raised in the effective set.
946 If this bit is not set, then after an
948 none of the new permitted capabilities is in the new effective set.
950 Enabling the file effective capability bit implies
951 that any file permitted or inheritable capability that causes a
952 thread to acquire the corresponding permitted capability during an
954 (see the transformation rules described below) will also acquire that
955 capability in its effective set.
956 Therefore, when assigning capabilities to a file
958 .BR cap_set_file (3),
960 if we specify the effective flag as being enabled for any capability,
961 then the effective flag must also be specified as enabled
962 for all other capabilities for which the corresponding permitted or
963 inheritable flags is enabled.
965 .SS File capability extended attribute versioning
966 To allow extensibility,
967 the kernel supports a scheme to encode a version number inside the
968 .I security.capability
969 extended attribute that is used to implement file capabilities.
970 These version numbers are internal to the implementation,
971 and not directly visible to user-space applications.
972 To date, the following versions are supported:
974 .BR VFS_CAP_REVISION_1
975 This was the original file capability implementation,
976 which supported 32-bit masks for file capabilities.
978 .BR VFS_CAP_REVISION_2 " (since Linux 2.6.25)"
979 .\" commit e338d263a76af78fe8f38a72131188b58fceb591
980 This version allows for file capability masks that are 64 bits in size,
981 and was necessary as the number of supported capabilities grew beyond 32.
982 The kernel transparently continues to support the execution of files
983 that have 32-bit version 1 capability masks,
984 but when adding capabilities to files that did not previously
985 have capabilities, or modifying the capabilities of existing files,
986 it automatically uses the version 2 scheme
987 (or possibly the version 3 scheme, as described below).
989 .BR VFS_CAP_REVISION_3 " (since Linux 4.14)"
990 .\" commit 8db6c34f1dbc8e06aa016a9b829b06902c3e1340
991 Version 3 file capabilities are provided
992 to support namespaced file capabilities (described below).
994 As with version 2 file capabilities,
995 version 3 capability masks are 64 bits in size.
996 But in addition, the root user ID of namespace is encoded in the
997 .I security.capability
999 (A namespace's root user ID is the value that user ID 0
1000 inside that namespace maps to in the initial user namespace.)
1002 Version 3 file capabilities are designed to coexist
1003 with version 2 capabilities;
1004 that is, on a modern Linux system,
1005 there may be some files with version 2 capabilities
1006 while others have version 3 capabilities.
1009 the only kind of file capability extended attribute
1010 that could be attached to a file was a
1011 .B VFS_CAP_REVISION_2
1015 .I security.capability
1016 extended attribute that is attached to a file
1017 depends on the circumstances in which the attribute was created.
1019 Starting with Linux 4.14, a
1020 .I security.capability
1021 extended attribute is automatically created as (or converted to)
1023 .RB ( VFS_CAP_REVISION_3 )
1024 attribute if both of the following are true:
1026 The thread writing the attribute resides in a noninitial user namespace.
1027 (More precisely: the thread resides in a user namespace other
1028 than the one from which the underlying filesystem was mounted.)
1032 capability over the file inode,
1033 meaning that (a) the thread has the
1035 capability in its own user namespace;
1036 and (b) the UID and GID of the file inode have mappings in
1037 the writer's user namespace.
1040 .BR VFS_CAP_REVISION_3
1041 .I security.capability
1042 extended attribute is created, the root user ID of the creating thread's
1043 user namespace is saved in the extended attribute.
1045 By contrast, creating or modifying a
1046 .I security.capability
1047 extended attribute from a privileged
1049 thread that resides in the
1050 namespace where the underlying filesystem was mounted
1051 (this normally means the initial user namespace)
1052 automatically results in the creation of a version 2
1053 .RB ( VFS_CAP_REVISION_2 )
1056 Note that the creation of a version 3
1057 .I security.capability
1058 extended attribute is automatic.
1059 That is to say, when a user-space application writes
1062 .I security.capability
1063 attribute in the version 2 format,
1064 the kernel will automatically create a version 3 attribute
1065 if the attribute is created in the circumstances described above.
1066 Correspondingly, when a version 3
1067 .I security.capability
1068 attribute is retrieved
1070 by a process that resides inside a user namespace that was created by the
1071 root user ID (or a descendant of that user namespace),
1072 the returned attribute is (automatically)
1073 simplified to appear as a version 2 attribute
1074 (i.e., the returned value is the size of a version 2 attribute and does
1075 not include the root user ID).
1076 These automatic translations mean that no changes are required to
1077 user-space tools (e.g.,
1081 in order for those tools to be used to create and retrieve version 3
1082 .I security.capability
1085 Note that a file can have either a version 2 or a version 3
1086 .I security.capability
1087 extended attribute associated with it, but not both:
1088 creation or modification of the
1089 .I security.capability
1090 extended attribute will automatically modify the version
1091 according to the circumstances in which the extended attribute is
1092 created or modified.
1094 .SS Transformation of capabilities during execve()
1098 the kernel calculates the new capabilities of
1099 the process using the following algorithm:
1103 P'(ambient) = (file is privileged) ? 0 : P(ambient)
1105 P'(permitted) = (P(inheritable) & F(inheritable)) |
1106 (F(permitted) & P(bounding)) | P'(ambient)
1108 P'(effective) = F(effective) ? P'(permitted) : P'(ambient)
1110 P'(inheritable) = P(inheritable) [i.e., unchanged]
1112 P'(bounding) = P(bounding) [i.e., unchanged]
1119 denotes the value of a thread capability set before the
1122 denotes the value of a thread capability set after the
1125 denotes a file capability set
1128 Note the following details relating to the above capability
1129 transformation rules:
1131 The ambient capability set is present only since Linux 4.3.
1132 When determining the transformation of the ambient set during
1134 a privileged file is one that has capabilities or
1135 has the set-user-ID or set-group-ID bit set.
1137 Prior to Linux 2.6.25,
1138 the bounding set was a system-wide attribute shared by all threads.
1139 That system-wide value was employed to calculate the new permitted set during
1141 in the same manner as shown above for
1145 during the capability transitions described above,
1146 file capabilities may be ignored (treated as empty) for the same reasons
1147 that the set-user-ID and set-group-ID bits are ignored; see
1149 File capabilities are similarly ignored if the kernel was booted with the
1154 according to the rules above,
1155 if a process with nonzero user IDs performs an
1157 then any capabilities that are present in
1158 its permitted and effective sets will be cleared.
1159 For the treatment of capabilities when a process with a
1160 user ID of zero performs an
1163 .IR "Capabilities and execution of programs by root" .
1165 .SS Safety checking for capability-dumb binaries
1166 A capability-dumb binary is an application that has been
1167 marked to have file capabilities, but has not been converted to use the
1169 API to manipulate its capabilities.
1170 (In other words, this is a traditional set-user-ID-root program
1171 that has been switched to use file capabilities,
1172 but whose code has not been modified to understand capabilities.)
1173 For such applications,
1174 the effective capability bit is set on the file,
1175 so that the file permitted capabilities are automatically
1176 enabled in the process effective set when executing the file.
1177 The kernel recognizes a file which has the effective capability bit set
1178 as capability-dumb for the purpose of the check described here.
1180 When executing a capability-dumb binary,
1181 the kernel checks if the process obtained all permitted capabilities
1182 that were specified in the file permitted set,
1183 after the capability transformations described above have been performed.
1184 (The typical reason why this might
1186 occur is that the capability bounding set masked out some
1187 of the capabilities in the file permitted set.)
1188 If the process did not obtain the full set of
1189 file permitted capabilities, then
1191 fails with the error
1193 This prevents possible security risks that could arise when
1194 a capability-dumb application is executed with less privilege that it needs.
1195 Note that, by definition,
1196 the application could not itself recognize this problem,
1197 since it does not employ the
1201 .SS Capabilities and execution of programs by root
1202 .\" See cap_bprm_set_creds(), bprm_caps_from_vfs_cap() and
1203 .\" handle_privileged_root() in security/commoncap.c (Linux 5.0 source)
1204 In order to mirror traditional UNIX semantics,
1205 the kernel performs special treatment of file capabilities when
1206 a process with UID 0 (root) executes a program and
1207 when a set-user-ID-root program is executed.
1209 After having performed any changes to the process effective ID that
1210 were triggered by the set-user-ID mode bit of the binary\(eme.g.,
1211 switching the effective user ID to 0 (root) because
1212 a set-user-ID-root program was executed\(emthe
1213 kernel calculates the file capability sets as follows:
1215 If the real or effective user ID of the process is 0 (root),
1216 then the file inheritable and permitted sets are ignored;
1217 instead they are notionally considered to be all ones
1218 (i.e., all capabilities enabled).
1219 (There is one exception to this behavior, described below in
1220 .IR "Set-user-ID-root programs that have file capabilities" .)
1222 If the effective user ID of the process is 0 (root) or
1223 the file effective bit is in fact enabled,
1224 then the file effective bit is notionally defined to be one (enabled).
1226 These notional values for the file's capability sets are then used
1227 as described above to calculate the transformation of the process's
1231 Thus, when a process with nonzero UIDs
1233 a set-user-ID-root program that does not have capabilities attached,
1234 or when a process whose real and effective UIDs are zero
1236 a program, the calculation of the process's new
1237 permitted capabilities simplifies to:
1241 P'(permitted) = P(inheritable) | P(bounding)
1243 P'(effective) = P'(permitted)
1247 Consequently, the process gains all capabilities in its permitted and
1248 effective capability sets,
1249 except those masked out by the capability bounding set.
1250 (In the calculation of P'(permitted),
1251 the P'(ambient) term can be simplified away because it is by
1252 definition a proper subset of P(inheritable).)
1254 The special treatments of user ID 0 (root) described in this subsection
1255 can be disabled using the securebits mechanism described below.
1258 .SS Set-user-ID-root programs that have file capabilities
1259 There is one exception to the behavior described under
1260 .IR "Capabilities and execution of programs by root" .
1261 If (a) the binary that is being executed has capabilities attached and
1262 (b) the real user ID of the process is
1265 (c) the effective user ID of the process
1267 0 (root), then the file capability bits are honored
1268 (i.e., they are not notionally considered to be all ones).
1269 The usual way in which this situation can arise is when executing
1270 a set-UID-root program that also has file capabilities.
1271 When such a program is executed,
1272 the process gains just the capabilities granted by the program
1273 (i.e., not all capabilities,
1274 as would occur when executing a set-user-ID-root program
1275 that does not have any associated file capabilities).
1277 Note that one can assign empty capability sets to a program file,
1278 and thus it is possible to create a set-user-ID-root program that
1279 changes the effective and saved set-user-ID of the process
1280 that executes the program to 0,
1281 but confers no capabilities to that process.
1283 .SS Capability bounding set
1284 The capability bounding set is a security mechanism that can be used
1285 to limit the capabilities that can be gained during an
1287 The bounding set is used in the following ways:
1291 the capability bounding set is ANDed with the file permitted
1292 capability set, and the result of this operation is assigned to the
1293 thread's permitted capability set.
1294 The capability bounding set thus places a limit on the permitted
1295 capabilities that may be granted by an executable file.
1297 (Since Linux 2.6.25)
1298 The capability bounding set acts as a limiting superset for
1299 the capabilities that a thread can add to its inheritable set using
1301 This means that if a capability is not in the bounding set,
1302 then a thread can't add this capability to its
1303 inheritable set, even if it was in its permitted capabilities,
1304 and thereby cannot have this capability preserved in its
1305 permitted set when it
1307 a file that has the capability in its inheritable set.
1309 Note that the bounding set masks the file permitted capabilities,
1310 but not the inheritable capabilities.
1311 If a thread maintains a capability in its inheritable set
1312 that is not in its bounding set,
1313 then it can still gain that capability in its permitted set
1314 by executing a file that has the capability in its inheritable set.
1316 Depending on the kernel version, the capability bounding set is either
1317 a system-wide attribute, or a per-process attribute.
1319 .B "Capability bounding set from Linux 2.6.25 onward"
1321 From Linux 2.6.25, the
1322 .I "capability bounding set"
1323 is a per-thread attribute.
1324 (The system-wide capability bounding set described below no longer exists.)
1326 The bounding set is inherited at
1328 from the thread's parent, and is preserved across an
1331 A thread may remove capabilities from its capability bounding set using the
1334 operation, provided it has the
1337 Once a capability has been dropped from the bounding set,
1338 it cannot be restored to that set.
1339 A thread can determine if a capability is in its bounding set using the
1344 Removing capabilities from the bounding set is supported only if file
1345 capabilities are compiled into the kernel.
1346 In kernels before Linux 2.6.33,
1347 file capabilities were an optional feature configurable via the
1348 .B CONFIG_SECURITY_FILE_CAPABILITIES
1351 .\" commit b3a222e52e4d4be77cc4520a57af1a4a0d8222d1
1352 the configuration option has been removed
1353 and file capabilities are always part of the kernel.
1354 When file capabilities are compiled into the kernel, the
1356 process (the ancestor of all processes) begins with a full bounding set.
1357 If file capabilities are not compiled into the kernel, then
1359 begins with a full bounding set minus
1361 because this capability has a different meaning when there are
1362 no file capabilities.
1364 Removing a capability from the bounding set does not remove it
1365 from the thread's inheritable set.
1366 However it does prevent the capability from being added
1367 back into the thread's inheritable set in the future.
1369 .B "Capability bounding set prior to Linux 2.6.25"
1371 In kernels before 2.6.25, the capability bounding set is a system-wide
1372 attribute that affects all threads on the system.
1373 The bounding set is accessible via the file
1374 .IR /proc/sys/kernel/cap-bound .
1375 (Confusingly, this bit mask parameter is expressed as a
1376 signed decimal number in
1377 .IR /proc/sys/kernel/cap-bound .)
1381 process may set capabilities in the capability bounding set;
1382 other than that, the superuser (more precisely: a process with the
1384 capability) may only clear capabilities from this set.
1386 On a standard system the capability bounding set always masks out the
1389 To remove this restriction (dangerous!), modify the definition of
1392 .I include/linux/capability.h
1393 and rebuild the kernel.
1395 The system-wide capability bounding set feature was added
1396 to Linux starting with kernel version 2.2.11.
1400 .SS Effect of user ID changes on capabilities
1401 To preserve the traditional semantics for transitions between
1402 0 and nonzero user IDs,
1403 the kernel makes the following changes to a thread's capability
1404 sets on changes to the thread's real, effective, saved set,
1405 and filesystem user IDs (using
1410 If one or more of the real, effective or saved set user IDs
1411 was previously 0, and as a result of the UID changes all of these IDs
1412 have a nonzero value,
1413 then all capabilities are cleared from the permitted, effective, and ambient
1416 If the effective user ID is changed from 0 to nonzero,
1417 then all capabilities are cleared from the effective set.
1419 If the effective user ID is changed from nonzero to 0,
1420 then the permitted set is copied to the effective set.
1422 If the filesystem user ID is changed from 0 to nonzero (see
1424 then the following capabilities are cleared from the effective set:
1426 .BR CAP_DAC_OVERRIDE ,
1427 .BR CAP_DAC_READ_SEARCH ,
1430 .B CAP_LINUX_IMMUTABLE
1431 (since Linux 2.6.30),
1432 .BR CAP_MAC_OVERRIDE ,
1435 (since Linux 2.6.30).
1436 If the filesystem UID is changed from nonzero to 0,
1437 then any of these capabilities that are enabled in the permitted set
1438 are enabled in the effective set.
1440 If a thread that has a 0 value for one or more of its user IDs wants
1441 to prevent its permitted capability set being cleared when it resets
1442 all of its user IDs to nonzero values, it can do so using the
1444 securebits flag described below.
1446 .SS Programmatically adjusting capability sets
1447 A thread can retrieve and change its permitted, effective, and inheritable
1448 capability sets using the
1454 .BR cap_get_proc (3)
1456 .BR cap_set_proc (3),
1457 both provided in the
1460 is preferred for this purpose.
1461 The following rules govern changes to the thread capability sets:
1463 If the caller does not have the
1466 the new inheritable set must be a subset of the combination
1467 of the existing inheritable and permitted sets.
1469 (Since Linux 2.6.25)
1470 The new inheritable set must be a subset of the combination of the
1471 existing inheritable set and the capability bounding set.
1473 The new permitted set must be a subset of the existing permitted set
1474 (i.e., it is not possible to acquire permitted capabilities
1475 that the thread does not currently have).
1477 The new effective set must be a subset of the new permitted set.
1478 .SS The securebits flags: establishing a capabilities-only environment
1479 .\" For some background:
1480 .\" see http://lwn.net/Articles/280279/ and
1481 .\" http://article.gmane.org/gmane.linux.kernel.lsm/5476/
1482 Starting with kernel 2.6.26,
1483 and with a kernel in which file capabilities are enabled,
1484 Linux implements a set of per-thread
1486 flags that can be used to disable special handling of capabilities for UID 0
1488 These flags are as follows:
1491 Setting this flag allows a thread that has one or more 0 UIDs to retain
1492 capabilities in its permitted set
1493 when it switches all of its UIDs to nonzero values.
1494 If this flag is not set,
1495 then such a UID switch causes the thread to lose all permitted capabilities.
1496 This flag is always cleared on an
1499 Note that even with the
1501 flag set, the effective capabilities of a thread are cleared when it
1502 switches its effective UID to a nonzero value.
1504 if the thread has set this flag and its effective UID is already nonzero,
1505 and the thread subsequently switches all other UIDs to nonzero values,
1506 then the effective capabilities will not be cleared.
1510 flag is ignored if the
1511 .B SECBIT_NO_SETUID_FIXUP
1513 (The latter flag provides a superset of the effect of the former flag.)
1515 This flag provides the same functionality as the older
1520 .B SECBIT_NO_SETUID_FIXUP
1521 Setting this flag stops the kernel from adjusting the process's
1522 permitted, effective, and ambient capability sets when
1523 the thread's effective and filesystem UIDs are switched between
1524 zero and nonzero values.
1526 .IR "Effect of user ID changes on capabilities" .)
1529 If this bit is set, then the kernel does not grant capabilities
1530 when a set-user-ID-root program is executed, or when a process with
1531 an effective or real UID of 0 calls
1534 .IR "Capabilities and execution of programs by root" .)
1536 .B SECBIT_NO_CAP_AMBIENT_RAISE
1537 Setting this flag disallows raising ambient capabilities via the
1539 .BR PR_CAP_AMBIENT_RAISE
1542 Each of the above "base" flags has a companion "locked" flag.
1543 Setting any of the "locked" flags is irreversible,
1544 and has the effect of preventing further changes to the
1545 corresponding "base" flag.
1546 The locked flags are:
1547 .BR SECBIT_KEEP_CAPS_LOCKED ,
1548 .BR SECBIT_NO_SETUID_FIXUP_LOCKED ,
1549 .BR SECBIT_NOROOT_LOCKED ,
1551 .BR SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED .
1555 flags can be modified and retrieved using the
1557 .B PR_SET_SECUREBITS
1559 .B PR_GET_SECUREBITS
1563 capability is required to modify the flags.
1566 constants are available only after including the
1567 .I <linux/securebits.h>
1572 flags are inherited by child processes.
1575 all of the flags are preserved, except
1577 which is always cleared.
1579 An application can use the following call to lock itself,
1580 and all of its descendants,
1581 into an environment where the only way of gaining capabilities
1582 is by executing a program with associated file capabilities:
1586 prctl(PR_SET_SECUREBITS,
1587 /* SECBIT_KEEP_CAPS off */
1588 SECBIT_KEEP_CAPS_LOCKED |
1589 SECBIT_NO_SETUID_FIXUP |
1590 SECBIT_NO_SETUID_FIXUP_LOCKED |
1592 SECBIT_NOROOT_LOCKED);
1593 /* Setting/locking SECBIT_NO_CAP_AMBIENT_RAISE
1599 .SS Per-user-namespace """set-user-ID-root""" programs
1600 A set-user-ID program whose UID matches the UID that
1601 created a user namespace will confer capabilities
1602 in the process's permitted and effective sets
1603 when executed by any process inside that namespace
1604 or any descendant user namespace.
1606 The rules about the transformation of the process's capabilities during the
1608 are exactly as described in the subsections
1609 .IR "Transformation of capabilities during execve()"
1611 .IR "Capabilities and execution of programs by root" ,
1612 with the difference that, in the latter subsection, "root"
1613 is the UID of the creator of the user namespace.
1616 .SS Namespaced file capabilities
1617 .\" commit 8db6c34f1dbc8e06aa016a9b829b06902c3e1340
1618 Traditional (i.e., version 2) file capabilities associate
1619 only a set of capability masks with a binary executable file.
1620 When a process executes a binary with such capabilities,
1621 it gains the associated capabilities (within its user namespace)
1622 as per the rules described above in
1623 "Transformation of capabilities during execve()".
1625 Because version 2 file capabilities confer capabilities to
1626 the executing process regardless of which user namespace it resides in,
1627 only privileged processes are permitted to associate capabilities with a file.
1628 Here, "privileged" means a process that has the
1630 capability in the user namespace where the filesystem was mounted
1631 (normally the initial user namespace).
1632 This limitation renders file capabilities useless for certain use cases.
1633 For example, in user-namespaced containers,
1634 it can be desirable to be able to create a binary that
1635 confers capabilities only to processes executed inside that container,
1636 but not to processes that are executed outside the container.
1638 Linux 4.14 added so-called namespaced file capabilities
1639 to support such use cases.
1640 Namespaced file capabilities are recorded as version 3 (i.e.,
1641 .BR VFS_CAP_REVISION_3 )
1642 .I security.capability
1643 extended attributes.
1644 Such an attribute is automatically created in the circumstances described
1645 above under "File capability extended attribute versioning".
1647 .I security.capability
1648 extended attribute is created,
1649 the kernel records not just the capability masks in the extended attribute,
1650 but also the namespace root user ID.
1652 As with a binary that has
1653 .BR VFS_CAP_REVISION_2
1654 file capabilities, a binary with
1655 .BR VFS_CAP_REVISION_3
1656 file capabilities confers capabilities to a process during
1658 However, capabilities are conferred only if the binary is executed by
1659 a process that resides in a user namespace whose
1660 UID 0 maps to the root user ID that is saved in the extended attribute,
1661 or when executed by a process that resides in a descendant of such a namespace.
1664 .SS Interaction with user namespaces
1665 For further information on the interaction of
1666 capabilities and user namespaces, see
1667 .BR user_namespaces (7).
1670 No standards govern capabilities, but the Linux capability implementation
1671 is based on the withdrawn POSIX.1e draft standard; see
1672 .UR https://archive.org\:/details\:/posix_1003.1e-990310
1677 binaries that have capabilities (or set-user-ID-root binaries),
1685 $ \fBsudo strace \-o trace.log \-u ceci ./myprivprog\fP
1689 From kernel 2.5.27 to kernel 2.6.26,
1690 .\" commit 5915eb53861c5776cfec33ca4fcc1fd20d66dd27 removed
1691 .\" CONFIG_SECURITY_CAPABILITIES
1692 capabilities were an optional kernel component,
1693 and could be enabled/disabled via the
1694 .B CONFIG_SECURITY_CAPABILITIES
1695 kernel configuration option.
1698 .I /proc/[pid]/task/TID/status
1699 file can be used to view the capability sets of a thread.
1701 .I /proc/[pid]/status
1702 file shows the capability sets of a process's main thread.
1703 Before Linux 3.8, nonexistent capabilities were shown as being
1704 enabled (1) in these sets.
1706 .\" 7b9a7ec565505699f503b4fcf61500dceb36e744
1707 all nonexistent capabilities (above
1709 are shown as disabled (0).
1713 package provides a suite of routines for setting and
1714 getting capabilities that is more comfortable and less likely
1715 to change than the interface provided by
1719 This package also provides the
1726 .UR https://git.kernel.org\:/pub\:/scm\:/libs\:/libcap\:/libcap.git\:/refs/
1729 Before kernel 2.6.24, and from kernel 2.6.24 to kernel 2.6.32 if
1730 file capabilities are not enabled, a thread with the
1732 capability can manipulate the capabilities of threads other than itself.
1733 However, this is only theoretically possible,
1734 since no thread ever has
1736 in either of these cases:
1738 In the pre-2.6.25 implementation the system-wide capability bounding set,
1739 .IR /proc/sys/kernel/cap-bound ,
1740 always masks out this capability, and this can not be changed
1741 without modifying the kernel source and rebuilding.
1743 If file capabilities are disabled in the current implementation, then
1745 starts out with this capability removed from its per-process bounding
1746 set, and that bounding set is inherited by all other processes
1747 created on the system.
1754 .BR cap_copy_ext (3),
1755 .BR cap_from_text (3),
1756 .BR cap_get_file (3),
1757 .BR cap_get_proc (3),
1763 .BR credentials (7),
1765 .BR user_namespaces (7),
1766 .BR captest (8), \" from libcap-ng
1767 .BR filecap (8), \" from libcap-ng
1769 .BR netcap (8), \" from libcap-ng
1770 .BR pscap (8), \" from libcap-ng
1773 .I include/linux/capability.h
1774 in the Linux kernel source tree