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-01-31 "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.,
305 Load and unload kernel modules
309 .BR delete_module (2));
310 in kernels before 2.6.25:
311 drop capabilities from the system-wide capability bounding set.
317 Raise process nice value
320 and change the nice value for arbitrary processes;
322 set real-time scheduling policies for calling process,
323 and set scheduling policies and priorities for arbitrary processes
324 .RB ( sched_setscheduler (2),
325 .BR sched_setparam (2));
327 set CPU affinity for arbitrary processes
328 .RB ( sched_setaffinity (2));
330 set I/O scheduling class and priority for arbitrary processes
331 .RB ( ioprio_set (2));
334 .BR migrate_pages (2)
335 to arbitrary processes and allow processes
336 to be migrated to arbitrary nodes;
337 .\" FIXME CAP_SYS_NICE also has the following effect for
338 .\" migrate_pages(2):
339 .\" do_migrate_pages(mm, &old, &new,
340 .\" capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
344 to arbitrary processes;
360 Trace arbitrary processes using
364 Perform I/O port operations
375 Use reserved space on ext2 file systems;
379 calls controlling ext3 journaling;
381 override disk quota limits;
383 increase resource limits (see
392 limit for a System V message queue above the limit in
393 .I /proc/sys/kernel/msgmnb
403 .RB ( settimeofday (2),
406 set real-time (hardware) clock.
408 .B CAP_SYS_TTY_CONFIG
412 .SS Past and Current Implementation
413 A full implementation of capabilities requires that:
415 For all privileged operations,
416 the kernel must check whether the thread has the required
417 capability in its effective set.
419 The kernel must provide system calls allowing a thread's capability sets to
420 be changed and retrieved.
422 The file system must support attaching capabilities to an executable file,
423 so that a process gains those capabilities when the file is executed.
425 Before kernel 2.6.24, only the first two of these requirements are met;
426 since kernel 2.6.24, all three requirements are met.
428 .SS Thread Capability Sets
429 Each thread has three capability sets containing zero or more
430 of the above capabilities:
433 This is a limiting superset for the effective
434 capabilities that the thread may assume.
435 It is also a limiting superset for the capabilities that
436 may be added to the inheritable set by a thread that does not have the
438 capability in its effective set.
440 If a thread drops a capability from its permitted set,
441 it can never reacquire that capability (unless it
443 either a set-user-ID-root program, or
444 a program whose associated file capabilities grant that capability).
447 This is a set of capabilities preserved across an
449 It provides a mechanism for a process to assign capabilities
450 to the permitted set of the new program during an
454 This is the set of capabilities used by the kernel to
455 perform permission checks for the thread.
459 inherits copies of its parent's capability sets.
460 See below for a discussion of the treatment of capabilities during
465 a thread may manipulate its own capability sets (see below).
467 .SS File Capabilities
468 Since kernel 2.6.24, the kernel supports
469 associating capability sets with an executable file using
471 The file capability sets are stored in an extended attribute (see
474 .IR "security.capability" .
475 Writing to this extended attribute requires the
478 The file capability sets,
479 in conjunction with the capability sets of the thread,
480 determine the capabilities of a thread after an
483 The three file capability sets are:
485 .IR Permitted " (formerly known as " forced ):
486 These capabilities are automatically permitted to the thread,
487 regardless of the thread's inheritable capabilities.
489 .IR Inheritable " (formerly known as " allowed ):
490 This set is ANDed with the thread's inheritable set to determine which
491 inheritable capabilities are enabled in the permitted set of
496 This is not a set, but rather just a single bit.
497 If this bit is set, then during an
499 all of the new permitted capabilities for the thread are
500 also raised in the effective set.
501 If this bit is not set, then after an
503 none of the new permitted capabilities is in the new effective set.
505 Enabling the file effective capability bit implies
506 that any file permitted or inheritable capability that causes a
507 thread to acquire the corresponding permitted capability during an
509 (see the transformation rules described below) will also acquire that
510 capability in its effective set.
511 Therefore, when assigning capabilities to a file
513 .BR cap_set_file (3),
515 if we specify the effective flag as being enabled for any capability,
516 then the effective flag must also be specified as enabled
517 for all other capabilities for which the corresponding permitted or
518 inheritable flags is enabled.
520 .SS Transformation of Capabilities During execve()
524 the kernel calculates the new capabilities of
525 the process using the following algorithm:
529 P'(permitted) = (P(inheritable) & F(inheritable)) |
530 (F(permitted) & cap_bset)
532 P'(effective) = F(effective) ? P'(permitted) : 0
534 P'(inheritable) = P(inheritable) [i.e., unchanged]
541 denotes the value of a thread capability set before the
544 denotes the value of a capability set after the
547 denotes a file capability set
549 is the value of the capability bounding set (described below).
552 .SS Capabilities and execution of programs by root
553 In order to provide an all-powerful
555 using capability sets, during an
558 If a set-user-ID-root program is being executed,
559 or the real user ID of the process is 0 (root)
560 then the file inheritable and permitted sets are defined to be all ones
561 (i.e., all capabilities enabled).
563 If a set-user-ID-root program is being executed,
564 then the file effective bit is defined to be one (enabled).
566 The upshot of the above rules,
567 combined with the capabilities transformations described above,
568 is that when a process
570 a set-user-ID-root program, or when a process with an effective UID of 0
573 it gains all capabilities in its permitted and effective capability sets,
574 except those masked out by the capability bounding set.
575 .\" If a process with real UID 0, and nonzero effective UID does an
576 .\" exec(), then it gets all capabilities in its
577 .\" permitted set, and no effective capabilities
578 This provides semantics that are the same as those provided by
579 traditional Unix systems.
580 .SS Capability bounding set
581 The capability bounding set is a security mechanism that can be used
582 to limit the capabilities that can be gained during an
584 The bounding set is used in the following ways:
588 the capability bounding set is ANDed with the file permitted
589 capability set, and the result of this operation is assigned to the
590 thread's permitted capability set.
591 The capability bounding set thus places a limit on the permitted
592 capabilities that may be granted by an executable file.
595 The capability bounding set acts as a limiting superset for
596 the capabilities that a thread can add to its inheritable set using
598 This means that if a capability is not in the bounding set,
599 then a thread can't add this capability to its
600 inheritable set, even if it was in its permitted capabilities,
601 and thereby cannot have this capability preserved in its
602 permitted set when it
604 a file that has the capability in its inheritable set.
606 Note that the bounding set masks the file permitted capabilities,
607 but not the inherited capabilities.
608 If a thread maintains a capability in its inherited set
609 that is not in its bounding set,
610 then it can still gain that capability in its permitted set
611 by executing a file that has the capability in its inherited set.
613 Depending on the kernel version, the capability bounding set is either
614 a system-wide attribute, or a per-process attribute.
616 .B "Capability bounding set prior to Linux 2.6.25"
618 In kernels before 2.6.25, the capability bounding set is a system-wide
619 attribute that affects all threads on the system.
620 The bounding set is accessible via the file
621 .IR /proc/sys/kernel/cap-bound .
622 (Confusingly, this bit mask parameter is expressed as a
623 signed decimal number in
624 .IR /proc/sys/kernel/cap-bound .)
628 process may set capabilities in the capability bounding set;
629 other than that, the superuser (more precisely: programs with the
631 capability) may only clear capabilities from this set.
633 On a standard system the capability bounding set always masks out the
636 To remove this restriction (dangerous!), modify the definition of
639 .I include/linux/capability.h
640 and rebuild the kernel.
642 The system-wide capability bounding set feature was added
643 to Linux starting with kernel version 2.2.11.
646 .B "Capability bounding set from Linux 2.6.25 onwards"
648 From Linux 2.6.25, the
649 .I "capability bounding set"
650 is a per-thread attribute.
651 (There is no longer a system-wide capability bounding set.)
653 The bounding set is inherited at
655 from the thread's parent, and is preserved across an
658 A thread may remove capabilities from its capability bounding set using the
661 operation, provided it has the
664 Once a capability has been dropped from the bounding set,
665 it cannot be restored to that set.
666 A thread can determine if a capability is in its bounding set using the
671 Removing capabilities from the bounding set is only supported if file
672 capabilities are compiled into the kernel
673 (CONFIG_SECURITY_FILE_CAPABILITIES).
676 process (the ancestor of all processes) begins with a full bounding set.
677 If file capabilities are not compiled into the kernel, then
679 begins with a full bounding set minus
681 because this capability has a different meaning when there are
682 no file capabilities.
684 Removing a capability from the bounding set does not remove it
685 from the thread's inherited set.
686 However it does prevent the capability from being added
687 back into the thread's inherited set in the future.
690 .SS Effect of User ID Changes on Capabilities
691 To preserve the traditional semantics for transitions between
692 0 and nonzero user IDs,
693 the kernel makes the following changes to a thread's capability
694 sets on changes to the thread's real, effective, saved set,
695 and file system user IDs (using
700 If one or more of the real, effective or saved set user IDs
701 was previously 0, and as a result of the UID changes all of these IDs
702 have a nonzero value,
703 then all capabilities are cleared from the permitted and effective
706 If the effective user ID is changed from 0 to nonzero,
707 then all capabilities are cleared from the effective set.
709 If the effective user ID is changed from nonzero to 0,
710 then the permitted set is copied to the effective set.
712 If the file system user ID is changed from 0 to nonzero (see
714 then the following capabilities are cleared from the effective set:
716 .BR CAP_DAC_OVERRIDE ,
717 .BR CAP_DAC_READ_SEARCH ,
720 .B CAP_LINUX_IMMUTABLE
721 (since Linux 2.2.30),
722 .BR CAP_MAC_OVERRIDE ,
725 (since Linux 2.2.30).
726 If the file system UID is changed from nonzero to 0,
727 then any of these capabilities that are enabled in the permitted set
728 are enabled in the effective set.
730 If a thread that has a 0 value for one or more of its user IDs wants
731 to prevent its permitted capability set being cleared when it resets
732 all of its user IDs to nonzero values, it can do so using the
737 .SS Programmatically adjusting capability sets
738 A thread can retrieve and change its capability sets using the
746 .BR cap_set_proc (3),
750 is preferred for this purpose.
751 The following rules govern changes to the thread capability sets:
753 If the caller does not have the
756 the new inheritable set must be a subset of the combination
757 of the existing inheritable and permitted sets.
759 (Since kernel 2.6.25)
760 The new inheritable set must be a subset of the combination of the
761 existing inheritable set and the capability bounding set.
763 The new permitted set must be a subset of the existing permitted set
764 (i.e., it is not possible to acquire permitted capabilities
765 that the thread does not currently have).
767 The new effective set must be a subset of the new permitted set.
768 .SS The """securebits"" flags: establishing a capabilities-only environment
769 .\" For some background:
770 .\" see http://lwn.net/Articles/280279/ and
771 .\" http://article.gmane.org/gmane.linux.kernel.lsm/5476/
772 Starting with kernel 2.6.26,
773 and with a kernel in which file capabilities are enabled,
774 Linux implements a set of per-thread
776 flags that can be used to disable special handling of capabilities for UID 0
778 These flags are as follows:
781 Setting this flag allows a thread that has one or more 0 UIDs to retain
782 its capabilities when it switches all of its UIDs to a nonzero value.
783 If this flag is not set,
784 then such a UID switch causes the thread to lose all capabilities.
785 This flag is always cleared on an
787 (This flag provides the same functionality as the older
792 .B SECBIT_NO_SETUID_FIXUP
793 Setting this flag stops the kernel from adjusting capability sets when
794 the threads's effective and file system UIDs are switched between
795 zero and nonzero values.
797 .IR "Effect of User ID Changes on Capabilities" .)
800 If this bit is set, then the kernel does not grant capabilities
801 when a set-user-ID-root program is executed, or when a process with
802 an effective or real UID of 0 calls
805 .IR "Capabilities and execution of programs by root" .)
807 Each of the above "base" flags has a companion "locked" flag.
808 Setting any of the "locked" flags is irreversible,
809 and has the effect of preventing further changes to the
810 corresponding "base" flag.
811 The locked flags are:
812 .BR SECBIT_KEEP_CAPS_LOCKED ,
813 .BR SECBIT_NO_SETUID_FIXUP_LOCKED ,
815 .BR SECBIT_NOROOT_LOCKED .
819 flags can be modified and retrieved using the
827 capability is required to modify the flags.
831 flags are inherited by child processes.
834 all of the flags are preserved, except
836 which is always cleared.
838 An application can use the following call to lock itself,
839 and all of its descendants,
840 into an environment where the only way of gaining capabilities
841 is by executing a program with associated file capabilities:
845 prctl(PR_SET_SECUREBITS,
846 SECBIT_KEEP_CAPS_LOCKED |
847 SECBIT_NO_SETUID_FIXUP |
848 SECBIT_NO_SETUID_FIXUP_LOCKED |
850 SECBIT_NOROOT_LOCKED);
855 No standards govern capabilities, but the Linux capability implementation
856 is based on the withdrawn POSIX.1e draft standard; see
857 .IR http://wt.xpilot.org/publications/posix.1e/ .
859 Since kernel 2.5.27, capabilities are an optional kernel component,
860 and can be enabled/disabled via the CONFIG_SECURITY_CAPABILITIES
861 kernel configuration option.
864 .I /proc/PID/task/TID/status
865 file can be used to view the capability sets of a thread.
868 file shows the capability sets of a process's main thread.
872 package provides a suite of routines for setting and
873 getting capabilities that is more comfortable and less likely
874 to change than the interface provided by
878 This package also provides the
885 .IR http://www.kernel.org/pub/linux/libs/security/linux-privs .
887 Before kernel 2.6.24, and since kernel 2.6.24 if
888 file capabilities are not enabled, a thread with the
890 capability can manipulate the capabilities of threads other than itself.
891 However, this is only theoretically possible,
892 since no thread ever has
894 in either of these cases:
896 In the pre-2.6.25 implementation the system-wide capability bounding set,
897 .IR /proc/sys/kernel/cap-bound ,
898 always masks out this capability, and this can not be changed
899 without modifying the kernel source and rebuilding.
901 If file capabilities are disabled in the current implementation, then
903 starts out with this capability removed from its per-process bounding
904 set, and that bounding set is inherited by all other processes
905 created on the system.
911 .BR cap_copy_ext (3),
912 .BR cap_from_text (3),
913 .BR cap_get_file (3),
914 .BR cap_get_proc (3),
923 .I include/linux/capability.h