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

RETURN VALUE

101       On success, zero is returned.  On error, -1 is returned, and  errno  is
102       set appropriately.
103
104       The calls fail with the error EINVAL, and set the version field of hdrp
105       to the kernel preferred value of _LINUX_CAPABILITY_VERSION_?   when  an
106       unsupported  version  value  is  specified.  In this way, one can probe
107       what the current preferred capability revision is.
108

ERRORS

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

CONFORMING TO

133       These system calls are Linux-specific.
134

NOTES

136       The portable interface to the capability querying and setting functions
137       is provided by the libcap library and is available here:
138http://git.kernel.org/cgit/linux/kernel/git/morgan/libcap.git
139

SEE ALSO

141       clone(2), gettid(2), capabilities(7)
142

COLOPHON

144       This  page  is  part of release 5.04 of the Linux man-pages project.  A
145       description of the project, information about reporting bugs,  and  the
146       latest     version     of     this    page,    can    be    found    at
147       https://www.kernel.org/doc/man-pages/.
148
149
150
151Linux                             2019-03-06                         CAPGET(2)
Impressum