1CAPGET(2)                  Linux Programmer's Manual                 CAPGET(2)
2
3
4

NAME

6       capget, capset - set/get capabilities of thread(s)
7

SYNOPSIS

9       #include <sys/capability.h>
10
11       int capget(cap_user_header_t hdrp, cap_user_data_t datap);
12
13       int capset(cap_user_header_t hdrp, const cap_user_data_t datap);
14

DESCRIPTION

16       Since Linux 2.2, the power of the superuser (root) has been partitioned
17       into a set of discrete capabilities.  Each thread has a set  of  effec‐
18       tive  capabilities  identifying which capabilities (if any) it may cur‐
19       rently exercise.  Each thread also has a set of  inheritable  capabili‐
20       ties that may be passed through an execve(2) call, and a set of permit‐
21       ted capabilities that it can make effective or inheritable.
22
23       These two system calls are the raw kernel  interface  for  getting  and
24       setting  thread capabilities.  Not only are these system calls specific
25       to Linux, but the kernel API is likely to change and use of these  sys‐
26       tem  calls (in particular the format of the cap_user_*_t types) is sub‐
27       ject to extension with each kernel revision, but old programs will keep
28       working.
29
30       The  portable  interfaces  are  cap_set_proc(3) and cap_get_proc(3); if
31       possible, you should use those interfaces in applications.  If you wish
32       to use the Linux extensions in applications, you should use the easier-
33       to-use interfaces capsetp(3) and capgetp(3).
34
35   Current details
36       Now that you have been warned, some current kernel details.  The struc‐
37       tures are defined as follows.
38
39           #define _LINUX_CAPABILITY_VERSION_1  0x19980330
40           #define _LINUX_CAPABILITY_U32S_1     1
41
42                   /* V2 added in Linux 2.6.25; deprecated */
43           #define _LINUX_CAPABILITY_VERSION_2  0x20071026
44           #define _LINUX_CAPABILITY_U32S_2     2
45
46                   /* V3 added in Linux 2.6.26 */
47           #define _LINUX_CAPABILITY_VERSION_3  0x20080522
48           #define _LINUX_CAPABILITY_U32S_3     2
49
50           typedef struct __user_cap_header_struct {
51              __u32 version;
52              int pid;
53           } *cap_user_header_t;
54
55           typedef struct __user_cap_data_struct {
56              __u32 effective;
57              __u32 permitted;
58              __u32 inheritable;
59           } *cap_user_data_t;
60
61       The  effective,  permitted, and inheritable fields are bit masks of the
62       capabilities defined in capabilities(7).  Note that  the  CAP_*  values
63       are  bit  indexes  and need to be bit-shifted before ORing into the bit
64       fields.  To define the structures for passing to the system  call,  you
65       have   to   use   the   struct   __user_cap_header_struct   and  struct
66       __user_cap_data_struct names because the typedefs are only pointers.
67
68       Kernels  prior  to  2.6.25  prefer  32-bit  capabilities  with  version
69       _LINUX_CAPABILITY_VERSION_1.   Linux  2.6.25  added  64-bit  capability
70       sets, with version _LINUX_CAPABILITY_VERSION_2.  There was, however, an
71       API  glitch,  and Linux 2.6.26 added _LINUX_CAPABILITY_VERSION_3 to fix
72       the problem.
73
74       Note that 64-bit capabilities use datap[0] and datap[1], whereas 32-bit
75       capabilities use only datap[0].
76
77       On  kernels  that support file capabilities (VFS capabilities support),
78       these system calls behave slightly differently.  This support was added
79       as  an  option in Linux 2.6.24, and became fixed (nonoptional) in Linux
80       2.6.33.
81
82       For capget() calls, one can probe the capabilities of  any  process  by
83       specifying its process ID with the hdrp->pid field value.
84
85   With VFS capabilities support
86       VFS  capabilities  employ  a  file extended attribute (see xattr(7)) to
87       allow capabilities to be attached to executables.  This privilege model
88       obsoletes  kernel  support  for  one process asynchronously setting the
89       capabilities of another.  That is, on kernels that have  VFS  capabili‐
90       ties  support,  when  calling  capset(),  the only permitted values for
91       hdrp->pid are 0 or, equivalently, the value returned by gettid(2).
92
93   Without VFS capabilities support
94       On older kernels that do not provide VFS capabilities support  capset()
95       can,  if  the  caller has the CAP_SETPCAP capability, be used to change
96       not only the caller's own capabilities, but also  the  capabilities  of
97       other  threads.   The  call  operates on the capabilities of the thread
98       specified by the pid field of hdrp when that  is  nonzero,  or  on  the
99       capabilities  of  the  calling  thread if pid is 0.  If pid refers to a
100       single-threaded process, then pid can be  specified  as  a  traditional
101       process ID; operating on a thread of a multithreaded process requires a
102       thread ID of the type returned by gettid(2).   For  capset(),  pid  can
103       also be: -1, meaning perform the change on all threads except the call‐
104       er and init(1); or a value less than -1, in which case  the  change  is
105       applied to all members of the process group whose ID is -pid.
106
107       For details on the data, see capabilities(7).
108

RETURN VALUE

110       On  success,  zero is returned.  On error, -1 is returned, and errno is
111       set appropriately.
112
113       The calls fail with the error EINVAL, and set the version field of hdrp
114       to  the  kernel preferred value of _LINUX_CAPABILITY_VERSION_?  when an
115       unsupported version value is specified.  In this  way,  one  can  probe
116       what the current preferred capability revision is.
117

ERRORS

119       EFAULT Bad  memory  address.  hdrp must not be NULL.  datap may be NULL
120              only when the user is trying to determine the preferred capabil‐
121              ity version format supported by the kernel.
122
123       EINVAL One of the arguments was invalid.
124
125       EPERM  An attempt was made to add a capability to the Permitted set, or
126              to set a capability in the Effective or Inheritable sets that is
127              not in the Permitted set.
128
129       EPERM  The  caller attempted to use capset() to modify the capabilities
130              of a thread other than itself, but lacked sufficient  privilege.
131              For  kernels  supporting VFS capabilities, this is never permit‐
132              ted.  For kernels lacking VFS support, the CAP_SETPCAP  capabil‐
133              ity  is  required.   (A  bug in kernels before 2.6.11 meant that
134              this error could also occur if a thread without this  capability
135              tried to change its own capabilities by specifying the pid field
136              as a nonzero value  (i.e.,  the  value  returned  by  getpid(2))
137              instead of 0.)
138
139       ESRCH  No such thread.
140

CONFORMING TO

142       These system calls are Linux-specific.
143

NOTES

145       The portable interface to the capability querying and setting functions
146       is provided by the libcap library and is available here:
147http://git.kernel.org/cgit/linux/kernel/git/morgan/libcap.git
148

SEE ALSO

150       clone(2), gettid(2), capabilities(7)
151

COLOPHON

153       This page is part of release 4.15 of the Linux  man-pages  project.   A
154       description  of  the project, information about reporting bugs, and the
155       latest    version    of    this    page,    can     be     found     at
156       https://www.kernel.org/doc/man-pages/.
157
158
159
160Linux                             2017-09-15                         CAPGET(2)
Impressum