OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[linuxjm/LDP_man-pages.git] / original / 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 .\"
45 .TH CAPABILITIES 7 2010-01-31 "Linux" "Linux Programmer's Manual"
46 .SH NAME
47 capabilities \- overview of Linux capabilities
48 .SH DESCRIPTION
49 For the purpose of performing permission checks,
50 traditional Unix implementations distinguish two categories of processes:
51 .I privileged
52 processes (whose effective user ID is 0, referred to as superuser or root),
53 and
54 .I unprivileged
55 processes (whose effective UID is nonzero).
56 Privileged processes bypass all kernel permission checks,
57 while unprivileged processes are subject to full permission
58 checking based on the process's credentials
59 (usually: effective UID, effective GID, and supplementary group list).
60
61 Starting with kernel 2.2, Linux divides the privileges traditionally
62 associated with superuser into distinct units, known as
63 .IR capabilities ,
64 which can be independently enabled and disabled.
65 Capabilities are a per-thread attribute.
66 .\"
67 .SS Capabilities List
68 The following list shows the capabilities implemented on Linux,
69 and the operations or behaviors that each capability permits:
70 .TP
71 .BR CAP_AUDIT_CONTROL " (since Linux 2.6.11)"
72 Enable and disable kernel auditing; change auditing filter rules;
73 retrieve auditing status and filtering rules.
74 .TP
75 .BR CAP_AUDIT_WRITE " (since Linux 2.6.11)"
76 Write records to kernel auditing log.
77 .TP
78 .B CAP_CHOWN
79 Make arbitrary changes to file UIDs and GIDs (see
80 .BR chown (2)).
81 .TP
82 .B CAP_DAC_OVERRIDE
83 Bypass file read, write, and execute permission checks.
84 (DAC is an abbreviation of "discretionary access control".)
85 .TP
86 .B CAP_DAC_READ_SEARCH
87 Bypass file read permission checks and
88 directory read and execute permission checks.
89 .TP
90 .B CAP_FOWNER
91 .PD 0
92 .RS
93 .IP * 2
94 Bypass permission checks on operations that normally
95 require the file system UID of the process to match the UID of
96 the file (e.g.,
97 .BR chmod (2),
98 .BR utime (2)),
99 excluding those operations covered by
100 .B CAP_DAC_OVERRIDE
101 and
102 .BR CAP_DAC_READ_SEARCH ;
103 .IP *
104 set extended file attributes (see
105 .BR chattr (1))
106 on arbitrary files;
107 .IP *
108 set Access Control Lists (ACLs) on arbitrary files;
109 .IP *
110 ignore directory sticky bit on file deletion;
111 .IP *
112 specify
113 .B O_NOATIME
114 for arbitrary files in
115 .BR open (2)
116 and
117 .BR fcntl (2).
118 .RE
119 .PD
120 .TP
121 .B CAP_FSETID
122 Don't clear set-user-ID and set-group-ID permission
123 bits when a file is modified;
124 set the set-group-ID bit for a file whose GID does not match
125 the file system or any of the supplementary GIDs of the calling process.
126 .TP
127 .B CAP_IPC_LOCK
128 Lock memory
129 .RB ( mlock (2),
130 .BR mlockall (2),
131 .BR mmap (2),
132 .BR shmctl (2)).
133 .TP
134 .B CAP_IPC_OWNER
135 Bypass permission checks for operations on System V IPC objects.
136 .TP
137 .B CAP_KILL
138 Bypass permission checks for sending signals (see
139 .BR kill (2)).
140 This includes use of the
141 .BR ioctl (2)
142 .B KDSIGACCEPT
143 operation.
144 .\" FIXME CAP_KILL also has an effect for threads + setting child
145 .\"       termination signal to other than SIGCHLD: without this
146 .\"       capability, the termination signal reverts to SIGCHLD
147 .\"       if the child does an exec().  What is the rationale
148 .\"       for this?
149 .TP
150 .BR CAP_LEASE " (since Linux 2.4)"
151 Establish leases on arbitrary files (see
152 .BR fcntl (2)).
153 .TP
154 .B CAP_LINUX_IMMUTABLE
155 Set the
156 .B FS_APPEND_FL
157 and
158 .B FS_IMMUTABLE_FL
159 .\" These attributes are now available on ext2, ext3, Reiserfs, XFS, JFS
160 i-node flags (see
161 .BR chattr (1)).
162 .TP
163 .BR CAP_MAC_ADMIN " (since Linux 2.6.25)"
164 Override Mandatory Access Control (MAC).
165 Implemented for the Smack Linux Security Module (LSM).
166 .TP
167 .BR CAP_MAC_OVERRIDE " (since Linux 2.6.25)"
168 Allow MAC configuration or state changes.
169 Implemented for the Smack LSM.
170 .TP
171 .BR CAP_MKNOD " (since Linux 2.4)"
172 Create special files using
173 .BR mknod (2).
174 .TP
175 .B CAP_NET_ADMIN
176 Perform various network-related operations
177 (e.g., setting privileged socket options,
178 enabling multicasting, interface configuration,
179 modifying routing tables).
180 .TP
181 .B CAP_NET_BIND_SERVICE
182 Bind a socket to Internet domain privileged ports
183 (port numbers less than 1024).
184 .TP
185 .B CAP_NET_BROADCAST
186 (Unused)  Make socket broadcasts, and listen to multicasts.
187 .TP
188 .B CAP_NET_RAW
189 Use RAW and PACKET sockets.
190 .\" Also various IP options and setsockopt(SO_BINDTODEVICE)
191 .TP
192 .B CAP_SETGID
193 Make arbitrary manipulations of process GIDs and supplementary GID list;
194 forge GID when passing socket credentials via Unix domain sockets.
195 .TP
196 .BR CAP_SETFCAP " (since Linux 2.6.24)"
197 Set file capabilities.
198 .TP
199 .B CAP_SETPCAP
200 If file capabilities are not supported:
201 grant or remove any capability in the
202 caller's permitted capability set to or from any other process.
203 (This property of
204 .B CAP_SETPCAP
205 is not available when the kernel is configured to support
206 file capabilities, since
207 .B CAP_SETPCAP
208 has entirely different semantics for such kernels.)
209
210 If file capabilities are supported:
211 add any capability from the calling thread's bounding set
212 to its inheritable set;
213 drop capabilities from the bounding set (via
214 .BR prctl (2)
215 .BR PR_CAPBSET_DROP );
216 make changes to the
217 .I securebits
218 flags.
219 .TP
220 .B CAP_SETUID
221 Make arbitrary manipulations of process UIDs
222 .RB ( setuid (2),
223 .BR setreuid (2),
224 .BR setresuid (2),
225 .BR setfsuid (2));
226 make forged UID when passing socket credentials via Unix domain sockets.
227 .\" FIXME CAP_SETUID also an effect in exec(); document this.
228 .TP
229 .B CAP_SYS_ADMIN
230 .PD 0
231 .RS
232 .IP * 2
233 Perform a range of system administration operations including:
234 .BR quotactl (2),
235 .BR mount (2),
236 .BR umount (2),
237 .BR swapon (2),
238 .BR swapoff (2),
239 .BR sethostname (2),
240 and
241 .BR setdomainname (2);
242 .IP *
243 perform
244 .B IPC_SET
245 and
246 .B IPC_RMID
247 operations on arbitrary System V IPC objects;
248 .IP *
249 perform operations on
250 .I trusted
251 and
252 .I security
253 Extended Attributes (see
254 .BR attr (5));
255 .IP *
256 use
257 .BR lookup_dcookie (2);
258 .IP *
259 use
260 .BR ioprio_set (2)
261 to assign
262 .B IOPRIO_CLASS_RT
263 and (before Linux 2.6.25)
264 .B IOPRIO_CLASS_IDLE
265 I/O scheduling classes;
266 .IP *
267 forge UID when passing socket credentials;
268 .IP *
269 exceed
270 .IR /proc/sys/fs/file-max ,
271 the system-wide limit on the number of open files,
272 in system calls that open files (e.g.,
273 .BR accept (2),
274 .BR execve (2),
275 .BR open (2),
276 .BR pipe (2));
277 .IP *
278 employ
279 .B CLONE_NEWNS
280 flag with
281 .BR clone (2)
282 and
283 .BR unshare (2);
284 .IP *
285 perform
286 .B KEYCTL_CHOWN
287 and
288 .B KEYCTL_SETPERM
289 .BR keyctl (2)
290 operations.
291 .RE
292 .PD
293 .TP
294 .B CAP_SYS_BOOT
295 Use
296 .BR reboot (2)
297 and
298 .BR kexec_load (2).
299 .TP
300 .B CAP_SYS_CHROOT
301 Use
302 .BR chroot (2).
303 .TP
304 .B CAP_SYS_MODULE
305 Load and unload kernel modules
306 (see
307 .BR init_module (2)
308 and
309 .BR delete_module (2));
310 in kernels before 2.6.25:
311 drop capabilities from the system-wide capability bounding set.
312 .TP
313 .B CAP_SYS_NICE
314 .PD 0
315 .RS
316 .IP * 2
317 Raise process nice value
318 .RB ( nice (2),
319 .BR setpriority (2))
320 and change the nice value for arbitrary processes;
321 .IP *
322 set real-time scheduling policies for calling process,
323 and set scheduling policies and priorities for arbitrary processes
324 .RB ( sched_setscheduler (2),
325 .BR sched_setparam (2));
326 .IP *
327 set CPU affinity for arbitrary processes
328 .RB ( sched_setaffinity (2));
329 .IP *
330 set I/O scheduling class and priority for arbitrary processes
331 .RB ( ioprio_set (2));
332 .IP *
333 apply
334 .BR migrate_pages (2)
335 to arbitrary processes and allow processes
336 to be migrated to arbitrary nodes;
337 .\" FIXME CAP_SYS_NICE also has the following effect for
338 .\" migrate_pages(2):
339 .\"     do_migrate_pages(mm, &old, &new,
340 .\"         capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
341 .IP *
342 apply
343 .BR move_pages (2)
344 to arbitrary processes;
345 .IP *
346 use the
347 .B MPOL_MF_MOVE_ALL
348 flag with
349 .BR mbind (2)
350 and
351 .BR move_pages (2).
352 .RE
353 .PD
354 .TP
355 .B CAP_SYS_PACCT
356 Use
357 .BR acct (2).
358 .TP
359 .B CAP_SYS_PTRACE
360 Trace arbitrary processes using
361 .BR ptrace (2)
362 .TP
363 .B CAP_SYS_RAWIO
364 Perform I/O port operations
365 .RB ( iopl (2)
366 and
367 .BR ioperm (2));
368 access
369 .IR /proc/kcore .
370 .TP
371 .B CAP_SYS_RESOURCE
372 .PD 0
373 .RS
374 .IP * 2
375 Use reserved space on ext2 file systems;
376 .IP *
377 make
378 .BR ioctl (2)
379 calls controlling ext3 journaling;
380 .IP *
381 override disk quota limits;
382 .IP *
383 increase resource limits (see
384 .BR setrlimit (2));
385 .IP *
386 override
387 .B RLIMIT_NPROC
388 resource limit;
389 .IP *
390 raise
391 .I msg_qbytes
392 limit for a System V message queue above the limit in
393 .I /proc/sys/kernel/msgmnb
394 (see
395 .BR msgop (2)
396 and
397 .BR msgctl (2)).
398 .RE
399 .PD
400 .TP
401 .B CAP_SYS_TIME
402 Set system clock
403 .RB ( settimeofday (2),
404 .BR stime (2),
405 .BR adjtimex (2));
406 set real-time (hardware) clock.
407 .TP
408 .B CAP_SYS_TTY_CONFIG
409 Use
410 .BR vhangup (2).
411 .\"
412 .SS Past and Current Implementation
413 A full implementation of capabilities requires that:
414 .IP 1. 3
415 For all privileged operations,
416 the kernel must check whether the thread has the required
417 capability in its effective set.
418 .IP 2.
419 The kernel must provide system calls allowing a thread's capability sets to
420 be changed and retrieved.
421 .IP 3.
422 The file system must support attaching capabilities to an executable file,
423 so that a process gains those capabilities when the file is executed.
424 .PP
425 Before kernel 2.6.24, only the first two of these requirements are met;
426 since kernel 2.6.24, all three requirements are met.
427 .\"
428 .SS Thread Capability Sets
429 Each thread has three capability sets containing zero or more
430 of the above capabilities:
431 .TP
432 .IR Permitted :
433 This is a limiting superset for the effective
434 capabilities that the thread may assume.
435 It is also a limiting superset for the capabilities that
436 may be added to the inheritable set by a thread that does not have the
437 .B CAP_SETPCAP
438 capability in its effective set.
439
440 If a thread drops a capability from its permitted set,
441 it can never reacquire that capability (unless it
442 .BR execve (2)s
443 either a set-user-ID-root program, or
444 a program whose associated file capabilities grant that capability).
445 .TP
446 .IR Inheritable :
447 This is a set of capabilities preserved across an
448 .BR execve (2).
449 It provides a mechanism for a process to assign capabilities
450 to the permitted set of the new program during an
451 .BR execve (2).
452 .TP
453 .IR Effective :
454 This is the set of capabilities used by the kernel to
455 perform permission checks for the thread.
456 .PP
457 A child created via
458 .BR fork (2)
459 inherits copies of its parent's capability sets.
460 See below for a discussion of the treatment of capabilities during
461 .BR execve (2).
462 .PP
463 Using
464 .BR capset (2),
465 a thread may manipulate its own capability sets (see below).
466 .\"
467 .SS File Capabilities
468 Since kernel 2.6.24, the kernel supports
469 associating capability sets with an executable file using
470 .BR setcap (8).
471 The file capability sets are stored in an extended attribute (see
472 .BR setxattr (2))
473 named
474 .IR "security.capability" .
475 Writing to this extended attribute requires the
476 .BR CAP_SETFCAP
477 capability.
478 The file capability sets,
479 in conjunction with the capability sets of the thread,
480 determine the capabilities of a thread after an
481 .BR execve (2).
482
483 The three file capability sets are:
484 .TP
485 .IR Permitted " (formerly known as " forced ):
486 These capabilities are automatically permitted to the thread,
487 regardless of the thread's inheritable capabilities.
488 .TP
489 .IR Inheritable " (formerly known as " allowed ):
490 This set is ANDed with the thread's inheritable set to determine which
491 inheritable capabilities are enabled in the permitted set of
492 the thread after the
493 .BR execve (2).
494 .TP
495 .IR Effective :
496 This is not a set, but rather just a single bit.
497 If this bit is set, then during an
498 .BR execve (2)
499 all of the new permitted capabilities for the thread are
500 also raised in the effective set.
501 If this bit is not set, then after an
502 .BR execve (2),
503 none of the new permitted capabilities is in the new effective set.
504
505 Enabling the file effective capability bit implies
506 that any file permitted or inheritable capability that causes a
507 thread to acquire the corresponding permitted capability during an
508 .BR execve (2)
509 (see the transformation rules described below) will also acquire that
510 capability in its effective set.
511 Therefore, when assigning capabilities to a file
512 .RB ( setcap (8),
513 .BR cap_set_file (3),
514 .BR cap_set_fd (3)),
515 if we specify the effective flag as being enabled for any capability,
516 then the effective flag must also be specified as enabled
517 for all other capabilities for which the corresponding permitted or
518 inheritable flags is enabled.
519 .\"
520 .SS Transformation of Capabilities During execve()
521 .PP
522 During an
523 .BR execve (2),
524 the kernel calculates the new capabilities of
525 the process using the following algorithm:
526 .in +4n
527 .nf
528
529 P'(permitted) = (P(inheritable) & F(inheritable)) |
530                 (F(permitted) & cap_bset)
531
532 P'(effective) = F(effective) ? P'(permitted) : 0
533
534 P'(inheritable) = P(inheritable)    [i.e., unchanged]
535
536 .fi
537 .in
538 where:
539 .RS 4
540 .IP P 10
541 denotes the value of a thread capability set before the
542 .BR execve (2)
543 .IP P'
544 denotes the value of a capability set after the
545 .BR execve (2)
546 .IP F
547 denotes a file capability set
548 .IP cap_bset
549 is the value of the capability bounding set (described below).
550 .RE
551 .\"
552 .SS Capabilities and execution of programs by root
553 In order to provide an all-powerful
554 .I root
555 using capability sets, during an
556 .BR execve (2):
557 .IP 1. 3
558 If a set-user-ID-root program is being executed,
559 or the real user ID of the process is 0 (root)
560 then the file inheritable and permitted sets are defined to be all ones
561 (i.e., all capabilities enabled).
562 .IP 2.
563 If a set-user-ID-root program is being executed,
564 then the file effective bit is defined to be one (enabled).
565 .PP
566 The upshot of the above rules,
567 combined with the capabilities transformations described above,
568 is that when a process
569 .BR execve (2)s
570 a set-user-ID-root program, or when a process with an effective UID of 0
571 .BR execve (2)s
572 a program,
573 it gains all capabilities in its permitted and effective capability sets,
574 except those masked out by the capability bounding set.
575 .\" If a process with real UID 0, and nonzero effective UID does an
576 .\" exec(), then it gets all capabilities in its
577 .\" permitted set, and no effective capabilities
578 This provides semantics that are the same as those provided by
579 traditional Unix systems.
580 .SS Capability bounding set
581 The capability bounding set is a security mechanism that can be used
582 to limit the capabilities that can be gained during an
583 .BR execve (2).
584 The bounding set is used in the following ways:
585 .IP * 2
586 During an
587 .BR execve (2),
588 the capability bounding set is ANDed with the file permitted
589 capability set, and the result of this operation is assigned to the
590 thread's permitted capability set.
591 The capability bounding set thus places a limit on the permitted
592 capabilities that may be granted by an executable file.
593 .IP *
594 (Since Linux 2.6.25)
595 The capability bounding set acts as a limiting superset for
596 the capabilities that a thread can add to its inheritable set using
597 .BR capset (2).
598 This means that if a capability is not in the bounding set,
599 then a thread can't add this capability to its
600 inheritable set, even if it was in its permitted capabilities,
601 and thereby cannot have this capability preserved in its
602 permitted set when it
603 .BR execve (2)s
604 a file that has the capability in its inheritable set.
605 .PP
606 Note that the bounding set masks the file permitted capabilities,
607 but not the inherited capabilities.
608 If a thread maintains a capability in its inherited set
609 that is not in its bounding set,
610 then it can still gain that capability in its permitted set
611 by executing a file that has the capability in its inherited set.
612 .PP
613 Depending on the kernel version, the capability bounding set is either
614 a system-wide attribute, or a per-process attribute.
615 .PP
616 .B "Capability bounding set prior to Linux 2.6.25"
617 .PP
618 In kernels before 2.6.25, the capability bounding set is a system-wide
619 attribute that affects all threads on the system.
620 The bounding set is accessible via the file
621 .IR /proc/sys/kernel/cap-bound .
622 (Confusingly, this bit mask parameter is expressed as a
623 signed decimal number in
624 .IR /proc/sys/kernel/cap-bound .)
625
626 Only the
627 .B init
628 process may set capabilities in the capability bounding set;
629 other than that, the superuser (more precisely: programs with the
630 .B CAP_SYS_MODULE
631 capability) may only clear capabilities from this set.
632
633 On a standard system the capability bounding set always masks out the
634 .B CAP_SETPCAP
635 capability.
636 To remove this restriction (dangerous!), modify the definition of
637 .B CAP_INIT_EFF_SET
638 in
639 .I include/linux/capability.h
640 and rebuild the kernel.
641
642 The system-wide capability bounding set feature was added
643 to Linux starting with kernel version 2.2.11.
644 .\"
645 .PP
646 .B "Capability bounding set from Linux 2.6.25 onwards"
647 .PP
648 From Linux 2.6.25, the
649 .I "capability bounding set"
650 is a per-thread attribute.
651 (There is no longer a system-wide capability bounding set.)
652
653 The bounding set is inherited at
654 .BR fork (2)
655 from the thread's parent, and is preserved across an
656 .BR execve (2).
657
658 A thread may remove capabilities from its capability bounding set using the
659 .BR prctl (2)
660 .B PR_CAPBSET_DROP
661 operation, provided it has the
662 .B CAP_SETPCAP
663 capability.
664 Once a capability has been dropped from the bounding set,
665 it cannot be restored to that set.
666 A thread can determine if a capability is in its bounding set using the
667 .BR prctl (2)
668 .B PR_CAPBSET_READ
669 operation.
670
671 Removing capabilities from the bounding set is only supported if file
672 capabilities are compiled into the kernel
673 (CONFIG_SECURITY_FILE_CAPABILITIES).
674 In that case, the
675 .B init
676 process (the ancestor of all processes) begins with a full bounding set.
677 If file capabilities are not compiled into the kernel, then
678 .B init
679 begins with a full bounding set minus
680 .BR CAP_SETPCAP ,
681 because this capability has a different meaning when there are
682 no file capabilities.
683
684 Removing a capability from the bounding set does not remove it
685 from the thread's inherited set.
686 However it does prevent the capability from being added
687 back into the thread's inherited set in the future.
688 .\"
689 .\"
690 .SS Effect of User ID Changes on Capabilities
691 To preserve the traditional semantics for transitions between
692 0 and nonzero user IDs,
693 the kernel makes the following changes to a thread's capability
694 sets on changes to the thread's real, effective, saved set,
695 and file system user IDs (using
696 .BR setuid (2),
697 .BR setresuid (2),
698 or similar):
699 .IP 1. 3
700 If one or more of the real, effective or saved set user IDs
701 was previously 0, and as a result of the UID changes all of these IDs
702 have a nonzero value,
703 then all capabilities are cleared from the permitted and effective
704 capability sets.
705 .IP 2.
706 If the effective user ID is changed from 0 to nonzero,
707 then all capabilities are cleared from the effective set.
708 .IP 3.
709 If the effective user ID is changed from nonzero to 0,
710 then the permitted set is copied to the effective set.
711 .IP 4.
712 If the file system user ID is changed from 0 to nonzero (see
713 .BR setfsuid (2))
714 then the following capabilities are cleared from the effective set:
715 .BR CAP_CHOWN ,
716 .BR CAP_DAC_OVERRIDE ,
717 .BR CAP_DAC_READ_SEARCH ,
718 .BR CAP_FOWNER ,
719 .BR CAP_FSETID ,
720 .B CAP_LINUX_IMMUTABLE
721 (since Linux 2.2.30),
722 .BR CAP_MAC_OVERRIDE ,
723 and
724 .B CAP_MKNOD
725 (since Linux 2.2.30).
726 If the file system UID is changed from nonzero to 0,
727 then any of these capabilities that are enabled in the permitted set
728 are enabled in the effective set.
729 .PP
730 If a thread that has a 0 value for one or more of its user IDs wants
731 to prevent its permitted capability set being cleared when it resets
732 all of its user IDs to nonzero values, it can do so using the
733 .BR prctl (2)
734 .B PR_SET_KEEPCAPS
735 operation.
736 .\"
737 .SS Programmatically adjusting capability sets
738 A thread can retrieve and change its capability sets using the
739 .BR capget (2)
740 and
741 .BR capset (2)
742 system calls.
743 However, the use of
744 .BR cap_get_proc (3)
745 and
746 .BR cap_set_proc (3),
747 both provided in the
748 .I libcap
749 package,
750 is preferred for this purpose.
751 The following rules govern changes to the thread capability sets:
752 .IP 1. 3
753 If the caller does not have the
754 .B CAP_SETPCAP
755 capability,
756 the new inheritable set must be a subset of the combination
757 of the existing inheritable and permitted sets.
758 .IP 2.
759 (Since kernel 2.6.25)
760 The new inheritable set must be a subset of the combination of the
761 existing inheritable set and the capability bounding set.
762 .IP 3.
763 The new permitted set must be a subset of the existing permitted set
764 (i.e., it is not possible to acquire permitted capabilities
765 that the thread does not currently have).
766 .IP 4.
767 The new effective set must be a subset of the new permitted set.
768 .SS The """securebits"" flags: establishing a capabilities-only environment
769 .\" For some background:
770 .\"       see http://lwn.net/Articles/280279/ and
771 .\"       http://article.gmane.org/gmane.linux.kernel.lsm/5476/
772 Starting with kernel 2.6.26,
773 and with a kernel in which file capabilities are enabled,
774 Linux implements a set of per-thread
775 .I securebits
776 flags that can be used to disable special handling of capabilities for UID 0
777 .RI ( root ).
778 These flags are as follows:
779 .TP
780 .B SECBIT_KEEP_CAPS
781 Setting this flag allows a thread that has one or more 0 UIDs to retain
782 its capabilities when it switches all of its UIDs to a nonzero value.
783 If this flag is not set,
784 then such a UID switch causes the thread to lose all capabilities.
785 This flag is always cleared on an
786 .BR execve (2).
787 (This flag provides the same functionality as the older
788 .BR prctl (2)
789 .B PR_SET_KEEPCAPS
790 operation.)
791 .TP
792 .B SECBIT_NO_SETUID_FIXUP
793 Setting this flag stops the kernel from adjusting  capability sets when
794 the threads's effective and file system UIDs are switched between
795 zero and nonzero values.
796 (See the subsection
797 .IR "Effect of User ID Changes on Capabilities" .)
798 .TP
799 .B SECBIT_NOROOT
800 If this bit is set, then the kernel does not grant capabilities
801 when a set-user-ID-root program is executed, or when a process with
802 an effective or real UID of 0 calls
803 .BR execve (2).
804 (See the subsection
805 .IR "Capabilities and execution of programs by root" .)
806 .PP
807 Each of the above "base" flags has a companion "locked" flag.
808 Setting any of the "locked" flags is irreversible,
809 and has the effect of preventing further changes to the
810 corresponding "base" flag.
811 The locked flags are:
812 .BR SECBIT_KEEP_CAPS_LOCKED ,
813 .BR SECBIT_NO_SETUID_FIXUP_LOCKED ,
814 and
815 .BR SECBIT_NOROOT_LOCKED .
816 .PP
817 The
818 .I securebits
819 flags can be modified and retrieved using the
820 .BR prctl (2)
821 .B PR_SET_SECUREBITS
822 and
823 .B PR_GET_SECUREBITS
824 operations.
825 The
826 .B CAP_SETPCAP
827 capability is required to modify the flags.
828
829 The
830 .I securebits
831 flags are inherited by child processes.
832 During an
833 .BR execve (2),
834 all of the flags are preserved, except
835 .B SECURE_KEEP_CAPS
836 which is always cleared.
837
838 An application can use the following call to lock itself,
839 and all of its descendants,
840 into an environment where the only way of gaining capabilities
841 is by executing a program with associated file capabilities:
842 .in +4n
843 .nf
844
845 prctl(PR_SET_SECUREBITS,
846         SECBIT_KEEP_CAPS_LOCKED |
847         SECBIT_NO_SETUID_FIXUP |
848         SECBIT_NO_SETUID_FIXUP_LOCKED |
849         SECBIT_NOROOT |
850         SECBIT_NOROOT_LOCKED);
851 .fi
852 .in
853 .SH "CONFORMING TO"
854 .PP
855 No standards govern capabilities, but the Linux capability implementation
856 is based on the withdrawn POSIX.1e draft standard; see
857 .IR http://wt.xpilot.org/publications/posix.1e/ .
858 .SH NOTES
859 Since kernel 2.5.27, capabilities are an optional kernel component,
860 and can be enabled/disabled via the CONFIG_SECURITY_CAPABILITIES
861 kernel configuration option.
862
863 The
864 .I /proc/PID/task/TID/status
865 file can be used to view the capability sets of a thread.
866 The
867 .I /proc/PID/status
868 file shows the capability sets of a process's main thread.
869
870 The
871 .I libcap
872 package provides a suite of routines for setting and
873 getting capabilities that is more comfortable and less likely
874 to change than the interface provided by
875 .BR capset (2)
876 and
877 .BR capget (2).
878 This package also provides the
879 .BR setcap (8)
880 and
881 .BR getcap (8)
882 programs.
883 It can be found at
884 .br
885 .IR http://www.kernel.org/pub/linux/libs/security/linux-privs .
886
887 Before kernel 2.6.24, and since kernel 2.6.24 if
888 file capabilities are not enabled, a thread with the
889 .B CAP_SETPCAP
890 capability can manipulate the capabilities of threads other than itself.
891 However, this is only theoretically possible,
892 since no thread ever has
893 .BR CAP_SETPCAP
894 in either of these cases:
895 .IP * 2
896 In the pre-2.6.25 implementation the system-wide capability bounding set,
897 .IR /proc/sys/kernel/cap-bound ,
898 always masks out this capability, and this can not be changed
899 without modifying the kernel source and rebuilding.
900 .IP *
901 If file capabilities are disabled in the current implementation, then
902 .B init
903 starts out with this capability removed from its per-process bounding
904 set, and that bounding set is inherited by all other processes
905 created on the system.
906 .SH "SEE ALSO"
907 .BR capget (2),
908 .BR prctl (2),
909 .BR setfsuid (2),
910 .BR cap_clear (3),
911 .BR cap_copy_ext (3),
912 .BR cap_from_text (3),
913 .BR cap_get_file (3),
914 .BR cap_get_proc (3),
915 .BR cap_init (3),
916 .BR capgetp (3),
917 .BR capsetp (3),
918 .BR credentials (7),
919 .BR pthreads (7),
920 .BR getcap (8),
921 .BR setcap (8)
922 .PP
923 .I include/linux/capability.h
924 in the kernel source