]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man7/capabilities.7
getent.1, intro.1, time.1, _exit.2, _syscall.2, accept.2, access.2, acct.2, adjtimex...
[thirdparty/man-pages.git] / man7 / capabilities.7
CommitLineData
c11b1abf 1.\" Copyright (c) 2002 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da
MK
2.\"
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.
6.\"
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.
11.\"
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
10d76543
MK
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
18.\" professionally.
fea681da
MK
19.\"
20.\" Formatted or processed versions of this manual, if unaccompanied by
21.\" the source, must acknowledge the copyright and authors of this work.
fea681da
MK
22.\"
23.\" 6 Aug 2002 - Initial Creation
c11b1abf
MK
24.\" Modified 2003-05-23, Michael Kerrisk, <mtk.manpages@gmail.com>
25.\" Modified 2004-05-27, Michael Kerrisk, <mtk.manpages@gmail.com>
1c1e15ed 26.\" 2004-12-08, mtk Added O_NOATIME for CAP_FOWNER
5eaee3d9 27.\" 2005-08-16, mtk, Added CAP_AUDIT_CONTROL and CAP_AUDIT_WRITE
c8e68512
MK
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.
33.\" 2008-07-15, mtk
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.
bfb730f9 44.\" 2011-09-07, mtk/Serge hallyn: Add CAP_SYSLOG
5eaee3d9 45.\"
38b6e5b0 46.TH CAPABILITIES 7 2012-12-22 "Linux" "Linux Programmer's Manual"
fea681da
MK
47.SH NAME
48capabilities \- overview of Linux capabilities
49.SH DESCRIPTION
fea681da 50For the purpose of performing permission checks,
008f1ecc 51traditional UNIX implementations distinguish two categories of processes:
fea681da
MK
52.I privileged
53processes (whose effective user ID is 0, referred to as superuser or root),
54and
55.I unprivileged
c7094399 56processes (whose effective UID is nonzero).
fea681da
MK
57Privileged processes bypass all kernel permission checks,
58while unprivileged processes are subject to full permission
59checking based on the process's credentials
60(usually: effective UID, effective GID, and supplementary group list).
61
c13182ef
MK
62Starting with kernel 2.2, Linux divides the privileges traditionally
63associated with superuser into distinct units, known as
fea681da 64.IR capabilities ,
3dfe7e0d 65which can be independently enabled and disabled.
cf7a13d4 66Capabilities are a per-thread attribute.
c8e68512 67.\"
c634028a 68.SS Capabilities list
c8e68512
MK
69The following list shows the capabilities implemented on Linux,
70and the operations or behaviors that each capability permits:
fea681da 71.TP
45286787 72.BR CAP_AUDIT_CONTROL " (since Linux 2.6.11)"
5eaee3d9
MK
73Enable and disable kernel auditing; change auditing filter rules;
74retrieve auditing status and filtering rules.
75.TP
45286787 76.BR CAP_AUDIT_WRITE " (since Linux 2.6.11)"
c8e68512 77Write records to kernel auditing log.
5eaee3d9 78.TP
9339d749
MK
79.BR CAP_BLOCK_SUSPEND " (since Linux 3.5)"
80Employ features that can block system suspend
81.RB ( epoll (7)
82.BR EPOLLWAKEUP ,
83.IR /proc/sys/wake_lock ).
84.TP
fea681da 85.B CAP_CHOWN
c8e68512 86Make arbitrary changes to file UIDs and GIDs (see
fea681da
MK
87.BR chown (2)).
88.TP
89.B CAP_DAC_OVERRIDE
90Bypass file read, write, and execute permission checks.
c8e68512 91(DAC is an abbreviation of "discretionary access control".)
fea681da
MK
92.TP
93.B CAP_DAC_READ_SEARCH
94Bypass file read permission checks and
95directory read and execute permission checks.
96.TP
97.B CAP_FOWNER
c8e68512
MK
98.PD 0
99.RS
100.IP * 2
fea681da
MK
101Bypass permission checks on operations that normally
102require the file system UID of the process to match the UID of
103the file (e.g.,
104.BR chmod (2),
105.BR utime (2)),
c8e68512 106excluding those operations covered by
fea681da
MK
107.B CAP_DAC_OVERRIDE
108and
109.BR CAP_DAC_READ_SEARCH ;
c8e68512 110.IP *
fea681da
MK
111set extended file attributes (see
112.BR chattr (1))
113on arbitrary files;
c8e68512 114.IP *
fea681da 115set Access Control Lists (ACLs) on arbitrary files;
c8e68512 116.IP *
1c1e15ed 117ignore directory sticky bit on file deletion;
c8e68512 118.IP *
1c1e15ed
MK
119specify
120.B O_NOATIME
121for arbitrary files in
122.BR open (2)
123and
124.BR fcntl (2).
c8e68512
MK
125.RE
126.PD
fea681da
MK
127.TP
128.B CAP_FSETID
c8e68512
MK
129Don't clear set-user-ID and set-group-ID permission
130bits when a file is modified;
131set the set-group-ID bit for a file whose GID does not match
fea681da
MK
132the file system or any of the supplementary GIDs of the calling process.
133.TP
134.B CAP_IPC_LOCK
46c73a44
MK
135.\" FIXME As at Linux 3.2, there are some strange uses of this capability
136.\" in other places; they probably should be replaced with something else.
c8e68512 137Lock memory
fea681da
MK
138.RB ( mlock (2),
139.BR mlockall (2),
140.BR mmap (2),
141.BR shmctl (2)).
142.TP
143.B CAP_IPC_OWNER
144Bypass permission checks for operations on System V IPC objects.
145.TP
146.B CAP_KILL
147Bypass permission checks for sending signals (see
148.BR kill (2)).
097585ed 149This includes use of the
c8e68512 150.BR ioctl (2)
097585ed 151.B KDSIGACCEPT
c8e68512 152operation.
afc322c2 153.\" FIXME CAP_KILL also has an effect for threads + setting child
a7c1e564
MK
154.\" termination signal to other than SIGCHLD: without this
155.\" capability, the termination signal reverts to SIGCHLD
c13182ef 156.\" if the child does an exec(). What is the rationale
a7c1e564 157.\" for this?
fea681da 158.TP
c8e68512
MK
159.BR CAP_LEASE " (since Linux 2.4)"
160Establish leases on arbitrary files (see
fea681da
MK
161.BR fcntl (2)).
162.TP
163.B CAP_LINUX_IMMUTABLE
c8e68512
MK
164Set the
165.B FS_APPEND_FL
fea681da 166and
c8e68512
MK
167.B FS_IMMUTABLE_FL
168.\" These attributes are now available on ext2, ext3, Reiserfs, XFS, JFS
169i-node flags (see
fea681da
MK
170.BR chattr (1)).
171.TP
c8e68512
MK
172.BR CAP_MAC_ADMIN " (since Linux 2.6.25)"
173Override Mandatory Access Control (MAC).
174Implemented for the Smack Linux Security Module (LSM).
175.TP
176.BR CAP_MAC_OVERRIDE " (since Linux 2.6.25)"
177Allow MAC configuration or state changes.
178Implemented for the Smack LSM.
179.TP
180.BR CAP_MKNOD " (since Linux 2.4)"
181Create special files using
fea681da
MK
182.BR mknod (2).
183.TP
184.B CAP_NET_ADMIN
e87268ec
MK
185Perform various network-related operations:
186.PD 0
187.RS
188.IP * 2
189interface configuration;
190.IP *
191administration of IP firewall, masquerading, and accounting
192.IP *
193modify routing tables;
194.IP *
195bind to any address for transparent proxying;
196.IP *
197set type-of-service (TOS)
198.IP *
199clear driver statistics;
200.IP *
201set promiscuous mode;
202.IP *
203enabling multicasting;
204.IP *
205use
206.BR setsockopt (2)
207to set the following socket options:
208.BR SO_DEBUG ,
209.BR SO_MARK ,
210.BR SO_PRIORITY
211(for a priority outside the range 0 to 6),
212.BR SO_RCVBUFFORCE ,
213and
214.BR SO_SNDBUFFORCE .
215.RE
216.PD
fea681da
MK
217.TP
218.B CAP_NET_BIND_SERVICE
6eb334b2 219Bind a socket to Internet domain privileged ports
fea681da
MK
220(port numbers less than 1024).
221.TP
222.B CAP_NET_BROADCAST
c8e68512 223(Unused) Make socket broadcasts, and listen to multicasts.
fea681da
MK
224.TP
225.B CAP_NET_RAW
93e9e2d6
MK
226.PD 0
227.RS
228.IP * 2
229use RAW and PACKET sockets;
230.IP *
231bind to any address for transparent proxying.
232.RE
233.PD
fea681da
MK
234.\" Also various IP options and setsockopt(SO_BINDTODEVICE)
235.TP
236.B CAP_SETGID
c8e68512 237Make arbitrary manipulations of process GIDs and supplementary GID list;
008f1ecc 238forge GID when passing socket credentials via UNIX domain sockets.
fea681da 239.TP
c8e68512
MK
240.BR CAP_SETFCAP " (since Linux 2.6.24)"
241Set file capabilities.
242.TP
243.B CAP_SETPCAP
244If file capabilities are not supported:
245grant or remove any capability in the
246caller's permitted capability set to or from any other process.
247(This property of
248.B CAP_SETPCAP
249is not available when the kernel is configured to support
250file capabilities, since
fea681da 251.B CAP_SETPCAP
c8e68512
MK
252has entirely different semantics for such kernels.)
253
254If file capabilities are supported:
255add any capability from the calling thread's bounding set
256to its inheritable set;
257drop capabilities from the bounding set (via
258.BR prctl (2)
259.BR PR_CAPBSET_DROP );
260make changes to the
261.I securebits
262flags.
fea681da
MK
263.TP
264.B CAP_SETUID
c8e68512 265Make arbitrary manipulations of process UIDs
fea681da
MK
266.RB ( setuid (2),
267.BR setreuid (2),
268.BR setresuid (2),
269.BR setfsuid (2));
008f1ecc 270make forged UID when passing socket credentials via UNIX domain sockets.
777f5a9e 271.\" FIXME CAP_SETUID also an effect in exec(); document this.
fea681da
MK
272.TP
273.B CAP_SYS_ADMIN
c8e68512
MK
274.PD 0
275.RS
276.IP * 2
277Perform a range of system administration operations including:
fea681da
MK
278.BR quotactl (2),
279.BR mount (2),
280.BR umount (2),
1368e847
MK
281.BR swapon (2),
282.BR swapoff (2),
fea681da 283.BR sethostname (2),
f169a862 284and
c8e68512
MK
285.BR setdomainname (2);
286.IP *
bfb730f9
MK
287perform privileged
288.BR syslog (2)
289operations (since Linux 2.6.37,
290.BR CAP_SYSLOG
291should be used to permit such operations);
292.IP *
c8e68512 293perform
c11e3891
MK
294.B VM86_REQUEST_IRQ
295.BR vm86 (2)
296command;
297.IP *
298perform
fea681da
MK
299.B IPC_SET
300and
301.B IPC_RMID
302operations on arbitrary System V IPC objects;
c8e68512 303.IP *
fea681da
MK
304perform operations on
305.I trusted
306and
307.I security
308Extended Attributes (see
309.BR attr (5));
c8e68512
MK
310.IP *
311use
08baa0af 312.BR lookup_dcookie (2);
c8e68512 313.IP *
a1f926b8
MK
314use
315.BR ioprio_set (2)
316to assign
317.B IOPRIO_CLASS_RT
83ee9237 318and (before Linux 2.6.25)
237aa7c5 319.B IOPRIO_CLASS_IDLE
a1f926b8 320I/O scheduling classes;
c8e68512 321.IP *
c8e68512
MK
322forge UID when passing socket credentials;
323.IP *
fea681da 324exceed
3dfe7e0d
MK
325.IR /proc/sys/fs/file-max ,
326the system-wide limit on the number of open files,
327in system calls that open files (e.g.,
fea681da
MK
328.BR accept (2),
329.BR execve (2),
330.BR open (2),
f169a862 331.BR pipe (2));
c8e68512 332.IP *
c13182ef 333employ
0f807eea
MK
334.B CLONE_*
335flags that create new namespaces with
a7c1e564
MK
336.BR clone (2)
337and
338.BR unshare (2);
c8e68512 339.IP *
e4698850 340call
0f322ccc
MK
341.BR perf_event_open (2);
342.IP *
0f322ccc
MK
343access privileged
344.I perf
345event information;
2bfe6656
MK
346.IP *
347call
e4698850
MK
348.BR setns (2);
349.IP *
0f807eea
MK
350call
351.BR fanotify_init (2);
352.IP *
c13182ef 353perform
a7c1e564
MK
354.B KEYCTL_CHOWN
355and
356.B KEYCTL_SETPERM
357.BR keyctl (2)
e64e6056
MK
358operations;
359.IP *
360perform
361.BR madvise (2)
362.B MADV_HWPOISON
0f807eea
MK
363operation;
364.IP *
365employ the
366.B TIOCSTI
367.BR ioctl (2)
368to insert characters into the input queue of a terminal other than
369the caller's controlling terminal.
370.IP *
0f807eea 371employ the obsolete
51c5c662 372.BR nfsservctl (2)
c42221c4
MK
373system call;
374.IP *
375employ the obsolete
0f807eea
MK
376.BR bdflush (2)
377system call;
378.IP *
379perform various privileged block-device
380.BR ioctl (2)
381operations;
382.IP *
383perform various privileged file-system
384.BR ioctl (2)
385operations;
386.IP *
387perform administrative operations on many device drivers.
c8e68512
MK
388.RE
389.PD
fea681da
MK
390.TP
391.B CAP_SYS_BOOT
c8e68512 392Use
08baa0af
MK
393.BR reboot (2)
394and
395.BR kexec_load (2).
fea681da
MK
396.TP
397.B CAP_SYS_CHROOT
c8e68512 398Use
fea681da
MK
399.BR chroot (2).
400.TP
401.B CAP_SYS_MODULE
c8e68512
MK
402Load and unload kernel modules
403(see
fea681da
MK
404.BR init_module (2)
405and
c8e68512
MK
406.BR delete_module (2));
407in kernels before 2.6.25:
408drop capabilities from the system-wide capability bounding set.
fea681da
MK
409.TP
410.B CAP_SYS_NICE
c8e68512
MK
411.PD 0
412.RS
413.IP * 2
414Raise process nice value
fea681da
MK
415.RB ( nice (2),
416.BR setpriority (2))
c8e68512
MK
417and change the nice value for arbitrary processes;
418.IP *
419set real-time scheduling policies for calling process,
420and set scheduling policies and priorities for arbitrary processes
fea681da
MK
421.RB ( sched_setscheduler (2),
422.BR sched_setparam (2));
c8e68512 423.IP *
fea681da 424set CPU affinity for arbitrary processes
c13182ef 425.RB ( sched_setaffinity (2));
c8e68512 426.IP *
a1f926b8 427set I/O scheduling class and priority for arbitrary processes
c13182ef 428.RB ( ioprio_set (2));
c8e68512
MK
429.IP *
430apply
a1f926b8 431.BR migrate_pages (2)
c8e68512 432to arbitrary processes and allow processes
a1f926b8 433to be migrated to arbitrary nodes;
c13182ef 434.\" FIXME CAP_SYS_NICE also has the following effect for
a1f926b8
MK
435.\" migrate_pages(2):
436.\" do_migrate_pages(mm, &old, &new,
437.\" capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
c8e68512
MK
438.IP *
439apply
a7c1e564 440.BR move_pages (2)
c8e68512
MK
441to arbitrary processes;
442.IP *
4d62f7b6
MK
443use the
444.B MPOL_MF_MOVE_ALL
c13182ef 445flag with
a7c1e564 446.BR mbind (2)
c13182ef 447and
a7c1e564 448.BR move_pages (2).
c8e68512
MK
449.RE
450.PD
fea681da
MK
451.TP
452.B CAP_SYS_PACCT
c8e68512 453Use
fea681da
MK
454.BR acct (2).
455.TP
456.B CAP_SYS_PTRACE
c8e68512 457Trace arbitrary processes using
cbd7b9bf
MK
458.BR ptrace (2);
459apply
460.BR get_robust_list (2)
38b6e5b0
MK
461to arbitrary processes;
462inspect processes using
463.BR kcmp (2).
fea681da
MK
464.TP
465.B CAP_SYS_RAWIO
c8e68512 466Perform I/O port operations
fea681da
MK
467.RB ( iopl (2)
468and
469.BR ioperm (2));
470access
474e1f9d
MK
471.IR /proc/kcore ;
472employ the
473.B FIBMAP
474.BR ioctl (2)
475operation.
fea681da
MK
476.TP
477.B CAP_SYS_RESOURCE
c8e68512
MK
478.PD 0
479.RS
480.IP * 2
481Use reserved space on ext2 file systems;
482.IP *
483make
fea681da
MK
484.BR ioctl (2)
485calls controlling ext3 journaling;
c8e68512
MK
486.IP *
487override disk quota limits;
488.IP *
489increase resource limits (see
fea681da 490.BR setrlimit (2));
c8e68512
MK
491.IP *
492override
fea681da 493.B RLIMIT_NPROC
c8e68512
MK
494resource limit;
495.IP *
aa66392d
MK
496override maximum number of consoles on console allocation;
497.IP *
498override maximum number of keymaps;
499.IP *
500allow more than 64hz interrupts from the real-time clock;
501.IP *
c8e68512 502raise
fea681da 503.I msg_qbytes
c8e68512 504limit for a System V message queue above the limit in
0daa9e92 505.I /proc/sys/kernel/msgmnb
fea681da
MK
506(see
507.BR msgop (2)
508and
ad7b0f91
MK
509.BR msgctl (2));
510.IP *
511override the
512.I /proc/sys/fs/pipe-size-max
513limit when setting the capacity of a pipe using the
514.B F_SETPIPE_SZ
515.BR fcntl (2)
516command.
46883521
MK
517.IP *
518use
519.BR F_SETPIPE_SZ
520to increase the capacity of a pipe above the limit specified by
b39a2012
MK
521.IR /proc/sys/fs/pipe-max-size ;
522.IP *
523override
524.I /proc/sys/fs/mqueue/queues_max
525limit when creating POSIX message queues (see
ecc1f45b
MK
526.BR mq_overview (7));
527.IP *
528employ
529.BR prctl (2)
530.B PR_SET_MM
531operation.
c8e68512
MK
532.RE
533.PD
fea681da
MK
534.TP
535.B CAP_SYS_TIME
c8e68512 536Set system clock
fea681da
MK
537.RB ( settimeofday (2),
538.BR stime (2),
539.BR adjtimex (2));
c8e68512 540set real-time (hardware) clock.
fea681da
MK
541.TP
542.B CAP_SYS_TTY_CONFIG
c8e68512 543Use
749ac769
MK
544.BR vhangup (2);
545employ various privileged
546.BR ioctl (2)
547operations on virtual terminals.
bfb730f9
MK
548.TP
549.BR CAP_SYSLOG " (since Linux 2.6.37)"
10fe5485 550.IP * 3
bfb730f9
MK
551Perform privileged
552.BR syslog (2)
553operations.
554See
555.BR syslog (2)
556for information on which operations require privilege.
10fe5485
MK
557.IP *
558View kernel addresses exposed via
559.I /proc
560and other interfaces when
561.IR /proc/sys/kernel/kptr_restrict
562has the value 1.
4eaa04c5 563(See the discussion of the
10fe5485
MK
564.I kptr_restrict
565in
566.BR proc (5).)
d6b08708
MK
567.TP
568.BR CAP_WAKE_ALARM " (since Linux 3.0)"
569Trigger something that will wake up the system (set
570.B CLOCK_REALTIME_ALARM
571and
572.B CLOCK_BOOTTIME_ALARM
573timers).
c8e68512 574.\"
c634028a 575.SS Past and current implementation
c8e68512
MK
576A full implementation of capabilities requires that:
577.IP 1. 3
578For all privileged operations,
579the kernel must check whether the thread has the required
580capability in its effective set.
581.IP 2.
137d81b5 582The kernel must provide system calls allowing a thread's capability sets to
c8e68512
MK
583be changed and retrieved.
584.IP 3.
585The file system must support attaching capabilities to an executable file,
586so that a process gains those capabilities when the file is executed.
587.PP
588Before kernel 2.6.24, only the first two of these requirements are met;
589since kernel 2.6.24, all three requirements are met.
590.\"
c634028a 591.SS Thread capability sets
cf7a13d4 592Each thread has three capability sets containing zero or more
fea681da
MK
593of the above capabilities:
594.TP
fea681da 595.IR Permitted :
c8e68512
MK
596This is a limiting superset for the effective
597capabilities that the thread may assume.
598It is also a limiting superset for the capabilities that
599may be added to the inheritable set by a thread that does not have the
600.B CAP_SETPCAP
601capability in its effective set.
602
cf7a13d4 603If a thread drops a capability from its permitted set,
3b777aff 604it can never reacquire that capability (unless it
c930827f 605.BR execve (2)s
c8e68512
MK
606either a set-user-ID-root program, or
607a program whose associated file capabilities grant that capability).
fea681da 608.TP
c8e68512
MK
609.IR Inheritable :
610This is a set of capabilities preserved across an
fea681da 611.BR execve (2).
c8e68512
MK
612It provides a mechanism for a process to assign capabilities
613to the permitted set of the new program during an
614.BR execve (2).
615.TP
616.IR Effective :
617This is the set of capabilities used by the kernel to
618perform permission checks for the thread.
fea681da 619.PP
fea681da
MK
620A child created via
621.BR fork (2)
622inherits copies of its parent's capability sets.
3dfe7e0d 623See below for a discussion of the treatment of capabilities during
c930827f 624.BR execve (2).
fea681da
MK
625.PP
626Using
627.BR capset (2),
c8e68512
MK
628a thread may manipulate its own capability sets (see below).
629.\"
c634028a 630.SS File capabilities
c8e68512
MK
631Since kernel 2.6.24, the kernel supports
632associating capability sets with an executable file using
633.BR setcap (8).
634The file capability sets are stored in an extended attribute (see
635.BR setxattr (2))
636named
637.IR "security.capability" .
638Writing to this extended attribute requires the
639.BR CAP_SETFCAP
fea681da 640capability.
c8e68512 641The file capability sets,
cf7a13d4 642in conjunction with the capability sets of the thread,
c8e68512 643determine the capabilities of a thread after an
c930827f 644.BR execve (2).
c8e68512
MK
645
646The three file capability sets are:
fea681da 647.TP
3dfe7e0d 648.IR Permitted " (formerly known as " forced ):
c8e68512 649These capabilities are automatically permitted to the thread,
cf7a13d4 650regardless of the thread's inheritable capabilities.
fea681da 651.TP
c8e68512
MK
652.IR Inheritable " (formerly known as " allowed ):
653This set is ANDed with the thread's inheritable set to determine which
654inheritable capabilities are enabled in the permitted set of
655the thread after the
656.BR execve (2).
657.TP
fea681da 658.IR Effective :
c8e68512
MK
659This is not a set, but rather just a single bit.
660If this bit is set, then during an
661.BR execve (2)
662all of the new permitted capabilities for the thread are
663also raised in the effective set.
664If this bit is not set, then after an
665.BR execve (2),
666none of the new permitted capabilities is in the new effective set.
667
668Enabling the file effective capability bit implies
2914a14d 669that any file permitted or inheritable capability that causes a
c8e68512
MK
670thread to acquire the corresponding permitted capability during an
671.BR execve (2)
e33a08e1 672(see the transformation rules described below) will also acquire that
c8e68512
MK
673capability in its effective set.
674Therefore, when assigning capabilities to a file
675.RB ( setcap (8),
676.BR cap_set_file (3),
677.BR cap_set_fd (3)),
678if we specify the effective flag as being enabled for any capability,
679then the effective flag must also be specified as enabled
680for all other capabilities for which the corresponding permitted or
681inheritable flags is enabled.
682.\"
c634028a 683.SS Transformation of capabilities during execve()
fea681da 684.PP
c13182ef 685During an
c930827f 686.BR execve (2),
1e321034 687the kernel calculates the new capabilities of
fea681da 688the process using the following algorithm:
088a639b 689.in +4n
fea681da
MK
690.nf
691
c13182ef 692P'(permitted) = (P(inheritable) & F(inheritable)) |
3dfe7e0d 693 (F(permitted) & cap_bset)
fea681da 694
c8e68512 695P'(effective) = F(effective) ? P'(permitted) : 0
fea681da 696
5bdccabd 697P'(inheritable) = P(inheritable) [i.e., unchanged]
fea681da
MK
698
699.fi
088a639b 700.in
fea681da 701where:
c8e68512 702.RS 4
fea681da 703.IP P 10
c13182ef 704denotes the value of a thread capability set before the
c930827f 705.BR execve (2)
c8e68512 706.IP P'
c13182ef 707denotes the value of a capability set after the
c930827f 708.BR execve (2)
c8e68512 709.IP F
fea681da 710denotes a file capability set
c8e68512
MK
711.IP cap_bset
712is the value of the capability bounding set (described below).
713.RE
714.\"
715.SS Capabilities and execution of programs by root
716In order to provide an all-powerful
717.I root
718using capability sets, during an
719.BR execve (2):
720.IP 1. 3
721If a set-user-ID-root program is being executed,
722or the real user ID of the process is 0 (root)
723then the file inheritable and permitted sets are defined to be all ones
724(i.e., all capabilities enabled).
725.IP 2.
726If a set-user-ID-root program is being executed,
727then the file effective bit is defined to be one (enabled).
3dfe7e0d 728.PP
c8e68512
MK
729The upshot of the above rules,
730combined with the capabilities transformations described above,
731is that when a process
c930827f 732.BR execve (2)s
3dfe7e0d 733a set-user-ID-root program, or when a process with an effective UID of 0
c930827f 734.BR execve (2)s
3dfe7e0d 735a program,
c13182ef 736it gains all capabilities in its permitted and effective capability sets,
c8e68512 737except those masked out by the capability bounding set.
c7094399 738.\" If a process with real UID 0, and nonzero effective UID does an
c8e68512 739.\" exec(), then it gets all capabilities in its
35fb7de5 740.\" permitted set, and no effective capabilities
3dfe7e0d 741This provides semantics that are the same as those provided by
008f1ecc 742traditional UNIX systems.
c8e68512
MK
743.SS Capability bounding set
744The capability bounding set is a security mechanism that can be used
745to limit the capabilities that can be gained during an
746.BR execve (2).
747The bounding set is used in the following ways:
748.IP * 2
749During an
750.BR execve (2),
751the capability bounding set is ANDed with the file permitted
752capability set, and the result of this operation is assigned to the
753thread's permitted capability set.
754The capability bounding set thus places a limit on the permitted
755capabilities that may be granted by an executable file.
756.IP *
757(Since Linux 2.6.25)
758The capability bounding set acts as a limiting superset for
759the capabilities that a thread can add to its inheritable set using
760.BR capset (2).