1 .\" Copyright (c) 2002 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" 6 Aug 2002 - Initial Creation
24 .\" Modified 2003-05-23, Michael Kerrisk, <mtk.manpages@gmail.com>
25 .\" Modified 2004-05-27, Michael Kerrisk, <mtk.manpages@gmail.com>
26 .\" 2004-12-08, mtk Added O_NOATIME for CAP_FOWNER
27 .\" 2005-08-16, mtk, Added CAP_AUDIT_CONTROL and CAP_AUDIT_WRITE
28 .\" 2008-07-15, Serge Hallyn <serue@us.bbm.com>
29 .\" Document file capabilities, per-process capability
30 .\" bounding set, changed semantics for CAP_SETPCAP,
31 .\" and other changes in 2.6.2[45].
32 .\" Add CAP_MAC_ADMIN, CAP_MAC_OVERRIDE, CAP_SETFCAP.
34 .\" Add text describing circumstances in which CAP_SETPCAP
35 .\" (theoretically) permits a thread to change the
36 .\" capability sets of another thread.
37 .\" Add section describing rules for programmatically
38 .\" adjusting thread capability sets.
39 .\" Describe rationale for capability bounding set.
40 .\" Document "securebits" flags.
41 .\" Add text noting that if we set the effective flag for one file
42 .\" capability, then we must also set the effective flag for all
43 .\" other capabilities where the permitted or inheritable bit is set.
45 .TH CAPABILITIES 7 2010-06-19 "Linux" "Linux Programmer's Manual"
47 capabilities \- overview of Linux capabilities
49 For the purpose of performing permission checks,
50 traditional UNIX implementations distinguish two categories of processes:
52 processes (whose effective user ID is 0, referred to as superuser or root),
55 processes (whose effective UID is nonzero).
56 Privileged processes bypass all kernel permission checks,
57 while unprivileged processes are subject to full permission
58 checking based on the process's credentials
59 (usually: effective UID, effective GID, and supplementary group list).
61 Starting with kernel 2.2, Linux divides the privileges traditionally
62 associated with superuser into distinct units, known as
64 which can be independently enabled and disabled.
65 Capabilities are a per-thread attribute.
68 The following list shows the capabilities implemented on Linux,
69 and the operations or behaviors that each capability permits:
71 .BR CAP_AUDIT_CONTROL " (since Linux 2.6.11)"
72 Enable and disable kernel auditing; change auditing filter rules;
73 retrieve auditing status and filtering rules.
75 .BR CAP_AUDIT_WRITE " (since Linux 2.6.11)"
76 Write records to kernel auditing log.
79 Make arbitrary changes to file UIDs and GIDs (see
83 Bypass file read, write, and execute permission checks.
84 (DAC is an abbreviation of "discretionary access control".)
86 .B CAP_DAC_READ_SEARCH
87 Bypass file read permission checks and
88 directory read and execute permission checks.
94 Bypass permission checks on operations that normally
95 require the file system UID of the process to match the UID of
99 excluding those operations covered by
102 .BR CAP_DAC_READ_SEARCH ;
104 set extended file attributes (see
108 set Access Control Lists (ACLs) on arbitrary files;
110 ignore directory sticky bit on file deletion;
114 for arbitrary files in
122 Don't clear set-user-ID and set-group-ID permission
123 bits when a file is modified;
124 set the set-group-ID bit for a file whose GID does not match
125 the file system or any of the supplementary GIDs of the calling process.
135 Bypass permission checks for operations on System V IPC objects.
138 Bypass permission checks for sending signals (see
140 This includes use of the
144 .\" FIXME CAP_KILL also has an effect for threads + setting child
145 .\" termination signal to other than SIGCHLD: without this
146 .\" capability, the termination signal reverts to SIGCHLD
147 .\" if the child does an exec(). What is the rationale
150 .BR CAP_LEASE " (since Linux 2.4)"
151 Establish leases on arbitrary files (see
154 .B CAP_LINUX_IMMUTABLE
159 .\" These attributes are now available on ext2, ext3, Reiserfs, XFS, JFS
163 .BR CAP_MAC_ADMIN " (since Linux 2.6.25)"
164 Override Mandatory Access Control (MAC).
165 Implemented for the Smack Linux Security Module (LSM).
167 .BR CAP_MAC_OVERRIDE " (since Linux 2.6.25)"
168 Allow MAC configuration or state changes.
169 Implemented for the Smack LSM.
171 .BR CAP_MKNOD " (since Linux 2.4)"
172 Create special files using
176 Perform various network-related operations
177 (e.g., setting privileged socket options,
178 enabling multicasting, interface configuration,
179 modifying routing tables).
181 .B CAP_NET_BIND_SERVICE
182 Bind a socket to Internet domain privileged ports
183 (port numbers less than 1024).
186 (Unused) Make socket broadcasts, and listen to multicasts.
189 Use RAW and PACKET sockets.
190 .\" Also various IP options and setsockopt(SO_BINDTODEVICE)
193 Make arbitrary manipulations of process GIDs and supplementary GID list;
194 forge GID when passing socket credentials via UNIX domain sockets.
196 .BR CAP_SETFCAP " (since Linux 2.6.24)"
197 Set file capabilities.
200 If file capabilities are not supported:
201 grant or remove any capability in the
202 caller's permitted capability set to or from any other process.
205 is not available when the kernel is configured to support
206 file capabilities, since
208 has entirely different semantics for such kernels.)
210 If file capabilities are supported:
211 add any capability from the calling thread's bounding set
212 to its inheritable set;
213 drop capabilities from the bounding set (via
215 .BR PR_CAPBSET_DROP );
221 Make arbitrary manipulations of process UIDs
226 make forged UID when passing socket credentials via UNIX domain sockets.
227 .\" FIXME CAP_SETUID also an effect in exec(); document this.
233 Perform a range of system administration operations including:
241 .BR setdomainname (2);
247 operations on arbitrary System V IPC objects;
249 perform operations on
253 Extended Attributes (see
257 .BR lookup_dcookie (2);
263 and (before Linux 2.6.25)
265 I/O scheduling classes;
267 forge UID when passing socket credentials;
270 .IR /proc/sys/fs/file-max ,
271 the system-wide limit on the number of open files,
272 in system calls that open files (e.g.,
310 Load and unload kernel modules
314 .BR delete_module (2));
315 in kernels before 2.6.25:
316 drop capabilities from the system-wide capability bounding set.
322 Raise process nice value
325 and change the nice value for arbitrary processes;
327 set real-time scheduling policies for calling process,
328 and set scheduling policies and priorities for arbitrary processes
329 .RB ( sched_setscheduler (2),
330 .BR sched_setparam (2));
332 set CPU affinity for arbitrary processes
333 .RB ( sched_setaffinity (2));
335 set I/O scheduling class and priority for arbitrary processes
336 .RB ( ioprio_set (2));
339 .BR migrate_pages (2)
340 to arbitrary processes and allow processes
341 to be migrated to arbitrary nodes;
342 .\" FIXME CAP_SYS_NICE also has the following effect for
343 .\" migrate_pages(2):
344 .\" do_migrate_pages(mm, &old, &new,
345 .\" capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
349 to arbitrary processes;
365 Trace arbitrary processes using
368 .BR get_robust_list (2)
369 to arbitrary processes.
372 Perform I/O port operations
383 Use reserved space on ext2 file systems;
387 calls controlling ext3 journaling;
389 override disk quota limits;
391 increase resource limits (see
400 limit for a System V message queue above the limit in
401 .I /proc/sys/kernel/msgmnb
409 to increase the capacity of a pipe above the limit specified by
410 .IR /proc/sys/fs/pipe-max-size .
416 .RB ( settimeofday (2),
419 set real-time (hardware) clock.
421 .B CAP_SYS_TTY_CONFIG
425 .SS Past and Current Implementation
426 A full implementation of capabilities requires that:
428 For all privileged operations,
429 the kernel must check whether the thread has the required
430 capability in its effective set.
432 The kernel must provide system calls allowing a thread's capability sets to
433 be changed and retrieved.
435 The file system must support attaching capabilities to an executable file,
436 so that a process gains those capabilities when the file is executed.
438 Before kernel 2.6.24, only the first two of these requirements are met;
439 since kernel 2.6.24, all three requirements are met.
441 .SS Thread Capability Sets
442 Each thread has three capability sets containing zero or more
443 of the above capabilities:
446 This is a limiting superset for the effective
447 capabilities that the thread may assume.
448 It is also a limiting superset for the capabilities that
449 may be added to the inheritable set by a thread that does not have the
451 capability in its effective set.
453 If a thread drops a capability from its permitted set,
454 it can never reacquire that capability (unless it
456 either a set-user-ID-root program, or
457 a program whose associated file capabilities grant that capability).
460 This is a set of capabilities preserved across an
462 It provides a mechanism for a process to assign capabilities
463 to the permitted set of the new program during an
467 This is the set of capabilities used by the kernel to
468 perform permission checks for the thread.
472 inherits copies of its parent's capability sets.
473 See below for a discussion of the treatment of capabilities during
478 a thread may manipulate its own capability sets (see below).
480 .SS File Capabilities
481 Since kernel 2.6.24, the kernel supports
482 associating capability sets with an executable file using
484 The file capability sets are stored in an extended attribute (see
487 .IR "security.capability" .
488 Writing to this extended attribute requires the
491 The file capability sets,
492 in conjunction with the capability sets of the thread,
493 determine the capabilities of a thread after an
496 The three file capability sets are:
498 .IR Permitted " (formerly known as " forced ):
499 These capabilities are automatically permitted to the thread,
500 regardless of the thread's inheritable capabilities.
502 .IR Inheritable " (formerly known as " allowed ):
503 This set is ANDed with the thread's inheritable set to determine which
504 inheritable capabilities are enabled in the permitted set of
509 This is not a set, but rather just a single bit.
510 If this bit is set, then during an
512 all of the new permitted capabilities for the thread are
513 also raised in the effective set.
514 If this bit is not set, then after an
516 none of the new permitted capabilities is in the new effective set.
518 Enabling the file effective capability bit implies
519 that any file permitted or inheritable capability that causes a
520 thread to acquire the corresponding permitted capability during an
522 (see the transformation rules described below) will also acquire that
523 capability in its effective set.
524 Therefore, when assigning capabilities to a file
526 .BR cap_set_file (3),
528 if we specify the effective flag as being enabled for any capability,
529 then the effective flag must also be specified as enabled
530 for all other capabilities for which the corresponding permitted or
531 inheritable flags is enabled.
533 .SS Transformation of Capabilities During execve()
537 the kernel calculates the new capabilities of
538 the process using the following algorithm:
542 P'(permitted) = (P(inheritable) & F(inheritable)) |
543 (F(permitted) & cap_bset)
545 P'(effective) = F(effective) ? P'(permitted) : 0
547 P'(inheritable) = P(inheritable) [i.e., unchanged]
554 denotes the value of a thread capability set before the
557 denotes the value of a capability set after the
560 denotes a file capability set
562 is the value of the capability bounding set (described below).
565 .SS Capabilities and execution of programs by root
566 In order to provide an all-powerful
568 using capability sets, during an
571 If a set-user-ID-root program is being executed,
572 or the real user ID of the process is 0 (root)
573 then the file inheritable and permitted sets are defined to be all ones
574 (i.e., all capabilities enabled).
576 If a set-user-ID-root program is being executed,
577 then the file effective bit is defined to be one (enabled).
579 The upshot of the above rules,
580 combined with the capabilities transformations described above,
581 is that when a process
583 a set-user-ID-root program, or when a process with an effective UID of 0
586 it gains all capabilities in its permitted and effective capability sets,
587 except those masked out by the capability bounding set.
588 .\" If a process with real UID 0, and nonzero effective UID does an
589 .\" exec(), then it gets all capabilities in its
590 .\" permitted set, and no effective capabilities
591 This provides semantics that are the same as those provided by
592 traditional UNIX systems.
593 .SS Capability bounding set
594 The capability bounding set is a security mechanism that can be used
595 to limit the capabilities that can be gained during an
597 The bounding set is used in the following ways:
601 the capability bounding set is ANDed with the file permitted
602 capability set, and the result of this operation is assigned to the
603 thread's permitted capability set.
604 The capability bounding set thus places a limit on the permitted
605 capabilities that may be granted by an executable file.
608 The capability bounding set acts as a limiting superset for
609 the capabilities that a thread can add to its inheritable set using
611 This means that if a capability is not in the bounding set,
612 then a thread can't add this capability to its
613 inheritable set, even if it was in its permitted capabilities,
614 and thereby cannot have this capability preserved in its
615 permitted set when it
617 a file that has the capability in its inheritable set.
619 Note that the bounding set masks the file permitted capabilities,
620 but not the inherited capabilities.
621 If a thread maintains a capability in its inherited set
622 that is not in its bounding set,
623 then it can still gain that capability in its permitted set
624 by executing a file that has the capability in its inherited set.
626 Depending on the kernel version, the capability bounding set is either
627 a system-wide attribute, or a per-process attribute.
629 .B "Capability bounding set prior to Linux 2.6.25"
631 In kernels before 2.6.25, the capability bounding set is a system-wide
632 attribute that affects all threads on the system.
633 The bounding set is accessible via the file
634 .IR /proc/sys/kernel/cap-bound .
635 (Confusingly, this bit mask parameter is expressed as a
636 signed decimal number in
637 .IR /proc/sys/kernel/cap-bound .)
641 process may set capabilities in the capability bounding set;
642 other than that, the superuser (more precisely: programs with the
644 capability) may only clear capabilities from this set.
646 On a standard system the capability bounding set always masks out the
649 To remove this restriction (dangerous!), modify the definition of
652 .I include/linux/capability.h
653 and rebuild the kernel.
655 The system-wide capability bounding set feature was added
656 to Linux starting with kernel version 2.2.11.
659 .B "Capability bounding set from Linux 2.6.25 onward"
661 From Linux 2.6.25, the
662 .I "capability bounding set"
663 is a per-thread attribute.
664 (There is no longer a system-wide capability bounding set.)
666 The bounding set is inherited at
668 from the thread's parent, and is preserved across an
671 A thread may remove capabilities from its capability bounding set using the
674 operation, provided it has the
677 Once a capability has been dropped from the bounding set,
678 it cannot be restored to that set.
679 A thread can determine if a capability is in its bounding set using the
684 Removing capabilities from the bounding set is only supported if file
685 capabilities are compiled into the kernel
686 (CONFIG_SECURITY_FILE_CAPABILITIES).
689 process (the ancestor of all processes) begins with a full bounding set.
690 If file capabilities are not compiled into the kernel, then
692 begins with a full bounding set minus
694 because this capability has a different meaning when there are
695 no file capabilities.
697 Removing a capability from the bounding set does not remove it
698 from the thread's inherited set.
699 However it does prevent the capability from being added
700 back into the thread's inherited set in the future.
703 .SS Effect of User ID Changes on Capabilities
704 To preserve the traditional semantics for transitions between
705 0 and nonzero user IDs,
706 the kernel makes the following changes to a thread's capability
707 sets on changes to the thread's real, effective, saved set,
708 and file system user IDs (using
713 If one or more of the real, effective or saved set user IDs
714 was previously 0, and as a result of the UID changes all of these IDs
715 have a nonzero value,
716 then all capabilities are cleared from the permitted and effective
719 If the effective user ID is changed from 0 to nonzero,
720 then all capabilities are cleared from the effective set.
722 If the effective user ID is changed from nonzero to 0,
723 then the permitted set is copied to the effective set.
725 If the file system user ID is changed from 0 to nonzero (see
727 then the following capabilities are cleared from the effective set:
729 .BR CAP_DAC_OVERRIDE ,
730 .BR CAP_DAC_READ_SEARCH ,
733 .B CAP_LINUX_IMMUTABLE
734 (since Linux 2.2.30),
735 .BR CAP_MAC_OVERRIDE ,
738 (since Linux 2.2.30).
739 If the file system UID is changed from nonzero to 0,
740 then any of these capabilities that are enabled in the permitted set
741 are enabled in the effective set.
743 If a thread that has a 0 value for one or more of its user IDs wants
744 to prevent its permitted capability set being cleared when it resets
745 all of its user IDs to nonzero values, it can do so using the
750 .SS Programmatically adjusting capability sets
751 A thread can retrieve and change its capability sets using the
759 .BR cap_set_proc (3),
763 is preferred for this purpose.
764 The following rules govern changes to the thread capability sets:
766 If the caller does not have the
769 the new inheritable set must be a subset of the combination
770 of the existing inheritable and permitted sets.
772 (Since kernel 2.6.25)
773 The new inheritable set must be a subset of the combination of the
774 existing inheritable set and the capability bounding set.
776 The new permitted set must be a subset of the existing permitted set
777 (i.e., it is not possible to acquire permitted capabilities
778 that the thread does not currently have).
780 The new effective set must be a subset of the new permitted set.
781 .SS The """securebits"" flags: establishing a capabilities-only environment
782 .\" For some background:
783 .\" see http://lwn.net/Articles/280279/ and
784 .\" http://article.gmane.org/gmane.linux.kernel.lsm/5476/
785 Starting with kernel 2.6.26,
786 and with a kernel in which file capabilities are enabled,
787 Linux implements a set of per-thread
789 flags that can be used to disable special handling of capabilities for UID 0
791 These flags are as follows:
794 Setting this flag allows a thread that has one or more 0 UIDs to retain
795 its capabilities when it switches all of its UIDs to a nonzero value.
796 If this flag is not set,
797 then such a UID switch causes the thread to lose all capabilities.
798 This flag is always cleared on an
800 (This flag provides the same functionality as the older
805 .B SECBIT_NO_SETUID_FIXUP
806 Setting this flag stops the kernel from adjusting capability sets when
807 the threads's effective and file system UIDs are switched between
808 zero and nonzero values.
810 .IR "Effect of User ID Changes on Capabilities" .)
813 If this bit is set, then the kernel does not grant capabilities
814 when a set-user-ID-root program is executed, or when a process with
815 an effective or real UID of 0 calls
818 .IR "Capabilities and execution of programs by root" .)
820 Each of the above "base" flags has a companion "locked" flag.
821 Setting any of the "locked" flags is irreversible,
822 and has the effect of preventing further changes to the
823 corresponding "base" flag.
824 The locked flags are:
825 .BR SECBIT_KEEP_CAPS_LOCKED ,
826 .BR SECBIT_NO_SETUID_FIXUP_LOCKED ,
828 .BR SECBIT_NOROOT_LOCKED .
832 flags can be modified and retrieved using the
840 capability is required to modify the flags.
844 flags are inherited by child processes.
847 all of the flags are preserved, except
849 which is always cleared.
851 An application can use the following call to lock itself,
852 and all of its descendants,
853 into an environment where the only way of gaining capabilities
854 is by executing a program with associated file capabilities:
858 prctl(PR_SET_SECUREBITS,
859 SECBIT_KEEP_CAPS_LOCKED |
860 SECBIT_NO_SETUID_FIXUP |
861 SECBIT_NO_SETUID_FIXUP_LOCKED |
863 SECBIT_NOROOT_LOCKED);
868 No standards govern capabilities, but the Linux capability implementation
869 is based on the withdrawn POSIX.1e draft standard; see
870 .IR http://wt.xpilot.org/publications/posix.1e/ .
872 Since kernel 2.5.27, capabilities are an optional kernel component,
873 and can be enabled/disabled via the CONFIG_SECURITY_CAPABILITIES
874 kernel configuration option.
877 .I /proc/PID/task/TID/status
878 file can be used to view the capability sets of a thread.
881 file shows the capability sets of a process's main thread.
885 package provides a suite of routines for setting and
886 getting capabilities that is more comfortable and less likely
887 to change than the interface provided by
891 This package also provides the
898 .IR http://www.kernel.org/pub/linux/libs/security/linux-privs .
900 Before kernel 2.6.24, and since kernel 2.6.24 if
901 file capabilities are not enabled, a thread with the
903 capability can manipulate the capabilities of threads other than itself.
904 However, this is only theoretically possible,
905 since no thread ever has
907 in either of these cases:
909 In the pre-2.6.25 implementation the system-wide capability bounding set,
910 .IR /proc/sys/kernel/cap-bound ,
911 always masks out this capability, and this can not be changed
912 without modifying the kernel source and rebuilding.
914 If file capabilities are disabled in the current implementation, then
916 starts out with this capability removed from its per-process bounding
917 set, and that bounding set is inherited by all other processes
918 created on the system.
924 .BR cap_copy_ext (3),
925 .BR cap_from_text (3),
926 .BR cap_get_file (3),
927 .BR cap_get_proc (3),
936 .I include/linux/capability.h