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