]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/capabilities.7
74226647da26a1c8cbd22c1d78c732abf8a29b81
[thirdparty/man-pages.git] / man7 / capabilities.7
1 .\" Copyright (c) 2002 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .\" 6 Aug 2002 - Initial Creation
6 .\" Modified 2003-05-23, Michael Kerrisk, <mtk.manpages@gmail.com>
7 .\" Modified 2004-05-27, Michael Kerrisk, <mtk.manpages@gmail.com>
8 .\" 2004-12-08, mtk Added O_NOATIME for CAP_FOWNER
9 .\" 2005-08-16, mtk, Added CAP_AUDIT_CONTROL and CAP_AUDIT_WRITE
10 .\" 2008-07-15, Serge Hallyn <serue@us.bbm.com>
11 .\" Document file capabilities, per-process capability
12 .\" bounding set, changed semantics for CAP_SETPCAP,
13 .\" and other changes in 2.6.2[45].
14 .\" Add CAP_MAC_ADMIN, CAP_MAC_OVERRIDE, CAP_SETFCAP.
15 .\" 2008-07-15, mtk
16 .\" Add text describing circumstances in which CAP_SETPCAP
17 .\" (theoretically) permits a thread to change the
18 .\" capability sets of another thread.
19 .\" Add section describing rules for programmatically
20 .\" adjusting thread capability sets.
21 .\" Describe rationale for capability bounding set.
22 .\" Document "securebits" flags.
23 .\" Add text noting that if we set the effective flag for one file
24 .\" capability, then we must also set the effective flag for all
25 .\" other capabilities where the permitted or inheritable bit is set.
26 .\" 2011-09-07, mtk/Serge hallyn: Add CAP_SYSLOG
27 .\"
28 .TH CAPABILITIES 7 2021-08-27 "Linux" "Linux Programmer's Manual"
29 .SH NAME
30 capabilities \- overview of Linux capabilities
31 .SH DESCRIPTION
32 For the purpose of performing permission checks,
33 traditional UNIX implementations distinguish two categories of processes:
34 .I privileged
35 processes (whose effective user ID is 0, referred to as superuser or root),
36 and
37 .I unprivileged
38 processes (whose effective UID is nonzero).
39 Privileged processes bypass all kernel permission checks,
40 while unprivileged processes are subject to full permission
41 checking based on the process's credentials
42 (usually: effective UID, effective GID, and supplementary group list).
43 .PP
44 Starting with kernel 2.2, Linux divides the privileges traditionally
45 associated with superuser into distinct units, known as
46 .IR capabilities ,
47 which can be independently enabled and disabled.
48 Capabilities are a per-thread attribute.
49 .\"
50 .SS Capabilities list
51 The following list shows the capabilities implemented on Linux,
52 and the operations or behaviors that each capability permits:
53 .TP
54 .BR CAP_AUDIT_CONTROL " (since Linux 2.6.11)"
55 Enable and disable kernel auditing; change auditing filter rules;
56 retrieve auditing status and filtering rules.
57 .TP
58 .BR CAP_AUDIT_READ " (since Linux 3.16)"
59 .\" commit a29b694aa1739f9d76538e34ae25524f9c549d59
60 .\" commit 3a101b8de0d39403b2c7e5c23fd0b005668acf48
61 Allow reading the audit log via a multicast netlink socket.
62 .TP
63 .BR CAP_AUDIT_WRITE " (since Linux 2.6.11)"
64 Write records to kernel auditing log.
65 .\" FIXME Add FAN_ENABLE_AUDIT
66 .TP
67 .BR CAP_BLOCK_SUSPEND " (since Linux 3.5)"
68 Employ features that can block system suspend
69 .RB ( epoll (7)
70 .BR EPOLLWAKEUP ,
71 .IR /proc/sys/wake_lock ).
72 .TP
73 .BR CAP_BPF " (since Linux 5.8)"
74 Employ privileged BPF operations; see
75 .BR bpf (2)
76 and
77 .BR bpf\-helpers (7).
78 .IP
79 This capability was added in Linux 5.8 to separate out
80 BPF functionality from the overloaded
81 .BR CAP_SYS_ADMIN
82 capability.
83 .TP
84 .BR CAP_CHECKPOINT_RESTORE " (since Linux 5.9)"
85 .\" commit 124ea650d3072b005457faed69909221c2905a1f
86 .PD 0
87 .RS
88 .IP * 2
89 Update
90 .I /proc/sys/kernel/ns_last_pid
91 (see
92 .BR pid_namespaces (7));
93 .IP *
94 employ the
95 .I set_tid
96 feature of
97 .BR clone3 (2);
98 .\" FIXME There is also some use case relating to
99 .\" prctl_set_mm_exe_file(); in the 5.9 sources, see
100 .\" prctl_set_mm_map().
101 .IP *
102 read the contents of the symbolic links in
103 .IR /proc/[pid]/map_files
104 for other processes.
105 .RE
106 .PD
107 .IP
108 This capability was added in Linux 5.9 to separate out
109 checkpoint/restore functionality from the overloaded
110 .BR CAP_SYS_ADMIN
111 capability.
112 .TP
113 .B CAP_CHOWN
114 Make arbitrary changes to file UIDs and GIDs (see
115 .BR chown (2)).
116 .TP
117 .B CAP_DAC_OVERRIDE
118 Bypass file read, write, and execute permission checks.
119 (DAC is an abbreviation of "discretionary access control".)
120 .TP
121 .B CAP_DAC_READ_SEARCH
122 .PD 0
123 .RS
124 .IP * 2
125 Bypass file read permission checks and
126 directory read and execute permission checks;
127 .IP *
128 invoke
129 .BR open_by_handle_at (2);
130 .IP *
131 use the
132 .BR linkat (2)
133 .B AT_EMPTY_PATH
134 flag to create a link to a file referred to by a file descriptor.
135 .RE
136 .PD
137 .TP
138 .B CAP_FOWNER
139 .PD 0
140 .RS
141 .IP * 2
142 Bypass permission checks on operations that normally
143 require the filesystem UID of the process to match the UID of
144 the file (e.g.,
145 .BR chmod (2),
146 .BR utime (2)),
147 excluding those operations covered by
148 .B CAP_DAC_OVERRIDE
149 and
150 .BR CAP_DAC_READ_SEARCH ;
151 .IP *
152 set inode flags (see
153 .BR ioctl_iflags (2))
154 on arbitrary files;
155 .IP *
156 set Access Control Lists (ACLs) on arbitrary files;
157 .IP *
158 ignore directory sticky bit on file deletion;
159 .IP *
160 modify
161 .I user
162 extended attributes on sticky directory owned by any user;
163 .IP *
164 specify
165 .B O_NOATIME
166 for arbitrary files in
167 .BR open (2)
168 and
169 .BR fcntl (2).
170 .RE
171 .PD
172 .TP
173 .B CAP_FSETID
174 .PD 0
175 .RS
176 .IP * 2
177 Don't clear set-user-ID and set-group-ID mode
178 bits when a file is modified;
179 .IP *
180 set the set-group-ID bit for a file whose GID does not match
181 the filesystem or any of the supplementary GIDs of the calling process.
182 .RE
183 .PD
184 .TP
185 .B CAP_IPC_LOCK
186 .\" FIXME . As at Linux 3.2, there are some strange uses of this capability
187 .\" in other places; they probably should be replaced with something else.
188 .PD 0
189 .RS
190 .IP * 2
191 Lock memory
192 .RB ( mlock (2),
193 .BR mlockall (2),
194 .BR mmap (2),
195 .BR shmctl (2));
196 .IP *
197 Allocate memory using huge pages
198 .RB ( memfd_create (2),
199 .BR mmap (2),
200 .BR shmctl (2)).
201 .PD 0
202 .RE
203 .TP
204 .B CAP_IPC_OWNER
205 Bypass permission checks for operations on System V IPC objects.
206 .TP
207 .B CAP_KILL
208 Bypass permission checks for sending signals (see
209 .BR kill (2)).
210 This includes use of the
211 .BR ioctl (2)
212 .B KDSIGACCEPT
213 operation.
214 .\" FIXME . CAP_KILL also has an effect for threads + setting child
215 .\" termination signal to other than SIGCHLD: without this
216 .\" capability, the termination signal reverts to SIGCHLD
217 .\" if the child does an exec(). What is the rationale
218 .\" for this?
219 .TP
220 .BR CAP_LEASE " (since Linux 2.4)"
221 Establish leases on arbitrary files (see
222 .BR fcntl (2)).
223 .TP
224 .B CAP_LINUX_IMMUTABLE
225 Set the
226 .B FS_APPEND_FL
227 and
228 .B FS_IMMUTABLE_FL
229 inode flags (see
230 .BR ioctl_iflags (2)).
231 .TP
232 .BR CAP_MAC_ADMIN " (since Linux 2.6.25)"
233 Allow MAC configuration or state changes.
234 Implemented for the Smack Linux Security Module (LSM).
235 .TP
236 .BR CAP_MAC_OVERRIDE " (since Linux 2.6.25)"
237 Override Mandatory Access Control (MAC).
238 Implemented for the Smack LSM.
239 .TP
240 .BR CAP_MKNOD " (since Linux 2.4)"
241 Create special files using
242 .BR mknod (2).
243 .TP
244 .B CAP_NET_ADMIN
245 Perform various network-related operations:
246 .PD 0
247 .RS
248 .IP * 2
249 interface configuration;
250 .IP *
251 administration of IP firewall, masquerading, and accounting;
252 .IP *
253 modify routing tables;
254 .IP *
255 bind to any address for transparent proxying;
256 .IP *
257 set type-of-service (TOS);
258 .IP *
259 clear driver statistics;
260 .IP *
261 set promiscuous mode;
262 .IP *
263 enabling multicasting;
264 .IP *
265 use
266 .BR setsockopt (2)
267 to set the following socket options:
268 .BR SO_DEBUG ,
269 .BR SO_MARK ,
270 .BR SO_PRIORITY
271 (for a priority outside the range 0 to 6),
272 .BR SO_RCVBUFFORCE ,
273 and
274 .BR SO_SNDBUFFORCE .
275 .RE
276 .PD
277 .TP
278 .B CAP_NET_BIND_SERVICE
279 Bind a socket to Internet domain privileged ports
280 (port numbers less than 1024).
281 .TP
282 .B CAP_NET_BROADCAST
283 (Unused) Make socket broadcasts, and listen to multicasts.
284 .\" FIXME Since Linux 4.2, there are use cases for netlink sockets
285 .\" commit 59324cf35aba5336b611074028777838a963d03b
286 .TP
287 .B CAP_NET_RAW
288 .PD 0
289 .RS
290 .IP * 2
291 Use RAW and PACKET sockets;
292 .IP *
293 bind to any address for transparent proxying.
294 .RE
295 .PD
296 .\" Also various IP options and setsockopt(SO_BINDTODEVICE)
297 .TP
298 .BR CAP_PERFMON " (since Linux 5.8)"
299 Employ various performance-monitoring mechanisms, including:
300 .RS
301 .IP * 2
302 .PD 0
303 call
304 .BR perf_event_open (2);
305 .IP *
306 employ various BPF operations that have performance implications.
307 .RE
308 .PD
309 .IP
310 This capability was added in Linux 5.8 to separate out
311 performance monitoring functionality from the overloaded
312 .BR CAP_SYS_ADMIN
313 capability.
314 See also the kernel source file
315 .IR Documentation/admin\-guide/perf\-security.rst .
316 .TP
317 .B CAP_SETGID
318 .RS
319 .PD 0
320 .IP * 2
321 Make arbitrary manipulations of process GIDs and supplementary GID list;
322 .IP *
323 forge GID when passing socket credentials via UNIX domain sockets;
324 .IP *
325 write a group ID mapping in a user namespace (see
326 .BR user_namespaces (7)).
327 .PD
328 .RE
329 .TP
330 .BR CAP_SETFCAP " (since Linux 2.6.24)"
331 Set arbitrary capabilities on a file.
332 .IP
333 .\" commit db2e718a47984b9d71ed890eb2ea36ecf150de18
334 Since Linux 5.12, this capability is
335 also needed to map user ID 0 in a new user namespace; see
336 .BR user_namespaces (7)
337 for details.
338 .TP
339 .B CAP_SETPCAP
340 If file capabilities are supported (i.e., since Linux 2.6.24):
341 add any capability from the calling thread's bounding set
342 to its inheritable set;
343 drop capabilities from the bounding set (via
344 .BR prctl (2)
345 .BR PR_CAPBSET_DROP );
346 make changes to the
347 .I securebits
348 flags.
349 .IP
350 If file capabilities are not supported (i.e., kernels before Linux 2.6.24):
351 grant or remove any capability in the
352 caller's permitted capability set to or from any other process.
353 (This property of
354 .B CAP_SETPCAP
355 is not available when the kernel is configured to support
356 file capabilities, since
357 .B CAP_SETPCAP
358 has entirely different semantics for such kernels.)
359 .TP
360 .B CAP_SETUID
361 .RS
362 .PD 0
363 .IP * 2
364 Make arbitrary manipulations of process UIDs
365 .RB ( setuid (2),
366 .BR setreuid (2),
367 .BR setresuid (2),
368 .BR setfsuid (2));
369 .IP *
370 forge UID when passing socket credentials via UNIX domain sockets;
371 .IP *
372 write a user ID mapping in a user namespace (see
373 .BR user_namespaces (7)).
374 .PD
375 .RE
376 .\" FIXME CAP_SETUID also an effect in exec(); document this.
377 .TP
378 .B CAP_SYS_ADMIN
379 .IR Note :
380 this capability is overloaded; see
381 .I Notes to kernel developers
382 below.
383 .IP
384 .PD 0
385 .RS
386 .IP * 2
387 Perform a range of system administration operations including:
388 .BR quotactl (2),
389 .BR mount (2),
390 .BR umount (2),
391 .BR pivot_root (2),
392 .BR swapon (2),
393 .BR swapoff (2),
394 .BR sethostname (2),
395 and
396 .BR setdomainname (2);
397 .IP *
398 perform privileged
399 .BR syslog (2)
400 operations (since Linux 2.6.37,
401 .BR CAP_SYSLOG
402 should be used to permit such operations);
403 .IP *
404 perform
405 .B VM86_REQUEST_IRQ
406 .BR vm86 (2)
407 command;
408 .IP *
409 access the same checkpoint/restore functionality that is governed by
410 .BR CAP_CHECKPOINT_RESTORE
411 (but the latter, weaker capability is preferred for accessing
412 that functionality).
413 .IP *
414 perform the same BPF operations as are governed by
415 .BR CAP_BPF
416 (but the latter, weaker capability is preferred for accessing
417 that functionality).
418 .IP *
419 employ the same performance monitoring mechanisms as are governed by
420 .BR CAP_PERFMON
421 (but the latter, weaker capability is preferred for accessing
422 that functionality).
423 .IP *
424 perform
425 .B IPC_SET
426 and
427 .B IPC_RMID
428 operations on arbitrary System V IPC objects;
429 .IP *
430 override
431 .B RLIMIT_NPROC
432 resource limit;
433 .IP *
434 perform operations on
435 .I trusted
436 and
437 .I security
438 extended attributes (see
439 .BR xattr (7));
440 .IP *
441 use
442 .BR lookup_dcookie (2);
443 .IP *
444 use
445 .BR ioprio_set (2)
446 to assign
447 .B IOPRIO_CLASS_RT
448 and (before Linux 2.6.25)
449 .B IOPRIO_CLASS_IDLE
450 I/O scheduling classes;
451 .IP *
452 forge PID when passing socket credentials via UNIX domain sockets;
453 .IP *
454 exceed
455 .IR /proc/sys/fs/file\-max ,
456 the system-wide limit on the number of open files,
457 in system calls that open files (e.g.,
458 .BR accept (2),
459 .BR execve (2),
460 .BR open (2),
461 .BR pipe (2));
462 .IP *
463 employ
464 .B CLONE_*
465 flags that create new namespaces with
466 .BR clone (2)
467 and
468 .BR unshare (2)
469 (but, since Linux 3.8,
470 creating user namespaces does not require any capability);
471 .IP *
472 access privileged
473 .I perf
474 event information;
475 .IP *
476 call
477 .BR setns (2)
478 (requires
479 .B CAP_SYS_ADMIN
480 in the
481 .I target
482 namespace);
483 .IP *
484 call
485 .BR fanotify_init (2);
486 .IP *
487 perform privileged
488 .B KEYCTL_CHOWN
489 and
490 .B KEYCTL_SETPERM
491 .BR keyctl (2)
492 operations;
493 .IP *
494 perform
495 .BR madvise (2)
496 .B MADV_HWPOISON
497 operation;
498 .IP *
499 employ the
500 .B TIOCSTI
501 .BR ioctl (2)
502 to insert characters into the input queue of a terminal other than
503 the caller's controlling terminal;
504 .IP *
505 employ the obsolete
506 .BR nfsservctl (2)
507 system call;
508 .IP *
509 employ the obsolete
510 .BR bdflush (2)
511 system call;
512 .IP *
513 perform various privileged block-device
514 .BR ioctl (2)
515 operations;
516 .IP *
517 perform various privileged filesystem
518 .BR ioctl (2)
519 operations;
520 .IP *
521 perform privileged
522 .BR ioctl (2)
523 operations on the
524 .IR /dev/random
525 device (see
526 .BR random (4));
527 .IP *
528 install a
529 .BR seccomp (2)
530 filter without first having to set the
531 .I no_new_privs
532 thread attribute;
533 .IP *
534 modify allow/deny rules for device control groups;
535 .IP *
536 employ the
537 .BR ptrace (2)
538 .B PTRACE_SECCOMP_GET_FILTER
539 operation to dump tracee's seccomp filters;
540 .IP *
541 employ the
542 .BR ptrace (2)
543 .B PTRACE_SETOPTIONS
544 operation to suspend the tracee's seccomp protections (i.e., the
545 .B PTRACE_O_SUSPEND_SECCOMP
546 flag);
547 .IP *
548 perform administrative operations on many device drivers;
549 .IP *
550 modify autogroup nice values by writing to
551 .IR /proc/[pid]/autogroup
552 (see
553 .BR sched (7)).
554 .RE
555 .PD
556 .TP
557 .B CAP_SYS_BOOT
558 Use
559 .BR reboot (2)
560 and
561 .BR kexec_load (2).
562 .TP
563 .B CAP_SYS_CHROOT
564 .RS
565 .PD 0
566 .IP * 2
567 Use
568 .BR chroot (2);
569 .IP *
570 change mount namespaces using
571 .BR setns (2).
572 .PD
573 .RE
574 .TP
575 .B CAP_SYS_MODULE
576 .RS
577 .PD 0
578 .IP * 2
579 Load and unload kernel modules
580 (see
581 .BR init_module (2)
582 and
583 .BR delete_module (2));
584 .IP *
585 in kernels before 2.6.25:
586 drop capabilities from the system-wide capability bounding set.
587 .PD
588 .RE
589 .TP
590 .B CAP_SYS_NICE
591 .PD 0
592 .RS
593 .IP * 2
594 Lower the process nice value
595 .RB ( nice (2),
596 .BR setpriority (2))
597 and change the nice value for arbitrary processes;
598 .IP *
599 set real-time scheduling policies for calling process,
600 and set scheduling policies and priorities for arbitrary processes
601 .RB ( sched_setscheduler (2),
602 .BR sched_setparam (2),
603 .BR sched_setattr (2));
604 .IP *
605 set CPU affinity for arbitrary processes
606 .RB ( sched_setaffinity (2));
607 .IP *
608 set I/O scheduling class and priority for arbitrary processes
609 .RB ( ioprio_set (2));
610 .IP *
611 apply
612 .BR migrate_pages (2)
613 to arbitrary processes and allow processes
614 to be migrated to arbitrary nodes;
615 .\" FIXME CAP_SYS_NICE also has the following effect for
616 .\" migrate_pages(2):
617 .\" do_migrate_pages(mm, &old, &new,
618 .\" capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
619 .\"
620 .\" Document this.
621 .IP *
622 apply
623 .BR move_pages (2)
624 to arbitrary processes;
625 .IP *
626 use the
627 .B MPOL_MF_MOVE_ALL
628 flag with
629 .BR mbind (2)
630 and
631 .BR move_pages (2).
632 .RE
633 .PD
634 .TP
635 .B CAP_SYS_PACCT
636 Use
637 .BR acct (2).
638 .TP
639 .B CAP_SYS_PTRACE
640 .PD 0
641 .RS
642 .IP * 2
643 Trace arbitrary processes using
644 .BR ptrace (2);
645 .IP *
646 apply
647 .BR get_robust_list (2)
648 to arbitrary processes;
649 .IP *
650 transfer data to or from the memory of arbitrary processes using
651 .BR process_vm_readv (2)
652 and
653 .BR process_vm_writev (2);
654 .IP *
655 inspect processes using
656 .BR kcmp (2).
657 .RE
658 .PD
659 .TP
660 .B CAP_SYS_RAWIO
661 .PD 0
662 .RS
663 .IP * 2
664 Perform I/O port operations
665 .RB ( iopl (2)
666 and
667 .BR ioperm (2));
668 .IP *
669 access
670 .IR /proc/kcore ;
671 .IP *
672 employ the
673 .B FIBMAP
674 .BR ioctl (2)
675 operation;
676 .IP *
677 open devices for accessing x86 model-specific registers (MSRs, see
678 .BR msr (4));
679 .IP *
680 update
681 .IR /proc/sys/vm/mmap_min_addr ;
682 .IP *
683 create memory mappings at addresses below the value specified by
684 .IR /proc/sys/vm/mmap_min_addr ;
685 .IP *
686 map files in
687 .IR /proc/bus/pci ;
688 .IP *
689 open
690 .IR /dev/mem
691 and
692 .IR /dev/kmem ;
693 .IP *
694 perform various SCSI device commands;
695 .IP *
696 perform certain operations on
697 .BR hpsa (4)
698 and
699 .BR cciss (4)
700 devices;
701 .IP *
702 perform a range of device-specific operations on other devices.
703 .RE
704 .PD
705 .TP
706 .B CAP_SYS_RESOURCE
707 .PD 0
708 .RS
709 .IP * 2
710 Use reserved space on ext2 filesystems;
711 .IP *
712 make
713 .BR ioctl (2)
714 calls controlling ext3 journaling;
715 .IP *
716 override disk quota limits;
717 .IP *
718 increase resource limits (see
719 .BR setrlimit (2));
720 .IP *
721 override
722 .B RLIMIT_NPROC
723 resource limit;
724 .IP *
725 override maximum number of consoles on console allocation;
726 .IP *
727 override maximum number of keymaps;
728 .IP *
729 allow more than 64hz interrupts from the real-time clock;
730 .IP *
731 raise
732 .I msg_qbytes
733 limit for a System V message queue above the limit in
734 .I /proc/sys/kernel/msgmnb
735 (see
736 .BR msgop (2)
737 and
738 .BR msgctl (2));
739 .IP *
740 allow the
741 .B RLIMIT_NOFILE
742 resource limit on the number of "in-flight" file descriptors
743 to be bypassed when passing file descriptors to another process
744 via a UNIX domain socket (see
745 .BR unix (7));
746 .IP *
747 override the
748 .I /proc/sys/fs/pipe\-size\-max
749 limit when setting the capacity of a pipe using the
750 .B F_SETPIPE_SZ
751 .BR fcntl (2)
752 command;
753 .IP *
754 use
755 .BR F_SETPIPE_SZ
756 to increase the capacity of a pipe above the limit specified by
757 .IR /proc/sys/fs/pipe\-max\-size ;
758 .IP *
759 override
760 .IR /proc/sys/fs/mqueue/queues_max ,
761 .IR /proc/sys/fs/mqueue/msg_max ,
762 and
763 .I /proc/sys/fs/mqueue/msgsize_max
764 limits when creating POSIX message queues (see
765 .BR mq_overview (7));
766 .IP *
767 employ the
768 .BR prctl (2)
769 .B PR_SET_MM
770 operation;
771 .IP *
772 set
773 .IR /proc/[pid]/oom_score_adj
774 to a value lower than the value last set by a process with
775 .BR CAP_SYS_RESOURCE .
776 .RE
777 .PD
778 .TP
779 .B CAP_SYS_TIME
780 Set system clock
781 .RB ( settimeofday (2),
782 .BR stime (2),
783 .BR adjtimex (2));
784 set real-time (hardware) clock.
785 .TP
786 .B CAP_SYS_TTY_CONFIG
787 Use
788 .BR vhangup (2);
789 employ various privileged
790 .BR ioctl (2)
791 operations on virtual terminals.
792 .TP
793 .BR CAP_SYSLOG " (since Linux 2.6.37)"
794 .RS
795 .PD 0
796 .IP * 2
797 Perform privileged
798 .BR syslog (2)
799 operations.
800 See
801 .BR syslog (2)
802 for information on which operations require privilege.
803 .IP *
804 View kernel addresses exposed via
805 .I /proc
806 and other interfaces when
807 .IR /proc/sys/kernel/kptr_restrict
808 has the value 1.
809 (See the discussion of the
810 .I kptr_restrict
811 in
812 .BR proc (5).)
813 .PD
814 .RE
815 .TP
816 .BR CAP_WAKE_ALARM " (since Linux 3.0)"
817 Trigger something that will wake up the system (set
818 .B CLOCK_REALTIME_ALARM
819 and
820 .B CLOCK_BOOTTIME_ALARM
821 timers).
822 .\"
823 .SS Past and current implementation
824 A full implementation of capabilities requires that:
825 .IP 1. 3
826 For all privileged operations,
827 the kernel must check whether the thread has the required
828 capability in its effective set.
829 .IP 2.
830 The kernel must provide system calls allowing a thread's capability sets to
831 be changed and retrieved.
832 .IP 3.
833 The filesystem must support attaching capabilities to an executable file,
834 so that a process gains those capabilities when the file is executed.
835 .PP
836 Before kernel 2.6.24, only the first two of these requirements are met;
837 since kernel 2.6.24, all three requirements are met.
838 .\"
839 .SS Notes to kernel developers
840 When adding a new kernel feature that should be governed by a capability,
841 consider the following points.
842 .IP * 3
843 The goal of capabilities is divide the power of superuser into pieces,
844 such that if a program that has one or more capabilities is compromised,
845 its power to do damage to the system would be less than the same program
846 running with root privilege.
847 .IP *
848 You have the choice of either creating a new capability for your new feature,
849 or associating the feature with one of the existing capabilities.
850 In order to keep the set of capabilities to a manageable size,
851 the latter option is preferable,
852 unless there are compelling reasons to take the former option.
853 (There is also a technical limit:
854 the size of capability sets is currently limited to 64 bits.)
855 .IP *
856 To determine which existing capability might best be associated
857 with your new feature, review the list of capabilities above in order
858 to find a "silo" into which your new feature best fits.
859 One approach to take is to determine if there are other features
860 requiring capabilities that will always be used along with the new feature.
861 If the new feature is useless without these other features,
862 you should use the same capability as the other features.
863 .IP *
864 .IR Don't
865 choose
866 .B CAP_SYS_ADMIN
867 if you can possibly avoid it!
868 A vast proportion of existing capability checks are associated
869 with this capability (see the partial list above).
870 It can plausibly be called "the new root",
871 since on the one hand, it confers a wide range of powers,
872 and on the other hand,
873 its broad scope means that this is the capability
874 that is required by many privileged programs.
875 Don't make the problem worse.
876 The only new features that should be associated with
877 .B CAP_SYS_ADMIN
878 are ones that
879 .I closely
880 match existing uses in that silo.
881 .IP *
882 If you have determined that it really is necessary to create
883 a new capability for your feature,
884 don't make or name it as a "single-use" capability.
885 Thus, for example, the addition of the highly specific
886 .BR CAP_SYS_PACCT
887 was probably a mistake.
888 Instead, try to identify and name your new capability as a broader
889 silo into which other related future use cases might fit.
890 .\"
891 .SS Thread capability sets
892 Each thread has the following capability sets containing zero or more
893 of the above capabilities:
894 .TP
895 .IR Permitted
896 This is a limiting superset for the effective
897 capabilities that the thread may assume.
898 It is also a limiting superset for the capabilities that
899 may be added to the inheritable set by a thread that does not have the
900 .B CAP_SETPCAP
901 capability in its effective set.
902 .IP
903 If a thread drops a capability from its permitted set,
904 it can never reacquire that capability (unless it
905 .BR execve (2)s
906 either a set-user-ID-root program, or
907 a program whose associated file capabilities grant that capability).
908 .TP
909 .IR Inheritable
910 This is a set of capabilities preserved across an
911 .BR execve (2).
912 Inheritable capabilities remain inheritable when executing any program,
913 and inheritable capabilities are added to the permitted set when executing
914 a program that has the corresponding bits set in the file inheritable set.
915 .IP
916 Because inheritable capabilities are not generally preserved across
917 .BR execve (2)
918 when running as a non-root user, applications that wish to run helper
919 programs with elevated capabilities should consider using
920 ambient capabilities, described below.
921 .TP
922 .IR Effective
923 This is the set of capabilities used by the kernel to
924 perform permission checks for the thread.
925 .TP
926 .IR Bounding " (per-thread since Linux 2.6.25)"
927 The capability bounding set is a mechanism that can be used
928 to limit the capabilities that are gained during
929 .BR execve (2).
930 .IP
931 Since Linux 2.6.25, this is a per-thread capability set.
932 In older kernels, the capability bounding set was a system wide attribute
933 shared by all threads on the system.
934 .IP
935 For more details, see
936 .I Capability bounding set
937 below.
938 .TP
939 .IR Ambient " (since Linux 4.3)"
940 .\" commit 58319057b7847667f0c9585b9de0e8932b0fdb08
941 This is a set of capabilities that are preserved across an
942 .BR execve (2)
943 of a program that is not privileged.
944 The ambient capability set obeys the invariant that no capability
945 can ever be ambient if it is not both permitted and inheritable.
946 .IP
947 The ambient capability set can be directly modified using
948 .BR prctl (2).
949 Ambient capabilities are automatically lowered if either of
950 the corresponding permitted or inheritable capabilities is lowered.
951 .IP
952 Executing a program that changes UID or GID due to the
953 set-user-ID or set-group-ID bits or executing a program that has
954 any file capabilities set will clear the ambient set.
955 Ambient capabilities are added to the permitted set and
956 assigned to the effective set when
957 .BR execve (2)
958 is called.
959 If ambient capabilities cause a process's permitted and effective
960 capabilities to increase during an
961 .BR execve (2),
962 this does not trigger the secure-execution mode described in
963 .BR ld.so (8).
964 .PP
965 A child created via
966 .BR fork (2)
967 inherits copies of its parent's capability sets.
968 For details on how
969 .BR execve (2)
970 affects capabilities, see
971 .I Transformation of capabilities during execve()
972 below.
973 .PP
974 Using
975 .BR capset (2),
976 a thread may manipulate its own capability sets; see
977 .I Programmatically adjusting capability sets
978 below.
979 .PP
980 Since Linux 3.2, the file
981 .I /proc/sys/kernel/cap_last_cap
982 .\" commit 73efc0394e148d0e15583e13712637831f926720
983 exposes the numerical value of the highest capability
984 supported by the running kernel;
985 this can be used to determine the highest bit
986 that may be set in a capability set.
987 .\"
988 .SS File capabilities
989 Since kernel 2.6.24, the kernel supports
990 associating capability sets with an executable file using
991 .BR setcap (8).
992 The file capability sets are stored in an extended attribute (see
993 .BR setxattr (2)
994 and
995 .BR xattr (7))
996 named
997 .IR "security.capability" .
998 Writing to this extended attribute requires the
999 .BR CAP_SETFCAP
1000 capability.
1001 The file capability sets,
1002 in conjunction with the capability sets of the thread,
1003 determine the capabilities of a thread after an
1004 .BR execve (2).
1005 .PP
1006 The three file capability sets are:
1007 .TP
1008 .IR Permitted " (formerly known as " forced ):
1009 These capabilities are automatically permitted to the thread,
1010 regardless of the thread's inheritable capabilities.
1011 .TP
1012 .IR Inheritable " (formerly known as " allowed ):
1013 This set is ANDed with the thread's inheritable set to determine which
1014 inheritable capabilities are enabled in the permitted set of
1015 the thread after the
1016 .BR execve (2).
1017 .TP
1018 .IR Effective :
1019 This is not a set, but rather just a single bit.
1020 If this bit is set, then during an
1021 .BR execve (2)
1022 all of the new permitted capabilities for the thread are
1023 also raised in the effective set.
1024 If this bit is not set, then after an
1025 .BR execve (2),
1026 none of the new permitted capabilities is in the new effective set.
1027 .IP
1028 Enabling the file effective capability bit implies
1029 that any file permitted or inheritable capability that causes a
1030 thread to acquire the corresponding permitted capability during an
1031 .BR execve (2)
1032 (see
1033 .I Transformation of capabilities during execve()
1034 below) will also acquire that
1035 capability in its effective set.
1036 Therefore, when assigning capabilities to a file
1037 .RB ( setcap (8),
1038 .BR cap_set_file (3),
1039 .BR cap_set_fd (3)),
1040 if we specify the effective flag as being enabled for any capability,
1041 then the effective flag must also be specified as enabled
1042 for all other capabilities for which the corresponding permitted or
1043 inheritable flags is enabled.
1044 .\"
1045 .SS File capability extended attribute versioning
1046 To allow extensibility,
1047 the kernel supports a scheme to encode a version number inside the
1048 .I security.capability
1049 extended attribute that is used to implement file capabilities.
1050 These version numbers are internal to the implementation,
1051 and not directly visible to user-space applications.
1052 To date, the following versions are supported:
1053 .TP
1054 .BR VFS_CAP_REVISION_1
1055 This was the original file capability implementation,
1056 which supported 32-bit masks for file capabilities.
1057 .TP
1058 .BR VFS_CAP_REVISION_2 " (since Linux 2.6.25)"
1059 .\" commit e338d263a76af78fe8f38a72131188b58fceb591
1060 This version allows for file capability masks that are 64 bits in size,
1061 and was necessary as the number of supported capabilities grew beyond 32.
1062 The kernel transparently continues to support the execution of files
1063 that have 32-bit version 1 capability masks,
1064 but when adding capabilities to files that did not previously
1065 have capabilities, or modifying the capabilities of existing files,
1066 it automatically uses the version 2 scheme
1067 (or possibly the version 3 scheme, as described below).
1068 .TP
1069 .BR VFS_CAP_REVISION_3 " (since Linux 4.14)"
1070 .\" commit 8db6c34f1dbc8e06aa016a9b829b06902c3e1340
1071 Version 3 file capabilities are provided
1072 to support namespaced file capabilities (described below).
1073 .IP
1074 As with version 2 file capabilities,
1075 version 3 capability masks are 64 bits in size.
1076 But in addition, the root user ID of namespace is encoded in the
1077 .I security.capability
1078 extended attribute.
1079 (A namespace's root user ID is the value that user ID 0
1080 inside that namespace maps to in the initial user namespace.)
1081 .IP
1082 Version 3 file capabilities are designed to coexist
1083 with version 2 capabilities;
1084 that is, on a modern Linux system,
1085 there may be some files with version 2 capabilities
1086 while others have version 3 capabilities.
1087 .PP
1088 Before Linux 4.14,
1089 the only kind of file capability extended attribute
1090 that could be attached to a file was a
1091 .B VFS_CAP_REVISION_2
1092 attribute.
1093 Since Linux 4.14,
1094 the version of the
1095 .I security.capability
1096 extended attribute that is attached to a file
1097 depends on the circumstances in which the attribute was created.
1098 .PP
1099 Starting with Linux 4.14, a
1100 .I security.capability
1101 extended attribute is automatically created as (or converted to)
1102 a version 3
1103 .RB ( VFS_CAP_REVISION_3 )
1104 attribute if both of the following are true:
1105 .IP (1) 4
1106 The thread writing the attribute resides in a noninitial user namespace.
1107 (More precisely: the thread resides in a user namespace other
1108 than the one from which the underlying filesystem was mounted.)
1109 .IP (2)
1110 The thread has the
1111 .BR CAP_SETFCAP
1112 capability over the file inode,
1113 meaning that (a) the thread has the
1114 .B CAP_SETFCAP
1115 capability in its own user namespace;
1116 and (b) the UID and GID of the file inode have mappings in
1117 the writer's user namespace.
1118 .PP
1119 When a
1120 .BR VFS_CAP_REVISION_3
1121 .I security.capability
1122 extended attribute is created, the root user ID of the creating thread's
1123 user namespace is saved in the extended attribute.
1124 .PP
1125 By contrast, creating or modifying a
1126 .I security.capability
1127 extended attribute from a privileged
1128 .RB ( CAP_SETFCAP )
1129 thread that resides in the
1130 namespace where the underlying filesystem was mounted
1131 (this normally means the initial user namespace)
1132 automatically results in the creation of a version 2
1133 .RB ( VFS_CAP_REVISION_2 )
1134 attribute.
1135 .PP
1136 Note that the creation of a version 3
1137 .I security.capability
1138 extended attribute is automatic.
1139 That is to say, when a user-space application writes
1140 .RB ( setxattr (2))
1141 a
1142 .I security.capability
1143 attribute in the version 2 format,
1144 the kernel will automatically create a version 3 attribute
1145 if the attribute is created in the circumstances described above.
1146 Correspondingly, when a version 3
1147 .I security.capability
1148 attribute is retrieved
1149 .RB ( getxattr (2))
1150 by a process that resides inside a user namespace that was created by the
1151 root user ID (or a descendant of that user namespace),
1152 the returned attribute is (automatically)
1153 simplified to appear as a version 2 attribute
1154 (i.e., the returned value is the size of a version 2 attribute and does
1155 not include the root user ID).
1156 These automatic translations mean that no changes are required to
1157 user-space tools (e.g.,
1158 .BR setcap (1)
1159 and
1160 .BR getcap (1))
1161 in order for those tools to be used to create and retrieve version 3
1162 .I security.capability
1163 attributes.
1164 .PP
1165 Note that a file can have either a version 2 or a version 3
1166 .I security.capability
1167 extended attribute associated with it, but not both:
1168 creation or modification of the
1169 .I security.capability
1170 extended attribute will automatically modify the version
1171 according to the circumstances in which the extended attribute is
1172 created or modified.
1173 .\"
1174 .SS Transformation of capabilities during execve()
1175 During an
1176 .BR execve (2),
1177 the kernel calculates the new capabilities of
1178 the process using the following algorithm:
1179 .PP
1180 .in +4n
1181 .EX
1182 P'(ambient) = (file is privileged) ? 0 : P(ambient)
1183
1184 P'(permitted) = (P(inheritable) & F(inheritable)) |
1185 (F(permitted) & P(bounding)) | P'(ambient)
1186
1187 P'(effective) = F(effective) ? P'(permitted) : P'(ambient)
1188
1189 P'(inheritable) = P(inheritable) [i.e., unchanged]
1190
1191 P'(bounding) = P(bounding) [i.e., unchanged]
1192 .EE
1193 .in
1194 .PP
1195 where:
1196 .RS 4
1197 .IP P() 6
1198 denotes the value of a thread capability set before the
1199 .BR execve (2)
1200 .IP P'()
1201 denotes the value of a thread capability set after the
1202 .BR execve (2)
1203 .IP F()
1204 denotes a file capability set
1205 .RE
1206 .PP
1207 Note the following details relating to the above capability
1208 transformation rules:
1209 .IP * 3
1210 The ambient capability set is present only since Linux 4.3.
1211 When determining the transformation of the ambient set during
1212 .BR execve (2),
1213 a privileged file is one that has capabilities or
1214 has the set-user-ID or set-group-ID bit set.
1215 .IP *
1216 Prior to Linux 2.6.25,
1217 the bounding set was a system-wide attribute shared by all threads.
1218 That system-wide value was employed to calculate the new permitted set during
1219 .BR execve (2)
1220 in the same manner as shown above for
1221 .IR P(bounding) .
1222 .PP
1223 .IR Note :
1224 during the capability transitions described above,
1225 file capabilities may be ignored (treated as empty) for the same reasons
1226 that the set-user-ID and set-group-ID bits are ignored; see
1227 .BR execve (2).
1228 File capabilities are similarly ignored if the kernel was booted with the
1229 .I no_file_caps
1230 option.
1231 .PP
1232 .IR Note :
1233 according to the rules above,
1234 if a process with nonzero user IDs performs an
1235 .BR execve (2)
1236 then any capabilities that are present in
1237 its permitted and effective sets will be cleared.
1238 For the treatment of capabilities when a process with a
1239 user ID of zero performs an
1240 .BR execve (2),
1241 see
1242 .I Capabilities and execution of programs by root
1243 below.
1244 .\"
1245 .SS Safety checking for capability-dumb binaries
1246 A capability-dumb binary is an application that has been
1247 marked to have file capabilities, but has not been converted to use the
1248 .BR libcap (3)
1249 API to manipulate its capabilities.
1250 (In other words, this is a traditional set-user-ID-root program
1251 that has been switched to use file capabilities,
1252 but whose code has not been modified to understand capabilities.)
1253 For such applications,
1254 the effective capability bit is set on the file,
1255 so that the file permitted capabilities are automatically
1256 enabled in the process effective set when executing the file.
1257 The kernel recognizes a file which has the effective capability bit set
1258 as capability-dumb for the purpose of the check described here.
1259 .PP
1260 When executing a capability-dumb binary,
1261 the kernel checks if the process obtained all permitted capabilities
1262 that were specified in the file permitted set,
1263 after the capability transformations described above have been performed.
1264 (The typical reason why this might
1265 .I not
1266 occur is that the capability bounding set masked out some
1267 of the capabilities in the file permitted set.)
1268 If the process did not obtain the full set of
1269 file permitted capabilities, then
1270 .BR execve (2)
1271 fails with the error
1272 .BR EPERM .
1273 This prevents possible security risks that could arise when
1274 a capability-dumb application is executed with less privilege that it needs.
1275 Note that, by definition,
1276 the application could not itself recognize this problem,
1277 since it does not employ the
1278 .BR libcap (3)
1279 API.
1280 .\"
1281 .SS Capabilities and execution of programs by root
1282 .\" See cap_bprm_set_creds(), bprm_caps_from_vfs_cap() and
1283 .\" handle_privileged_root() in security/commoncap.c (Linux 5.0 source)
1284 In order to mirror traditional UNIX semantics,
1285 the kernel performs special treatment of file capabilities when
1286 a process with UID 0 (root) executes a program and
1287 when a set-user-ID-root program is executed.
1288 .PP
1289 After having performed any changes to the process effective ID that
1290 were triggered by the set-user-ID mode bit of the binary\(eme.g.,
1291 switching the effective user ID to 0 (root) because
1292 a set-user-ID-root program was executed\(emthe
1293 kernel calculates the file capability sets as follows:
1294 .IP 1. 3
1295 If the real or effective user ID of the process is 0 (root),
1296 then the file inheritable and permitted sets are ignored;
1297 instead they are notionally considered to be all ones
1298 (i.e., all capabilities enabled).
1299 (There is one exception to this behavior, described in
1300 .I Set-user-ID-root programs that have file capabilities
1301 below.)
1302 .IP 2.
1303 If the effective user ID of the process is 0 (root) or
1304 the file effective bit is in fact enabled,
1305 then the file effective bit is notionally defined to be one (enabled).
1306 .PP
1307 These notional values for the file's capability sets are then used
1308 as described above to calculate the transformation of the process's
1309 capabilities during
1310 .BR execve (2).
1311 .PP
1312 Thus, when a process with nonzero UIDs
1313 .BR execve (2)s
1314 a set-user-ID-root program that does not have capabilities attached,
1315 or when a process whose real and effective UIDs are zero
1316 .BR execve (2)s
1317 a program, the calculation of the process's new
1318 permitted capabilities simplifies to:
1319 .PP
1320 .in +4n
1321 .EX
1322 P'(permitted) = P(inheritable) | P(bounding)
1323
1324 P'(effective) = P'(permitted)
1325 .EE
1326 .in
1327 .PP
1328 Consequently, the process gains all capabilities in its permitted and
1329 effective capability sets,
1330 except those masked out by the capability bounding set.
1331 (In the calculation of P'(permitted),
1332 the P'(ambient) term can be simplified away because it is by
1333 definition a proper subset of P(inheritable).)
1334 .PP
1335 The special treatments of user ID 0 (root) described in this subsection
1336 can be disabled using the securebits mechanism described below.
1337 .\"
1338 .\"
1339 .SS Set-user-ID-root programs that have file capabilities
1340 There is one exception to the behavior described in
1341 .I Capabilities and execution of programs by root
1342 above.
1343 If (a) the binary that is being executed has capabilities attached and
1344 (b) the real user ID of the process is
1345 .I not
1346 0 (root) and
1347 (c) the effective user ID of the process
1348 .I is
1349 0 (root), then the file capability bits are honored
1350 (i.e., they are not notionally considered to be all ones).
1351 The usual way in which this situation can arise is when executing
1352 a set-UID-root program that also has file capabilities.
1353 When such a program is executed,
1354 the process gains just the capabilities granted by the program
1355 (i.e., not all capabilities,
1356 as would occur when executing a set-user-ID-root program
1357 that does not have any associated file capabilities).
1358 .PP
1359 Note that one can assign empty capability sets to a program file,
1360 and thus it is possible to create a set-user-ID-root program that
1361 changes the effective and saved set-user-ID of the process
1362 that executes the program to 0,
1363 but confers no capabilities to that process.
1364 .\"
1365 .SS Capability bounding set
1366 The capability bounding set is a security mechanism that can be used
1367 to limit the capabilities that can be gained during an
1368 .BR execve (2).
1369 The bounding set is used in the following ways:
1370 .IP * 2
1371 During an
1372 .BR execve (2),
1373 the capability bounding set is ANDed with the file permitted
1374 capability set, and the result of this operation is assigned to the
1375 thread's permitted capability set.
1376 The capability bounding set thus places a limit on the permitted
1377 capabilities that may be granted by an executable file.
1378 .IP *
1379 (Since Linux 2.6.25)
1380 The capability bounding set acts as a limiting superset for
1381 the capabilities that a thread can add to its inheritable set using
1382 .BR capset (2).
1383 This means that if a capability is not in the bounding set,
1384 then a thread can't add this capability to its
1385 inheritable set, even if it was in its permitted capabilities,
1386 and thereby cannot have this capability preserved in its
1387 permitted set when it
1388 .BR execve (2)s
1389 a file that has the capability in its inheritable set.
1390 .PP
1391 Note that the bounding set masks the file permitted capabilities,
1392 but not the inheritable capabilities.
1393 If a thread maintains a capability in its inheritable set
1394 that is not in its bounding set,
1395 then it can still gain that capability in its permitted set
1396 by executing a file that has the capability in its inheritable set.
1397 .PP
1398 Depending on the kernel version, the capability bounding set is either
1399 a system-wide attribute, or a per-process attribute.
1400 .PP
1401 .B "Capability bounding set from Linux 2.6.25 onward"
1402 .PP
1403 From Linux 2.6.25, the
1404 .I "capability bounding set"
1405 is a per-thread attribute.
1406 (The system-wide capability bounding set described below no longer exists.)
1407 .PP
1408 The bounding set is inherited at
1409 .BR fork (2)
1410 from the thread's parent, and is preserved across an
1411 .BR execve (2).
1412 .PP
1413 A thread may remove capabilities from its capability bounding set using the
1414 .BR prctl (2)
1415 .B PR_CAPBSET_DROP
1416 operation, provided it has the
1417 .B CAP_SETPCAP
1418 capability.
1419 Once a capability has been dropped from the bounding set,
1420 it cannot be restored to that set.
1421 A thread can determine if a capability is in its bounding set using the
1422 .BR prctl (2)
1423 .B PR_CAPBSET_READ
1424 operation.
1425 .PP
1426 Removing capabilities from the bounding set is supported only if file
1427 capabilities are compiled into the kernel.
1428 In kernels before Linux 2.6.33,
1429 file capabilities were an optional feature configurable via the
1430 .B CONFIG_SECURITY_FILE_CAPABILITIES
1431 option.
1432 Since Linux 2.6.33,
1433 .\" commit b3a222e52e4d4be77cc4520a57af1a4a0d8222d1
1434 the configuration option has been removed
1435 and file capabilities are always part of the kernel.
1436 When file capabilities are compiled into the kernel, the
1437 .B init
1438 process (the ancestor of all processes) begins with a full bounding set.
1439 If file capabilities are not compiled into the kernel, then
1440 .B init
1441 begins with a full bounding set minus
1442 .BR CAP_SETPCAP ,
1443 because this capability has a different meaning when there are
1444 no file capabilities.
1445 .PP
1446 Removing a capability from the bounding set does not remove it
1447 from the thread's inheritable set.
1448 However it does prevent the capability from being added
1449 back into the thread's inheritable set in the future.
1450 .PP
1451 .B "Capability bounding set prior to Linux 2.6.25"
1452 .PP
1453 In kernels before 2.6.25, the capability bounding set is a system-wide
1454 attribute that affects all threads on the system.
1455 The bounding set is accessible via the file
1456 .IR /proc/sys/kernel/cap\-bound .
1457 (Confusingly, this bit mask parameter is expressed as a
1458 signed decimal number in
1459 .IR /proc/sys/kernel/cap\-bound .)
1460 .PP
1461 Only the
1462 .B init
1463 process may set capabilities in the capability bounding set;
1464 other than that, the superuser (more precisely: a process with the
1465 .B CAP_SYS_MODULE
1466 capability) may only clear capabilities from this set.
1467 .PP
1468 On a standard system the capability bounding set always masks out the
1469 .B CAP_SETPCAP
1470 capability.
1471 To remove this restriction (dangerous!), modify the definition of
1472 .B CAP_INIT_EFF_SET
1473 in
1474 .I include/linux/capability.h
1475 and rebuild the kernel.
1476 .PP
1477 The system-wide capability bounding set feature was added
1478 to Linux starting with kernel version 2.2.11.
1479 .\"
1480 .\"
1481 .\"
1482 .SS Effect of user ID changes on capabilities
1483 To preserve the traditional semantics for transitions between
1484 0 and nonzero user IDs,
1485 the kernel makes the following changes to a thread's capability
1486 sets on changes to the thread's real, effective, saved set,
1487 and filesystem user IDs (using
1488 .BR setuid (2),
1489 .BR setresuid (2),
1490 or similar):
1491 .IP 1. 3
1492 If one or more of the real, effective, or saved set user IDs
1493 was previously 0, and as a result of the UID changes all of these IDs
1494 have a nonzero value,
1495 then all capabilities are cleared from the permitted, effective, and ambient
1496 capability sets.
1497 .IP 2.
1498 If the effective user ID is changed from 0 to nonzero,
1499 then all capabilities are cleared from the effective set.
1500 .IP 3.
1501 If the effective user ID is changed from nonzero to 0,
1502 then the permitted set is copied to the effective set.
1503 .IP 4.
1504 If the filesystem user ID is changed from 0 to nonzero (see
1505 .BR setfsuid (2)),
1506 then the following capabilities are cleared from the effective set:
1507 .BR CAP_CHOWN ,
1508 .BR CAP_DAC_OVERRIDE ,
1509 .BR CAP_DAC_READ_SEARCH ,
1510 .BR CAP_FOWNER ,
1511 .BR CAP_FSETID ,
1512 .B CAP_LINUX_IMMUTABLE
1513 (since Linux 2.6.30),
1514 .BR CAP_MAC_OVERRIDE ,
1515 and
1516 .B CAP_MKNOD
1517 (since Linux 2.6.30).
1518 If the filesystem UID is changed from nonzero to 0,
1519 then any of these capabilities that are enabled in the permitted set
1520 are enabled in the effective set.
1521 .PP
1522 If a thread that has a 0 value for one or more of its user IDs wants
1523 to prevent its permitted capability set being cleared when it resets
1524 all of its user IDs to nonzero values, it can do so using the
1525 .B SECBIT_KEEP_CAPS
1526 securebits flag described below.
1527 .\"
1528 .SS Programmatically adjusting capability sets
1529 A thread can retrieve and change its permitted, effective, and inheritable
1530 capability sets using the
1531 .BR capget (2)
1532 and
1533 .BR capset (2)
1534 system calls.
1535 However, the use of
1536 .BR cap_get_proc (3)
1537 and
1538 .BR cap_set_proc (3),
1539 both provided in the
1540 .I libcap
1541 package,
1542 is preferred for this purpose.
1543 The following rules govern changes to the thread capability sets:
1544 .IP 1. 3
1545 If the caller does not have the
1546 .B CAP_SETPCAP
1547 capability,
1548 the new inheritable set must be a subset of the combination
1549 of the existing inheritable and permitted sets.
1550 .IP 2.
1551 (Since Linux 2.6.25)
1552 The new inheritable set must be a subset of the combination of the
1553 existing inheritable set and the capability bounding set.
1554 .IP 3.
1555 The new permitted set must be a subset of the existing permitted set
1556 (i.e., it is not possible to acquire permitted capabilities
1557 that the thread does not currently have).
1558 .IP 4.
1559 The new effective set must be a subset of the new permitted set.
1560 .SS The securebits flags: establishing a capabilities-only environment
1561 .\" For some background:
1562 .\" see http://lwn.net/Articles/280279/ and
1563 .\" http://article.gmane.org/gmane.linux.kernel.lsm/5476/
1564 Starting with kernel 2.6.26,
1565 and with a kernel in which file capabilities are enabled,
1566 Linux implements a set of per-thread
1567 .I securebits
1568 flags that can be used to disable special handling of capabilities for UID 0
1569 .RI ( root ).
1570 These flags are as follows:
1571 .TP
1572 .B SECBIT_KEEP_CAPS
1573 Setting this flag allows a thread that has one or more 0 UIDs to retain
1574 capabilities in its permitted set
1575 when it switches all of its UIDs to nonzero values.
1576 If this flag is not set,
1577 then such a UID switch causes the thread to lose all permitted capabilities.
1578 This flag is always cleared on an
1579 .BR execve (2).
1580 .IP
1581 Note that even with the
1582 .B SECBIT_KEEP_CAPS
1583 flag set, the effective capabilities of a thread are cleared when it
1584 switches its effective UID to a nonzero value.
1585 However,
1586 if the thread has set this flag and its effective UID is already nonzero,
1587 and the thread subsequently switches all other UIDs to nonzero values,
1588 then the effective capabilities will not be cleared.
1589 .IP
1590 The setting of the
1591 .B SECBIT_KEEP_CAPS
1592 flag is ignored if the
1593 .B SECBIT_NO_SETUID_FIXUP
1594 flag is set.
1595 (The latter flag provides a superset of the effect of the former flag.)
1596 .IP
1597 This flag provides the same functionality as the older
1598 .BR prctl (2)
1599 .B PR_SET_KEEPCAPS
1600 operation.
1601 .TP
1602 .B SECBIT_NO_SETUID_FIXUP
1603 Setting this flag stops the kernel from adjusting the process's
1604 permitted, effective, and ambient capability sets when
1605 the thread's effective and filesystem UIDs are switched between
1606 zero and nonzero values.
1607 See
1608 .I Effect of user ID changes on capabilities
1609 above.
1610 .TP
1611 .B SECBIT_NOROOT
1612 If this bit is set, then the kernel does not grant capabilities
1613 when a set-user-ID-root program is executed, or when a process with
1614 an effective or real UID of 0 calls
1615 .BR execve (2).
1616 (See
1617 .I Capabilities and execution of programs by root
1618 above.)
1619 .TP
1620 .B SECBIT_NO_CAP_AMBIENT_RAISE
1621 Setting this flag disallows raising ambient capabilities via the
1622 .BR prctl (2)
1623 .BR PR_CAP_AMBIENT_RAISE
1624 operation.
1625 .PP
1626 Each of the above "base" flags has a companion "locked" flag.
1627 Setting any of the "locked" flags is irreversible,
1628 and has the effect of preventing further changes to the
1629 corresponding "base" flag.
1630 The locked flags are:
1631 .BR SECBIT_KEEP_CAPS_LOCKED ,
1632 .BR SECBIT_NO_SETUID_FIXUP_LOCKED ,
1633 .BR SECBIT_NOROOT_LOCKED ,
1634 and
1635 .BR SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED .
1636 .PP
1637 The
1638 .I securebits
1639 flags can be modified and retrieved using the
1640 .BR prctl (2)
1641 .B PR_SET_SECUREBITS
1642 and
1643 .B PR_GET_SECUREBITS
1644 operations.
1645 The
1646 .B CAP_SETPCAP
1647 capability is required to modify the flags.
1648 Note that the
1649 .BR SECBIT_*
1650 constants are available only after including the
1651 .I <linux/securebits.h>
1652 header file.
1653 .PP
1654 The
1655 .I securebits
1656 flags are inherited by child processes.
1657 During an
1658 .BR execve (2),
1659 all of the flags are preserved, except
1660 .B SECBIT_KEEP_CAPS
1661 which is always cleared.
1662 .PP
1663 An application can use the following call to lock itself,
1664 and all of its descendants,
1665 into an environment where the only way of gaining capabilities
1666 is by executing a program with associated file capabilities:
1667 .PP
1668 .in +4n
1669 .EX
1670 prctl(PR_SET_SECUREBITS,
1671 /* SECBIT_KEEP_CAPS off */
1672 SECBIT_KEEP_CAPS_LOCKED |
1673 SECBIT_NO_SETUID_FIXUP |
1674 SECBIT_NO_SETUID_FIXUP_LOCKED |
1675 SECBIT_NOROOT |
1676 SECBIT_NOROOT_LOCKED);
1677 /* Setting/locking SECBIT_NO_CAP_AMBIENT_RAISE
1678 is not required */
1679 .EE
1680 .in
1681 .\"
1682 .\"
1683 .SS Per-user-namespace """set-user-ID-root""" programs
1684 A set-user-ID program whose UID matches the UID that
1685 created a user namespace will confer capabilities
1686 in the process's permitted and effective sets
1687 when executed by any process inside that namespace
1688 or any descendant user namespace.
1689 .PP
1690 The rules about the transformation of the process's capabilities during the
1691 .BR execve (2)
1692 are exactly as described in
1693 .I Transformation of capabilities during execve()
1694 and
1695 .I Capabilities and execution of programs by root
1696 above,
1697 with the difference that, in the latter subsection, "root"
1698 is the UID of the creator of the user namespace.
1699 .\"
1700 .\"
1701 .SS Namespaced file capabilities
1702 .\" commit 8db6c34f1dbc8e06aa016a9b829b06902c3e1340
1703 Traditional (i.e., version 2) file capabilities associate
1704 only a set of capability masks with a binary executable file.
1705 When a process executes a binary with such capabilities,
1706 it gains the associated capabilities (within its user namespace)
1707 as per the rules described in
1708 .I Transformation of capabilities during execve()
1709 above.
1710 .PP
1711 Because version 2 file capabilities confer capabilities to
1712 the executing process regardless of which user namespace it resides in,
1713 only privileged processes are permitted to associate capabilities with a file.
1714 Here, "privileged" means a process that has the
1715 .BR CAP_SETFCAP
1716 capability in the user namespace where the filesystem was mounted
1717 (normally the initial user namespace).
1718 This limitation renders file capabilities useless for certain use cases.
1719 For example, in user-namespaced containers,
1720 it can be desirable to be able to create a binary that
1721 confers capabilities only to processes executed inside that container,
1722 but not to processes that are executed outside the container.
1723 .PP
1724 Linux 4.14 added so-called namespaced file capabilities
1725 to support such use cases.
1726 Namespaced file capabilities are recorded as version 3 (i.e.,
1727 .BR VFS_CAP_REVISION_3 )
1728 .I security.capability
1729 extended attributes.
1730 Such an attribute is automatically created in the circumstances described
1731 in
1732 .I File capability extended attribute versioning
1733 above.
1734 When a version 3
1735 .I security.capability
1736 extended attribute is created,
1737 the kernel records not just the capability masks in the extended attribute,
1738 but also the namespace root user ID.
1739 .PP
1740 As with a binary that has
1741 .BR VFS_CAP_REVISION_2
1742 file capabilities, a binary with
1743 .BR VFS_CAP_REVISION_3
1744 file capabilities confers capabilities to a process during
1745 .BR execve ().
1746 However, capabilities are conferred only if the binary is executed by
1747 a process that resides in a user namespace whose
1748 UID 0 maps to the root user ID that is saved in the extended attribute,
1749 or when executed by a process that resides in a descendant of such a namespace.
1750 .\"
1751 .\"
1752 .SS Interaction with user namespaces
1753 For further information on the interaction of
1754 capabilities and user namespaces, see
1755 .BR user_namespaces (7).
1756 .SH CONFORMING TO
1757 No standards govern capabilities, but the Linux capability implementation
1758 is based on the withdrawn POSIX.1e draft standard; see
1759 .UR https://archive.org\:/details\:/posix_1003.1e-990310
1760 .UE .
1761 .SH NOTES
1762 When attempting to
1763 .BR strace (1)
1764 binaries that have capabilities (or set-user-ID-root binaries),
1765 you may find the
1766 .I \-u <username>
1767 option useful.
1768 Something like:
1769 .PP
1770 .in +4n
1771 .EX
1772 $ \fBsudo strace \-o trace.log \-u ceci ./myprivprog\fP
1773 .EE
1774 .in
1775 .PP
1776 From kernel 2.5.27 to kernel 2.6.26,
1777 .\" commit 5915eb53861c5776cfec33ca4fcc1fd20d66dd27 removed
1778 .\" CONFIG_SECURITY_CAPABILITIES
1779 capabilities were an optional kernel component,
1780 and could be enabled/disabled via the
1781 .B CONFIG_SECURITY_CAPABILITIES
1782 kernel configuration option.
1783 .PP
1784 The
1785 .I /proc/[pid]/task/TID/status
1786 file can be used to view the capability sets of a thread.
1787 The
1788 .I /proc/[pid]/status
1789 file shows the capability sets of a process's main thread.
1790 Before Linux 3.8, nonexistent capabilities were shown as being
1791 enabled (1) in these sets.
1792 Since Linux 3.8,
1793 .\" 7b9a7ec565505699f503b4fcf61500dceb36e744
1794 all nonexistent capabilities (above
1795 .BR CAP_LAST_CAP )
1796 are shown as disabled (0).
1797 .PP
1798 The
1799 .I libcap
1800 package provides a suite of routines for setting and
1801 getting capabilities that is more comfortable and less likely
1802 to change than the interface provided by
1803 .BR capset (2)
1804 and
1805 .BR capget (2).
1806 This package also provides the
1807 .BR setcap (8)
1808 and
1809 .BR getcap (8)
1810 programs.
1811 It can be found at
1812 .br
1813 .UR https://git.kernel.org\:/pub\:/scm\:/libs\:/libcap\:/libcap.git\:/refs/
1814 .UE .
1815 .PP
1816 Before kernel 2.6.24, and from kernel 2.6.24 to kernel 2.6.32 if
1817 file capabilities are not enabled, a thread with the
1818 .B CAP_SETPCAP
1819 capability can manipulate the capabilities of threads other than itself.
1820 However, this is only theoretically possible,
1821 since no thread ever has
1822 .BR CAP_SETPCAP
1823 in either of these cases:
1824 .IP * 2
1825 In the pre-2.6.25 implementation the system-wide capability bounding set,
1826 .IR /proc/sys/kernel/cap\-bound ,
1827 always masks out the
1828 .B CAP_SETPCAP
1829 capability, and this can not be changed
1830 without modifying the kernel source and rebuilding the kernel.
1831 .IP *
1832 If file capabilities are disabled (i.e., the kernel
1833 .B CONFIG_SECURITY_FILE_CAPABILITIES
1834 option is disabled), then
1835 .B init
1836 starts out with the
1837 .B CAP_SETPCAP
1838 capability removed from its per-process bounding
1839 set, and that bounding set is inherited by all other processes
1840 created on the system.
1841 .SH SEE ALSO
1842 .BR capsh (1),
1843 .BR setpriv (1),
1844 .BR prctl (2),
1845 .BR setfsuid (2),
1846 .BR cap_clear (3),
1847 .BR cap_copy_ext (3),
1848 .BR cap_from_text (3),
1849 .BR cap_get_file (3),
1850 .BR cap_get_proc (3),
1851 .BR cap_init (3),
1852 .BR capgetp (3),
1853 .BR capsetp (3),
1854 .BR libcap (3),
1855 .BR proc (5),
1856 .BR credentials (7),
1857 .BR pthreads (7),
1858 .BR user_namespaces (7),
1859 .BR captest (8), \" from libcap-ng
1860 .BR filecap (8), \" from libcap-ng
1861 .BR getcap (8),
1862 .BR getpcaps (8),
1863 .BR netcap (8), \" from libcap-ng
1864 .BR pscap (8), \" from libcap-ng
1865 .BR setcap (8)
1866 .PP
1867 .I include/linux/capability.h
1868 in the Linux kernel source tree