OSDN Git Service

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