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