]>
Commit | Line | Data |
---|---|---|
c11b1abf | 1 | .\" Copyright (c) 2002 by Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 2 | .\" |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
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 | |
10d76543 MK |
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. | |
fea681da MK |
20 | .\" |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by | |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
fea681da MK |
24 | .\" |
25 | .\" 6 Aug 2002 - Initial Creation | |
c11b1abf MK |
26 | .\" Modified 2003-05-23, Michael Kerrisk, <mtk.manpages@gmail.com> |
27 | .\" Modified 2004-05-27, Michael Kerrisk, <mtk.manpages@gmail.com> | |
1c1e15ed | 28 | .\" 2004-12-08, mtk Added O_NOATIME for CAP_FOWNER |
5eaee3d9 | 29 | .\" 2005-08-16, mtk, Added CAP_AUDIT_CONTROL and CAP_AUDIT_WRITE |
c8e68512 MK |
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. | |
bfb730f9 | 46 | .\" 2011-09-07, mtk/Serge hallyn: Add CAP_SYSLOG |
5eaee3d9 | 47 | .\" |
9ba01802 | 48 | .TH CAPABILITIES 7 2019-03-06 "Linux" "Linux Programmer's Manual" |
fea681da MK |
49 | .SH NAME |
50 | capabilities \- overview of Linux capabilities | |
51 | .SH DESCRIPTION | |
fea681da | 52 | For the purpose of performing permission checks, |
008f1ecc | 53 | traditional UNIX implementations distinguish two categories of processes: |
fea681da MK |
54 | .I privileged |
55 | processes (whose effective user ID is 0, referred to as superuser or root), | |
56 | and | |
57 | .I unprivileged | |
c7094399 | 58 | processes (whose effective UID is nonzero). |
fea681da MK |
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). | |
ade303d7 | 63 | .PP |
c13182ef MK |
64 | Starting with kernel 2.2, Linux divides the privileges traditionally |
65 | associated with superuser into distinct units, known as | |
fea681da | 66 | .IR capabilities , |
3dfe7e0d | 67 | which can be independently enabled and disabled. |
cf7a13d4 | 68 | Capabilities are a per-thread attribute. |
c8e68512 | 69 | .\" |
c634028a | 70 | .SS Capabilities list |
c8e68512 MK |
71 | The following list shows the capabilities implemented on Linux, |
72 | and the operations or behaviors that each capability permits: | |
fea681da | 73 | .TP |
45286787 | 74 | .BR CAP_AUDIT_CONTROL " (since Linux 2.6.11)" |
5eaee3d9 MK |
75 | Enable and disable kernel auditing; change auditing filter rules; |
76 | retrieve auditing status and filtering rules. | |
77 | .TP | |
c81cea2c MK |
78 | .BR CAP_AUDIT_READ " (since Linux 3.16)" |
79 | .\" commit a29b694aa1739f9d76538e34ae25524f9c549d59 | |
80 | .\" commit 3a101b8de0d39403b2c7e5c23fd0b005668acf48 | |
81 | Allow reading the audit log via a multicast netlink socket. | |
82 | .TP | |
45286787 | 83 | .BR CAP_AUDIT_WRITE " (since Linux 2.6.11)" |
c8e68512 | 84 | Write records to kernel auditing log. |
dd61e8a8 | 85 | .\" FIXME Add FAN_ENABLE_AUDIT |
5eaee3d9 | 86 | .TP |
9339d749 MK |
87 | .BR CAP_BLOCK_SUSPEND " (since Linux 3.5)" |
88 | Employ features that can block system suspend | |
89 | .RB ( epoll (7) | |
90 | .BR EPOLLWAKEUP , | |
91 | .IR /proc/sys/wake_lock ). | |
92 | .TP | |
fea681da | 93 | .B CAP_CHOWN |
c8e68512 | 94 | Make arbitrary changes to file UIDs and GIDs (see |
fea681da MK |
95 | .BR chown (2)). |
96 | .TP | |
97 | .B CAP_DAC_OVERRIDE | |
98 | Bypass file read, write, and execute permission checks. | |
c8e68512 | 99 | (DAC is an abbreviation of "discretionary access control".) |
fea681da MK |
100 | .TP |
101 | .B CAP_DAC_READ_SEARCH | |
a537062e MK |
102 | .PD 0 |
103 | .RS | |
104 | .IP * 2 | |
fea681da | 105 | Bypass file read permission checks and |
a537062e MK |
106 | directory read and execute permission checks; |
107 | .IP * | |
3bbab71a | 108 | invoke |
24ee13df MK |
109 | .BR open_by_handle_at (2); |
110 | .IP * | |
111 | use the | |
112 | .BR linkat (2) | |
113 | .B AT_EMPTY_PATH | |
114 | flag to create a link to a file referred to by a file descriptor. | |
a537062e MK |
115 | .RE |
116 | .PD | |
fea681da MK |
117 | .TP |
118 | .B CAP_FOWNER | |
c8e68512 MK |
119 | .PD 0 |
120 | .RS | |
121 | .IP * 2 | |
fea681da | 122 | Bypass permission checks on operations that normally |
9ee4a2b6 | 123 | require the filesystem UID of the process to match the UID of |
fea681da MK |
124 | the file (e.g., |
125 | .BR chmod (2), | |
126 | .BR utime (2)), | |
c8e68512 | 127 | excluding those operations covered by |
fea681da MK |
128 | .B CAP_DAC_OVERRIDE |
129 | and | |
130 | .BR CAP_DAC_READ_SEARCH ; | |
c8e68512 | 131 | .IP * |
1dc9bca6 MK |
132 | set inode flags (see |
133 | .BR ioctl_iflags (2)) | |
fea681da | 134 | on arbitrary files; |
c8e68512 | 135 | .IP * |
fea681da | 136 | set Access Control Lists (ACLs) on arbitrary files; |
c8e68512 | 137 | .IP * |
1c1e15ed | 138 | ignore directory sticky bit on file deletion; |
c8e68512 | 139 | .IP * |
1c1e15ed MK |
140 | specify |
141 | .B O_NOATIME | |
142 | for arbitrary files in | |
143 | .BR open (2) | |
144 | and | |
145 | .BR fcntl (2). | |
c8e68512 MK |
146 | .RE |
147 | .PD | |
fea681da MK |
148 | .TP |
149 | .B CAP_FSETID | |
3bbab71a MK |
150 | .PD 0 |
151 | .RS | |
152 | .IP * 2 | |
ed948c28 | 153 | Don't clear set-user-ID and set-group-ID mode |
c8e68512 | 154 | bits when a file is modified; |
3bbab71a | 155 | .IP * |
c8e68512 | 156 | set the set-group-ID bit for a file whose GID does not match |
9ee4a2b6 | 157 | the filesystem or any of the supplementary GIDs of the calling process. |
3bbab71a MK |
158 | .RE |
159 | .PD | |
fea681da MK |
160 | .TP |
161 | .B CAP_IPC_LOCK | |
bea08fec | 162 | .\" FIXME . As at Linux 3.2, there are some strange uses of this capability |
46c73a44 | 163 | .\" in other places; they probably should be replaced with something else. |
c8e68512 | 164 | Lock memory |
fea681da MK |
165 | .RB ( mlock (2), |
166 | .BR mlockall (2), | |
167 | .BR mmap (2), | |
168 | .BR shmctl (2)). | |
169 | .TP | |
170 | .B CAP_IPC_OWNER | |
171 | Bypass permission checks for operations on System V IPC objects. | |
172 | .TP | |
173 | .B CAP_KILL | |
174 | Bypass permission checks for sending signals (see | |
175 | .BR kill (2)). | |
097585ed | 176 | This includes use of the |
c8e68512 | 177 | .BR ioctl (2) |
097585ed | 178 | .B KDSIGACCEPT |
c8e68512 | 179 | operation. |
bea08fec | 180 | .\" FIXME . CAP_KILL also has an effect for threads + setting child |
a7c1e564 MK |
181 | .\" termination signal to other than SIGCHLD: without this |
182 | .\" capability, the termination signal reverts to SIGCHLD | |
c13182ef | 183 | .\" if the child does an exec(). What is the rationale |
a7c1e564 | 184 | .\" for this? |
fea681da | 185 | .TP |
c8e68512 MK |
186 | .BR CAP_LEASE " (since Linux 2.4)" |
187 | Establish leases on arbitrary files (see | |
fea681da MK |
188 | .BR fcntl (2)). |
189 | .TP | |
190 | .B CAP_LINUX_IMMUTABLE | |
c8e68512 MK |
191 | Set the |
192 | .B FS_APPEND_FL | |
fea681da | 193 | and |
c8e68512 | 194 | .B FS_IMMUTABLE_FL |
e7e006f2 | 195 | inode flags (see |
1dc9bca6 | 196 | .BR ioctl_iflags (2)). |
fea681da | 197 | .TP |
c8e68512 | 198 | .BR CAP_MAC_ADMIN " (since Linux 2.6.25)" |
7f82d0b0 | 199 | Allow MAC configuration or state changes. |
c8e68512 MK |
200 | Implemented for the Smack Linux Security Module (LSM). |
201 | .TP | |
202 | .BR CAP_MAC_OVERRIDE " (since Linux 2.6.25)" | |
7f82d0b0 | 203 | Override Mandatory Access Control (MAC). |
c8e68512 MK |
204 | Implemented for the Smack LSM. |
205 | .TP | |
206 | .BR CAP_MKNOD " (since Linux 2.4)" | |
207 | Create special files using | |
fea681da MK |
208 | .BR mknod (2). |
209 | .TP | |
210 | .B CAP_NET_ADMIN | |
e87268ec MK |
211 | Perform various network-related operations: |
212 | .PD 0 | |
213 | .RS | |
214 | .IP * 2 | |
215 | interface configuration; | |
216 | .IP * | |
12fe8fd3 | 217 | administration of IP firewall, masquerading, and accounting; |
e87268ec MK |
218 | .IP * |
219 | modify routing tables; | |
220 | .IP * | |
221 | bind to any address for transparent proxying; | |
222 | .IP * | |
223 | set type-of-service (TOS) | |
224 | .IP * | |
225 | clear driver statistics; | |
226 | .IP * | |
227 | set promiscuous mode; | |
228 | .IP * | |
229 | enabling multicasting; | |
230 | .IP * | |
231 | use | |
232 | .BR setsockopt (2) | |
233 | to set the following socket options: | |
234 | .BR SO_DEBUG , | |
235 | .BR SO_MARK , | |
236 | .BR SO_PRIORITY | |
237 | (for a priority outside the range 0 to 6), | |
238 | .BR SO_RCVBUFFORCE , | |
239 | and | |
240 | .BR SO_SNDBUFFORCE . | |
241 | .RE | |
242 | .PD | |
fea681da MK |
243 | .TP |
244 | .B CAP_NET_BIND_SERVICE | |
6eb334b2 | 245 | Bind a socket to Internet domain privileged ports |
fea681da MK |
246 | (port numbers less than 1024). |
247 | .TP | |
248 | .B CAP_NET_BROADCAST | |
c8e68512 | 249 | (Unused) Make socket broadcasts, and listen to multicasts. |
fd39ef0c MK |
250 | .\" FIXME Since Linux 4.2, there are use cases for netlink sockets |
251 | .\" commit 59324cf35aba5336b611074028777838a963d03b | |
fea681da MK |
252 | .TP |
253 | .B CAP_NET_RAW | |
93e9e2d6 MK |
254 | .PD 0 |
255 | .RS | |
256 | .IP * 2 | |
dd55b8a1 | 257 | Use RAW and PACKET sockets; |
93e9e2d6 MK |
258 | .IP * |
259 | bind to any address for transparent proxying. | |
260 | .RE | |
261 | .PD | |
fea681da MK |
262 | .\" Also various IP options and setsockopt(SO_BINDTODEVICE) |
263 | .TP | |
264 | .B CAP_SETGID | |
3bbab71a MK |
265 | .RS |
266 | .PD 0 | |
267 | .IP * 2 | |
c8e68512 | 268 | Make arbitrary manipulations of process GIDs and supplementary GID list; |
3bbab71a | 269 | .IP * |
5bea231d | 270 | forge GID when passing socket credentials via UNIX domain sockets; |
3bbab71a | 271 | .IP * |
5bea231d | 272 | write a group ID mapping in a user namespace (see |
f58fb24f | 273 | .BR user_namespaces (7)). |
3bbab71a MK |
274 | .PD |
275 | .RE | |
fea681da | 276 | .TP |
c8e68512 | 277 | .BR CAP_SETFCAP " (since Linux 2.6.24)" |
b8cee784 | 278 | Set arbitrary capabilities on a file. |
c8e68512 MK |
279 | .TP |
280 | .B CAP_SETPCAP | |
e62172cb | 281 | If file capabilities are supported (i.e., since Linux 2.6.24): |
c8e68512 MK |
282 | add any capability from the calling thread's bounding set |
283 | to its inheritable set; | |
284 | drop capabilities from the bounding set (via | |
285 | .BR prctl (2) | |
286 | .BR PR_CAPBSET_DROP ); | |
287 | make changes to the | |
288 | .I securebits | |
289 | flags. | |
e62172cb MK |
290 | .IP |
291 | If file capabilities are not supported (i.e., kernels before Linux 2.6.24): | |
292 | grant or remove any capability in the | |
293 | caller's permitted capability set to or from any other process. | |
294 | (This property of | |
295 | .B CAP_SETPCAP | |
296 | is not available when the kernel is configured to support | |
297 | file capabilities, since | |
298 | .B CAP_SETPCAP | |
299 | has entirely different semantics for such kernels.) | |
fea681da MK |
300 | .TP |
301 | .B CAP_SETUID | |
3bbab71a MK |
302 | .RS |
303 | .PD 0 | |
304 | .IP * 2 | |
c8e68512 | 305 | Make arbitrary manipulations of process UIDs |
fea681da MK |
306 | .RB ( setuid (2), |
307 | .BR setreuid (2), | |
308 | .BR setresuid (2), | |
309 | .BR setfsuid (2)); | |
3bbab71a | 310 | .IP * |
a7d96776 | 311 | forge UID when passing socket credentials via UNIX domain sockets; |
3bbab71a | 312 | .IP * |
5bea231d | 313 | write a user ID mapping in a user namespace (see |
f58fb24f | 314 | .BR user_namespaces (7)). |
3bbab71a MK |
315 | .PD |
316 | .RE | |
777f5a9e | 317 | .\" FIXME CAP_SETUID also an effect in exec(); document this. |
fea681da MK |
318 | .TP |
319 | .B CAP_SYS_ADMIN | |
fa50d3d4 MK |
320 | .IR Note : |
321 | this capability is overloaded; see | |
322 | .IR "Notes to kernel developers" , | |
323 | below. | |
ade303d7 | 324 | .IP |
c8e68512 MK |
325 | .PD 0 |
326 | .RS | |
327 | .IP * 2 | |
328 | Perform a range of system administration operations including: | |
fea681da MK |
329 | .BR quotactl (2), |
330 | .BR mount (2), | |
331 | .BR umount (2), | |
1368e847 MK |
332 | .BR swapon (2), |
333 | .BR swapoff (2), | |
fea681da | 334 | .BR sethostname (2), |
f169a862 | 335 | and |
c8e68512 MK |
336 | .BR setdomainname (2); |
337 | .IP * | |
bfb730f9 MK |
338 | perform privileged |
339 | .BR syslog (2) | |
340 | operations (since Linux 2.6.37, | |
341 | .BR CAP_SYSLOG | |
342 | should be used to permit such operations); | |
343 | .IP * | |
c8e68512 | 344 | perform |
c11e3891 MK |
345 | .B VM86_REQUEST_IRQ |
346 | .BR vm86 (2) | |
347 | command; | |
348 | .IP * | |
349 | perform | |
fea681da MK |
350 | .B IPC_SET |
351 | and | |
352 | .B IPC_RMID | |
353 | operations on arbitrary System V IPC objects; | |
c8e68512 | 354 | .IP * |
1a3b63f7 MK |
355 | override |
356 | .B RLIMIT_NPROC | |
357 | resource limit; | |
358 | .IP * | |
fea681da MK |
359 | perform operations on |
360 | .I trusted | |
361 | and | |
362 | .I security | |
363 | Extended Attributes (see | |
89fabe2e | 364 | .BR xattr (7)); |
c8e68512 MK |
365 | .IP * |
366 | use | |
08baa0af | 367 | .BR lookup_dcookie (2); |
c8e68512 | 368 | .IP * |
a1f926b8 MK |
369 | use |
370 | .BR ioprio_set (2) | |
371 | to assign | |
372 | .B IOPRIO_CLASS_RT | |
83ee9237 | 373 | and (before Linux 2.6.25) |
237aa7c5 | 374 | .B IOPRIO_CLASS_IDLE |
a1f926b8 | 375 | I/O scheduling classes; |
c8e68512 | 376 | .IP * |
f5ac5bbf | 377 | forge PID when passing socket credentials via UNIX domain sockets; |
c8e68512 | 378 | .IP * |
fea681da | 379 | exceed |
3dfe7e0d MK |
380 | .IR /proc/sys/fs/file-max , |
381 | the system-wide limit on the number of open files, | |
382 | in system calls that open files (e.g., | |
fea681da MK |
383 | .BR accept (2), |
384 | .BR execve (2), | |
385 | .BR open (2), | |
f169a862 | 386 | .BR pipe (2)); |
c8e68512 | 387 | .IP * |
c13182ef | 388 | employ |
0f807eea MK |
389 | .B CLONE_* |
390 | flags that create new namespaces with | |
a7c1e564 MK |
391 | .BR clone (2) |
392 | and | |
c67d3814 MK |
393 | .BR unshare (2) |
394 | (but, since Linux 3.8, | |
395 | creating user namespaces does not require any capability); | |
c8e68512 | 396 | .IP * |
e4698850 | 397 | call |
0f322ccc MK |
398 | .BR perf_event_open (2); |
399 | .IP * | |
0f322ccc MK |
400 | access privileged |
401 | .I perf | |
402 | event information; | |
2bfe6656 MK |
403 | .IP * |
404 | call | |
c3b49118 MK |
405 | .BR setns (2) |
406 | (requires | |
407 | .B CAP_SYS_ADMIN | |
408 | in the | |
409 | .I target | |
410 | namespace); | |
e4698850 | 411 | .IP * |
0f807eea MK |
412 | call |
413 | .BR fanotify_init (2); | |
414 | .IP * | |
0563f204 MK |
415 | call |
416 | .BR bpf (2); | |
417 | .IP * | |
2cf45b0d | 418 | perform privileged |
a7c1e564 MK |
419 | .B KEYCTL_CHOWN |
420 | and | |
421 | .B KEYCTL_SETPERM | |
422 | .BR keyctl (2) | |
e64e6056 MK |
423 | operations; |
424 | .IP * | |
425 | perform | |
426 | .BR madvise (2) | |
427 | .B MADV_HWPOISON | |
0f807eea MK |
428 | operation; |
429 | .IP * | |
430 | employ the | |
431 | .B TIOCSTI | |
432 | .BR ioctl (2) | |
433 | to insert characters into the input queue of a terminal other than | |
838ad419 | 434 | the caller's controlling terminal; |
0f807eea | 435 | .IP * |
0f807eea | 436 | employ the obsolete |
51c5c662 | 437 | .BR nfsservctl (2) |
c42221c4 MK |
438 | system call; |
439 | .IP * | |
440 | employ the obsolete | |
0f807eea MK |
441 | .BR bdflush (2) |
442 | system call; | |
443 | .IP * | |
444 | perform various privileged block-device | |
445 | .BR ioctl (2) | |
446 | operations; | |
447 | .IP * | |
9ee4a2b6 | 448 | perform various privileged filesystem |
0f807eea MK |
449 | .BR ioctl (2) |
450 | operations; | |
451 | .IP * | |
fdf41f57 MK |
452 | perform privileged |
453 | .BR ioctl (2) | |
454 | operations on the | |
455 | .IR /dev/random | |
456 | device (see | |
457 | .BR random (4)); | |
458 | .IP * | |
c6ddae52 MK |
459 | install a |
460 | .BR seccomp (2) | |
461 | filter without first having to set the | |
462 | .I no_new_privs | |
463 | thread attribute; | |
464 | .IP * | |
968b27aa MK |
465 | modify allow/deny rules for device control groups; |
466 | .IP * | |
467 | employ the | |
468 | .BR ptrace (2) | |
469 | .B PTRACE_SECCOMP_GET_FILTER | |
470 | operation to dump tracee's seccomp filters; | |
471 | .IP * | |
472 | employ the | |
473 | .BR ptrace (2) | |
474 | .B PTRACE_SETOPTIONS | |
475 | operation to suspend the tracee's seccomp protections (i.e., the | |
476 | .B PTRACE_O_SUSPEND_SECCOMP | |
115c1eb4 | 477 | flag); |
c6ddae52 | 478 | .IP * |
0f807eea | 479 | perform administrative operations on many device drivers. |
c8e68512 MK |
480 | .RE |
481 | .PD | |
fea681da MK |
482 | .TP |
483 | .B CAP_SYS_BOOT | |
c8e68512 | 484 | Use |
08baa0af MK |
485 | .BR reboot (2) |
486 | and | |
487 | .BR kexec_load (2). | |
fea681da MK |
488 | .TP |
489 | .B CAP_SYS_CHROOT | |
4312e0cb MK |
490 | .RS |
491 | .PD 0 | |
492 | .IP * 2 | |
c8e68512 | 493 | Use |
4312e0cb MK |
494 | .BR chroot (2); |
495 | .IP * | |
496 | change mount namespaces using | |
497 | .BR setns (2). | |
498 | .PD | |
499 | .RE | |
fea681da MK |
500 | .TP |
501 | .B CAP_SYS_MODULE | |
3bbab71a MK |
502 | .RS |
503 | .PD 0 | |
504 | .IP * 2 | |
c8e68512 MK |
505 | Load and unload kernel modules |
506 | (see | |
fea681da MK |
507 | .BR init_module (2) |
508 | and | |
c8e68512 | 509 | .BR delete_module (2)); |
3bbab71a | 510 | .IP * |
c8e68512 MK |
511 | in kernels before 2.6.25: |
512 | drop capabilities from the system-wide capability bounding set. | |
3bbab71a MK |
513 | .PD |
514 | .RE | |
fea681da MK |
515 | .TP |
516 | .B CAP_SYS_NICE | |
c8e68512 MK |
517 | .PD 0 |
518 | .RS | |
519 | .IP * 2 | |
520 | Raise process nice value | |
fea681da MK |
521 | .RB ( nice (2), |
522 | .BR setpriority (2)) | |
c8e68512 MK |
523 | and change the nice value for arbitrary processes; |
524 | .IP * | |
525 | set real-time scheduling policies for calling process, | |
526 | and set scheduling policies and priorities for arbitrary processes | |
fea681da | 527 | .RB ( sched_setscheduler (2), |
f96787ab | 528 | .BR sched_setparam (2), |
0d59d0c8 | 529 | .BR sched_setattr (2)); |
c8e68512 | 530 | .IP * |
fea681da | 531 | set CPU affinity for arbitrary processes |
c13182ef | 532 | .RB ( sched_setaffinity (2)); |
c8e68512 | 533 | .IP * |
a1f926b8 | 534 | set I/O scheduling class and priority for arbitrary processes |
c13182ef | 535 | .RB ( ioprio_set (2)); |
c8e68512 MK |
536 | .IP * |
537 | apply | |
a1f926b8 | 538 | .BR migrate_pages (2) |
c8e68512 | 539 | to arbitrary processes and allow processes |
a1f926b8 | 540 | to be migrated to arbitrary nodes; |
c13182ef | 541 | .\" FIXME CAP_SYS_NICE also has the following effect for |
a1f926b8 MK |
542 | .\" migrate_pages(2): |
543 | .\" do_migrate_pages(mm, &old, &new, | |
544 | .\" capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE); | |
1a0fbe37 | 545 | .\" |
bea08fec | 546 | .\" Document this. |
c8e68512 MK |
547 | .IP * |
548 | apply | |
a7c1e564 | 549 | .BR move_pages (2) |
c8e68512 MK |
550 | to arbitrary processes; |
551 | .IP * | |
4d62f7b6 MK |
552 | use the |
553 | .B MPOL_MF_MOVE_ALL | |
c13182ef | 554 | flag with |
a7c1e564 | 555 | .BR mbind (2) |
c13182ef | 556 | and |
a7c1e564 | 557 | .BR move_pages (2). |
c8e68512 MK |
558 | .RE |
559 | .PD | |
fea681da MK |
560 | .TP |
561 | .B CAP_SYS_PACCT | |
c8e68512 | 562 | Use |
fea681da MK |
563 | .BR acct (2). |
564 | .TP | |
565 | .B CAP_SYS_PTRACE | |
eb64a9cb MK |
566 | .PD 0 |
567 | .RS | |
de6a5c05 | 568 | .IP * 2 |
c8e68512 | 569 | Trace arbitrary processes using |
cbd7b9bf | 570 | .BR ptrace (2); |
eb64a9cb | 571 | .IP * |
cbd7b9bf MK |
572 | apply |
573 | .BR get_robust_list (2) | |
38b6e5b0 | 574 | to arbitrary processes; |
eb64a9cb | 575 | .IP * |
b8f84ce2 MK |
576 | transfer data to or from the memory of arbitrary processes using |
577 | .BR process_vm_readv (2) | |
578 | and | |
3bbab71a | 579 | .BR process_vm_writev (2); |
b8f84ce2 | 580 | .IP * |
38b6e5b0 MK |
581 | inspect processes using |
582 | .BR kcmp (2). | |
eb64a9cb MK |
583 | .RE |
584 | .PD | |
fea681da MK |
585 | .TP |
586 | .B CAP_SYS_RAWIO | |
4637c8cb MK |
587 | .PD 0 |
588 | .RS | |
589 | .IP * 2 | |
c8e68512 | 590 | Perform I/O port operations |
fea681da MK |
591 | .RB ( iopl (2) |
592 | and | |
593 | .BR ioperm (2)); | |
4637c8cb | 594 | .IP * |
fea681da | 595 | access |
474e1f9d | 596 | .IR /proc/kcore ; |
4637c8cb | 597 | .IP * |
474e1f9d MK |
598 | employ the |
599 | .B FIBMAP | |
600 | .BR ioctl (2) | |
4637c8cb MK |
601 | operation; |
602 | .IP * | |
603 | open devices for accessing x86 model-specific registers (MSRs, see | |
3bbab71a | 604 | .BR msr (4)); |
4637c8cb MK |
605 | .IP * |
606 | update | |
607 | .IR /proc/sys/vm/mmap_min_addr ; | |
608 | .IP * | |
609 | create memory mappings at addresses below the value specified by | |
610 | .IR /proc/sys/vm/mmap_min_addr ; | |
611 | .IP * | |
50b2aa27 | 612 | map files in |
cef53f3e | 613 | .IR /proc/bus/pci ; |
4637c8cb MK |
614 | .IP * |
615 | open | |
616 | .IR /dev/mem | |
617 | and | |
618 | .IR /dev/kmem ; | |
619 | .IP * | |
620 | perform various SCSI device commands; | |
621 | .IP * | |
622 | perform certain operations on | |
623 | .BR hpsa (4) | |
624 | and | |
625 | .BR cciss (4) | |
626 | devices; | |
627 | .IP * | |
628 | perform a range of device-specific operations on other devices. | |
629 | .RE | |
630 | .PD | |
fea681da MK |
631 | .TP |
632 | .B CAP_SYS_RESOURCE | |
c8e68512 MK |
633 | .PD 0 |
634 | .RS | |
635 | .IP * 2 | |
9ee4a2b6 | 636 | Use reserved space on ext2 filesystems; |
c8e68512 MK |
637 | .IP * |
638 | make | |
fea681da MK |
639 | .BR ioctl (2) |
640 | calls controlling ext3 journaling; | |
c8e68512 MK |
641 | .IP * |
642 | override disk quota limits; | |
643 | .IP * | |
644 | increase resource limits (see | |
fea681da | 645 | .BR setrlimit (2)); |
c8e68512 MK |
646 | .IP * |
647 | override | |
fea681da | 648 | .B RLIMIT_NPROC |
c8e68512 MK |
649 | resource limit; |
650 | .IP * | |
aa66392d MK |
651 | override maximum number of consoles on console allocation; |
652 | .IP * | |
653 | override maximum number of keymaps; | |
654 | .IP * | |
655 | allow more than 64hz interrupts from the real-time clock; | |
656 | .IP * | |
c8e68512 | 657 | raise |
fea681da | 658 | .I msg_qbytes |
c8e68512 | 659 | limit for a System V message queue above the limit in |
0daa9e92 | 660 | .I /proc/sys/kernel/msgmnb |
fea681da MK |
661 | (see |
662 | .BR msgop (2) | |
663 | and | |
ad7b0f91 MK |
664 | .BR msgctl (2)); |
665 | .IP * | |
7509f758 MK |
666 | allow the |
667 | .B RLIMIT_NOFILE | |
668 | resource limit on the number of "in-flight" file descriptors | |
669 | to be bypassed when passing file descriptors to another process | |
670 | via a UNIX domain socket (see | |
671 | .BR unix (7)); | |
672 | .IP * | |
ad7b0f91 MK |
673 | override the |
674 | .I /proc/sys/fs/pipe-size-max | |
675 | limit when setting the capacity of a pipe using the | |
676 | .B F_SETPIPE_SZ | |
677 | .BR fcntl (2) | |
678 | command. | |
46883521 MK |
679 | .IP * |
680 | use | |
681 | .BR F_SETPIPE_SZ | |
682 | to increase the capacity of a pipe above the limit specified by | |
b39a2012 MK |
683 | .IR /proc/sys/fs/pipe-max-size ; |
684 | .IP * | |
685 | override | |
686 | .I /proc/sys/fs/mqueue/queues_max | |
687 | limit when creating POSIX message queues (see | |
ecc1f45b MK |
688 | .BR mq_overview (7)); |
689 | .IP * | |
3bbab71a | 690 | employ the |
ecc1f45b MK |
691 | .BR prctl (2) |
692 | .B PR_SET_MM | |
8ddcc591 | 693 | operation; |
41f00272 | 694 | .IP * |
8ddcc591 | 695 | set |
750653a8 | 696 | .IR /proc/[pid]/oom_score_adj |
8ddcc591 MK |
697 | to a value lower than the value last set by a process with |
698 | .BR CAP_SYS_RESOURCE . | |
c8e68512 MK |
699 | .RE |
700 | .PD | |
fea681da MK |
701 | .TP |
702 | .B CAP_SYS_TIME | |
c8e68512 | 703 | Set system clock |
fea681da MK |
704 | .RB ( settimeofday (2), |
705 | .BR stime (2), | |
706 | .BR adjtimex (2)); | |
c8e68512 | 707 | set real-time (hardware) clock. |
fea681da MK |
708 | .TP |
709 | .B CAP_SYS_TTY_CONFIG | |
c8e68512 | 710 | Use |
749ac769 MK |
711 | .BR vhangup (2); |
712 | employ various privileged | |
713 | .BR ioctl (2) | |
714 | operations on virtual terminals. | |
bfb730f9 MK |
715 | .TP |
716 | .BR CAP_SYSLOG " (since Linux 2.6.37)" | |
5f94327c MK |
717 | .RS |
718 | .PD 0 | |
de6a5c05 | 719 | .IP * 2 |
bfb730f9 MK |
720 | Perform privileged |
721 | .BR syslog (2) | |
722 | operations. | |
723 | See | |
724 | .BR syslog (2) | |
725 | for information on which operations require privilege. | |
10fe5485 MK |
726 | .IP * |
727 | View kernel addresses exposed via | |
728 | .I /proc | |
729 | and other interfaces when | |
730 | .IR /proc/sys/kernel/kptr_restrict | |
731 | has the value 1. | |
4eaa04c5 | 732 | (See the discussion of the |
10fe5485 MK |
733 | .I kptr_restrict |
734 | in | |
735 | .BR proc (5).) | |
5f94327c MK |
736 | .PD |
737 | .RE | |
d6b08708 MK |
738 | .TP |
739 | .BR CAP_WAKE_ALARM " (since Linux 3.0)" | |
740 | Trigger something that will wake up the system (set | |
741 | .B CLOCK_REALTIME_ALARM | |
742 | and | |
743 | .B CLOCK_BOOTTIME_ALARM | |
744 | timers). | |
c8e68512 | 745 | .\" |
c634028a | 746 | .SS Past and current implementation |
c8e68512 MK |
747 | A full implementation of capabilities requires that: |
748 | .IP 1. 3 | |
749 | For all privileged operations, | |
750 | the kernel must check whether the thread has the required | |
751 | capability in its effective set. | |
752 | .IP 2. | |
137d81b5 | 753 | The kernel must provide system calls allowing a thread's capability sets to |
c8e68512 MK |
754 | be changed and retrieved. |
755 | .IP 3. | |
9ee4a2b6 | 756 | The filesystem must support attaching capabilities to an executable file, |
c8e68512 MK |
757 | so that a process gains those capabilities when the file is executed. |
758 | .PP | |
759 | Before kernel 2.6.24, only the first two of these requirements are met; | |
760 | since kernel 2.6.24, all three requirements are met. | |
761 | .\" | |
8de5616f MK |
762 | .SS Notes to kernel developers |
763 | When adding a new kernel feature that should be governed by a capability, | |
764 | consider the following points. | |
765 | .IP * 3 | |
ddb624a9 MK |
766 | The goal of capabilities is divide the power of superuser into pieces, |
767 | such that if a program that has one or more capabilities is compromised, | |
768 | its power to do damage to the system would be less than the same program | |
769 | running with root privilege. | |
8de5616f MK |
770 | .IP * |
771 | You have the choice of either creating a new capability for your new feature, | |
772 | or associating the feature with one of the existing capabilities. | |
ddb624a9 | 773 | In order to keep the set of capabilities to a manageable size, |
8de5616f MK |
774 | the latter option is preferable, |
775 | unless there are compelling reasons to take the former option. | |
ddb624a9 MK |
776 | (There is also a technical limit: |
777 | the size of capability sets is currently limited to 64 bits.) | |
8de5616f MK |
778 | .IP * |
779 | To determine which existing capability might best be associated | |
780 | with your new feature, review the list of capabilities above in order | |
781 | to find a "silo" into which your new feature best fits. | |
ddb624a9 | 782 | One approach to take is to determine if there are other features |
9f92e4e1 | 783 | requiring capabilities that will always be used along with the new feature. |
ddb624a9 MK |
784 | If the new feature is useless without these other features, |
785 | you should use the same capability as the other features. | |
8de5616f MK |
786 | .IP * |
787 | .IR Don't | |
788 | choose | |
789 | .B CAP_SYS_ADMIN | |
790 | if you can possibly avoid it! | |
791 | A vast proportion of existing capability checks are associated | |
6e9219f7 MK |
792 | with this capability (see the partial list above). |
793 | It can plausibly be called "the new root", | |
794 | since on the one hand, it confers a wide range of powers, | |
795 | and on the other hand, | |
796 | its broad scope means that this is the capability | |
797 | that is required by many privileged programs. | |
8de5616f MK |
798 | Don't make the problem worse. |
799 | The only new features that should be associated with | |
800 | .B CAP_SYS_ADMIN | |
801 | are ones that | |
802 | .I closely | |
803 | match existing uses in that silo. | |
804 | .IP * | |
805 | If you have determined that it really is necessary to create | |
806 | a new capability for your feature, | |
ddb624a9 | 807 | don't make or name it as a "single-use" capability. |
8de5616f | 808 | Thus, for example, the addition of the highly specific |
42dfc34c | 809 | .BR CAP_SYS_PACCT |
8de5616f MK |
810 | was probably a mistake. |
811 | Instead, try to identify and name your new capability as a broader | |
812 | silo into which other related future use cases might fit. | |
813 | .\" | |
c634028a | 814 | .SS Thread capability sets |
1db1d36d | 815 | Each thread has the following capability sets containing zero or more |
fea681da MK |
816 | of the above capabilities: |
817 | .TP | |
c2b279af | 818 | .IR Permitted |
c8e68512 MK |
819 | This is a limiting superset for the effective |
820 | capabilities that the thread may assume. | |
821 | It is also a limiting superset for the capabilities that | |
822 | may be added to the inheritable set by a thread that does not have the | |
823 | .B CAP_SETPCAP | |
824 | capability in its effective set. | |
ade303d7 | 825 | .IP |
cf7a13d4 | 826 | If a thread drops a capability from its permitted set, |
3b777aff | 827 | it can never reacquire that capability (unless it |
c930827f | 828 | .BR execve (2)s |
c8e68512 MK |
829 | either a set-user-ID-root program, or |
830 | a program whose associated file capabilities grant that capability). | |
fea681da | 831 | .TP |
c2b279af | 832 | .IR Inheritable |
c8e68512 | 833 | This is a set of capabilities preserved across an |
fea681da | 834 | .BR execve (2). |
6260f4cd AL |
835 | Inheritable capabilities remain inheritable when executing any program, |
836 | and inheritable capabilities are added to the permitted set when executing | |
837 | a program that has the corresponding bits set in the file inheritable set. | |
838 | .IP | |
839 | Because inheritable capabilities are not generally preserved across | |
840 | .BR execve (2) | |
841 | when running as a non-root user, applications that wish to run helper | |
e574dcd0 MK |
842 | programs with elevated capabilities should consider using |
843 | ambient capabilities, described below. | |
c8e68512 | 844 | .TP |
c2b279af | 845 | .IR Effective |
c8e68512 MK |
846 | This is the set of capabilities used by the kernel to |
847 | perform permission checks for the thread. | |
6260f4cd | 848 | .TP |
36de80b9 MK |
849 | .IR Bounding " (per-thread since Linux 2.6.25)" |
850 | The capability bounding set is a mechanism that can be used | |
851 | to limit the capabilities that are gained during | |
852 | .BR execve (2). | |
853 | .IP | |
854 | Since Linux 2.6.25, this is a per-thread capability set. | |
855 | In older kernels, the capability bounding set was a system wide attribute | |
856 | shared by all threads on the system. | |
857 | .IP | |
858 | .IP | |
859 | For more details on the capability bounding set, see below. | |
860 | .TP | |
c2b279af | 861 | .IR Ambient " (since Linux 4.3)" |
e574dcd0 | 862 | .\" commit 58319057b7847667f0c9585b9de0e8932b0fdb08 |
6260f4cd AL |
863 | This is a set of capabilities that are preserved across an |
864 | .BR execve (2) | |
3375bef1 | 865 | of a program that is not privileged. |
e574dcd0 MK |
866 | The ambient capability set obeys the invariant that no capability |
867 | can ever be ambient if it is not both permitted and inheritable. | |
ade303d7 | 868 | .IP |
3375bef1 MK |
869 | The ambient capability set can be directly modified using |
870 | .BR prctl (2). | |
871 | Ambient capabilities are automatically lowered if either of | |
872 | the corresponding permitted or inheritable capabilities is lowered. | |
ade303d7 | 873 | .IP |
3375bef1 MK |
874 | Executing a program that changes UID or GID due to the |
875 | set-user-ID or set-group-ID bits or executing a program that has | |
876 | any file capabilities set will clear the ambient set. | |
877 | Ambient capabilities are added to the permitted set and | |
878 | assigned to the effective set when | |
6260f4cd | 879 | .BR execve (2) |
e574dcd0 | 880 | is called. |
5367a9ab MK |
881 | If ambient capabilities cause a process's permitted and effective |
882 | capabilities to increase during an | |
883 | .BR execve (2), | |
884 | this does not trigger the secure-execution mode described in | |
885 | .BR ld.so (8). | |
fea681da | 886 | .PP |
fea681da MK |
887 | A child created via |
888 | .BR fork (2) | |
889 | inherits copies of its parent's capability sets. | |
3dfe7e0d | 890 | See below for a discussion of the treatment of capabilities during |
c930827f | 891 | .BR execve (2). |
fea681da MK |
892 | .PP |
893 | Using | |
894 | .BR capset (2), | |
c8e68512 | 895 | a thread may manipulate its own capability sets (see below). |
afae50e4 MK |
896 | .PP |
897 | Since Linux 3.2, the file | |
898 | .I /proc/sys/kernel/cap_last_cap | |
a60b1f03 | 899 | .\" commit 73efc0394e148d0e15583e13712637831f926720 |
afae50e4 MK |
900 | exposes the numerical value of the highest capability |
901 | supported by the running kernel; | |
902 | this can be used to determine the highest bit | |
903 | that may be set in a capability set. | |
c8e68512 | 904 | .\" |
c634028a | 905 | .SS File capabilities |
c8e68512 MK |
906 | Since kernel 2.6.24, the kernel supports |
907 | associating capability sets with an executable file using | |
908 | .BR setcap (8). | |
909 | The file capability sets are stored in an extended attribute (see | |
6a65cff8 MK |
910 | .BR setxattr (2) |
911 | and | |
912 | .BR xattr (7)) | |
c8e68512 MK |
913 | named |
914 | .IR "security.capability" . | |
915 | Writing to this extended attribute requires the | |
916 | .BR CAP_SETFCAP | |
fea681da | 917 | capability. |
c8e68512 | 918 | The file capability sets, |
cf7a13d4 | 919 | in conjunction with the capability sets of the thread, |
c8e68512 | 920 | determine the capabilities of a thread after an |
c930827f | 921 | .BR execve (2). |
ade303d7 | 922 | .PP |
c8e68512 | 923 | The three file capability sets are: |
fea681da | 924 | .TP |
3dfe7e0d | 925 | .IR Permitted " (formerly known as " forced ): |
c8e68512 | 926 | These capabilities are automatically permitted to the thread, |
cf7a13d4 | 927 | regardless of the thread's inheritable capabilities. |
fea681da | 928 | .TP |
c8e68512 MK |
929 | .IR Inheritable " (formerly known as " allowed ): |
930 | This set is ANDed with the thread's inheritable set to determine which | |
931 | inheritable capabilities are enabled in the permitted set of | |
932 | the thread after the | |
933 | .BR execve (2). | |
934 | .TP | |
fea681da | 935 | .IR Effective : |
c8e68512 MK |
936 | This is not a set, but rather just a single bit. |
937 | If this bit is set, then during an | |
938 | .BR execve (2) | |
939 | all of the new permitted capabilities for the thread are | |
940 | also raised in the effective set. | |
941 | If this bit is not set, then after an | |
942 | .BR execve (2), | |
943 | none of the new permitted capabilities is in the new effective set. | |
ade303d7 | 944 | .IP |
c8e68512 | 945 | Enabling the file effective capability bit implies |
2914a14d | 946 | that any file permitted or inheritable capability that causes a |
c8e68512 MK |
947 | thread to acquire the corresponding permitted capability during an |
948 | .BR execve (2) | |
e33a08e1 | 949 | (see the transformation rules described below) will also acquire that |
c8e68512 MK |
950 | capability in its effective set. |
951 | Therefore, when assigning capabilities to a file | |
952 | .RB ( setcap (8), | |
953 | .BR cap_set_file (3), | |
954 | .BR cap_set_fd (3)), | |
955 | if we specify the effective flag as being enabled for any capability, | |
956 | then the effective flag must also be specified as enabled | |
957 | for all other capabilities for which the corresponding permitted or | |
958 | inheritable flags is enabled. | |
959 | .\" | |
c281d050 | 960 | .SS File capability extended attribute versioning |
b6848704 MK |
961 | To allow extensibility, |
962 | the kernel supports a scheme to encode a version number inside the | |
963 | .I security.capability | |
964 | extended attribute that is used to implement file capabilities. | |
965 | These version numbers are internal to the implementation, | |
966 | and not directly visible to user-space applications. | |
967 | To date, the following versions are supported: | |
968 | .TP | |
969 | .BR VFS_CAP_REVISION_1 | |
970 | This was the original file capability implementation, | |
971 | which supported 32-bit masks for file capabilities. | |
972 | .TP | |
973 | .BR VFS_CAP_REVISION_2 " (since Linux 2.6.25)" | |
974 | .\" commit e338d263a76af78fe8f38a72131188b58fceb591 | |
975 | This version allows for file capability masks that are 64 bits in size, | |
976 | and was necessary as the number of supported capabilities grew beyond 32. | |
977 | The kernel transparently continues to support the execution of files | |
978 | that have 32-bit version 1 capability masks, | |
979 | but when adding capabilities to files that did not previously | |
980 | have capabilities, or modifying the capabilities of existing files, | |
bcaa30c9 MK |
981 | it automatically uses the version 2 scheme |
982 | (or possibly the version 3 scheme, as described below). | |
b6848704 MK |
983 | .TP |
984 | .BR VFS_CAP_REVISION_3 " (since Linux 4.14)" | |
985 | .\" commit 8db6c34f1dbc8e06aa016a9b829b06902c3e1340 | |
bcaa30c9 | 986 | Version 3 file capabilities are provided |
12dce731 | 987 | to support namespaced file capabilities (described below). |
bcaa30c9 | 988 | .IP |
b6848704 | 989 | As with version 2 file capabilities, |
bcaa30c9 MK |
990 | version 3 capability masks are 64 bits in size. |
991 | But in addition, the root user ID of namespace is encoded in the | |
b6848704 MK |
992 | .I security.capability |
993 | extended attribute. | |
7da0c87a MK |
994 | (A namespace's root user ID is the value that user ID 0 |
995 | inside that namespace maps to in the initial user namespace.) | |
7b45f4b2 | 996 | .IP |
bcaa30c9 MK |
997 | Version 3 file capabilities are designed to coexist |
998 | with version 2 capabilities; | |
999 | that is, on a modern Linux system, | |
1000 | there may be some files with version 2 capabilities | |
1001 | while others have version 3 capabilities. | |
1002 | .PP | |
1003 | Before Linux 4.14, | |
c281d050 MK |
1004 | the only kind of file capability extended attribute |
1005 | that could be attached to a file was a | |
bcaa30c9 | 1006 | .B VFS_CAP_REVISION_2 |
c281d050 | 1007 | attribute. |
bcaa30c9 | 1008 | Since Linux 4.14, |
9b2c207a | 1009 | the version of the |
bcaa30c9 | 1010 | .I security.capability |
9b2c207a MK |
1011 | extended attribute that is attached to a file |
1012 | depends on the circumstances in which the attribute was created. | |
bcaa30c9 | 1013 | .PP |
7b45f4b2 | 1014 | Starting with Linux 4.14, a |
7b45f4b2 MK |
1015 | .I security.capability |
1016 | extended attribute is automatically created as (or converted to) | |
bcaa30c9 MK |
1017 | a version 3 |
1018 | .RB ( VFS_CAP_REVISION_3 ) | |
1019 | attribute if both of the following are true: | |
7b45f4b2 | 1020 | .IP (1) 4 |
ffea2c14 | 1021 | The thread writing the attribute resides in a noninitial user namespace. |
7b45f4b2 MK |
1022 | (More precisely: the thread resides in a user namespace other |
1023 | than the one from which the underlying filesystem was mounted.) | |
1024 | .IP (2) | |
1025 | The thread has the | |
1026 | .BR CAP_SETFCAP | |
1027 | capability over the file inode, | |
1028 | meaning that (a) the thread has the | |
1029 | .B CAP_SETFCAP | |
1030 | capability in its own user namespace; | |
1031 | and (b) the UID and GID of the file inode have mappings in | |
1032 | the writer's user namespace. | |
bcaa30c9 | 1033 | .PP |
7b45f4b2 MK |
1034 | When a |
1035 | .BR VFS_CAP_REVISION_3 | |
1036 | .I security.capability | |
1037 | extended attribute is created, the root user ID of the creating thread's | |
1038 | user namespace is saved in the extended attribute. | |
bcaa30c9 | 1039 | .PP |
2c77e8de | 1040 | By contrast, creating or modifying a |
7b45f4b2 MK |
1041 | .I security.capability |
1042 | extended attribute from a privileged | |
1043 | .RB ( CAP_SETFCAP ) | |
1044 | thread that resides in the | |
90ef0f7b | 1045 | namespace where the underlying filesystem was mounted |
7b45f4b2 | 1046 | (this normally means the initial user namespace) |
2c77e8de | 1047 | automatically results in the creation of a version 2 |
bcaa30c9 | 1048 | .RB ( VFS_CAP_REVISION_2 ) |
7b45f4b2 | 1049 | attribute. |
bcaa30c9 | 1050 | .PP |
2c77e8de MK |
1051 | Note that the creation of a version 3 |
1052 | .I security.capability | |
1053 | extended attribute is automatic. | |
1054 | That is to say, when a user-space application writes | |
1055 | .RB ( setxattr (2)) | |
1056 | a | |
1057 | .I security.capability | |
1058 | attribute in the version 2 format, | |
1059 | the kernel will automatically create a version 3 attribute | |
1060 | if the attribute is created in the circumstances described above. | |
1061 | Correspondingly, when a version 3 | |
1062 | .I security.capability | |
1063 | attribute is retrieved | |
1064 | .RB ( getxattr (2)) | |
1065 | by a process that resides inside a user namespace that was created by the | |
1066 | root user ID (or a descendant of that user namespace), | |
1067 | the returned attribute is (automatically) | |
1068 | simplified to appear as a version 2 attribute | |
1069 | (i.e., the returned value is the size of a version 2 attribute and does | |
1070 | not include the root user ID). | |
1071 | These automatic translations mean that no changes are required to | |
1072 | user-space tools (e.g., | |
1073 | .BR setcap (1) | |
1074 | and | |
1075 | .BR getcap (1)) | |
1076 | in order for those tools to be used to create and retrieve version 3 | |
1077 | .I security.capability | |
1078 | attributes. | |
1079 | .PP | |
bcaa30c9 MK |
1080 | Note that a file can have either a version 2 or a version 3 |
1081 | .I security.capability | |
1082 | extended attribute associated with it, but not both: | |
1083 | creation or modification of the | |
1084 | .I security.capability | |
1085 | extended attribute will automatically modify the version | |
1086 | according to the circumstances in which the extended attribute is | |
1087 | created or modified. | |
b6848704 | 1088 | .\" |
c634028a | 1089 | .SS Transformation of capabilities during execve() |
fea681da | 1090 | .PP |
c13182ef | 1091 | During an |
c930827f | 1092 | .BR execve (2), |
1e321034 | 1093 | the kernel calculates the new capabilities of |
fea681da | 1094 | the process using the following algorithm: |
ade303d7 | 1095 | .PP |
088a639b | 1096 | .in +4n |
b8302363 | 1097 | .EX |
f04f131f | 1098 | P'(ambient) = (file is privileged) ? 0 : P(ambient) |
6260f4cd | 1099 | |
f04f131f | 1100 | P'(permitted) = (P(inheritable) & F(inheritable)) | |
2e87ced3 | 1101 | (F(permitted) & P(bounding)) | P'(ambient) |
fea681da | 1102 | |
f04f131f | 1103 | P'(effective) = F(effective) ? P'(permitted) : P'(ambient) |
fea681da | 1104 | |
5bdccabd | 1105 | P'(inheritable) = P(inheritable) [i.e., unchanged] |
2e87ced3 MK |
1106 | |
1107 | P'(bounding) = P(bounding) [i.e., unchanged] | |
b8302363 | 1108 | .EE |
088a639b | 1109 | .in |
ade303d7 | 1110 | .PP |
fea681da | 1111 | where: |
c8e68512 | 1112 | .RS 4 |
2e87ced3 | 1113 | .IP P() 6 |
c13182ef | 1114 | denotes the value of a thread capability set before the |
c930827f | 1115 | .BR execve (2) |
2e87ced3 | 1116 | .IP P'() |
8295fc02 | 1117 | denotes the value of a thread capability set after the |
c930827f | 1118 | .BR execve (2) |
2e87ced3 | 1119 | .IP F() |
fea681da | 1120 | denotes a file capability set |
c8e68512 | 1121 | .RE |
3375bef1 | 1122 | .PP |
ddc1ad30 MK |
1123 | Note the following details relating to the above capability |
1124 | transformation rules: | |
1125 | .IP * 3 | |
1126 | The ambient capability set is present only since Linux 4.3. | |
1127 | When determining the transformation of the ambient set during | |
1128 | .BR execve (2), | |
1129 | a privileged file is one that has capabilities or | |
3375bef1 | 1130 | has the set-user-ID or set-group-ID bit set. |
ddc1ad30 MK |
1131 | .IP * |
1132 | Prior to Linux 2.6.25, | |
1133 | the bounding set was a system-wide attribute shared by all threads. | |
1134 | That system-wide value was employed to calculate the new permitted set during | |
1135 | .BR execve (2) | |
1136 | in the same manner as shown above for | |
1137 | .IR P(bounding) . | |
ade303d7 | 1138 | .PP |
56cc88cb | 1139 | .IR Note : |
1a9ed17c MK |
1140 | during the capability transitions described above, |
1141 | file capabilities may be ignored (treated as empty) for the same reasons | |
56cc88cb MK |
1142 | that the set-user-ID and set-group-ID bits are ignored; see |
1143 | .BR execve (2). | |
1a9ed17c | 1144 | File capabilities are similarly ignored if the kernel was booted with the |
f6acfeb8 | 1145 | .I no_file_caps |
1a9ed17c | 1146 | option. |
ade303d7 | 1147 | .PP |
e3ed67ed MK |
1148 | .IR Note : |
1149 | according to the rules above, | |
1150 | if a process with nonzero user IDs performs an | |
1151 | .BR execve (2) | |
1152 | then any capabilities that are present in | |
1153 | its permitted and effective sets will be cleared. | |
1154 | For the treatment of capabilities when a process with a | |
1155 | user ID of zero performs an | |
1156 | .BR execve (2), | |
1157 | see below under | |
1158 | .IR "Capabilities and execution of programs by root" . | |
c8e68512 | 1159 | .\" |
e0e57837 | 1160 | .SS Safety checking for capability-dumb binaries |
4a866754 | 1161 | A capability-dumb binary is an application that has been |
e0e57837 MK |
1162 | marked to have file capabilities, but has not been converted to use the |
1163 | .BR libcap (3) | |
1164 | API to manipulate its capabilities. | |
1165 | (In other words, this is a traditional set-user-ID-root program | |
1166 | that has been switched to use file capabilities, | |
1167 | but whose code has not been modified to understand capabilities.) | |
2c767761 | 1168 | For such applications, |
e0e57837 MK |
1169 | the effective capability bit is set on the file, |
1170 | so that the file permitted capabilities are automatically | |
1171 | enabled in the process effective set when executing the file. | |
1172 | The kernel recognizes a file which has the effective capability bit set | |
1173 | as capability-dumb for the purpose of the check described here. | |
ade303d7 | 1174 | .PP |
e0e57837 MK |
1175 | When executing a capability-dumb binary, |
1176 | the kernel checks if the process obtained all permitted capabilities | |
1177 | that were specified in the file permitted set, | |
1178 | after the capability transformations described above have been performed. | |
1179 | (The typical reason why this might | |
1180 | .I not | |
1181 | occur is that the capability bounding set masked out some | |
1182 | of the capabilities in the file permitted set.) | |
1183 | If the process did not obtain the full set of | |
1184 | file permitted capabilities, then | |
1185 | .BR execve (2) | |
1186 | fails with the error | |
1187 | .BR EPERM . | |
1188 | This prevents possible security risks that could arise when | |
1189 | a capability-dumb application is executed with less privilege that it needs. | |
1190 | Note that, by definition, | |
1191 | the application could not itself recognize this problem, | |
1192 | since it does not employ the | |
1193 | .BR libcap (3) | |
1194 | API. | |
1195 | .\" | |
c8e68512 | 1196 | .SS Capabilities and execution of programs by root |
33d0916f MK |
1197 | .\" See cap_bprm_set_creds(), bprm_caps_from_vfs_cap() and |
1198 | .\" handle_privileged_root() in security/commoncap.c (Linux 5.0 source) | |
bc1950ac | 1199 | In order to mirror traditional UNIX semantics, |
33d0916f MK |
1200 | the kernel performs special treatment of file capabilities when |
1201 | a process with UID 0 (root) executes a program and | |
1202 | when a set-user-ID-root program is executed. | |
bc1950ac | 1203 | .PP |
33d0916f MK |
1204 | After having performed any changes to the process effective ID that |
1205 | were triggered by the set-user-ID mode bit of the binary\(eme.g., | |
1206 | switching the effective user ID to 0 (root) because | |
1207 | a set-user-ID-root program was executed\(emthe | |
1208 | kernel calculates the file capability sets as follows: | |
c8e68512 | 1209 | .IP 1. 3 |
bc1950ac | 1210 | If the real or effective user ID of the process is 0 (root), |
33d0916f MK |
1211 | then the file inheritable and permitted sets are ignored; |
1212 | instead they are notionally considered to be all ones | |
c8e68512 | 1213 | (i.e., all capabilities enabled). |
33d0916f MK |
1214 | (There is one exception to this behavior, described below in |
1215 | .IR "Set-user-ID-root programs that have file capabilities" .) | |
c8e68512 | 1216 | .IP 2. |
bc1950ac MK |
1217 | If the effective user ID of the process is 0 (root) or |
1218 | the file effective bit is in fact enabled, | |
33d0916f | 1219 | then the file effective bit is notionally defined to be one (enabled). |
3dfe7e0d | 1220 | .PP |
33d0916f MK |
1221 | These notional values for the file's capability sets are then used |
1222 | as described above to calculate the transformation of the process's | |
1223 | capabilities during | |
1224 | .BR execve (2). | |
bc1950ac | 1225 | .PP |
33d0916f | 1226 | Thus, when a process with nonzero UIDs |
c930827f | 1227 | .BR execve (2)s |
33d0916f MK |
1228 | a set-user-ID-root program that does not have capabilities attached, |
1229 | or when a process whose real and effective UIDs are zero | |
ab8aa2e4 | 1230 | .BR execve (2)s |
33d0916f MK |
1231 | a program, the calculation of the process's new |
1232 | permitted capabilities simplifies to: | |
1233 | .PP | |
1234 | .in +4n | |
1235 | .EX | |
1236 | P'(permitted) = P(inheritable) | P(bounding) | |
1237 | ||
1238 | P'(effective) = P'(permitted) | |
1239 | .EE | |
1240 | .in | |
1241 | .PP | |
1242 | Consequently, the process gains all capabilities in its permitted and | |
1243 | effective capability sets, | |
ab8aa2e4 | 1244 | except those masked out by the capability bounding set. |
33d0916f MK |
1245 | (In the calculation of P'(permitted), |
1246 | the P'(ambient) term can be simplified away because it is by | |
1247 | definition a proper subset of P(inheritable).) | |
ab8aa2e4 | 1248 | .PP |
33d0916f MK |
1249 | The special treatments of user ID 0 (root) described in this subsection |
1250 | can be disabled using the securebits mechanism described below. | |
1251 | .\" | |
0603dda3 MK |
1252 | .\" |
1253 | .SS Set-user-ID-root programs that have file capabilities | |
33d0916f MK |
1254 | There is one exception to the behavior described under |
1255 | .IR "Capabilities and execution of programs by root" . | |
1256 | If (a) the binary that is being executed has capabilities attached and | |
1257 | (b) the real user ID of the process is | |
1258 | .I not | |
1259 | 0 (root) and | |
1260 | (c) the effective user ID of the process | |
1261 | .I is | |
1262 | 0 (root), then the file capability bits are honored | |
1263 | (i.e., they are not notionally considered to be all ones). | |
1264 | The usual way in which this situation can arise is when executing | |
1265 | a set-UID-root program that also has file capabilities. | |
1266 | When such a program is executed, | |
1267 | the process gains just the capabilities granted by the program | |
0603dda3 MK |
1268 | (i.e., not all capabilities, |
1269 | as would occur when executing a set-user-ID-root program | |
1270 | that does not have any associated file capabilities). | |
bc1950ac | 1271 | .PP |
c199053b MK |
1272 | Note that one can assign empty capability sets to a program file, |
1273 | and thus it is possible to create a set-user-ID-root program that | |
1274 | changes the effective and saved set-user-ID of the process | |
1275 | that executes the program to 0, | |
1276 | but confers no capabilities to that process. | |
0603dda3 | 1277 | .\" |
c8e68512 MK |
1278 | .SS Capability bounding set |
1279 | The capability bounding set is a security mechanism that can be used | |
1280 | to limit the capabilities that can be gained during an | |
1281 | .BR execve (2). | |
1282 | The bounding set is used in the following ways: | |
1283 | .IP * 2 | |
1284 | During an | |
1285 | .BR execve (2), | |
1286 | the capability bounding set is ANDed with the file permitted | |
1287 | capability set, and the result of this operation is assigned to the | |
1288 | thread's permitted capability set. | |
1289 | The capability bounding set thus places a limit on the permitted | |
1290 | capabilities that may be granted by an executable file. | |
1291 | .IP * | |
1292 | (Since Linux 2.6.25) | |
1293 | The capability bounding set acts as a limiting superset for | |
1294 | the capabilities that a thread can add to its inheritable set using | |
1295 | .BR capset (2). | |