1capget(2) System Calls Manual capget(2)
2
3
4
6 capget, capset - set/get capabilities of thread(s)
7
9 Standard C library (libc, -lc)
10
12 #include <linux/capability.h> /* Definition of CAP_* and
13 _LINUX_CAPABILITY_* constants */
14 #include <sys/syscall.h> /* Definition of SYS_* constants */
15 #include <unistd.h>
16
17 int syscall(SYS_capget, cap_user_header_t hdrp,
18 cap_user_data_t datap);
19 int syscall(SYS_capset, cap_user_header_t hdrp,
20 const cap_user_data_t datap);
21
22 Note: glibc provides no wrappers for these system calls, necessitating
23 the use of syscall(2).
24
26 These two system calls are the raw kernel interface for getting and
27 setting thread capabilities. Not only are these system calls specific
28 to Linux, but the kernel API is likely to change and use of these sys‐
29 tem calls (in particular the format of the cap_user_*_t types) is sub‐
30 ject to extension with each kernel revision, but old programs will keep
31 working.
32
33 The portable interfaces are cap_set_proc(3) and cap_get_proc(3); if
34 possible, you should use those interfaces in applications; see NOTES.
35
36 Current details
37 Now that you have been warned, some current kernel details. The struc‐
38 tures are defined as follows.
39
40 #define _LINUX_CAPABILITY_VERSION_1 0x19980330
41 #define _LINUX_CAPABILITY_U32S_1 1
42
43 /* V2 added in Linux 2.6.25; deprecated */
44 #define _LINUX_CAPABILITY_VERSION_2 0x20071026
45 #define _LINUX_CAPABILITY_U32S_2 2
46
47 /* V3 added in Linux 2.6.26 */
48 #define _LINUX_CAPABILITY_VERSION_3 0x20080522
49 #define _LINUX_CAPABILITY_U32S_3 2
50
51 typedef struct __user_cap_header_struct {
52 __u32 version;
53 int pid;
54 } *cap_user_header_t;
55
56 typedef struct __user_cap_data_struct {
57 __u32 effective;
58 __u32 permitted;
59 __u32 inheritable;
60 } *cap_user_data_t;
61
62 The effective, permitted, and inheritable fields are bit masks of the
63 capabilities defined in capabilities(7). Note that the CAP_* values
64 are bit indexes and need to be bit-shifted before ORing into the bit
65 fields. To define the structures for passing to the system call, you
66 have to use the struct __user_cap_header_struct and struct
67 __user_cap_data_struct names because the typedefs are only pointers.
68
69 Kernels prior to Linux 2.6.25 prefer 32-bit capabilities with version
70 _LINUX_CAPABILITY_VERSION_1. Linux 2.6.25 added 64-bit capability
71 sets, with version _LINUX_CAPABILITY_VERSION_2. There was, however, an
72 API glitch, and Linux 2.6.26 added _LINUX_CAPABILITY_VERSION_3 to fix
73 the problem.
74
75 Note that 64-bit capabilities use datap[0] and datap[1], whereas 32-bit
76 capabilities use only datap[0].
77
78 On kernels that support file capabilities (VFS capabilities support),
79 these system calls behave slightly differently. This support was added
80 as an option in Linux 2.6.24, and became fixed (nonoptional) in Linux
81 2.6.33.
82
83 For capget() calls, one can probe the capabilities of any process by
84 specifying its process ID with the hdrp->pid field value.
85
86 For details on the data, see capabilities(7).
87
88 With VFS capabilities support
89 VFS capabilities employ a file extended attribute (see xattr(7)) to al‐
90 low capabilities to be attached to executables. This privilege model
91 obsoletes kernel support for one process asynchronously setting the ca‐
92 pabilities of another. That is, on kernels that have VFS capabilities
93 support, when calling capset(), the only permitted values for hdrp->pid
94 are 0 or, equivalently, the value returned by gettid(2).
95
96 Without VFS capabilities support
97 On older kernels that do not provide VFS capabilities support capset()
98 can, if the caller has the CAP_SETPCAP capability, be used to change
99 not only the caller's own capabilities, but also the capabilities of
100 other threads. The call operates on the capabilities of the thread
101 specified by the pid field of hdrp when that is nonzero, or on the ca‐
102 pabilities of the calling thread if pid is 0. If pid refers to a sin‐
103 gle-threaded process, then pid can be specified as a traditional
104 process ID; operating on a thread of a multithreaded process requires a
105 thread ID of the type returned by gettid(2). For capset(), pid can
106 also be: -1, meaning perform the change on all threads except the
107 caller and init(1); or a value less than -1, in which case the change
108 is applied to all members of the process group whose ID is -pid.
109
111 On success, zero is returned. On error, -1 is returned, and errno is
112 set to indicate the error.
113
114 The calls fail with the error EINVAL, and set the version field of hdrp
115 to the kernel preferred value of _LINUX_CAPABILITY_VERSION_? when an
116 unsupported version value is specified. In this way, one can probe
117 what the current preferred capability revision is.
118
120 EFAULT Bad memory address. hdrp must not be NULL. datap may be NULL
121 only when the user is trying to determine the preferred capabil‐
122 ity version format supported by the kernel.
123
124 EINVAL One of the arguments was invalid.
125
126 EPERM An attempt was made to add a capability to the permitted set, or
127 to set a capability in the effective set that is not in the per‐
128 mitted set.
129
130 EPERM An attempt was made to add a capability to the inheritable set,
131 and either:
132
133 • that capability was not in the caller's bounding set; or
134
135 • the capability was not in the caller's permitted set and the
136 caller lacked the CAP_SETPCAP capability in its effective
137 set.
138
139 EPERM The caller attempted to use capset() to modify the capabilities
140 of a thread other than itself, but lacked sufficient privilege.
141 For kernels supporting VFS capabilities, this is never permit‐
142 ted. For kernels lacking VFS support, the CAP_SETPCAP capabil‐
143 ity is required. (A bug in kernels before Linux 2.6.11 meant
144 that this error could also occur if a thread without this capa‐
145 bility tried to change its own capabilities by specifying the
146 pid field as a nonzero value (i.e., the value returned by get‐
147 pid(2)) instead of 0.)
148
149 ESRCH No such thread.
150
152 Linux.
153
155 The portable interface to the capability querying and setting functions
156 is provided by the libcap library and is available here:
157 ⟨http://git.kernel.org/cgit/linux/kernel/git/morgan/libcap.git⟩
158
160 clone(2), gettid(2), capabilities(7)
161
162
163
164Linux man-pages 6.04 2023-03-30 capget(2)