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.
486 Modify autogroup nice values by writing to
487 .IR /proc/[pid]/autogroup
506 change mount namespaces using
515 Load and unload kernel modules
519 .BR delete_module (2));
521 in kernels before 2.6.25:
522 drop capabilities from the system-wide capability bounding set.
530 Raise process nice value
533 and change the nice value for arbitrary processes;
535 set real-time scheduling policies for calling process,
536 and set scheduling policies and priorities for arbitrary processes
537 .RB ( sched_setscheduler (2),
538 .BR sched_setparam (2),
539 .BR sched_setattr (2));
541 set CPU affinity for arbitrary processes
542 .RB ( sched_setaffinity (2));
544 set I/O scheduling class and priority for arbitrary processes
545 .RB ( ioprio_set (2));
548 .BR migrate_pages (2)
549 to arbitrary processes and allow processes
550 to be migrated to arbitrary nodes;
551 .\" FIXME CAP_SYS_NICE also has the following effect for
552 .\" migrate_pages(2):
553 .\" do_migrate_pages(mm, &old, &new,
554 .\" capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
560 to arbitrary processes;
579 Trace arbitrary processes using
583 .BR get_robust_list (2)
584 to arbitrary processes;
586 transfer data to or from the memory of arbitrary processes using
587 .BR process_vm_readv (2)
589 .BR process_vm_writev (2);
591 inspect processes using
600 Perform I/O port operations
613 open devices for accessing x86 model-specific registers (MSRs, see
617 .IR /proc/sys/vm/mmap_min_addr ;
619 create memory mappings at addresses below the value specified by
620 .IR /proc/sys/vm/mmap_min_addr ;
630 perform various SCSI device commands;
632 perform certain operations on
638 perform a range of device-specific operations on other devices.
646 Use reserved space on ext2 filesystems;
650 calls controlling ext3 journaling;
652 override disk quota limits;
654 increase resource limits (see
661 override maximum number of consoles on console allocation;
663 override maximum number of keymaps;
665 allow more than 64hz interrupts from the real-time clock;
669 limit for a System V message queue above the limit in
670 .I /proc/sys/kernel/msgmnb
678 resource limit on the number of "in-flight" file descriptors
679 to be bypassed when passing file descriptors to another process
680 via a UNIX domain socket (see
684 .I /proc/sys/fs/pipe-size-max
685 limit when setting the capacity of a pipe using the
692 to increase the capacity of a pipe above the limit specified by
693 .IR /proc/sys/fs/pipe-max-size ;
696 .I /proc/sys/fs/mqueue/queues_max
697 limit when creating POSIX message queues (see
698 .BR mq_overview (7));
706 .IR /proc/[pid]/oom_score_adj
707 to a value lower than the value last set by a process with
708 .BR CAP_SYS_RESOURCE .
714 .RB ( settimeofday (2),
717 set real-time (hardware) clock.
719 .B CAP_SYS_TTY_CONFIG
722 employ various privileged
724 operations on virtual terminals.
726 .BR CAP_SYSLOG " (since Linux 2.6.37)"
735 for information on which operations require privilege.
737 View kernel addresses exposed via
739 and other interfaces when
740 .IR /proc/sys/kernel/kptr_restrict
742 (See the discussion of the
749 .BR CAP_WAKE_ALARM " (since Linux 3.0)"
750 Trigger something that will wake up the system (set
751 .B CLOCK_REALTIME_ALARM
753 .B CLOCK_BOOTTIME_ALARM
756 .SS Past and current implementation
757 A full implementation of capabilities requires that:
759 For all privileged operations,
760 the kernel must check whether the thread has the required
761 capability in its effective set.
763 The kernel must provide system calls allowing a thread's capability sets to
764 be changed and retrieved.
766 The filesystem must support attaching capabilities to an executable file,
767 so that a process gains those capabilities when the file is executed.
769 Before kernel 2.6.24, only the first two of these requirements are met;
770 since kernel 2.6.24, all three requirements are met.
772 .SS Notes to kernel developers
773 When adding a new kernel feature that should be governed by a capability,
774 consider the following points.
776 The goal of capabilities is divide the power of superuser into pieces,
777 such that if a program that has one or more capabilities is compromised,
778 its power to do damage to the system would be less than the same program
779 running with root privilege.
781 You have the choice of either creating a new capability for your new feature,
782 or associating the feature with one of the existing capabilities.
783 In order to keep the set of capabilities to a manageable size,
784 the latter option is preferable,
785 unless there are compelling reasons to take the former option.
786 (There is also a technical limit:
787 the size of capability sets is currently limited to 64 bits.)
789 To determine which existing capability might best be associated
790 with your new feature, review the list of capabilities above in order
791 to find a "silo" into which your new feature best fits.
792 One approach to take is to determine if there are other features
793 requiring capabilities that will always be used along with the new feature.
794 If the new feature is useless without these other features,
795 you should use the same capability as the other features.
800 if you can possibly avoid it!
801 A vast proportion of existing capability checks are associated
802 with this capability (see the partial list above).
803 It can plausibly be called "the new root",
804 since on the one hand, it confers a wide range of powers,
805 and on the other hand,
806 its broad scope means that this is the capability
807 that is required by many privileged programs.
808 Don't make the problem worse.
809 The only new features that should be associated with
813 match existing uses in that silo.
815 If you have determined that it really is necessary to create
816 a new capability for your feature,
817 don't make or name it as a "single-use" capability.
818 Thus, for example, the addition of the highly specific
820 was probably a mistake.
821 Instead, try to identify and name your new capability as a broader
822 silo into which other related future use cases might fit.
824 .SS Thread capability sets
825 Each thread has the following capability sets containing zero or more
826 of the above capabilities:
829 This is a limiting superset for the effective
830 capabilities that the thread may assume.
831 It is also a limiting superset for the capabilities that
832 may be added to the inheritable set by a thread that does not have the
834 capability in its effective set.
836 If a thread drops a capability from its permitted set,
837 it can never reacquire that capability (unless it
839 either a set-user-ID-root program, or
840 a program whose associated file capabilities grant that capability).
843 This is a set of capabilities preserved across an
845 Inheritable capabilities remain inheritable when executing any program,
846 and inheritable capabilities are added to the permitted set when executing
847 a program that has the corresponding bits set in the file inheritable set.
849 Because inheritable capabilities are not generally preserved across
851 when running as a non-root user, applications that wish to run helper
852 programs with elevated capabilities should consider using
853 ambient capabilities, described below.
856 This is the set of capabilities used by the kernel to
857 perform permission checks for the thread.
859 .IR Bounding " (per-thread since Linux 2.6.25)"
860 The capability bounding set is a mechanism that can be used
861 to limit the capabilities that are gained during
864 Since Linux 2.6.25, this is a per-thread capability set.
865 In older kernels, the capability bounding set was a system wide attribute
866 shared by all threads on the system.
869 For more details on the capability bounding set, see below.
871 .IR Ambient " (since Linux 4.3)"
872 .\" commit 58319057b7847667f0c9585b9de0e8932b0fdb08
873 This is a set of capabilities that are preserved across an
875 of a program that is not privileged.
876 The ambient capability set obeys the invariant that no capability
877 can ever be ambient if it is not both permitted and inheritable.
879 The ambient capability set can be directly modified using
881 Ambient capabilities are automatically lowered if either of
882 the corresponding permitted or inheritable capabilities is lowered.
884 Executing a program that changes UID or GID due to the
885 set-user-ID or set-group-ID bits or executing a program that has
886 any file capabilities set will clear the ambient set.
887 Ambient capabilities are added to the permitted set and
888 assigned to the effective set when
891 If ambient capabilities cause a process's permitted and effective
892 capabilities to increase during an
894 this does not trigger the secure-execution mode described in
899 inherits copies of its parent's capability sets.
900 See below for a discussion of the treatment of capabilities during
905 a thread may manipulate its own capability sets (see below).
907 Since Linux 3.2, the file
908 .I /proc/sys/kernel/cap_last_cap
909 .\" commit 73efc0394e148d0e15583e13712637831f926720
910 exposes the numerical value of the highest capability
911 supported by the running kernel;
912 this can be used to determine the highest bit
913 that may be set in a capability set.
915 .SS File capabilities
916 Since kernel 2.6.24, the kernel supports
917 associating capability sets with an executable file using
919 The file capability sets are stored in an extended attribute (see
924 .IR "security.capability" .
925 Writing to this extended attribute requires the
928 The file capability sets,
929 in conjunction with the capability sets of the thread,
930 determine the capabilities of a thread after an
933 The three file capability sets are:
935 .IR Permitted " (formerly known as " forced ):
936 These capabilities are automatically permitted to the thread,
937 regardless of the thread's inheritable capabilities.
939 .IR Inheritable " (formerly known as " allowed ):
940 This set is ANDed with the thread's inheritable set to determine which
941 inheritable capabilities are enabled in the permitted set of
946 This is not a set, but rather just a single bit.
947 If this bit is set, then during an
949 all of the new permitted capabilities for the thread are
950 also raised in the effective set.
951 If this bit is not set, then after an
953 none of the new permitted capabilities is in the new effective set.
955 Enabling the file effective capability bit implies
956 that any file permitted or inheritable capability that causes a
957 thread to acquire the corresponding permitted capability during an
959 (see the transformation rules described below) will also acquire that
960 capability in its effective set.
961 Therefore, when assigning capabilities to a file
963 .BR cap_set_file (3),
965 if we specify the effective flag as being enabled for any capability,
966 then the effective flag must also be specified as enabled
967 for all other capabilities for which the corresponding permitted or
968 inheritable flags is enabled.
970 .SS File capability extended attribute versioning
971 To allow extensibility,
972 the kernel supports a scheme to encode a version number inside the
973 .I security.capability
974 extended attribute that is used to implement file capabilities.
975 These version numbers are internal to the implementation,
976 and not directly visible to user-space applications.
977 To date, the following versions are supported:
979 .BR VFS_CAP_REVISION_1
980 This was the original file capability implementation,
981 which supported 32-bit masks for file capabilities.
983 .BR VFS_CAP_REVISION_2 " (since Linux 2.6.25)"
984 .\" commit e338d263a76af78fe8f38a72131188b58fceb591
985 This version allows for file capability masks that are 64 bits in size,
986 and was necessary as the number of supported capabilities grew beyond 32.
987 The kernel transparently continues to support the execution of files
988 that have 32-bit version 1 capability masks,
989 but when adding capabilities to files that did not previously
990 have capabilities, or modifying the capabilities of existing files,
991 it automatically uses the version 2 scheme
992 (or possibly the version 3 scheme, as described below).
994 .BR VFS_CAP_REVISION_3 " (since Linux 4.14)"
995 .\" commit 8db6c34f1dbc8e06aa016a9b829b06902c3e1340
996 Version 3 file capabilities are provided
997 to support namespaced file capabilities (described below).
999 As with version 2 file capabilities,
1000 version 3 capability masks are 64 bits in size.
1001 But in addition, the root user ID of namespace is encoded in the
1002 .I security.capability
1004 (A namespace's root user ID is the value that user ID 0
1005 inside that namespace maps to in the initial user namespace.)
1007 Version 3 file capabilities are designed to coexist
1008 with version 2 capabilities;
1009 that is, on a modern Linux system,
1010 there may be some files with version 2 capabilities
1011 while others have version 3 capabilities.
1014 the only kind of file capability extended attribute
1015 that could be attached to a file was a
1016 .B VFS_CAP_REVISION_2
1020 .I security.capability
1021 extended attribute that is attached to a file
1022 depends on the circumstances in which the attribute was created.
1024 Starting with Linux 4.14, a
1025 .I security.capability
1026 extended attribute is automatically created as (or converted to)
1028 .RB ( VFS_CAP_REVISION_3 )
1029 attribute if both of the following are true:
1031 The thread writing the attribute resides in a noninitial user namespace.
1032 (More precisely: the thread resides in a user namespace other
1033 than the one from which the underlying filesystem was mounted.)
1037 capability over the file inode,
1038 meaning that (a) the thread has the
1040 capability in its own user namespace;
1041 and (b) the UID and GID of the file inode have mappings in
1042 the writer's user namespace.
1045 .BR VFS_CAP_REVISION_3
1046 .I security.capability
1047 extended attribute is created, the root user ID of the creating thread's
1048 user namespace is saved in the extended attribute.
1050 By contrast, creating or modifying a
1051 .I security.capability
1052 extended attribute from a privileged
1054 thread that resides in the
1055 namespace where the underlying filesystem was mounted
1056 (this normally means the initial user namespace)
1057 automatically results in the creation of a version 2
1058 .RB ( VFS_CAP_REVISION_2 )
1061 Note that the creation of a version 3
1062 .I security.capability
1063 extended attribute is automatic.
1064 That is to say, when a user-space application writes
1067 .I security.capability
1068 attribute in the version 2 format,
1069 the kernel will automatically create a version 3 attribute
1070 if the attribute is created in the circumstances described above.
1071 Correspondingly, when a version 3
1072 .I security.capability
1073 attribute is retrieved
1075 by a process that resides inside a user namespace that was created by the
1076 root user ID (or a descendant of that user namespace),
1077 the returned attribute is (automatically)
1078 simplified to appear as a version 2 attribute
1079 (i.e., the returned value is the size of a version 2 attribute and does
1080 not include the root user ID).
1081 These automatic translations mean that no changes are required to
1082 user-space tools (e.g.,
1086 in order for those tools to be used to create and retrieve version 3
1087 .I security.capability
1090 Note that a file can have either a version 2 or a version 3
1091 .I security.capability
1092 extended attribute associated with it, but not both:
1093 creation or modification of the
1094 .I security.capability
1095 extended attribute will automatically modify the version
1096 according to the circumstances in which the extended attribute is
1097 created or modified.
1099 .SS Transformation of capabilities during execve()
1103 the kernel calculates the new capabilities of
1104 the process using the following algorithm:
1108 P'(ambient) = (file is privileged) ? 0 : P(ambient)
1110 P'(permitted) = (P(inheritable) & F(inheritable)) |
1111 (F(permitted) & P(bounding)) | P'(ambient)
1113 P'(effective) = F(effective) ? P'(permitted) : P'(ambient)
1115 P'(inheritable) = P(inheritable) [i.e., unchanged]
1117 P'(bounding) = P(bounding) [i.e., unchanged]
1124 denotes the value of a thread capability set before the
1127 denotes the value of a thread capability set after the
1130 denotes a file capability set
1133 Note the following details relating to the above capability
1134 transformation rules:
1136 The ambient capability set is present only since Linux 4.3.
1137 When determining the transformation of the ambient set during
1139 a privileged file is one that has capabilities or
1140 has the set-user-ID or set-group-ID bit set.
1142 Prior to Linux 2.6.25,
1143 the bounding set was a system-wide attribute shared by all threads.
1144 That system-wide value was employed to calculate the new permitted set during
1146 in the same manner as shown above for
1150 during the capability transitions described above,
1151 file capabilities may be ignored (treated as empty) for the same reasons
1152 that the set-user-ID and set-group-ID bits are ignored; see
1154 File capabilities are similarly ignored if the kernel was booted with the
1159 according to the rules above,
1160 if a process with nonzero user IDs performs an
1162 then any capabilities that are present in
1163 its permitted and effective sets will be cleared.
1164 For the treatment of capabilities when a process with a
1165 user ID of zero performs an
1168 .IR "Capabilities and execution of programs by root" .
1170 .SS Safety checking for capability-dumb binaries
1171 A capability-dumb binary is an application that has been
1172 marked to have file capabilities, but has not been converted to use the
1174 API to manipulate its capabilities.
1175 (In other words, this is a traditional set-user-ID-root program
1176 that has been switched to use file capabilities,
1177 but whose code has not been modified to understand capabilities.)
1178 For such applications,
1179 the effective capability bit is set on the file,
1180 so that the file permitted capabilities are automatically
1181 enabled in the process effective set when executing the file.
1182 The kernel recognizes a file which has the effective capability bit set
1183 as capability-dumb for the purpose of the check described here.
1185 When executing a capability-dumb binary,
1186 the kernel checks if the process obtained all permitted capabilities
1187 that were specified in the file permitted set,
1188 after the capability transformations described above have been performed.
1189 (The typical reason why this might
1191 occur is that the capability bounding set masked out some
1192 of the capabilities in the file permitted set.)
1193 If the process did not obtain the full set of
1194 file permitted capabilities, then
1196 fails with the error
1198 This prevents possible security risks that could arise when
1199 a capability-dumb application is executed with less privilege that it needs.
1200 Note that, by definition,
1201 the application could not itself recognize this problem,
1202 since it does not employ the
1206 .SS Capabilities and execution of programs by root
1207 .\" See cap_bprm_set_creds(), bprm_caps_from_vfs_cap() and
1208 .\" handle_privileged_root() in security/commoncap.c (Linux 5.0 source)
1209 In order to mirror traditional UNIX semantics,
1210 the kernel performs special treatment of file capabilities when
1211 a process with UID 0 (root) executes a program and
1212 when a set-user-ID-root program is executed.
1214 After having performed any changes to the process effective ID that
1215 were triggered by the set-user-ID mode bit of the binary\(eme.g.,
1216 switching the effective user ID to 0 (root) because
1217 a set-user-ID-root program was executed\(emthe
1218 kernel calculates the file capability sets as follows:
1220 If the real or effective user ID of the process is 0 (root),
1221 then the file inheritable and permitted sets are ignored;
1222 instead they are notionally considered to be all ones
1223 (i.e., all capabilities enabled).
1224 (There is one exception to this behavior, described below in
1225 .IR "Set-user-ID-root programs that have file capabilities" .)
1227 If the effective user ID of the process is 0 (root) or
1228 the file effective bit is in fact enabled,
1229 then the file effective bit is notionally defined to be one (enabled).
1231 These notional values for the file's capability sets are then used
1232 as described above to calculate the transformation of the process's
1236 Thus, when a process with nonzero UIDs
1238 a set-user-ID-root program that does not have capabilities attached,
1239 or when a process whose real and effective UIDs are zero
1241 a program, the calculation of the process's new
1242 permitted capabilities simplifies to:
1246 P'(permitted) = P(inheritable) | P(bounding)
1248 P'(effective) = P'(permitted)
1252 Consequently, the process gains all capabilities in its permitted and
1253 effective capability sets,
1254 except those masked out by the capability bounding set.
1255 (In the calculation of P'(permitted),
1256 the P'(ambient) term can be simplified away because it is by
1257 definition a proper subset of P(inheritable).)
1259 The special treatments of user ID 0 (root) described in this subsection
1260 can be disabled using the securebits mechanism described below.
1263 .SS Set-user-ID-root programs that have file capabilities
1264 There is one exception to the behavior described under
1265 .IR "Capabilities and execution of programs by root" .
1266 If (a) the binary that is being executed has capabilities attached and
1267 (b) the real user ID of the process is
1270 (c) the effective user ID of the process
1272 0 (root), then the file capability bits are honored
1273 (i.e., they are not notionally considered to be all ones).
1274 The usual way in which this situation can arise is when executing
1275 a set-UID-root program that also has file capabilities.
1276 When such a program is executed,
1277 the process gains just the capabilities granted by the program
1278 (i.e., not all capabilities,
1279 as would occur when executing a set-user-ID-root program
1280 that does not have any associated file capabilities).
1282 Note that one can assign empty capability sets to a program file,
1283 and thus it is possible to create a set-user-ID-root program that
1284 changes the effective and saved set-user-ID of the process
1285 that executes the program to 0,
1286 but confers no capabilities to that process.
1288 .SS Capability bounding set
1289 The capability bounding set is a security mechanism that can be used
1290 to limit the capabilities that can be gained during an
1292 The bounding set is used in the following ways:
1296 the capability bounding set is ANDed with the file permitted
1297 capability set, and the result of this operation is assigned to the
1298 thread's permitted capability set.
1299 The capability bounding set thus places a limit on the permitted
1300 capabilities that may be granted by an executable file.
1302 (Since Linux 2.6.25)
1303 The capability bounding set acts as a limiting superset for
1304 the capabilities that a thread can add to its inheritable set using
1306 This means that if a capability is not in the bounding set,
1307 then a thread can't add this capability to its
1308 inheritable set, even if it was in its permitted capabilities,
1309 and thereby cannot have this capability preserved in its
1310 permitted set when it
1312 a file that has the capability in its inheritable set.
1314 Note that the bounding set masks the file permitted capabilities,
1315 but not the inheritable capabilities.
1316 If a thread maintains a capability in its inheritable set
1317 that is not in its bounding set,
1318 then it can still gain that capability in its permitted set
1319 by executing a file that has the capability in its inheritable set.
1321 Depending on the kernel version, the capability bounding set is either
1322 a system-wide attribute, or a per-process attribute.
1324 .B "Capability bounding set from Linux 2.6.25 onward"
1326 From Linux 2.6.25, the
1327 .I "capability bounding set"
1328 is a per-thread attribute.
1329 (The system-wide capability bounding set described below no longer exists.)
1331 The bounding set is inherited at
1333 from the thread's parent, and is preserved across an
1336 A thread may remove capabilities from its capability bounding set using the
1339 operation, provided it has the
1342 Once a capability has been dropped from the bounding set,
1343 it cannot be restored to that set.
1344 A thread can determine if a capability is in its bounding set using the
1349 Removing capabilities from the bounding set is supported only if file
1350 capabilities are compiled into the kernel.
1351 In kernels before Linux 2.6.33,
1352 file capabilities were an optional feature configurable via the
1353 .B CONFIG_SECURITY_FILE_CAPABILITIES
1356 .\" commit b3a222e52e4d4be77cc4520a57af1a4a0d8222d1
1357 the configuration option has been removed
1358 and file capabilities are always part of the kernel.
1359 When file capabilities are compiled into the kernel, the
1361 process (the ancestor of all processes) begins with a full bounding set.
1362 If file capabilities are not compiled into the kernel, then
1364 begins with a full bounding set minus
1366 because this capability has a different meaning when there are
1367 no file capabilities.
1369 Removing a capability from the bounding set does not remove it
1370 from the thread's inheritable set.
1371 However it does prevent the capability from being added
1372 back into the thread's inheritable set in the future.
1374 .B "Capability bounding set prior to Linux 2.6.25"
1376 In kernels before 2.6.25, the capability bounding set is a system-wide
1377 attribute that affects all threads on the system.
1378 The bounding set is accessible via the file
1379 .IR /proc/sys/kernel/cap-bound .
1380 (Confusingly, this bit mask parameter is expressed as a
1381 signed decimal number in
1382 .IR /proc/sys/kernel/cap-bound .)
1386 process may set capabilities in the capability bounding set;
1387 other than that, the superuser (more precisely: a process with the
1389 capability) may only clear capabilities from this set.
1391 On a standard system the capability bounding set always masks out the
1394 To remove this restriction (dangerous!), modify the definition of
1397 .I include/linux/capability.h
1398 and rebuild the kernel.
1400 The system-wide capability bounding set feature was added
1401 to Linux starting with kernel version 2.2.11.
1405 .SS Effect of user ID changes on capabilities
1406 To preserve the traditional semantics for transitions between
1407 0 and nonzero user IDs,
1408 the kernel makes the following changes to a thread's capability
1409 sets on changes to the thread's real, effective, saved set,
1410 and filesystem user IDs (using
1415 If one or more of the real, effective or saved set user IDs
1416 was previously 0, and as a result of the UID changes all of these IDs
1417 have a nonzero value,
1418 then all capabilities are cleared from the permitted, effective, and ambient
1421 If the effective user ID is changed from 0 to nonzero,
1422 then all capabilities are cleared from the effective set.
1424 If the effective user ID is changed from nonzero to 0,
1425 then the permitted set is copied to the effective set.
1427 If the filesystem user ID is changed from 0 to nonzero (see
1429 then the following capabilities are cleared from the effective set:
1431 .BR CAP_DAC_OVERRIDE ,
1432 .BR CAP_DAC_READ_SEARCH ,
1435 .B CAP_LINUX_IMMUTABLE
1436 (since Linux 2.6.30),
1437 .BR CAP_MAC_OVERRIDE ,
1440 (since Linux 2.6.30).
1441 If the filesystem UID is changed from nonzero to 0,
1442 then any of these capabilities that are enabled in the permitted set
1443 are enabled in the effective set.
1445 If a thread that has a 0 value for one or more of its user IDs wants
1446 to prevent its permitted capability set being cleared when it resets
1447 all of its user IDs to nonzero values, it can do so using the
1449 securebits flag described below.
1451 .SS Programmatically adjusting capability sets
1452 A thread can retrieve and change its permitted, effective, and inheritable
1453 capability sets using the
1459 .BR cap_get_proc (3)
1461 .BR cap_set_proc (3),
1462 both provided in the
1465 is preferred for this purpose.
1466 The following rules govern changes to the thread capability sets:
1468 If the caller does not have the
1471 the new inheritable set must be a subset of the combination
1472 of the existing inheritable and permitted sets.
1474 (Since Linux 2.6.25)
1475 The new inheritable set must be a subset of the combination of the
1476 existing inheritable set and the capability bounding set.
1478 The new permitted set must be a subset of the existing permitted set
1479 (i.e., it is not possible to acquire permitted capabilities
1480 that the thread does not currently have).
1482 The new effective set must be a subset of the new permitted set.
1483 .SS The securebits flags: establishing a capabilities-only environment
1484 .\" For some background:
1485 .\" see http://lwn.net/Articles/280279/ and
1486 .\" http://article.gmane.org/gmane.linux.kernel.lsm/5476/
1487 Starting with kernel 2.6.26,
1488 and with a kernel in which file capabilities are enabled,
1489 Linux implements a set of per-thread
1491 flags that can be used to disable special handling of capabilities for UID 0
1493 These flags are as follows:
1496 Setting this flag allows a thread that has one or more 0 UIDs to retain
1497 capabilities in its permitted set
1498 when it switches all of its UIDs to nonzero values.
1499 If this flag is not set,
1500 then such a UID switch causes the thread to lose all permitted capabilities.
1501 This flag is always cleared on an
1504 Note that even with the
1506 flag set, the effective capabilities of a thread are cleared when it
1507 switches its effective UID to a nonzero value.
1509 if the thread has set this flag and its effective UID is already nonzero,
1510 and the thread subsequently switches all other UIDs to nonzero values,
1511 then the effective capabilities will not be cleared.
1515 flag is ignored if the
1516 .B SECBIT_NO_SETUID_FIXUP
1518 (The latter flag provides a superset of the effect of the former flag.)
1520 This flag provides the same functionality as the older
1525 .B SECBIT_NO_SETUID_FIXUP
1526 Setting this flag stops the kernel from adjusting the process's
1527 permitted, effective, and ambient capability sets when
1528 the thread's effective and filesystem UIDs are switched between
1529 zero and nonzero values.
1531 .IR "Effect of user ID changes on capabilities" .)
1534 If this bit is set, then the kernel does not grant capabilities
1535 when a set-user-ID-root program is executed, or when a process with
1536 an effective or real UID of 0 calls
1539 .IR "Capabilities and execution of programs by root" .)
1541 .B SECBIT_NO_CAP_AMBIENT_RAISE
1542 Setting this flag disallows raising ambient capabilities via the
1544 .BR PR_CAP_AMBIENT_RAISE
1547 Each of the above "base" flags has a companion "locked" flag.
1548 Setting any of the "locked" flags is irreversible,
1549 and has the effect of preventing further changes to the
1550 corresponding "base" flag.
1551 The locked flags are:
1552 .BR SECBIT_KEEP_CAPS_LOCKED ,
1553 .BR SECBIT_NO_SETUID_FIXUP_LOCKED ,
1554 .BR SECBIT_NOROOT_LOCKED ,
1556 .BR SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED .
1560 flags can be modified and retrieved using the
1562 .B PR_SET_SECUREBITS
1564 .B PR_GET_SECUREBITS
1568 capability is required to modify the flags.
1571 constants are available only after including the
1572 .I <linux/securebits.h>
1577 flags are inherited by child processes.
1580 all of the flags are preserved, except
1582 which is always cleared.
1584 An application can use the following call to lock itself,
1585 and all of its descendants,
1586 into an environment where the only way of gaining capabilities
1587 is by executing a program with associated file capabilities:
1591 prctl(PR_SET_SECUREBITS,
1592 /* SECBIT_KEEP_CAPS off */
1593 SECBIT_KEEP_CAPS_LOCKED |
1594 SECBIT_NO_SETUID_FIXUP |
1595 SECBIT_NO_SETUID_FIXUP_LOCKED |
1597 SECBIT_NOROOT_LOCKED);
1598 /* Setting/locking SECBIT_NO_CAP_AMBIENT_RAISE
1604 .SS Per-user-namespace """set-user-ID-root""" programs
1605 A set-user-ID program whose UID matches the UID that
1606 created a user namespace will confer capabilities
1607 in the process's permitted and effective sets
1608 when executed by any process inside that namespace
1609 or any descendant user namespace.
1611 The rules about the transformation of the process's capabilities during the
1613 are exactly as described in the subsections
1614 .IR "Transformation of capabilities during execve()"
1616 .IR "Capabilities and execution of programs by root" ,
1617 with the difference that, in the latter subsection, "root"
1618 is the UID of the creator of the user namespace.
1621 .SS Namespaced file capabilities
1622 .\" commit 8db6c34f1dbc8e06aa016a9b829b06902c3e1340
1623 Traditional (i.e., version 2) file capabilities associate
1624 only a set of capability masks with a binary executable file.
1625 When a process executes a binary with such capabilities,
1626 it gains the associated capabilities (within its user namespace)
1627 as per the rules described above in
1628 "Transformation of capabilities during execve()".
1630 Because version 2 file capabilities confer capabilities to
1631 the executing process regardless of which user namespace it resides in,
1632 only privileged processes are permitted to associate capabilities with a file.
1633 Here, "privileged" means a process that has the
1635 capability in the user namespace where the filesystem was mounted
1636 (normally the initial user namespace).
1637 This limitation renders file capabilities useless for certain use cases.
1638 For example, in user-namespaced containers,
1639 it can be desirable to be able to create a binary that
1640 confers capabilities only to processes executed inside that container,
1641 but not to processes that are executed outside the container.
1643 Linux 4.14 added so-called namespaced file capabilities
1644 to support such use cases.
1645 Namespaced file capabilities are recorded as version 3 (i.e.,
1646 .BR VFS_CAP_REVISION_3 )
1647 .I security.capability
1648 extended attributes.
1649 Such an attribute is automatically created in the circumstances described
1650 above under "File capability extended attribute versioning".
1652 .I security.capability
1653 extended attribute is created,
1654 the kernel records not just the capability masks in the extended attribute,
1655 but also the namespace root user ID.
1657 As with a binary that has
1658 .BR VFS_CAP_REVISION_2
1659 file capabilities, a binary with
1660 .BR VFS_CAP_REVISION_3
1661 file capabilities confers capabilities to a process during
1663 However, capabilities are conferred only if the binary is executed by
1664 a process that resides in a user namespace whose
1665 UID 0 maps to the root user ID that is saved in the extended attribute,
1666 or when executed by a process that resides in a descendant of such a namespace.
1669 .SS Interaction with user namespaces
1670 For further information on the interaction of
1671 capabilities and user namespaces, see
1672 .BR user_namespaces (7).
1675 No standards govern capabilities, but the Linux capability implementation
1676 is based on the withdrawn POSIX.1e draft standard; see
1677 .UR https://archive.org\:/details\:/posix_1003.1e-990310
1682 binaries that have capabilities (or set-user-ID-root binaries),
1690 $ \fBsudo strace \-o trace.log \-u ceci ./myprivprog\fP
1694 From kernel 2.5.27 to kernel 2.6.26,
1695 .\" commit 5915eb53861c5776cfec33ca4fcc1fd20d66dd27 removed
1696 .\" CONFIG_SECURITY_CAPABILITIES
1697 capabilities were an optional kernel component,
1698 and could be enabled/disabled via the
1699 .B CONFIG_SECURITY_CAPABILITIES
1700 kernel configuration option.
1703 .I /proc/[pid]/task/TID/status
1704 file can be used to view the capability sets of a thread.
1706 .I /proc/[pid]/status
1707 file shows the capability sets of a process's main thread.
1708 Before Linux 3.8, nonexistent capabilities were shown as being
1709 enabled (1) in these sets.
1711 .\" 7b9a7ec565505699f503b4fcf61500dceb36e744
1712 all nonexistent capabilities (above
1714 are shown as disabled (0).
1718 package provides a suite of routines for setting and
1719 getting capabilities that is more comfortable and less likely
1720 to change than the interface provided by
1724 This package also provides the
1731 .UR https://git.kernel.org\:/pub\:/scm\:/libs\:/libcap\:/libcap.git\:/refs/
1734 Before kernel 2.6.24, and from kernel 2.6.24 to kernel 2.6.32 if
1735 file capabilities are not enabled, a thread with the
1737 capability can manipulate the capabilities of threads other than itself.
1738 However, this is only theoretically possible,
1739 since no thread ever has
1741 in either of these cases:
1743 In the pre-2.6.25 implementation the system-wide capability bounding set,
1744 .IR /proc/sys/kernel/cap-bound ,
1745 always masks out the
1747 capability, and this can not be changed
1748 without modifying the kernel source and rebuilding the kernel.
1750 If file capabilities are disabled (i.e., the kernel
1751 .B CONFIG_SECURITY_FILE_CAPABILITIES
1752 option is disabled), then
1756 capability removed from its per-process bounding
1757 set, and that bounding set is inherited by all other processes
1758 created on the system.
1765 .BR cap_copy_ext (3),
1766 .BR cap_from_text (3),
1767 .BR cap_get_file (3),
1768 .BR cap_get_proc (3),
1774 .BR credentials (7),
1776 .BR user_namespaces (7),
1777 .BR captest (8), \" from libcap-ng
1778 .BR filecap (8), \" from libcap-ng
1780 .BR netcap (8), \" from libcap-ng
1781 .BR pscap (8), \" from libcap-ng
1784 .I include/linux/capability.h
1785 in the Linux kernel source tree