1CAPABILITIES(7)            Linux Programmer's Manual           CAPABILITIES(7)
2
3
4

NAME

6       capabilities - overview of Linux capabilities
7

DESCRIPTION

9       For  the  purpose  of  performing  permission  checks, traditional UNIX
10       implementations distinguish two  categories  of  processes:  privileged
11       processes  (whose  effective  user ID is 0, referred to as superuser or
12       root), and unprivileged processes (whose  effective  UID  is  nonzero).
13       Privileged processes bypass all kernel permission checks, while unpriv‐
14       ileged processes are subject to full permission checking based  on  the
15       process's  credentials (usually: effective UID, effective GID, and sup‐
16       plementary group list).
17
18       Starting with kernel 2.2, Linux divides  the  privileges  traditionally
19       associated  with  superuser into distinct units, known as capabilities,
20       which can be independently enabled and disabled.   Capabilities  are  a
21       per-thread attribute.
22
23   Capabilities list
24       The following list shows the capabilities implemented on Linux, and the
25       operations or behaviors that each capability permits:
26
27       CAP_AUDIT_CONTROL (since Linux 2.6.11)
28              Enable and  disable  kernel  auditing;  change  auditing  filter
29              rules; retrieve auditing status and filtering rules.
30
31       CAP_AUDIT_READ (since Linux 3.16)
32              Allow reading the audit log via a multicast netlink socket.
33
34       CAP_AUDIT_WRITE (since Linux 2.6.11)
35              Write records to kernel auditing log.
36
37       CAP_BLOCK_SUSPEND (since Linux 3.5)
38              Employ  features  that can block system suspend (epoll(7) EPOLL‐
39              WAKEUP, /proc/sys/wake_lock).
40
41       CAP_CHOWN
42              Make arbitrary changes to file UIDs and GIDs (see chown(2)).
43
44       CAP_DAC_OVERRIDE
45              Bypass file read, write, and execute permission checks.  (DAC is
46              an abbreviation of "discretionary access control".)
47
48       CAP_DAC_READ_SEARCH
49              * Bypass file read permission checks and directory read and exe‐
50                cute permission checks;
51              * invoke open_by_handle_at(2);
52              * use the linkat(2) AT_EMPTY_PATH flag to create  a  link  to  a
53                file referred to by a file descriptor.
54
55       CAP_FOWNER
56              * Bypass  permission  checks on operations that normally require
57                the filesystem UID of the process to match the UID of the file
58                (e.g., chmod(2), utime(2)), excluding those operations covered
59                by CAP_DAC_OVERRIDE and CAP_DAC_READ_SEARCH;
60              * set inode flags (see ioctl_iflags(2)) on arbitrary files;
61              * set Access Control Lists (ACLs) on arbitrary files;
62              * ignore directory sticky bit on file deletion;
63              * specify O_NOATIME for arbitrary files in open(2) and fcntl(2).
64
65       CAP_FSETID
66              * Don't clear set-user-ID and set-group-ID mode bits when a file
67                is modified;
68              * set  the  set-group-ID bit for a file whose GID does not match
69                the filesystem or any of the supplementary GIDs of the calling
70                process.
71
72       CAP_IPC_LOCK
73              Lock memory (mlock(2), mlockall(2), mmap(2), shmctl(2)).
74
75       CAP_IPC_OWNER
76              Bypass permission checks for operations on System V IPC objects.
77
78       CAP_KILL
79              Bypass  permission  checks  for  sending  signals (see kill(2)).
80              This includes use of the ioctl(2) KDSIGACCEPT operation.
81
82       CAP_LEASE (since Linux 2.4)
83              Establish leases on arbitrary files (see fcntl(2)).
84
85       CAP_LINUX_IMMUTABLE
86              Set  the  FS_APPEND_FL  and  FS_IMMUTABLE_FL  inode  flags  (see
87              ioctl_iflags(2)).
88
89       CAP_MAC_ADMIN (since Linux 2.6.25)
90              Allow  MAC  configuration or state changes.  Implemented for the
91              Smack Linux Security Module (LSM).
92
93       CAP_MAC_OVERRIDE (since Linux 2.6.25)
94              Override Mandatory Access Control (MAC).   Implemented  for  the
95              Smack LSM.
96
97       CAP_MKNOD (since Linux 2.4)
98              Create special files using mknod(2).
99
100       CAP_NET_ADMIN
101              Perform various network-related operations:
102              * interface configuration;
103              * administration of IP firewall, masquerading, and accounting;
104              * modify routing tables;
105              * bind to any address for transparent proxying;
106              * set type-of-service (TOS)
107              * clear driver statistics;
108              * set promiscuous mode;
109              * enabling multicasting;
110              * use   setsockopt(2)  to  set  the  following  socket  options:
111                SO_DEBUG, SO_MARK, SO_PRIORITY (for  a  priority  outside  the
112                range 0 to 6), SO_RCVBUFFORCE, and SO_SNDBUFFORCE.
113
114       CAP_NET_BIND_SERVICE
115              Bind  a socket to Internet domain privileged ports (port numbers
116              less than 1024).
117
118       CAP_NET_BROADCAST
119              (Unused)  Make socket broadcasts, and listen to multicasts.
120
121       CAP_NET_RAW
122              * Use RAW and PACKET sockets;
123              * bind to any address for transparent proxying.
124
125       CAP_SETGID
126              * Make arbitrary manipulations of process GIDs and supplementary
127                GID list;
128              * forge  GID  when  passing  socket  credentials via UNIX domain
129                sockets;
130              * write a group ID mapping in a user namespace (see  user_names‐
131                paces(7)).
132
133       CAP_SETFCAP (since Linux 2.6.24)
134              Set arbitrary capabilities on a file.
135
136       CAP_SETPCAP
137              If  file  capabilities are supported (i.e., since Linux 2.6.24):
138              add any capability from the calling thread's bounding set to its
139              inheritable  set;  drop  capabilities from the bounding set (via
140              prctl(2) PR_CAPBSET_DROP); make changes to the securebits flags.
141
142              If file capabilities are not  supported  (i.e.,  kernels  before
143              Linux  2.6.24):  grant  or remove any capability in the caller's
144              permitted capability set to or from any  other  process.   (This
145              property of CAP_SETPCAP is not available when the kernel is con‐
146              figured to support  file  capabilities,  since  CAP_SETPCAP  has
147              entirely different semantics for such kernels.)
148
149       CAP_SETUID
150              * Make  arbitrary  manipulations  of  process  UIDs  (setuid(2),
151                setreuid(2), setresuid(2), setfsuid(2));
152              * forge UID when passing  socket  credentials  via  UNIX  domain
153                sockets;
154              * write  a  user ID mapping in a user namespace (see user_names‐
155                paces(7)).
156
157       CAP_SYS_ADMIN
158              Note: this capability is overloaded; see Notes to kernel  devel‐
159              opers, below.
160
161              * Perform a range of system administration operations including:
162                quotactl(2),  mount(2),  umount(2),   swapon(2),   swapoff(2),
163                sethostname(2), and setdomainname(2);
164              * perform  privileged  syslog(2) operations (since Linux 2.6.37,
165                CAP_SYSLOG should be used to permit such operations);
166              * perform VM86_REQUEST_IRQ vm86(2) command;
167              * perform IPC_SET and IPC_RMID operations on arbitrary System  V
168                IPC objects;
169              * override RLIMIT_NPROC resource limit;
170              * perform operations on trusted and security Extended Attributes
171                (see xattr(7));
172              * use lookup_dcookie(2);
173              * use ioprio_set(2) to assign IOPRIO_CLASS_RT and (before  Linux
174                2.6.25) IOPRIO_CLASS_IDLE I/O scheduling classes;
175              * forge  PID  when  passing  socket  credentials via UNIX domain
176                sockets;
177              * exceed /proc/sys/fs/file-max, the  system-wide  limit  on  the
178                number  of  open files, in system calls that open files (e.g.,
179                accept(2), execve(2), open(2), pipe(2));
180              * employ CLONE_* flags that create new namespaces with  clone(2)
181                and unshare(2) (but, since Linux 3.8, creating user namespaces
182                does not require any capability);
183              * call perf_event_open(2);
184              * access privileged perf event information;
185              * call setns(2) (requires CAP_SYS_ADMIN  in  the  target  names‐
186                pace);
187              * call fanotify_init(2);
188              * call bpf(2);
189              * perform  privileged  KEYCTL_CHOWN and KEYCTL_SETPERM keyctl(2)
190                operations;
191              * use ptrace(2) PTRACE_SECCOMP_GET_FILTER to dump a tracees sec‐
192                comp filters;
193              * perform madvise(2) MADV_HWPOISON operation;
194              * employ  the  TIOCSTI  ioctl(2)  to  insert characters into the
195                input queue of a terminal other than the caller's  controlling
196                terminal;
197              * employ the obsolete nfsservctl(2) system call;
198              * employ the obsolete bdflush(2) system call;
199              * perform various privileged block-device ioctl(2) operations;
200              * perform various privileged filesystem ioctl(2) operations;
201              * perform  privileged  ioctl(2)  operations  on  the /dev/random
202                device (see random(4));
203              * install a seccomp(2) filter without first having  to  set  the
204                no_new_privs thread attribute;
205              * modify allow/deny rules for device control groups;
206              * employ  the  ptrace(2)  PTRACE_SECCOMP_GET_FILTER operation to
207                dump tracee's seccomp filters;
208              * employ the ptrace(2) PTRACE_SETOPTIONS  operation  to  suspend
209                the  tracee's  seccomp  protections  (i.e.,  the PTRACE_O_SUS‐
210                PEND_SECCOMP flag).
211              * perform administrative operations on many device drivers.
212
213       CAP_SYS_BOOT
214              Use reboot(2) and kexec_load(2).
215
216       CAP_SYS_CHROOT
217              Use chroot(2).
218
219       CAP_SYS_MODULE
220              * Load  and  unload  kernel  modules  (see  init_module(2)   and
221                delete_module(2));
222              * in  kernels  before 2.6.25: drop capabilities from the system-
223                wide capability bounding set.
224
225       CAP_SYS_NICE
226              * Raise process nice value (nice(2), setpriority(2)) and  change
227                the nice value for arbitrary processes;
228              * set real-time scheduling policies for calling process, and set
229                scheduling policies and  priorities  for  arbitrary  processes
230                (sched_setscheduler(2), sched_setparam(2), shed_setattr(2));
231              * set  CPU  affinity  for  arbitrary  processes (sched_setaffin‐
232                ity(2));
233              * set I/O scheduling class and priority for arbitrary  processes
234                (ioprio_set(2));
235              * apply  migrate_pages(2)  to arbitrary processes and allow pro‐
236                cesses to be migrated to arbitrary nodes;
237              * apply move_pages(2) to arbitrary processes;
238              * use the MPOL_MF_MOVE_ALL flag with mbind(2) and move_pages(2).
239
240       CAP_SYS_PACCT
241              Use acct(2).
242
243       CAP_SYS_PTRACE
244              * Trace arbitrary processes using ptrace(2);
245              * apply get_robust_list(2) to arbitrary processes;
246              * transfer data to or from the  memory  of  arbitrary  processes
247                using process_vm_readv(2) and process_vm_writev(2);
248              * inspect processes using kcmp(2).
249
250       CAP_SYS_RAWIO
251              * Perform I/O port operations (iopl(2) and ioperm(2));
252              * access /proc/kcore;
253              * employ the FIBMAP ioctl(2) operation;
254              * open devices for accessing x86 model-specific registers (MSRs,
255                see msr(4));
256              * update /proc/sys/vm/mmap_min_addr;
257              * create memory mappings at addresses below the value  specified
258                by /proc/sys/vm/mmap_min_addr;
259              * map files in /proc/bus/pci;
260              * open /dev/mem and /dev/kmem;
261              * perform various SCSI device commands;
262              * perform certain operations on hpsa(4) and cciss(4) devices;
263              * perform   a  range  of  device-specific  operations  on  other
264                devices.
265
266       CAP_SYS_RESOURCE
267              * Use reserved space on ext2 filesystems;
268              * make ioctl(2) calls controlling ext3 journaling;
269              * override disk quota limits;
270              * increase resource limits (see setrlimit(2));
271              * override RLIMIT_NPROC resource limit;
272              * override maximum number of consoles on console allocation;
273              * override maximum number of keymaps;
274              * allow more than 64hz interrupts from the real-time clock;
275              * raise msg_qbytes limit for a System V message queue above  the
276                limit in /proc/sys/kernel/msgmnb (see msgop(2) and msgctl(2));
277              * allow  the  RLIMIT_NOFILE resource limit on the number of "in-
278                flight" file descriptors to  be  bypassed  when  passing  file
279                descriptors  to  another process via a UNIX domain socket (see
280                unix(7));
281              * override the /proc/sys/fs/pipe-size-max limit when setting the
282                capacity of a pipe using the F_SETPIPE_SZ fcntl(2) command.
283              * use  F_SETPIPE_SZ to increase the capacity of a pipe above the
284                limit specified by /proc/sys/fs/pipe-max-size;
285              * override /proc/sys/fs/mqueue/queues_max  limit  when  creating
286                POSIX message queues (see mq_overview(7));
287              * employ the prctl(2) PR_SET_MM operation;
288              * set  /proc/[pid]/oom_score_adj to a value lower than the value
289                last set by a process with CAP_SYS_RESOURCE.
290
291       CAP_SYS_TIME
292              Set system clock (settimeofday(2), stime(2),  adjtimex(2));  set
293              real-time (hardware) clock.
294
295       CAP_SYS_TTY_CONFIG
296              Use vhangup(2); employ various privileged ioctl(2) operations on
297              virtual terminals.
298
299       CAP_SYSLOG (since Linux 2.6.37)
300              * Perform privileged syslog(2) operations.   See  syslog(2)  for
301                information on which operations require privilege.
302              * View  kernel  addresses exposed via /proc and other interfaces
303                when /proc/sys/kernel/kptr_restrict has the value 1.  (See the
304                discussion of the kptr_restrict in proc(5).)
305
306       CAP_WAKE_ALARM (since Linux 3.0)
307              Trigger  something that will wake up the system (set CLOCK_REAL‐
308              TIME_ALARM and CLOCK_BOOTTIME_ALARM timers).
309
310   Past and current implementation
311       A full implementation of capabilities requires that:
312
313       1. For all privileged operations, the kernel  must  check  whether  the
314          thread has the required capability in its effective set.
315
316       2. The  kernel must provide system calls allowing a thread's capability
317          sets to be changed and retrieved.
318
319       3. The filesystem must support attaching capabilities to an  executable
320          file,  so  that  a process gains those capabilities when the file is
321          executed.
322
323       Before kernel 2.6.24, only the first two of these requirements are met;
324       since kernel 2.6.24, all three requirements are met.
325
326   Notes to kernel developers
327       When  adding a new kernel feature that should be governed by a capabil‐
328       ity, consider the following points.
329
330       *  The goal of capabilities is  divide  the  power  of  superuser  into
331          pieces,  such that if a program that has one or more capabilities is
332          compromised, its power to do damage to the system would be less than
333          the same program running with root privilege.
334
335       *  You have the choice of either creating a new capability for your new
336          feature, or associating the feature with one of the  existing  capa‐
337          bilities.   In order to keep the set of capabilities to a manageable
338          size, the latter option is preferable, unless there  are  compelling
339          reasons  to  take  the  former  option.   (There is also a technical
340          limit: the size of capability sets is currently limited to 64 bits.)
341
342       *  To determine which existing capability might best be associated with
343          your  new feature, review the list of capabilities above in order to
344          find a "silo" into which your new feature best fits.   One  approach
345          to  take is to determine if there are other features requiring capa‐
346          bilities that will always be use along with the new feature.  If the
347          new  feature is useless without these other features, you should use
348          the same capability as the other features.
349
350       *  Don't choose CAP_SYS_ADMIN if you can possibly  avoid  it!   A  vast
351          proportion  of  existing  capability checks are associated with this
352          capability (see the partial list above).  It can plausibly be called
353          "the  new  root",  since on the one hand, it confers a wide range of
354          powers, and on the other hand, its broad scope means  that  this  is
355          the  capability that is required by many privileged programs.  Don't
356          make the problem worse.  The only new features that should be  asso‐
357          ciated  with CAP_SYS_ADMIN are ones that closely match existing uses
358          in that silo.
359
360       *  If you have determined that it really is necessary to create  a  new
361          capability for your feature, don't make or name it as a "single-use"
362          capability.  Thus, for example, the addition of the highly  specific
363          CAP_SYS_PACCT  was probably a mistake.  Instead, try to identify and
364          name your new capability as a broader silo into which other  related
365          future use cases might fit.
366
367   Thread capability sets
368       Each  thread  has  three capability sets containing zero or more of the
369       above capabilities:
370
371       Permitted:
372              This is a limiting superset for the effective capabilities  that
373              the  thread  may assume.  It is also a limiting superset for the
374              capabilities that may be added  to  the  inheritable  set  by  a
375              thread  that  does  not  have  the CAP_SETPCAP capability in its
376              effective set.
377
378              If a thread drops a capability from its permitted  set,  it  can
379              never  reacquire  that capability (unless it execve(2)s either a
380              set-user-ID-root program, or a  program  whose  associated  file
381              capabilities grant that capability).
382
383       Inheritable:
384              This  is  a  set  of capabilities preserved across an execve(2).
385              Inheritable capabilities remain inheritable when  executing  any
386              program, and inheritable capabilities are added to the permitted
387              set when executing a program that has the corresponding bits set
388              in the file inheritable set.
389
390              Because  inheritable  capabilities  are  not generally preserved
391              across execve(2) when running as a non-root  user,  applications
392              that  wish  to  run  helper  programs with elevated capabilities
393              should consider using ambient capabilities, described below.
394
395       Effective:
396              This is the set of capabilities used by the  kernel  to  perform
397              permission checks for the thread.
398
399       Ambient (since Linux 4.3):
400              This  is  a  set  of  capabilities  that are preserved across an
401              execve(2) of a program that  is  not  privileged.   The  ambient
402              capability  set  obeys the invariant that no capability can ever
403              be ambient if it is not both permitted and inheritable.
404
405              The ambient  capability  set  can  be  directly  modified  using
406              prctl(2).   Ambient  capabilities  are  automatically lowered if
407              either of the corresponding permitted or  inheritable  capabili‐
408              ties is lowered.
409
410              Executing a program that changes UID or GID due to the set-user-
411              ID or set-group-ID bits or executing a program that has any file
412              capabilities  set will clear the ambient set.  Ambient capabili‐
413              ties are added to the permitted set and assigned to  the  effec‐
414              tive set when execve(2) is called.
415
416       A  child created via fork(2) inherits copies of its parent's capability
417       sets.  See below for a discussion of the treatment of capabilities dur‐
418       ing execve(2).
419
420       Using  capset(2),  a thread may manipulate its own capability sets (see
421       below).
422
423       Since Linux 3.2, the  file  /proc/sys/kernel/cap_last_cap  exposes  the
424       numerical value of the highest capability supported by the running ker‐
425       nel; this can be used to determine the highest bit that may be set in a
426       capability set.
427
428   File capabilities
429       Since  kernel  2.6.24,  the kernel supports associating capability sets
430       with an executable file using setcap(8).  The file capability sets  are
431       stored  in  an  extended attribute (see setxattr(2) and xattr(7)) named
432       security.capability.  Writing to this extended attribute  requires  the
433       CAP_SETFCAP  capability.  The file capability sets, in conjunction with
434       the capability sets of the thread,  determine  the  capabilities  of  a
435       thread after an execve(2).
436
437       The three file capability sets are:
438
439       Permitted (formerly known as forced):
440              These  capabilities  are  automatically permitted to the thread,
441              regardless of the thread's inheritable capabilities.
442
443       Inheritable (formerly known as allowed):
444              This set is ANDed with the thread's inheritable set to determine
445              which  inheritable capabilities are enabled in the permitted set
446              of the thread after the execve(2).
447
448       Effective:
449              This is not a set, but rather just a single bit.  If this bit is
450              set, then during an execve(2) all of the new permitted capabili‐
451              ties for the thread are also raised in the  effective  set.   If
452              this  bit  is  not set, then after an execve(2), none of the new
453              permitted capabilities is in the new effective set.
454
455              Enabling the file effective capability bit implies that any file
456              permitted  or  inheritable  capability  that  causes a thread to
457              acquire  the  corresponding  permitted  capability   during   an
458              execve(2)  (see  the  transformation rules described below) will
459              also acquire that capability in its effective  set.   Therefore,
460              when    assigning    capabilities    to   a   file   (setcap(8),
461              cap_set_file(3), cap_set_fd(3)), if  we  specify  the  effective
462              flag  as  being  enabled  for any capability, then the effective
463              flag must also be specified as enabled for all  other  capabili‐
464              ties  for which the corresponding permitted or inheritable flags
465              is enabled.
466
467   Transformation of capabilities during execve()
468       During an execve(2), the kernel calculates the new capabilities of  the
469       process using the following algorithm:
470
471           P'(ambient)     = (file is privileged) ? 0 : P(ambient)
472
473           P'(permitted)   = (P(inheritable) & F(inheritable)) |
474                             (F(permitted) & cap_bset) | P'(ambient)
475
476           P'(effective)   = F(effective) ? P'(permitted) : P'(ambient)
477
478           P'(inheritable) = P(inheritable)    [i.e., unchanged]
479
480       where:
481
482           P         denotes  the  value of a thread capability set before the
483                     execve(2)
484
485           P'        denotes the value of a thread capability  set  after  the
486                     execve(2)
487
488           F         denotes a file capability set
489
490           cap_bset  is  the  value  of the capability bounding set (described
491                     below).
492
493       A privileged file is one that has capabilities or has  the  set-user-ID
494       or set-group-ID bit set.
495
496       Note:  the  capability transitions described above may not be performed
497       (i.e., file capabilities may be ignored) for the same reasons that  the
498       set-user-ID and set-group-ID bits are ignored; see execve(2).
499
500       Note:  according to the rules above, if a process with nonzero user IDs
501       performs an execve(2) then any capabilities that  are  present  in  its
502       permitted  and  effective  sets  will be cleared.  For the treatment of
503       capabilities when a  process  with  a  user  ID  of  zero  performs  an
504       execve(2),  see  below  under Capabilities and execution of programs by
505       root.
506
507   Safety checking for capability-dumb binaries
508       A capability-dumb binary is an application that has been marked to have
509       file  capabilities, but has not been converted to use the libcap(3) API
510       to manipulate its capabilities.  (In other words, this is a traditional
511       set-user-ID-root  program  that has been switched to use file capabili‐
512       ties, but whose code has not been modified to understand capabilities.)
513       For such applications, the effective capability bit is set on the file,
514       so that the file permitted capabilities are  automatically  enabled  in
515       the  process  effective set when executing the file.  The kernel recog‐
516       nizes a file which has the effective capability bit set as  capability-
517       dumb for the purpose of the check described here.
518
519       When  executing  a  capability-dumb  binary,  the  kernel checks if the
520       process obtained all permitted capabilities that were specified in  the
521       file  permitted  set,  after  the  capability transformations described
522       above have been performed.  (The typical  reason  why  this  might  not
523       occur  is that the capability bounding set masked out some of the capa‐
524       bilities in the file permitted set.)  If the process did not obtain the
525       full  set of file permitted capabilities, then execve(2) fails with the
526       error EPERM.  This prevents possible security risks  that  could  arise
527       when a capability-dumb application is executed with less privilege that
528       it needs.  Note that, by definition, the application could  not  itself
529       recognize this problem, since it does not employ the libcap(3) API.
530
531   Capabilities and execution of programs by root
532       In  order to provide an all-powerful root using capability sets, during
533       an execve(2):
534
535       1. If a set-user-ID-root program is being  executed,  or  the  real  or
536          effective user ID of the process is 0 (root) then the file inherita‐
537          ble and permitted sets are defined to be all ones (i.e.,  all  capa‐
538          bilities enabled).
539
540       2. If  a  set-user-ID-root  program is being executed, or the effective
541          user ID of the process is 0 (root) then the file  effective  bit  is
542          defined to be one (enabled).
543
544       The upshot of the above rules, combined with the capabilities transfor‐
545       mations described above, is as follows:
546
547       *  When a process execve(2)s a  set-user-ID-root  program,  or  when  a
548          process  with  an  effective UID of 0 execve(2)s a program, it gains
549          all capabilities in its permitted  and  effective  capability  sets,
550          except those masked out by the capability bounding set.
551
552       *  When  a  process with a real UID of 0 execve(2)s a program, it gains
553          all capabilities in  its  permitted  capability  set,  except  those
554          masked out by the capability bounding set.
555
556       The  above steps yield semantics that are the same as those provided by
557       traditional UNIX systems.
558
559   Set-user-ID-root programs that have file capabilities
560       Executing a program that is both set-user-ID root and has file capabil‐
561       ities  will  cause the process to gain just the capabilities granted by
562       the program (i.e., not all capabilities, as would occur when  executing
563       a set-user-ID-root program that does not have any associated file capa‐
564       bilities).  Note that one can assign empty capability sets to a program
565       file, and thus it is possible to create a set-user-ID-root program that
566       changes the effective and saved set-user-ID of the  process  that  exe‐
567       cutes the program to 0, but confers no capabilities to that process.
568
569   Capability bounding set
570       The capability bounding set is a security mechanism that can be used to
571       limit the capabilities that can be gained  during  an  execve(2).   The
572       bounding set is used in the following ways:
573
574       * During  an  execve(2),  the capability bounding set is ANDed with the
575         file permitted capability set, and the result of  this  operation  is
576         assigned  to  the  thread's permitted capability set.  The capability
577         bounding set thus places a limit on the permitted  capabilities  that
578         may be granted by an executable file.
579
580       * (Since  Linux  2.6.25) The capability bounding set acts as a limiting
581         superset for the capabilities that a thread can add to its  inherita‐
582         ble  set  using capset(2).  This means that if a capability is not in
583         the bounding set, then a thread can't  add  this  capability  to  its
584         inheritable  set,  even  if it was in its permitted capabilities, and
585         thereby cannot have this capability preserved in  its  permitted  set
586         when  it execve(2)s a file that has the capability in its inheritable
587         set.
588
589       Note that the bounding set masks the file permitted  capabilities,  but
590       not  the  inheritable capabilities.  If a thread maintains a capability
591       in its inheritable set that is not in its bounding  set,  then  it  can
592       still  gain  that  capability  in its permitted set by executing a file
593       that has the capability in its inheritable set.
594
595       Depending on the kernel version, the capability bounding set is  either
596       a system-wide attribute, or a per-process attribute.
597
598       Capability bounding set prior to Linux 2.6.25
599
600       In  kernels before 2.6.25, the capability bounding set is a system-wide
601       attribute that affects all threads on the system.  The bounding set  is
602       accessible via the file /proc/sys/kernel/cap-bound.  (Confusingly, this
603       bit  mask  parameter  is  expressed  as  a  signed  decimal  number  in
604       /proc/sys/kernel/cap-bound.)
605
606       Only  the  init process may set capabilities in the capability bounding
607       set; other than that, the superuser (more precisely: a process with the
608       CAP_SYS_MODULE capability) may only clear capabilities from this set.
609
610       On  a  standard system the capability bounding set always masks out the
611       CAP_SETPCAP capability.  To remove this restriction (dangerous!),  mod‐
612       ify  the  definition  of CAP_INIT_EFF_SET in include/linux/capability.h
613       and rebuild the kernel.
614
615       The system-wide capability bounding set  feature  was  added  to  Linux
616       starting with kernel version 2.2.11.
617
618       Capability bounding set from Linux 2.6.25 onward
619
620       From  Linux  2.6.25,  the  capability  bounding  set  is  a  per-thread
621       attribute.  (There is no longer a system-wide capability bounding set.)
622
623       The bounding set is inherited at fork(2) from the thread's parent,  and
624       is preserved across an execve(2).
625
626       A thread may remove capabilities from its capability bounding set using
627       the prctl(2) PR_CAPBSET_DROP operation, provided it has the CAP_SETPCAP
628       capability.   Once a capability has been dropped from the bounding set,
629       it cannot be restored to that set.  A thread can determine if  a  capa‐
630       bility is in its bounding set using the prctl(2) PR_CAPBSET_READ opera‐
631       tion.
632
633       Removing capabilities from the bounding set is supported only  if  file
634       capabilities  are  compiled  into  the kernel.  In kernels before Linux
635       2.6.33, file capabilities were an optional feature configurable via the
636       CONFIG_SECURITY_FILE_CAPABILITIES option.  Since Linux 2.6.33, the con‐
637       figuration option has been removed and  file  capabilities  are  always
638       part  of the kernel.  When file capabilities are compiled into the ker‐
639       nel, the init process (the ancestor of all  processes)  begins  with  a
640       full bounding set.  If file capabilities are not compiled into the ker‐
641       nel, then init begins with  a  full  bounding  set  minus  CAP_SETPCAP,
642       because  this capability has a different meaning when there are no file
643       capabilities.
644
645       Removing a capability from the bounding set does not remove it from the
646       thread's  inheritable set.  However it does prevent the capability from
647       being added back into the thread's inheritable set in the future.
648
649   Effect of user ID changes on capabilities
650       To preserve the traditional semantics for  transitions  between  0  and
651       nonzero  user IDs, the kernel makes the following changes to a thread's
652       capability sets on changes to the thread's real, effective, saved  set,
653       and filesystem user IDs (using setuid(2), setresuid(2), or similar):
654
655       1. If one or more of the real, effective or saved set user IDs was pre‐
656          viously 0, and as a result of the UID changes all of these IDs  have
657          a  nonzero value, then all capabilities are cleared from the permit‐
658          ted, effective, and ambient capability sets.
659
660       2. If the effective user ID is changed from  0  to  nonzero,  then  all
661          capabilities are cleared from the effective set.
662
663       3. If the effective user ID is changed from nonzero to 0, then the per‐
664          mitted set is copied to the effective set.
665
666       4. If the filesystem user ID is changed from 0 to  nonzero  (see  setf‐
667          suid(2)),  then  the  following  capabilities  are  cleared from the
668          effective  set:  CAP_CHOWN,  CAP_DAC_OVERRIDE,  CAP_DAC_READ_SEARCH,
669          CAP_FOWNER,  CAP_FSETID,  CAP_LINUX_IMMUTABLE  (since Linux 2.6.30),
670          CAP_MAC_OVERRIDE,  and  CAP_MKNOD  (since  Linux  2.6.30).   If  the
671          filesystem UID is changed from nonzero to 0, then any of these capa‐
672          bilities that are enabled in the permitted set are  enabled  in  the
673          effective set.
674
675       If a thread that has a 0 value for one or more of its user IDs wants to
676       prevent its permitted capability set being cleared when it  resets  all
677       of   its   user  IDs  to  nonzero  values,  it  can  do  so  using  the
678       SECBIT_KEEP_CAPS securebits flag described below.
679
680   Programmatically adjusting capability sets
681       A thread  can  retrieve  and  change  its  capability  sets  using  the
682       capget(2)   and   capset(2)   system   calls.    However,  the  use  of
683       cap_get_proc(3) and cap_set_proc(3), both provided in the libcap  pack‐
684       age, is preferred for this purpose.  The following rules govern changes
685       to the thread capability sets:
686
687       1. If the caller does not have  the  CAP_SETPCAP  capability,  the  new
688          inheritable  set must be a subset of the combination of the existing
689          inheritable and permitted sets.
690
691       2. (Since Linux 2.6.25) The new inheritable set must be a subset of the
692          combination  of  the  existing  inheritable  set  and the capability
693          bounding set.
694
695       3. The new permitted set must be a subset of the existing permitted set
696          (i.e., it is not possible to acquire permitted capabilities that the
697          thread does not currently have).
698
699       4. The new effective set must be a subset of the new permitted set.
700
701   The securebits flags: establishing a capabilities-only environment
702       Starting with kernel 2.6.26, and with a kernel in which file  capabili‐
703       ties are enabled, Linux implements a set of per-thread securebits flags
704       that can be used to disable special handling of capabilities for UID  0
705       (root).  These flags are as follows:
706
707       SECBIT_KEEP_CAPS
708              Setting this flag allows a thread that has one or more 0 UIDs to
709              retain capabilities in its permitted and effective sets when  it
710              switches all of its UIDs to nonzero values.  If this flag is not
711              set, then such a UID switch causes the thread to lose all  capa‐
712              bilities  in  those  sets.   This  flag  is always cleared on an
713              execve(2).
714
715              The setting of the  SECBIT_KEEP_CAPS  flag  is  ignored  if  the
716              SECBIT_NO_SETUID_FIXUP flag is set.  (The latter flag provides a
717              superset of the effect of the former flag.)
718
719              This flag provides the same functionality as the older  prctl(2)
720              PR_SET_KEEPCAPS operation.
721
722       SECBIT_NO_SETUID_FIXUP
723              Setting  this flag stops the kernel from adjusting the process's
724              permitted, effective,  and  ambient  capability  sets  when  the
725              thread's effective and filesystem UIDs are switched between zero
726              and nonzero values.  (See  the  subsection  Effect  of  user  ID
727              changes on capabilities.)
728
729       SECBIT_NOROOT
730              If  this bit is set, then the kernel does not grant capabilities
731              when a set-user-ID-root program is executed, or when  a  process
732              with  an  effective  or real UID of 0 calls execve(2).  (See the
733              subsection Capabilities and execution of programs by root.)
734
735       SECBIT_NO_CAP_AMBIENT_RAISE
736              Setting this flag disallows raising ambient capabilities via the
737              prctl(2) PR_CAP_AMBIENT_RAISE operation.
738
739       Each  of the above "base" flags has a companion "locked" flag.  Setting
740       any of the "locked" flags is irreversible, and has the effect  of  pre‐
741       venting  further  changes to the corresponding "base" flag.  The locked
742       flags  are:   SECBIT_KEEP_CAPS_LOCKED,   SECBIT_NO_SETUID_FIXUP_LOCKED,
743       SECBIT_NOROOT_LOCKED, and SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED.
744
745       The  securebits  flags can be modified and retrieved using the prctl(2)
746       PR_SET_SECUREBITS and PR_GET_SECUREBITS  operations.   The  CAP_SETPCAP
747       capability is required to modify the flags.
748
749       The  securebits  flags  are  inherited  by  child processes.  During an
750       execve(2), all of the  flags  are  preserved,  except  SECBIT_KEEP_CAPS
751       which is always cleared.
752
753       An  application  can  use the following call to lock itself, and all of
754       its descendants, into an environment where  the  only  way  of  gaining
755       capabilities  is  by executing a program with associated file capabili‐
756       ties:
757
758           prctl(PR_SET_SECUREBITS,
759                /* SECBIT_KEEP_CAPS off */
760                   SECBIT_KEEP_CAPS_LOCKED |
761                   SECBIT_NO_SETUID_FIXUP |
762                   SECBIT_NO_SETUID_FIXUP_LOCKED |
763                   SECBIT_NOROOT |
764                   SECBIT_NOROOT_LOCKED);
765                   /* Setting/locking SECBIT_NO_CAP_AMBIENT_RAISE
766                      is not required */
767
768   Interaction with user namespaces
769       For a discussion of the interaction of  capabilities  and  user  names‐
770       paces, see user_namespaces(7).
771

CONFORMING TO

773       No  standards govern capabilities, but the Linux capability implementa‐
774       tion  is  based  on  the  withdrawn  POSIX.1e   draft   standard;   see
775http://wt.tuxomania.net/publications/posix.1e/⟩.
776

NOTES

778       From kernel 2.5.27 to kernel 2.6.26, capabilities were an optional ker‐
779       nel component, and  could  be  enabled/disabled  via  the  CONFIG_SECU‐
780       RITY_CAPABILITIES kernel configuration option.
781
782       The /proc/[pid]/task/TID/status file can be used to view the capability
783       sets of a thread.  The /proc/[pid]/status  file  shows  the  capability
784       sets  of  a process's main thread.  Before Linux 3.8, nonexistent capa‐
785       bilities were shown as being enabled (1) in these  sets.   Since  Linux
786       3.8,  all  nonexistent  capabilities  (above CAP_LAST_CAP) are shown as
787       disabled (0).
788
789       The libcap package provides a suite of routines for setting and getting
790       capabilities  that  is  more comfortable and less likely to change than
791       the interface provided by capset(2) and capget(2).  This  package  also
792       provides the setcap(8) and getcap(8) programs.  It can be found at
793http://www.kernel.org/pub/linux/libs/security/linux-privs⟩.
794
795       Before  kernel  2.6.24, and from kernel 2.6.24 to kernel 2.6.32 if file
796       capabilities are not enabled, a thread with the CAP_SETPCAP  capability
797       can manipulate the capabilities of threads other than itself.  However,
798       this is only theoretically possible, since no thread ever has CAP_SETP‐
799       CAP in either of these cases:
800
801       * In  the pre-2.6.25 implementation the system-wide capability bounding
802         set, /proc/sys/kernel/cap-bound, always masks  out  this  capability,
803         and  this  can not be changed without modifying the kernel source and
804         rebuilding.
805
806       * If file capabilities are disabled in the current implementation, then
807         init  starts  out  with  this capability removed from its per-process
808         bounding set, and that bounding set is inherited by  all  other  pro‐
809         cesses created on the system.
810

SEE ALSO

812       capsh(1),     setpriv(1),    prctl(2),    setfsuid(2),    cap_clear(3),
813       cap_copy_ext(3),  cap_from_text(3),  cap_get_file(3),  cap_get_proc(3),
814       cap_init(3),   capgetp(3),   capsetp(3),  libcap(3),  proc(5),  creden‐
815       tials(7), pthreads(7), user_namespaces(7), captest(8), filecap(8), get‐
816       cap(8), netcap(8), pscap(8), setcap(8)
817
818       include/linux/capability.h in the Linux kernel source tree
819

COLOPHON

821       This  page  is  part of release 4.15 of the Linux man-pages project.  A
822       description of the project, information about reporting bugs,  and  the
823       latest     version     of     this    page,    can    be    found    at
824       https://www.kernel.org/doc/man-pages/.
825
826
827
828Linux                             2018-02-02                   CAPABILITIES(7)
Impressum