]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/capabilities.7
mdoc.7: wfix
[thirdparty/man-pages.git] / man7 / capabilities.7
1 .\" Copyright (c) 2002 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
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.
35 .\" 2008-07-15, mtk
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
47 .\"
48 .TH CAPABILITIES 7 2016-07-17 "Linux" "Linux Programmer's Manual"
49 .SH NAME
50 capabilities \- overview of Linux capabilities
51 .SH DESCRIPTION
52 For the purpose of performing permission checks,
53 traditional UNIX implementations distinguish two categories of processes:
54 .I privileged
55 processes (whose effective user ID is 0, referred to as superuser or root),
56 and
57 .I unprivileged
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).
63
64 Starting with kernel 2.2, Linux divides the privileges traditionally
65 associated with superuser into distinct units, known as
66 .IR capabilities ,
67 which can be independently enabled and disabled.
68 Capabilities are a per-thread attribute.
69 .\"
70 .SS Capabilities list
71 The following list shows the capabilities implemented on Linux,
72 and the operations or behaviors that each capability permits:
73 .TP
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.
77 .TP
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.
82 .TP
83 .BR CAP_AUDIT_WRITE " (since Linux 2.6.11)"
84 Write records to kernel auditing log.
85 .TP
86 .BR CAP_BLOCK_SUSPEND " (since Linux 3.5)"
87 Employ features that can block system suspend
88 .RB ( epoll (7)
89 .BR EPOLLWAKEUP ,
90 .IR /proc/sys/wake_lock ).
91 .TP
92 .B CAP_CHOWN
93 Make arbitrary changes to file UIDs and GIDs (see
94 .BR chown (2)).
95 .TP
96 .B CAP_DAC_OVERRIDE
97 Bypass file read, write, and execute permission checks.
98 (DAC is an abbreviation of "discretionary access control".)
99 .TP
100 .B CAP_DAC_READ_SEARCH
101 .PD 0
102 .RS
103 .IP * 2
104 Bypass file read permission checks and
105 directory read and execute permission checks;
106 .IP *
107 invoke
108 .BR open_by_handle_at (2).
109 .RE
110 .PD
111 .TP
112 .B CAP_FOWNER
113 .PD 0
114 .RS
115 .IP * 2
116 Bypass permission checks on operations that normally
117 require the filesystem UID of the process to match the UID of
118 the file (e.g.,
119 .BR chmod (2),
120 .BR utime (2)),
121 excluding those operations covered by
122 .B CAP_DAC_OVERRIDE
123 and
124 .BR CAP_DAC_READ_SEARCH ;
125 .IP *
126 set extended file attributes (see
127 .BR chattr (1))
128 on arbitrary files;
129 .IP *
130 set Access Control Lists (ACLs) on arbitrary files;
131 .IP *
132 ignore directory sticky bit on file deletion;
133 .IP *
134 specify
135 .B O_NOATIME
136 for arbitrary files in
137 .BR open (2)
138 and
139 .BR fcntl (2).
140 .RE
141 .PD
142 .TP
143 .B CAP_FSETID
144 .PD 0
145 .RS
146 .IP * 2
147 Don't clear set-user-ID and set-group-ID mode
148 bits when a file is modified;
149 .IP *
150 set the set-group-ID bit for a file whose GID does not match
151 the filesystem or any of the supplementary GIDs of the calling process.
152 .RE
153 .PD
154 .TP
155 .B CAP_IPC_LOCK
156 .\" FIXME . As at Linux 3.2, there are some strange uses of this capability
157 .\" in other places; they probably should be replaced with something else.
158 Lock memory
159 .RB ( mlock (2),
160 .BR mlockall (2),
161 .BR mmap (2),
162 .BR shmctl (2)).
163 .TP
164 .B CAP_IPC_OWNER
165 Bypass permission checks for operations on System V IPC objects.
166 .TP
167 .B CAP_KILL
168 Bypass permission checks for sending signals (see
169 .BR kill (2)).
170 This includes use of the
171 .BR ioctl (2)
172 .B KDSIGACCEPT
173 operation.
174 .\" FIXME . CAP_KILL also has an effect for threads + setting child
175 .\" termination signal to other than SIGCHLD: without this
176 .\" capability, the termination signal reverts to SIGCHLD
177 .\" if the child does an exec(). What is the rationale
178 .\" for this?
179 .TP
180 .BR CAP_LEASE " (since Linux 2.4)"
181 Establish leases on arbitrary files (see
182 .BR fcntl (2)).
183 .TP
184 .B CAP_LINUX_IMMUTABLE
185 Set the
186 .B FS_APPEND_FL
187 and
188 .B FS_IMMUTABLE_FL
189 .\" These attributes are now available on ext2, ext3, Reiserfs, XFS, JFS
190 inode flags (see
191 .BR chattr (1)).
192 .TP
193 .BR CAP_MAC_ADMIN " (since Linux 2.6.25)"
194 Override Mandatory Access Control (MAC).
195 Implemented for the Smack Linux Security Module (LSM).
196 .TP
197 .BR CAP_MAC_OVERRIDE " (since Linux 2.6.25)"
198 Allow MAC configuration or state changes.
199 Implemented for the Smack LSM.
200 .TP
201 .BR CAP_MKNOD " (since Linux 2.4)"
202 Create special files using
203 .BR mknod (2).
204 .TP
205 .B CAP_NET_ADMIN
206 Perform various network-related operations:
207 .PD 0
208 .RS
209 .IP * 2
210 interface configuration;
211 .IP *
212 administration of IP firewall, masquerading, and accounting;
213 .IP *
214 modify routing tables;
215 .IP *
216 bind to any address for transparent proxying;
217 .IP *
218 set type-of-service (TOS)
219 .IP *
220 clear driver statistics;
221 .IP *
222 set promiscuous mode;
223 .IP *
224 enabling multicasting;
225 .IP *
226 use
227 .BR setsockopt (2)
228 to set the following socket options:
229 .BR SO_DEBUG ,
230 .BR SO_MARK ,
231 .BR SO_PRIORITY
232 (for a priority outside the range 0 to 6),
233 .BR SO_RCVBUFFORCE ,
234 and
235 .BR SO_SNDBUFFORCE .
236 .RE
237 .PD
238 .TP
239 .B CAP_NET_BIND_SERVICE
240 Bind a socket to Internet domain privileged ports
241 (port numbers less than 1024).
242 .TP
243 .B CAP_NET_BROADCAST
244 (Unused) Make socket broadcasts, and listen to multicasts.
245 .TP
246 .B CAP_NET_RAW
247 .PD 0
248 .RS
249 .IP * 2
250 use RAW and PACKET sockets;
251 .IP *
252 bind to any address for transparent proxying.
253 .RE
254 .PD
255 .\" Also various IP options and setsockopt(SO_BINDTODEVICE)
256 .TP
257 .B CAP_SETGID
258 .RS
259 .PD 0
260 .IP * 2
261 Make arbitrary manipulations of process GIDs and supplementary GID list;
262 .IP *
263 forge GID when passing socket credentials via UNIX domain sockets;
264 .IP *
265 write a group ID mapping in a user namespace (see
266 .BR user_namespaces (7)).
267 .PD
268 .RE
269 .TP
270 .BR CAP_SETFCAP " (since Linux 2.6.24)"
271 Set file capabilities.
272 .TP
273 .B CAP_SETPCAP
274 If file capabilities are not supported:
275 grant or remove any capability in the
276 caller's permitted capability set to or from any other process.
277 (This property of
278 .B CAP_SETPCAP
279 is not available when the kernel is configured to support
280 file capabilities, since
281 .B CAP_SETPCAP
282 has entirely different semantics for such kernels.)
283
284 If file capabilities are supported:
285 add any capability from the calling thread's bounding set
286 to its inheritable set;
287 drop capabilities from the bounding set (via
288 .BR prctl (2)
289 .BR PR_CAPBSET_DROP );
290 make changes to the
291 .I securebits
292 flags.
293 .TP
294 .B CAP_SETUID
295 .RS
296 .PD 0
297 .IP * 2
298 Make arbitrary manipulations of process UIDs
299 .RB ( setuid (2),
300 .BR setreuid (2),
301 .BR setresuid (2),
302 .BR setfsuid (2));
303 .IP *
304 forge UID when passing socket credentials via UNIX domain sockets;
305 .IP *
306 write a user ID mapping in a user namespace (see
307 .BR user_namespaces (7)).
308 .PD
309 .RE
310 .\" FIXME CAP_SETUID also an effect in exec(); document this.
311 .TP
312 .B CAP_SYS_ADMIN
313 .PD 0
314 .RS
315 .IP * 2
316 Perform a range of system administration operations including:
317 .BR quotactl (2),
318 .BR mount (2),
319 .BR umount (2),
320 .BR swapon (2),
321 .BR swapoff (2),
322 .BR sethostname (2),
323 and
324 .BR setdomainname (2);
325 .IP *
326 perform privileged
327 .BR syslog (2)
328 operations (since Linux 2.6.37,
329 .BR CAP_SYSLOG
330 should be used to permit such operations);
331 .IP *
332 perform
333 .B VM86_REQUEST_IRQ
334 .BR vm86 (2)
335 command;
336 .IP *
337 perform
338 .B IPC_SET
339 and
340 .B IPC_RMID
341 operations on arbitrary System V IPC objects;
342 .IP *
343 override
344 .B RLIMIT_NPROC
345 resource limit;
346 .IP *
347 perform operations on
348 .I trusted
349 and
350 .I security
351 Extended Attributes (see
352 .BR xattr (7));
353 .IP *
354 use
355 .BR lookup_dcookie (2);
356 .IP *
357 use
358 .BR ioprio_set (2)
359 to assign
360 .B IOPRIO_CLASS_RT
361 and (before Linux 2.6.25)
362 .B IOPRIO_CLASS_IDLE
363 I/O scheduling classes;
364 .IP *
365 forge PID when passing socket credentials via UNIX domain sockets;
366 .IP *
367 exceed
368 .IR /proc/sys/fs/file-max ,
369 the system-wide limit on the number of open files,
370 in system calls that open files (e.g.,
371 .BR accept (2),
372 .BR execve (2),
373 .BR open (2),
374 .BR pipe (2));
375 .IP *
376 employ
377 .B CLONE_*
378 flags that create new namespaces with
379 .BR clone (2)
380 and
381 .BR unshare (2)
382 (but, since Linux 3.8,
383 creating user namespaces does not require any capability);
384 .IP *
385 call
386 .BR perf_event_open (2);
387 .IP *
388 access privileged
389 .I perf
390 event information;
391 .IP *
392 call
393 .BR setns (2)
394 (requires
395 .B CAP_SYS_ADMIN
396 in the
397 .I target
398 namespace);
399 .IP *
400 call
401 .BR fanotify_init (2);
402 .IP *
403 call
404 .BR bpf (2);
405 .IP *
406 perform privileged
407 .B KEYCTL_CHOWN
408 and
409 .B KEYCTL_SETPERM
410 .BR keyctl (2)
411 operations;
412 .IP *
413 use
414 .BR ptrace (2)
415 .B PTRACE_SECCOMP_GET_FILTER
416 to dump a tracees seccomp filters;
417 .IP *
418 perform
419 .BR madvise (2)
420 .B MADV_HWPOISON
421 operation;
422 .IP *
423 employ the
424 .B TIOCSTI
425 .BR ioctl (2)
426 to insert characters into the input queue of a terminal other than
427 the caller's controlling terminal;
428 .IP *
429 employ the obsolete
430 .BR nfsservctl (2)
431 system call;
432 .IP *
433 employ the obsolete
434 .BR bdflush (2)
435 system call;
436 .IP *
437 perform various privileged block-device
438 .BR ioctl (2)
439 operations;
440 .IP *
441 perform various privileged filesystem
442 .BR ioctl (2)
443 operations;
444 .IP *
445 perform privileged
446 .BR ioctl (2)
447 operations on the
448 .IR /dev/random
449 device (see
450 .BR random (4));
451 .IP *
452 perform administrative operations on many device drivers.
453 .RE
454 .PD
455 .TP
456 .B CAP_SYS_BOOT
457 Use
458 .BR reboot (2)
459 and
460 .BR kexec_load (2).
461 .TP
462 .B CAP_SYS_CHROOT
463 Use
464 .BR chroot (2).
465 .TP
466 .B CAP_SYS_MODULE
467 .RS
468 .PD 0
469 .IP * 2
470 Load and unload kernel modules
471 (see
472 .BR init_module (2)
473 and
474 .BR delete_module (2));
475 .IP *
476 in kernels before 2.6.25:
477 drop capabilities from the system-wide capability bounding set.
478 .PD
479 .RE
480 .TP
481 .B CAP_SYS_NICE
482 .PD 0
483 .RS
484 .IP * 2
485 Raise process nice value
486 .RB ( nice (2),
487 .BR setpriority (2))
488 and change the nice value for arbitrary processes;
489 .IP *
490 set real-time scheduling policies for calling process,
491 and set scheduling policies and priorities for arbitrary processes
492 .RB ( sched_setscheduler (2),
493 .BR sched_setparam (2),
494 .BR shed_setattr (2));
495 .IP *
496 set CPU affinity for arbitrary processes
497 .RB ( sched_setaffinity (2));
498 .IP *
499 set I/O scheduling class and priority for arbitrary processes
500 .RB ( ioprio_set (2));
501 .IP *
502 apply
503 .BR migrate_pages (2)
504 to arbitrary processes and allow processes
505 to be migrated to arbitrary nodes;
506 .\" FIXME CAP_SYS_NICE also has the following effect for
507 .\" migrate_pages(2):
508 .\" do_migrate_pages(mm, &old, &new,
509 .\" capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
510 .\"
511 .\" Document this.
512 .IP *
513 apply
514 .BR move_pages (2)
515 to arbitrary processes;
516 .IP *
517 use the
518 .B MPOL_MF_MOVE_ALL
519 flag with
520 .BR mbind (2)
521 and
522 .BR move_pages (2).
523 .RE
524 .PD
525 .TP
526 .B CAP_SYS_PACCT
527 Use
528 .BR acct (2).
529 .TP
530 .B CAP_SYS_PTRACE
531 .PD 0
532 .RS
533 .IP * 2
534 Trace arbitrary processes using
535 .BR ptrace (2);
536 .IP *
537 apply
538 .BR get_robust_list (2)
539 to arbitrary processes;
540 .IP *
541 transfer data to or from the memory of arbitrary processes using
542 .BR process_vm_readv (2)
543 and
544 .BR process_vm_writev (2);
545 .IP *
546 inspect processes using
547 .BR kcmp (2).
548 .RE
549 .PD
550 .TP
551 .B CAP_SYS_RAWIO
552 .PD 0
553 .RS
554 .IP * 2
555 Perform I/O port operations
556 .RB ( iopl (2)
557 and
558 .BR ioperm (2));
559 .IP *
560 access
561 .IR /proc/kcore ;
562 .IP *
563 employ the
564 .B FIBMAP
565 .BR ioctl (2)
566 operation;
567 .IP *
568 open devices for accessing x86 model-specific registers (MSRs, see
569 .BR msr (4));
570 .IP *
571 update
572 .IR /proc/sys/vm/mmap_min_addr ;
573 .IP *
574 create memory mappings at addresses below the value specified by
575 .IR /proc/sys/vm/mmap_min_addr ;
576 .IP *
577 map files in
578 .IR /proc/bus/pci ;
579 .IP *
580 open
581 .IR /dev/mem
582 and
583 .IR /dev/kmem ;
584 .IP *
585 perform various SCSI device commands;
586 .IP *
587 perform certain operations on
588 .BR hpsa (4)
589 and
590 .BR cciss (4)
591 devices;
592 .IP *
593 perform a range of device-specific operations on other devices.
594 .RE
595 .PD
596 .TP
597 .B CAP_SYS_RESOURCE
598 .PD 0
599 .RS
600 .IP * 2
601 Use reserved space on ext2 filesystems;
602 .IP *
603 make
604 .BR ioctl (2)
605 calls controlling ext3 journaling;
606 .IP *
607 override disk quota limits;
608 .IP *
609 increase resource limits (see
610 .BR setrlimit (2));
611 .IP *
612 override
613 .B RLIMIT_NPROC
614 resource limit;
615 .IP *
616 override maximum number of consoles on console allocation;
617 .IP *
618 override maximum number of keymaps;
619 .IP *
620 allow more than 64hz interrupts from the real-time clock;
621 .IP *
622 raise
623 .I msg_qbytes
624 limit for a System V message queue above the limit in
625 .I /proc/sys/kernel/msgmnb
626 (see
627 .BR msgop (2)
628 and
629 .BR msgctl (2));
630 .IP *
631 override the
632 .I /proc/sys/fs/pipe-size-max
633 limit when setting the capacity of a pipe using the
634 .B F_SETPIPE_SZ
635 .BR fcntl (2)
636 command.
637 .IP *
638 use
639 .BR F_SETPIPE_SZ
640 to increase the capacity of a pipe above the limit specified by
641 .IR /proc/sys/fs/pipe-max-size ;
642 .IP *
643 override
644 .I /proc/sys/fs/mqueue/queues_max
645 limit when creating POSIX message queues (see
646 .BR mq_overview (7));
647 .IP *
648 employ the
649 .BR prctl (2)
650 .B PR_SET_MM
651 operation;
652 .IP *
653 set
654 .IR /proc/[pid]/oom_score_adj
655 to a value lower than the value last set by a process with
656 .BR CAP_SYS_RESOURCE .
657 .RE
658 .PD
659 .TP
660 .B CAP_SYS_TIME
661 Set system clock
662 .RB ( settimeofday (2),
663 .BR stime (2),
664 .BR adjtimex (2));
665 set real-time (hardware) clock.
666 .TP
667 .B CAP_SYS_TTY_CONFIG
668 Use
669 .BR vhangup (2);
670 employ various privileged
671 .BR ioctl (2)
672 operations on virtual terminals.
673 .TP
674 .BR CAP_SYSLOG " (since Linux 2.6.37)"
675 .RS
676 .PD 0
677 .IP * 2
678 Perform privileged
679 .BR syslog (2)
680 operations.
681 See
682 .BR syslog (2)
683 for information on which operations require privilege.
684 .IP *
685 View kernel addresses exposed via
686 .I /proc
687 and other interfaces when
688 .IR /proc/sys/kernel/kptr_restrict
689 has the value 1.
690 (See the discussion of the
691 .I kptr_restrict
692 in
693 .BR proc (5).)
694 .PD
695 .RE
696 .TP
697 .BR CAP_WAKE_ALARM " (since Linux 3.0)"
698 Trigger something that will wake up the system (set
699 .B CLOCK_REALTIME_ALARM
700 and
701 .B CLOCK_BOOTTIME_ALARM
702 timers).
703 .\"
704 .SS Past and current implementation
705 A full implementation of capabilities requires that:
706 .IP 1. 3
707 For all privileged operations,
708 the kernel must check whether the thread has the required
709 capability in its effective set.
710 .IP 2.
711 The kernel must provide system calls allowing a thread's capability sets to
712 be changed and retrieved.
713 .IP 3.
714 The filesystem must support attaching capabilities to an executable file,
715 so that a process gains those capabilities when the file is executed.
716 .PP
717 Before kernel 2.6.24, only the first two of these requirements are met;
718 since kernel 2.6.24, all three requirements are met.
719 .\"
720 .SS Thread capability sets
721 Each thread has three capability sets containing zero or more
722 of the above capabilities:
723 .TP
724 .IR Permitted :
725 This is a limiting superset for the effective
726 capabilities that the thread may assume.
727 It is also a limiting superset for the capabilities that
728 may be added to the inheritable set by a thread that does not have the
729 .B CAP_SETPCAP
730 capability in its effective set.
731
732 If a thread drops a capability from its permitted set,
733 it can never reacquire that capability (unless it
734 .BR execve (2)s
735 either a set-user-ID-root program, or
736 a program whose associated file capabilities grant that capability).
737 .TP
738 .IR Inheritable :
739 This is a set of capabilities preserved across an
740 .BR execve (2).
741 Inheritable capabilities remain inheritable when executing any program,
742 and inheritable capabilities are added to the permitted set when executing
743 a program that has the corresponding bits set in the file inheritable set.
744 .IP
745 Because inheritable capabilities are not generally preserved across
746 .BR execve (2)
747 when running as a non-root user, applications that wish to run helper
748 programs with elevated capabilities should consider using
749 ambient capabilities, described below.
750 .TP
751 .IR Effective :
752 This is the set of capabilities used by the kernel to
753 perform permission checks for the thread.
754 .TP
755 .IR Ambient " (since Linux 4.3):"
756 .\" commit 58319057b7847667f0c9585b9de0e8932b0fdb08
757 This is a set of capabilities that are preserved across an
758 .BR execve (2)
759 of a program that is not privileged.
760 The ambient capability set obeys the invariant that no capability
761 can ever be ambient if it is not both permitted and inheritable.
762
763 The ambient capability set can be directly modified using
764 .BR prctl (2).
765 Ambient capabilities are automatically lowered if either of
766 the corresponding permitted or inheritable capabilities is lowered.
767
768 Executing a program that changes UID or GID due to the
769 set-user-ID or set-group-ID bits or executing a program that has
770 any file capabilities set will clear the ambient set.
771 Ambient capabilities are added to the permitted set and
772 assigned to the effective set when
773 .BR execve (2)
774 is called.
775 .PP
776 A child created via
777 .BR fork (2)
778 inherits copies of its parent's capability sets.
779 See below for a discussion of the treatment of capabilities during
780 .BR execve (2).
781 .PP
782 Using
783 .BR capset (2),
784 a thread may manipulate its own capability sets (see below).
785 .PP
786 Since Linux 3.2, the file
787 .I /proc/sys/kernel/cap_last_cap
788 .\" commit 73efc0394e148d0e15583e13712637831f926720
789 exposes the numerical value of the highest capability
790 supported by the running kernel;
791 this can be used to determine the highest bit
792 that may be set in a capability set.
793 .\"
794 .SS File capabilities
795 Since kernel 2.6.24, the kernel supports
796 associating capability sets with an executable file using
797 .BR setcap (8).
798 The file capability sets are stored in an extended attribute (see
799 .BR setxattr (2))
800 named
801 .IR "security.capability" .
802 Writing to this extended attribute requires the
803 .BR CAP_SETFCAP
804 capability.
805 The file capability sets,
806 in conjunction with the capability sets of the thread,
807 determine the capabilities of a thread after an
808 .BR execve (2).
809
810 The three file capability sets are:
811 .TP
812 .IR Permitted " (formerly known as " forced ):
813 These capabilities are automatically permitted to the thread,
814 regardless of the thread's inheritable capabilities.
815 .TP
816 .IR Inheritable " (formerly known as " allowed ):
817 This set is ANDed with the thread's inheritable set to determine which
818 inheritable capabilities are enabled in the permitted set of
819 the thread after the
820 .BR execve (2).
821 .TP
822 .IR Effective :
823 This is not a set, but rather just a single bit.
824 If this bit is set, then during an
825 .BR execve (2)
826 all of the new permitted capabilities for the thread are
827 also raised in the effective set.
828 If this bit is not set, then after an
829 .BR execve (2),
830 none of the new permitted capabilities is in the new effective set.
831
832 Enabling the file effective capability bit implies
833 that any file permitted or inheritable capability that causes a
834 thread to acquire the corresponding permitted capability during an
835 .BR execve (2)
836 (see the transformation rules described below) will also acquire that
837 capability in its effective set.
838 Therefore, when assigning capabilities to a file
839 .RB ( setcap (8),
840 .BR cap_set_file (3),
841 .BR cap_set_fd (3)),
842 if we specify the effective flag as being enabled for any capability,
843 then the effective flag must also be specified as enabled
844 for all other capabilities for which the corresponding permitted or
845 inheritable flags is enabled.
846 .RE
847
848 File capability sets are ignored if the executable file
849 resides on a filesystem mounted with the
850 .B nosuid
851 option (see
852 .BR mount (2)
853 and
854 .BR mount (8)).
855 .\"
856 .SS Transformation of capabilities during execve()
857 .PP
858 During an
859 .BR execve (2),
860 the kernel calculates the new capabilities of
861 the process using the following algorithm:
862 .in +4n
863 .nf
864
865 P'(ambient) = (file is privileged) ? 0 : P(ambient)
866
867 P'(permitted) = (P(inheritable) & F(inheritable)) |
868 (F(permitted) & cap_bset) | P'(ambient)
869
870 P'(effective) = F(effective) ? P'(permitted) : P'(ambient)
871
872 P'(inheritable) = P(inheritable) [i.e., unchanged]
873
874 .fi
875 .in
876 where:
877 .RS 4
878 .IP P 10
879 denotes the value of a thread capability set before the
880 .BR execve (2)
881 .IP P'
882 denotes the value of a thread capability set after the
883 .BR execve (2)
884 .IP F
885 denotes a file capability set
886 .IP cap_bset
887 is the value of the capability bounding set (described below).
888 .RE
889 .PP
890 A privileged file is one that has capabilities or
891 has the set-user-ID or set-group-ID bit set.
892 .\"
893 .SS Safety checking for capability-dumb binaries
894 A capability-dumb binary is an application that has been
895 marked to have file capabilities, but has not been converted to use the
896 .BR libcap (3)
897 API to manipulate its capabilities.
898 (In other words, this is a traditional set-user-ID-root program
899 that has been switched to use file capabilities,
900 but whose code has not been modified to understand capabilities.)
901 For such applications,
902 the effective capability bit is set on the file,
903 so that the file permitted capabilities are automatically
904 enabled in the process effective set when executing the file.
905 The kernel recognizes a file which has the effective capability bit set
906 as capability-dumb for the purpose of the check described here.
907
908 When executing a capability-dumb binary,
909 the kernel checks if the process obtained all permitted capabilities
910 that were specified in the file permitted set,
911 after the capability transformations described above have been performed.
912 (The typical reason why this might
913 .I not
914 occur is that the capability bounding set masked out some
915 of the capabilities in the file permitted set.)
916 If the process did not obtain the full set of
917 file permitted capabilities, then
918 .BR execve (2)
919 fails with the error
920 .BR EPERM .
921 This prevents possible security risks that could arise when
922 a capability-dumb application is executed with less privilege that it needs.
923 Note that, by definition,
924 the application could not itself recognize this problem,
925 since it does not employ the
926 .BR libcap (3)
927 API.
928 .\"
929 .SS Capabilities and execution of programs by root
930 In order to provide an all-powerful
931 .I root
932 using capability sets, during an
933 .BR execve (2):
934 .IP 1. 3
935 If a set-user-ID-root program is being executed,
936 or the real user ID of the process is 0 (root)
937 then the file inheritable and permitted sets are defined to be all ones
938 (i.e., all capabilities enabled).
939 .IP 2.
940 If a set-user-ID-root program is being executed,
941 then the file effective bit is defined to be one (enabled).
942 .PP
943 The upshot of the above rules,
944 combined with the capabilities transformations described above,
945 is that when a process
946 .BR execve (2)s
947 a set-user-ID-root program, or when a process with an effective UID of 0
948 .BR execve (2)s
949 a program,
950 it gains all capabilities in its permitted and effective capability sets,
951 except those masked out by the capability bounding set.
952 .\" If a process with real UID 0, and nonzero effective UID does an
953 .\" exec(), then it gets all capabilities in its
954 .\" permitted set, and no effective capabilities
955 This provides semantics that are the same as those provided by
956 traditional UNIX systems.
957 .SS Capability bounding set
958 The capability bounding set is a security mechanism that can be used
959 to limit the capabilities that can be gained during an
960 .BR execve (2).
961 The bounding set is used in the following ways:
962 .IP * 2
963 During an
964 .BR execve (2),
965 the capability bounding set is ANDed with the file permitted
966 capability set, and the result of this operation is assigned to the
967 thread's permitted capability set.
968 The capability bounding set thus places a limit on the permitted
969 capabilities that may be granted by an executable file.
970 .IP *
971 (Since Linux 2.6.25)
972 The capability bounding set acts as a limiting superset for
973 the capabilities that a thread can add to its inheritable set using
974 .BR capset (2).
975 This means that if a capability is not in the bounding set,
976 then a thread can't add this capability to its
977 inheritable set, even if it was in its permitted capabilities,
978 and thereby cannot have this capability preserved in its
979 permitted set when it
980 .BR execve (2)s
981 a file that has the capability in its inheritable set.
982 .PP
983 Note that the bounding set masks the file permitted capabilities,
984 but not the inherited capabilities.
985 If a thread maintains a capability in its inherited set
986 that is not in its bounding set,
987 then it can still gain that capability in its permitted set
988 by executing a file that has the capability in its inherited set.
989 .PP
990 Depending on the kernel version, the capability bounding set is either
991 a system-wide attribute, or a per-process attribute.
992 .PP
993 .B "Capability bounding set prior to Linux 2.6.25"
994 .PP
995 In kernels before 2.6.25, the capability bounding set is a system-wide
996 attribute that affects all threads on the system.
997 The bounding set is accessible via the file
998 .IR /proc/sys/kernel/cap-bound .
999 (Confusingly, this bit mask parameter is expressed as a
1000 signed decimal number in
1001 .IR /proc/sys/kernel/cap-bound .)
1002
1003 Only the
1004 .B init
1005 process may set capabilities in the capability bounding set;
1006 other than that, the superuser (more precisely: programs with the
1007 .B CAP_SYS_MODULE
1008 capability) may only clear capabilities from this set.
1009
1010 On a standard system the capability bounding set always masks out the
1011 .B CAP_SETPCAP
1012 capability.
1013 To remove this restriction (dangerous!), modify the definition of
1014 .B CAP_INIT_EFF_SET
1015 in
1016 .I include/linux/capability.h
1017 and rebuild the kernel.
1018
1019 The system-wide capability bounding set feature was added
1020 to Linux starting with kernel version 2.2.11.
1021 .\"
1022 .PP
1023 .B "Capability bounding set from Linux 2.6.25 onward"
1024 .PP
1025 From Linux 2.6.25, the
1026 .I "capability bounding set"
1027 is a per-thread attribute.
1028 (There is no longer a system-wide capability bounding set.)
1029
1030 The bounding set is inherited at
1031 .BR fork (2)
1032 from the thread's parent, and is preserved across an
1033 .BR execve (2).
1034
1035 A thread may remove capabilities from its capability bounding set using the
1036 .BR prctl (2)
1037 .B PR_CAPBSET_DROP
1038 operation, provided it has the
1039 .B CAP_SETPCAP
1040 capability.
1041 Once a capability has been dropped from the bounding set,
1042 it cannot be restored to that set.
1043 A thread can determine if a capability is in its bounding set using the
1044 .BR prctl (2)
1045 .B PR_CAPBSET_READ
1046 operation.
1047
1048 Removing capabilities from the bounding set is supported only if file
1049 capabilities are compiled into the kernel.
1050 In kernels before Linux 2.6.33,
1051 file capabilities were an optional feature configurable via the
1052 .B CONFIG_SECURITY_FILE_CAPABILITIES
1053 option.
1054 Since Linux 2.6.33,
1055 .\" commit b3a222e52e4d4be77cc4520a57af1a4a0d8222d1
1056 the configuration option has been removed
1057 and file capabilities are always part of the kernel.
1058 When file capabilities are compiled into the kernel, the
1059 .B init
1060 process (the ancestor of all processes) begins with a full bounding set.
1061 If file capabilities are not compiled into the kernel, then
1062 .B init
1063 begins with a full bounding set minus
1064 .BR CAP_SETPCAP ,
1065 because this capability has a different meaning when there are
1066 no file capabilities.
1067
1068 Removing a capability from the bounding set does not remove it
1069 from the thread's inherited set.
1070 However it does prevent the capability from being added
1071 back into the thread's inherited set in the future.
1072 .\"
1073 .\"
1074 .SS Effect of user ID changes on capabilities
1075 To preserve the traditional semantics for transitions between
1076 0 and nonzero user IDs,
1077 the kernel makes the following changes to a thread's capability
1078 sets on changes to the thread's real, effective, saved set,
1079 and filesystem user IDs (using
1080 .BR setuid (2),
1081 .BR setresuid (2),
1082 or similar):
1083 .IP 1. 3
1084 If one or more of the real, effective or saved set user IDs
1085 was previously 0, and as a result of the UID changes all of these IDs
1086 have a nonzero value,
1087 then all capabilities are cleared from the permitted and effective
1088 capability sets.
1089 .IP 2.
1090 If the effective user ID is changed from 0 to nonzero,
1091 then all capabilities are cleared from the effective set.
1092 .IP 3.
1093 If the effective user ID is changed from nonzero to 0,
1094 then the permitted set is copied to the effective set.
1095 .IP 4.
1096 If the filesystem user ID is changed from 0 to nonzero (see
1097 .BR setfsuid (2)),
1098 then the following capabilities are cleared from the effective set:
1099 .BR CAP_CHOWN ,
1100 .BR CAP_DAC_OVERRIDE ,
1101 .BR CAP_DAC_READ_SEARCH ,
1102 .BR CAP_FOWNER ,
1103 .BR CAP_FSETID ,
1104 .B CAP_LINUX_IMMUTABLE
1105 (since Linux 2.6.30),
1106 .BR CAP_MAC_OVERRIDE ,
1107 and
1108 .B CAP_MKNOD
1109 (since Linux 2.6.30).
1110 If the filesystem UID is changed from nonzero to 0,
1111 then any of these capabilities that are enabled in the permitted set
1112 are enabled in the effective set.
1113 .PP
1114 If a thread that has a 0 value for one or more of its user IDs wants
1115 to prevent its permitted capability set being cleared when it resets
1116 all of its user IDs to nonzero values, it can do so using the
1117 .BR prctl (2)
1118 .B PR_SET_KEEPCAPS
1119 operation or the
1120 .B SECBIT_KEEP_CAPS
1121 securebits flag described below.
1122 .\"
1123 .SS Programmatically adjusting capability sets
1124 A thread can retrieve and change its capability sets using the
1125 .BR capget (2)
1126 and
1127 .BR capset (2)
1128 system calls.
1129 However, the use of
1130 .BR cap_get_proc (3)
1131 and
1132 .BR cap_set_proc (3),
1133 both provided in the
1134 .I libcap
1135 package,
1136 is preferred for this purpose.
1137 The following rules govern changes to the thread capability sets:
1138 .IP 1. 3
1139 If the caller does not have the
1140 .B CAP_SETPCAP
1141 capability,
1142 the new inheritable set must be a subset of the combination
1143 of the existing inheritable and permitted sets.
1144 .IP 2.
1145 (Since Linux 2.6.25)
1146 The new inheritable set must be a subset of the combination of the
1147 existing inheritable set and the capability bounding set.
1148 .IP 3.
1149 The new permitted set must be a subset of the existing permitted set
1150 (i.e., it is not possible to acquire permitted capabilities
1151 that the thread does not currently have).
1152 .IP 4.
1153 The new effective set must be a subset of the new permitted set.
1154 .SS The securebits flags: establishing a capabilities-only environment
1155 .\" For some background:
1156 .\" see http://lwn.net/Articles/280279/ and
1157 .\" http://article.gmane.org/gmane.linux.kernel.lsm/5476/
1158 Starting with kernel 2.6.26,
1159 and with a kernel in which file capabilities are enabled,
1160 Linux implements a set of per-thread
1161 .I securebits
1162 flags that can be used to disable special handling of capabilities for UID 0
1163 .RI ( root ).
1164 These flags are as follows:
1165 .TP
1166 .B SECBIT_KEEP_CAPS
1167 Setting this flag allows a thread that has one or more 0 UIDs to retain
1168 its capabilities when it switches all of its UIDs to a nonzero value.
1169 If this flag is not set,
1170 then such a UID switch causes the thread to lose all capabilities.
1171 This flag is always cleared on an
1172 .BR execve (2).
1173 (This flag provides the same functionality as the older
1174 .BR prctl (2)
1175 .B PR_SET_KEEPCAPS
1176 operation.)
1177 .TP
1178 .B SECBIT_NO_SETUID_FIXUP
1179 Setting this flag stops the kernel from adjusting capability sets when
1180 the thread's effective and filesystem UIDs are switched between
1181 zero and nonzero values.
1182 (See the subsection
1183 .IR "Effect of user ID changes on capabilities" .)
1184 .TP
1185 .B SECBIT_NOROOT
1186 If this bit is set, then the kernel does not grant capabilities
1187 when a set-user-ID-root program is executed, or when a process with
1188 an effective or real UID of 0 calls
1189 .BR execve (2).
1190 (See the subsection
1191 .IR "Capabilities and execution of programs by root" .)
1192 .TP
1193 .B SECBIT_NO_CAP_AMBIENT_RAISE
1194 Setting this flag disallows raising ambient capabilities via the
1195 .BR prctl (2)
1196 .BR PR_CAP_AMBIENT_RAISE
1197 operation.
1198 .PP
1199 Each of the above "base" flags has a companion "locked" flag.
1200 Setting any of the "locked" flags is irreversible,
1201 and has the effect of preventing further changes to the
1202 corresponding "base" flag.
1203 The locked flags are:
1204 .BR SECBIT_KEEP_CAPS_LOCKED ,
1205 .BR SECBIT_NO_SETUID_FIXUP_LOCKED ,
1206 .BR SECBIT_NOROOT_LOCKED ,
1207 and
1208 .BR SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED .
1209 .PP
1210 The
1211 .I securebits
1212 flags can be modified and retrieved using the
1213 .BR prctl (2)
1214 .B PR_SET_SECUREBITS
1215 and
1216 .B PR_GET_SECUREBITS
1217 operations.
1218 The
1219 .B CAP_SETPCAP
1220 capability is required to modify the flags.
1221
1222 The
1223 .I securebits
1224 flags are inherited by child processes.
1225 During an
1226 .BR execve (2),
1227 all of the flags are preserved, except
1228 .B SECBIT_KEEP_CAPS
1229 which is always cleared.
1230
1231 An application can use the following call to lock itself,
1232 and all of its descendants,
1233 into an environment where the only way of gaining capabilities
1234 is by executing a program with associated file capabilities:
1235 .in +4n
1236 .nf
1237
1238 prctl(PR_SET_SECUREBITS,
1239 /* SECBIT_KEEP_CAPS off */
1240 SECBIT_KEEP_CAPS_LOCKED |
1241 SECBIT_NO_SETUID_FIXUP |
1242 SECBIT_NO_SETUID_FIXUP_LOCKED |
1243 SECBIT_NOROOT |
1244 SECBIT_NOROOT_LOCKED);
1245 /* Setting/locking SECURE_NO_CAP_AMBIENT_RAISE
1246 is not required */
1247 .fi
1248 .in
1249 .SS Interaction with user namespaces
1250 For a discussion of the interaction of capabilities and user namespaces, see
1251 .BR user_namespaces (7).
1252 .SH CONFORMING TO
1253 .PP
1254 No standards govern capabilities, but the Linux capability implementation
1255 is based on the withdrawn POSIX.1e draft standard; see
1256 .UR http://wt.tuxomania.net\:/publications\:/posix.1e/
1257 .UE .
1258 .SH NOTES
1259 From kernel 2.5.27 to kernel 2.6.26,
1260 .\" commit 5915eb53861c5776cfec33ca4fcc1fd20d66dd27 removed
1261 .\" CONFIG_SECURITY_CAPABILITIES
1262 capabilities were an optional kernel component,
1263 and could be enabled/disabled via the
1264 .B CONFIG_SECURITY_CAPABILITIES
1265 kernel configuration option.
1266
1267 The
1268 .I /proc/[pid]/task/TID/status
1269 file can be used to view the capability sets of a thread.
1270 The
1271 .I /proc/[pid]/status
1272 file shows the capability sets of a process's main thread.
1273 Before Linux 3.8, nonexistent capabilities were shown as being
1274 enabled (1) in these sets.
1275 Since Linux 3.8,
1276 .\" 7b9a7ec565505699f503b4fcf61500dceb36e744
1277 all nonexistent capabilities (above
1278 .BR CAP_LAST_CAP )
1279 are shown as disabled (0).
1280
1281 The
1282 .I libcap
1283 package provides a suite of routines for setting and
1284 getting capabilities that is more comfortable and less likely
1285 to change than the interface provided by
1286 .BR capset (2)
1287 and
1288 .BR capget (2).
1289 This package also provides the
1290 .BR setcap (8)
1291 and
1292 .BR getcap (8)
1293 programs.
1294 It can be found at
1295 .br
1296 .UR http://www.kernel.org\:/pub\:/linux\:/libs\:/security\:/linux-privs
1297 .UE .
1298
1299 Before kernel 2.6.24, and from kernel 2.6.24 to kernel 2.6.32 if
1300 file capabilities are not enabled, a thread with the
1301 .B CAP_SETPCAP
1302 capability can manipulate the capabilities of threads other than itself.
1303 However, this is only theoretically possible,
1304 since no thread ever has
1305 .BR CAP_SETPCAP
1306 in either of these cases:
1307 .IP * 2
1308 In the pre-2.6.25 implementation the system-wide capability bounding set,
1309 .IR /proc/sys/kernel/cap-bound ,
1310 always masks out this capability, and this can not be changed
1311 without modifying the kernel source and rebuilding.
1312 .IP *
1313 If file capabilities are disabled in the current implementation, then
1314 .B init
1315 starts out with this capability removed from its per-process bounding
1316 set, and that bounding set is inherited by all other processes
1317 created on the system.
1318 .SH SEE ALSO
1319 .BR capsh (1),
1320 .BR setpriv (1),
1321 .BR prctl (2),
1322 .BR setfsuid (2),
1323 .BR cap_clear (3),
1324 .BR cap_copy_ext (3),
1325 .BR cap_from_text (3),
1326 .BR cap_get_file (3),
1327 .BR cap_get_proc (3),
1328 .BR cap_init (3),
1329 .BR capgetp (3),
1330 .BR capsetp (3),
1331 .BR libcap (3),
1332 .BR proc (5),
1333 .BR credentials (7),
1334 .BR pthreads (7),
1335 .BR user_namespaces (7),
1336 .BR getcap (8),
1337 .BR setcap (8)
1338 .PP
1339 .I include/linux/capability.h
1340 in the Linux kernel source tree