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  non-zero).
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_WRITE (since Linux 2.6.11)
32              Write records to kernel auditing log.
33
34       CAP_CHOWN
35              Make arbitrary changes to file UIDs and GIDs (see chown(2)).
36
37       CAP_DAC_OVERRIDE
38              Bypass file read, write, and execute permission checks.  (DAC is
39              an abbreviation of "discretionary access control".)
40
41       CAP_DAC_READ_SEARCH
42              Bypass file read permission checks and directory read  and  exe‐
43              cute permission checks.
44
45       CAP_FOWNER
46              * Bypass  permission  checks on operations that normally require
47                the file system UID of the process to match  the  UID  of  the
48                file  (e.g.,  chmod(2),  utime(2)), excluding those operations
49                covered by CAP_DAC_OVERRIDE and CAP_DAC_READ_SEARCH;
50              * set extended file  attributes  (see  chattr(1))  on  arbitrary
51                files;
52              * set Access Control Lists (ACLs) on arbitrary files;
53              * ignore directory sticky bit on file deletion;
54              * specify O_NOATIME for arbitrary files in open(2) and fcntl(2).
55
56       CAP_FSETID
57              Don't  clear set-user-ID and set-group-ID permission bits when a
58              file is modified; set the set-group-ID bit for a file whose  GID
59              does  not match the file system or any of the supplementary GIDs
60              of the calling process.
61
62       CAP_IPC_LOCK
63              Lock memory (mlock(2), mlockall(2), mmap(2), shmctl(2)).
64
65       CAP_IPC_OWNER
66              Bypass permission checks for operations on System V IPC objects.
67
68       CAP_KILL
69              Bypass permission checks  for  sending  signals  (see  kill(2)).
70              This includes use of the ioctl(2) KDSIGACCEPT operation.
71
72       CAP_LEASE (since Linux 2.4)
73              Establish leases on arbitrary files (see fcntl(2)).
74
75       CAP_LINUX_IMMUTABLE
76              Set  the  FS_APPEND_FL  and  FS_IMMUTABLE_FL  i-node  flags (see
77              chattr(1)).
78
79       CAP_MAC_ADMIN (since Linux 2.6.25)
80              Override Mandatory Access Control (MAC).   Implemented  for  the
81              Smack Linux Security Module (LSM).
82
83       CAP_MAC_OVERRIDE (since Linux 2.6.25)
84              Allow  MAC  configuration or state changes.  Implemented for the
85              Smack LSM.
86
87       CAP_MKNOD (since Linux 2.4)
88              Create special files using mknod(2).
89
90       CAP_NET_ADMIN
91              Perform various network-related operations (e.g., setting privi‐
92              leged  socket options, enabling multicasting, interface configu‐
93              ration, modifying routing tables).
94
95       CAP_NET_BIND_SERVICE
96              Bind a socket to Internet domain privileged ports (port  numbers
97              less than 1024).
98
99       CAP_NET_BROADCAST
100              (Unused)  Make socket broadcasts, and listen to multicasts.
101
102       CAP_NET_RAW
103              Use RAW and PACKET sockets.
104
105       CAP_SETGID
106              Make  arbitrary  manipulations of process GIDs and supplementary
107              GID list; forge GID when passing  socket  credentials  via  Unix
108              domain sockets.
109
110       CAP_SETFCAP (since Linux 2.6.24)
111              Set file capabilities.
112
113       CAP_SETPCAP
114              If  file  capabilities  are  not  supported: grant or remove any
115              capability in the caller's permitted capability set to  or  from
116              any  other process.  (This property of CAP_SETPCAP is not avail‐
117              able when the kernel is configured to support file capabilities,
118              since CAP_SETPCAP has entirely different semantics for such ker‐
119              nels.)
120
121              If file capabilities are supported: add any capability from  the
122              calling thread's bounding set to its inheritable set; drop capa‐
123              bilities from the bounding set (via  prctl(2)  PR_CAPBSET_DROP);
124              make changes to the securebits flags.
125
126       CAP_SETUID
127              Make   arbitrary   manipulations  of  process  UIDs  (setuid(2),
128              setreuid(2), setresuid(2), setfsuid(2)); make  forged  UID  when
129              passing socket credentials via Unix domain sockets.
130
131       CAP_SYS_ADMIN
132              * Perform a range of system administration operations including:
133                quotactl(2),  mount(2),  umount(2),   swapon(2),   swapoff(2),
134                sethostname(2), and setdomainname(2);
135              * perform  IPC_SET and IPC_RMID operations on arbitrary System V
136                IPC objects;
137              * perform operations on trusted and security Extended Attributes
138                (see attr(5));
139              * use lookup_dcookie(2);
140              * use  ioprio_set(2) to assign IOPRIO_CLASS_RT and (before Linux
141                2.6.25) IOPRIO_CLASS_IDLE I/O scheduling classes;
142              * forge UID when passing socket credentials;
143              * exceed /proc/sys/fs/file-max, the  system-wide  limit  on  the
144                number  of  open files, in system calls that open files (e.g.,
145                accept(2), execve(2), open(2), pipe(2));
146              * employ CLONE_NEWNS flag with clone(2) and unshare(2);
147              * perform KEYCTL_CHOWN and KEYCTL_SETPERM keyctl(2) operations.
148
149       CAP_SYS_BOOT
150              Use reboot(2) and kexec_load(2).
151
152       CAP_SYS_CHROOT
153              Use chroot(2).
154
155       CAP_SYS_MODULE
156              Load  and  unload  kernel  modules   (see   init_module(2)   and
157              delete_module(2));  in  kernels before 2.6.25: drop capabilities
158              from the system-wide capability bounding set.
159
160       CAP_SYS_NICE
161              * Raise process nice value (nice(2), setpriority(2)) and  change
162                the nice value for arbitrary processes;
163              * set real-time scheduling policies for calling process, and set
164                scheduling policies and  priorities  for  arbitrary  processes
165                (sched_setscheduler(2), sched_setparam(2));
166              * set  CPU  affinity  for  arbitrary  processes (sched_setaffin‐
167                ity(2));
168              * set I/O scheduling class and priority for arbitrary  processes
169                (ioprio_set(2));
170              * apply  migrate_pages(2)  to arbitrary processes and allow pro‐
171                cesses to be migrated to arbitrary nodes;
172              * apply move_pages(2) to arbitrary processes;
173              * use the MPOL_MF_MOVE_ALL flag with mbind(2) and move_pages(2).
174
175       CAP_SYS_PACCT
176              Use acct(2).
177
178       CAP_SYS_PTRACE
179              Trace arbitrary processes using ptrace(2)
180
181       CAP_SYS_RAWIO
182              Perform I/O port  operations  (iopl(2)  and  ioperm(2));  access
183              /proc/kcore.
184
185       CAP_SYS_RESOURCE
186              * Use reserved space on ext2 file systems;
187              * make ioctl(2) calls controlling ext3 journaling;
188              * override disk quota limits;
189              * increase resource limits (see setrlimit(2));
190              * override RLIMIT_NPROC resource limit;
191              * raise  msg_qbytes limit for a System V message queue above the
192                limit in /proc/sys/kernel/msgmnb (see msgop(2) and msgctl(2)).
193
194       CAP_SYS_TIME
195              Set system clock (settimeofday(2), stime(2),  adjtimex(2));  set
196              real-time (hardware) clock.
197
198       CAP_SYS_TTY_CONFIG
199              Use vhangup(2).
200
201   Past and Current Implementation
202       A full implementation of capabilities requires that:
203
204       1. For  all  privileged  operations,  the kernel must check whether the
205          thread has the required capability in its effective set.
206
207       2. The kernel must provide system calls allowing a thread's  capability
208          sets to be changed and retrieved.
209
210       3. The file system must support attaching capabilities to an executable
211          file, so that a process gains those capabilities when  the  file  is
212          executed.
213
214       Before kernel 2.6.24, only the first two of these requirements are met;
215       since kernel 2.6.24, all three requirements are met.
216
217   Thread Capability Sets
218       Each thread has three capability sets containing zero or  more  of  the
219       above capabilities:
220
221       Permitted:
222              This  is a limiting superset for the effective capabilities that
223              the thread may assume.  It is also a limiting superset  for  the
224              capabilities  that  may  be  added  to  the inheritable set by a
225              thread that does not have  the  CAP_SETPCAP  capability  in  its
226              effective set.
227
228              If  a  thread  drops a capability from its permitted set, it can
229              never re-acquire that capability (unless it execve(2)s either  a
230              set-user-ID-root  program,  or  a  program whose associated file
231              capabilities grant that capability).
232
233       Inheritable:
234              This is a set of capabilities preserved across an execve(2).  It
235              provides a mechanism for a process to assign capabilities to the
236              permitted set of the new program during an execve(2).
237
238       Effective:
239              This is the set of capabilities used by the  kernel  to  perform
240              permission checks for the thread.
241
242       A  child created via fork(2) inherits copies of its parent's capability
243       sets.  See below for a discussion of the treatment of capabilities dur‐
244       ing execve(2).
245
246       Using  capset(2),  a thread may manipulate its own capability sets (see
247       below).
248
249   File Capabilities
250       Since kernel 2.6.24, the kernel supports  associating  capability  sets
251       with  an executable file using setcap(8).  The file capability sets are
252       stored in an extended attribute (see setxattr(2)) named  security.capa‐
253       bility.   Writing  to  this extended attribute requires the CAP_SETFCAP
254       capability.  The file capability sets, in conjunction with the capabil‐
255       ity sets of the thread, determine the capabilities of a thread after an
256       execve(2).
257
258       The three file capability sets are:
259
260       Permitted (formerly known as forced):
261              These capabilities are automatically permitted  to  the  thread,
262              regardless of the thread's inheritable capabilities.
263
264       Inheritable (formerly known as allowed):
265              This set is ANDed with the thread's inheritable set to determine
266              which inheritable capabilities are enabled in the permitted  set
267              of the thread after the execve(2).
268
269       Effective:
270              This is not a set, but rather just a single bit.  If this bit is
271              set, then during an execve(2) all of the new permitted capabili‐
272              ties  for  the  thread are also raised in the effective set.  If
273              this bit is not set, then after an execve(2), none  of  the  new
274              permitted capabilities is in the new effective set.
275
276              Enabling the file effective capability bit implies that any file
277              permitted or inheritable capability  that  causes  a  thread  to
278              acquire   the   corresponding  permitted  capability  during  an
279              execve(2) (see the transformation rules  described  below)  will
280              also  acquire  that capability in its effective set.  Therefore,
281              when   assigning   capabilities   to    a    file    (setcap(8),
282              cap_set_file(3),  cap_set_fd(3)),  if  we  specify the effective
283              flag as being enabled for any  capability,  then  the  effective
284              flag  must  also be specified as enabled for all other capabili‐
285              ties for which the corresponding permitted or inheritable  flags
286              is enabled.
287
288   Transformation of Capabilities During execve()
289       During  an execve(2), the kernel calculates the new capabilities of the
290       process using the following algorithm:
291
292           P'(permitted) = (P(inheritable) & F(inheritable)) |
293                           (F(permitted) & cap_bset)
294
295           P'(effective) = F(effective) ? P'(permitted) : 0
296
297           P'(inheritable) = P(inheritable)    [i.e., unchanged]
298
299       where:
300
301           P         denotes the value of a thread capability set  before  the
302                     execve(2)
303
304           P'        denotes the value of a capability set after the execve(2)
305
306           F         denotes a file capability set
307
308           cap_bset  is  the  value  of the capability bounding set (described
309                     below).
310
311   Capabilities and execution of programs by root
312       In order to provide an all-powerful root using capability sets,  during
313       an execve(2):
314
315       1. If a set-user-ID-root program is being executed, or the real user ID
316          of the process is 0 (root) then the file inheritable  and  permitted
317          sets are defined to be all ones (i.e., all capabilities enabled).
318
319       2. If  a  set-user-ID-root  program  is  being  executed, then the file
320          effective bit is defined to be one (enabled).
321
322       The upshot of the above rules, combined with the capabilities transfor‐
323       mations  described above, is that when a process execve(2)s a set-user-
324       ID-root program,  or  when  a  process  with  an  effective  UID  of  0
325       execve(2)s  a  program,  it gains all capabilities in its permitted and
326       effective capability sets, except those masked out  by  the  capability
327       bounding  set.  This provides semantics that are the same as those pro‐
328       vided by traditional Unix systems.
329
330   Capability bounding set
331       The capability bounding set is a security mechanism that can be used to
332       limit  the  capabilities  that  can be gained during an execve(2).  The
333       bounding set is used in the following ways:
334
335       * During an execve(2), the capability bounding set is  ANDed  with  the
336         file  permitted  capability  set, and the result of this operation is
337         assigned to the thread's permitted capability  set.   The  capability
338         bounding  set  thus places a limit on the permitted capabilities that
339         may be granted by an executable file.
340
341       * (Since Linux 2.6.25) The capability bounding set acts as  a  limiting
342         superset  for the capabilities that a thread can add to its inherita‐
343         ble set using capset(2).  This means that if the capability is not in
344         the  bounding set, then a thread can't add one of its permitted capa‐
345         bilities to its inheritable set and thereby have that capability pre‐
346         served  in  its  permitted set when it execve(2)s a file that has the
347         capability in its inheritable set.
348
349       Note that the bounding set masks the file permitted  capabilities,  but
350       not  the inherited capabilities.  If a thread maintains a capability in
351       its inherited set that is not in its bounding set, then  it  can  still
352       gain  that capability in its permitted set by executing a file that has
353       the capability in its inherited set.
354
355       Depending on the kernel version, the capability bounding set is  either
356       a system-wide attribute, or a per-process attribute.
357
358       Capability bounding set prior to Linux 2.6.25
359
360       In  kernels before 2.6.25, the capability bounding set is a system-wide
361       attribute that affects all threads on the system.  The bounding set  is
362       accessible via the file /proc/sys/kernel/cap-bound.  (Confusingly, this
363       bit  mask  parameter  is  expressed  as  a  signed  decimal  number  in
364       /proc/sys/kernel/cap-bound.)
365
366       Only  the  init process may set capabilities in the capability bounding
367       set; other than that, the superuser (more precisely: programs with  the
368       CAP_SYS_MODULE capability) may only clear capabilities from this set.
369
370       On  a  standard system the capability bounding set always masks out the
371       CAP_SETPCAP capability.  To remove this restriction (dangerous!),  mod‐
372       ify  the  definition  of CAP_INIT_EFF_SET in include/linux/capability.h
373       and rebuild the kernel.
374
375       The system-wide capability bounding set  feature  was  added  to  Linux
376       starting with kernel version 2.2.11.
377
378       Capability bounding set from Linux 2.6.25 onwards
379
380       From  Linux  2.6.25,  the  capability  bounding  set  is  a  per-thread
381       attribute.  (There is no longer a system-wide capability bounding set.)
382
383       The bounding set is inherited at fork(2) from the thread's parent,  and
384       is preserved across an execve(2).
385
386       A thread may remove capabilities from its capability bounding set using
387       the prctl(2) PR_CAPBSET_DROP operation, provided it has the CAP_SETPCAP
388       capability.   Once a capability has been dropped from the bounding set,
389       it cannot be restored to that set.  A thread can determine if  a  capa‐
390       bility is in its bounding set using the prctl(2) PR_CAPBSET_READ opera‐
391       tion.
392
393       Removing capabilities from the bounding set is only supported  if  file
394       capabilities  are  compiled into the kernel (CONFIG_SECURITY_FILE_CAPA‐
395       BILITIES).  In that case, the init process (the ancestor  of  all  pro‐
396       cesses)  begins with a full bounding set.  If file capabilities are not
397       compiled into the kernel, then init begins with  a  full  bounding  set
398       minus CAP_SETPCAP, because this capability has a different meaning when
399       there are no file capabilities.
400
401       Removing a capability from the bounding set does not remove it from the
402       thread's  inherited  set.   However it does prevent the capability from
403       being added back into the thread's inherited set in the future.
404
405   Effect of User ID Changes on Capabilities
406       To preserve the traditional semantics for  transitions  between  0  and
407       non-zero user IDs, the kernel makes the following changes to a thread's
408       capability sets on changes to the thread's real, effective, saved  set,
409       and file system user IDs (using setuid(2), setresuid(2), or similar):
410
411       1. If one or more of the real, effective or saved set user IDs was pre‐
412          viously 0, and as a result of the UID changes all of these IDs  have
413          a non-zero value, then all capabilities are cleared from the permit‐
414          ted and effective capability sets.
415
416       2. If the effective user ID is changed from 0  to  non-zero,  then  all
417          capabilities are cleared from the effective set.
418
419       3. If  the  effective  user  ID is changed from non-zero to 0, then the
420          permitted set is copied to the effective set.
421
422       4. If the file system user ID is changed from 0 to non-zero (see  setf‐
423          suid(2)) then the following capabilities are cleared from the effec‐
424          tive   set:   CAP_CHOWN,   CAP_DAC_OVERRIDE,    CAP_DAC_READ_SEARCH,
425          CAP_FOWNER,  CAP_FSETID,  and  CAP_MAC_OVERRIDE.  If the file system
426          UID is changed from non-zero to 0, then any  of  these  capabilities
427          that  are  enabled in the permitted set are enabled in the effective
428          set.
429
430       If a thread that has a 0 value for one or more of its user IDs wants to
431       prevent  its  permitted capability set being cleared when it resets all
432       of its user IDs to non-zero values, it can do  so  using  the  prctl(2)
433       PR_SET_KEEPCAPS operation.
434
435   Programmatically adjusting capability sets
436       A  thread  can  retrieve  and  change  its  capability  sets  using the
437       capget(2)  and  capset(2)  system   calls.    However,   the   use   of
438       cap_get_proc(3)  and cap_set_proc(3), both provided in the libcap pack‐
439       age, is preferred for this purpose.  The following rules govern changes
440       to the thread capability sets:
441
442       1. If  the  caller  does  not  have the CAP_SETPCAP capability, the new
443          inheritable set must be a subset of the combination of the  existing
444          inheritable and permitted sets.
445
446       2. (Since  kernel  2.6.25)  The new inheritable set must be a subset of
447          the combination of the existing inheritable set and  the  capability
448          bounding set.
449
450       3. The new permitted set must be a subset of the existing permitted set
451          (i.e., it is not possible to acquire permitted capabilities that the
452          thread does not currently have).
453
454       4. The new effective set must be a subset of the new permitted set.
455
456   The "securebits" flags: establishing a capabilities-only environment
457       Starting  with kernel 2.6.26, and with a kernel in which file capabili‐
458       ties are enabled, Linux implements a set of per-thread securebits flags
459       that  can be used to disable special handling of capabilities for UID 0
460       (root).  These flags are as follows:
461
462       SECURE_KEEP_CAPS
463              Setting this flag allows a thread that has one or more 0 UIDs to
464              retain  its  capabilities  when it switches all of its UIDs to a
465              non-zero value.  If this flag is not set, then such a UID switch
466              causes the thread to lose all capabilities.  This flag is always
467              cleared on an execve(2).  (This flag provides the same function‐
468              ality as the older prctl(2) PR_SET_KEEPCAPS operation.)
469
470       SECURE_NO_SETUID_FIXUP
471              Setting  this  flag  stops the kernel from adjusting  capability
472              sets when the threads's  effective  and  file  system  UIDs  are
473              switched  between zero and non-zero values.  (See the subsection
474              Effect of User ID Changes on Capabilities.)
475
476       SECURE_NOROOT
477              If this bit is set, then the kernel does not grant  capabilities
478              when  a  set-user-ID-root program is executed, or when a process
479              with an effective or real UID of 0 calls  execve(2).   (See  the
480              subsection Capabilities and execution of programs by root.)
481
482       Each  of the above "base" flags has a companion "locked" flag.  Setting
483       any of the "locked" flags is irreversible, and has the effect  of  pre‐
484       venting  further  changes to the corresponding "base" flag.  The locked
485       flags are: SECURE_KEEP_CAPS_LOCKED, SECURE_NO_SETUID_FIXUP_LOCKED,  and
486       SECURE_NOROOT_LOCKED.
487
488       The  securebits  flags can be modified and retrieved using the prctl(2)
489       PR_SET_SECUREBITS and PR_GET_SECUREBITS  operations.   The  CAP_SETPCAP
490       capability is required to modify the flags.
491
492       The  securebits  flags  are  inherited  by  child processes.  During an
493       execve(2), all of the  flags  are  preserved,  except  SECURE_KEEP_CAPS
494       which is always cleared.
495
496       An  application  can  use the following call to lock itself, and all of
497       its descendants, into an environment where  the  only  way  of  gaining
498       capabilities  is  by executing a program with associated file capabili‐
499       ties:
500
501           prctl(PR_SET_SECUREBITS,
502                   1 << SECURE_KEEP_CAPS_LOCKED |
503                   1 << SECURE_NO_SETUID_FIXUP |
504                   1 << SECURE_NO_SETUID_FIXUP_LOCKED |
505                   1 << SECURE_NOROOT |
506                   1 << SECURE_NOROOT_LOCKED);
507

CONFORMING TO

509       No standards govern capabilities, but the Linux capability  implementa‐
510       tion   is   based   on  the  withdrawn  POSIX.1e  draft  standard;  see
511       http://wt.xpilot.org/publications/posix.1e/.
512

NOTES

514       Since kernel 2.5.27, capabilities are an optional kernel component, and
515       can  be  enabled/disabled  via  the CONFIG_SECURITY_CAPABILITIES kernel
516       configuration option.
517
518       The /proc/PID/task/TID/status file can be used to view  the  capability
519       sets  of a thread.  The /proc/PID/status file shows the capability sets
520       of a process's main thread.
521
522       The libcap package provides a suite of routines for setting and getting
523       capabilities  that  is  more comfortable and less likely to change than
524       the interface provided by capset(2) and capget(2).  This  package  also
525       provides the setcap(8) and getcap(8) programs.  It can be found at
526       http://www.kernel.org/pub/linux/libs/security/linux-privs.
527
528       Before  kernel 2.6.24, and since kernel 2.6.24 if file capabilities are
529       not enabled, a thread with the CAP_SETPCAP  capability  can  manipulate
530       the  capabilities  of threads other than itself.  However, this is only
531       theoretically possible, since no thread ever has CAP_SETPCAP in  either
532       of these cases:
533
534       * In  the pre-2.6.25 implementation the system-wide capability bounding
535         set, /proc/sys/kernel/cap-bound, always masks  out  this  capability,
536         and  this  can not be changed without modifying the kernel source and
537         rebuilding.
538
539       * If file capabilities are disabled in the current implementation, then
540         init  starts  out  with  this capability removed from its per-process
541         bounding set, and that bounding set is inherited by  all  other  pro‐
542         cesses created on the system.
543

SEE ALSO

545       capget(2),   prctl(2),   setfsuid(2),   cap_clear(3),  cap_copy_ext(3),
546       cap_from_text(3),   cap_get_file(3),   cap_get_proc(3),    cap_init(3),
547       capgetp(3),  capsetp(3),  credentials(7),  pthreads(7), getcap(8), set‐
548       cap(8)
549
550       include/linux/capability.h in the kernel source
551

COLOPHON

553       This page is part of release 3.22 of the Linux  man-pages  project.   A
554       description  of  the project, and information about reporting bugs, can
555       be found at http://www.kernel.org/doc/man-pages/.
556
557
558
559Linux                             2008-11-27                   CAPABILITIES(7)
Impressum