OSDN Git Service

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