xref: /linux/include/uapi/linux/capability.h (revision 12ed593ee88170145fff25c7b3325b227731c2a1)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * This is <linux/capability.h>
4  *
5  * Andrew G. Morgan <morgan@kernel.org>
6  * Alexander Kjeldaas <astor@guardian.no>
7  * with help from Aleph1, Roland Buresund and Andrew Main.
8  *
9  * See here for the libcap2 library (compliant with Section 25 of
10  * the withdrawn POSIX 1003.1e Draft 17):
11  *
12  * https://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/
13  */
14 
15 #ifndef _UAPI_LINUX_CAPABILITY_H
16 #define _UAPI_LINUX_CAPABILITY_H
17 
18 #include <linux/types.h>
19 
20 /* User-level do most of the mapping between kernel and user
21    capabilities based on the version tag given by the kernel. The
22    kernel might be somewhat backwards compatible, but don't bet on
23    it. */
24 
25 /* Note, cap_t, is defined by POSIX (draft) to be an "opaque" pointer to
26    a set of three capability sets.  The transposition of 3*the
27    following structure to such a composite is better handled in a user
28    library since the draft standard requires the use of malloc/free
29    etc.. */
30 
31 #define _LINUX_CAPABILITY_VERSION_1  0x19980330
32 #define _LINUX_CAPABILITY_U32S_1     1
33 
34 #define _LINUX_CAPABILITY_VERSION_2  0x20071026  /* deprecated - use v3 */
35 #define _LINUX_CAPABILITY_U32S_2     2
36 
37 #define _LINUX_CAPABILITY_VERSION_3  0x20080522
38 #define _LINUX_CAPABILITY_U32S_3     2
39 
40 typedef struct __user_cap_header_struct {
41 	__u32 version;
42 	int pid;
43 } __user *cap_user_header_t;
44 
45 struct __user_cap_data_struct {
46         __u32 effective;
47         __u32 permitted;
48         __u32 inheritable;
49 };
50 typedef struct __user_cap_data_struct __user *cap_user_data_t;
51 
52 
53 #define VFS_CAP_REVISION_MASK	0xFF000000
54 #define VFS_CAP_REVISION_SHIFT	24
55 #define VFS_CAP_FLAGS_MASK	~VFS_CAP_REVISION_MASK
56 #define VFS_CAP_FLAGS_EFFECTIVE	0x000001
57 
58 #define VFS_CAP_REVISION_1	0x01000000
59 #define VFS_CAP_U32_1           1
60 #define XATTR_CAPS_SZ_1         (sizeof(__le32)*(1 + 2*VFS_CAP_U32_1))
61 
62 #define VFS_CAP_REVISION_2	0x02000000
63 #define VFS_CAP_U32_2           2
64 #define XATTR_CAPS_SZ_2         (sizeof(__le32)*(1 + 2*VFS_CAP_U32_2))
65 
66 #define VFS_CAP_REVISION_3	0x03000000
67 #define VFS_CAP_U32_3           2
68 #define XATTR_CAPS_SZ_3         (sizeof(__le32)*(2 + 2*VFS_CAP_U32_3))
69 
70 #define XATTR_CAPS_SZ           XATTR_CAPS_SZ_3
71 #define VFS_CAP_U32             VFS_CAP_U32_3
72 #define VFS_CAP_REVISION	VFS_CAP_REVISION_3
73 
74 struct vfs_cap_data {
75 	__le32 magic_etc;            /* Little endian */
76 	struct {
77 		__le32 permitted;    /* Little endian */
78 		__le32 inheritable;  /* Little endian */
79 	} data[VFS_CAP_U32];
80 };
81 
82 /*
83  * same as vfs_cap_data but with a rootid at the end
84  */
85 struct vfs_ns_cap_data {
86 	__le32 magic_etc;
87 	struct {
88 		__le32 permitted;    /* Little endian */
89 		__le32 inheritable;  /* Little endian */
90 	} data[VFS_CAP_U32];
91 	__le32 rootid;
92 };
93 
94 #ifndef __KERNEL__
95 
96 /*
97  * Backwardly compatible definition for source code - trapped in a
98  * 32-bit world. If you find you need this, please consider using
99  * libcap to untrap yourself...
100  */
101 #define _LINUX_CAPABILITY_VERSION  _LINUX_CAPABILITY_VERSION_1
102 #define _LINUX_CAPABILITY_U32S     _LINUX_CAPABILITY_U32S_1
103 
104 #endif
105 
106 
107 /**
108  ** POSIX-draft defined capabilities.
109  **/
110 
111 /* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this
112    overrides the restriction of changing file ownership and group
113    ownership. */
114 
115 #define CAP_CHOWN            0
116 
117 /* Override all DAC access, including ACL execute access if
118    [_POSIX_ACL] is defined. Excluding DAC access covered by
119    CAP_LINUX_IMMUTABLE. */
120 
121 #define CAP_DAC_OVERRIDE     1
122 
123 /* Overrides all DAC restrictions regarding read and search on files
124    and directories, including ACL restrictions if [_POSIX_ACL] is
125    defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */
126 
127 #define CAP_DAC_READ_SEARCH  2
128 
129 /* Overrides all restrictions about allowed operations on files, where
130    file owner ID must be equal to the user ID, except where CAP_FSETID
131    is applicable. It doesn't override MAC and DAC restrictions. */
132 
133 #define CAP_FOWNER           3
134 
135 /* Overrides the following restrictions that the effective user ID
136    shall match the file owner ID when setting the S_ISUID and S_ISGID
137    bits on that file; that the effective group ID (or one of the
138    supplementary group IDs) shall match the file owner ID when setting
139    the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are
140    cleared on successful return from chown(2) (not implemented). */
141 
142 #define CAP_FSETID           4
143 
144 /* Overrides the restriction that the real or effective user ID of a
145    process sending a signal must match the real or effective user ID
146    of the process receiving the signal. */
147 
148 #define CAP_KILL             5
149 
150 /* Allows setgid(2) manipulation */
151 /* Allows setgroups(2) */
152 /* Allows forged gids on socket credentials passing. */
153 
154 #define CAP_SETGID           6
155 
156 /* Allows set*uid(2) manipulation (including fsuid). */
157 /* Allows forged pids on socket credentials passing. */
158 
159 #define CAP_SETUID           7
160 
161 
162 /**
163  ** Linux-specific capabilities
164  **/
165 
166 /* Without VFS support for capabilities:
167  *   Transfer any capability in your permitted set to any pid,
168  *   remove any capability in your permitted set from any pid
169  * With VFS support for capabilities (neither of above, but)
170  *   Add any capability from current's capability bounding set
171  *       to the current process' inheritable set
172  *   Allow taking bits out of capability bounding set
173  *   Allow modification of the securebits for a process
174  */
175 
176 #define CAP_SETPCAP          8
177 
178 /* Allow modification of S_IMMUTABLE and S_APPEND file attributes */
179 
180 #define CAP_LINUX_IMMUTABLE  9
181 
182 /* Allows binding to TCP/UDP sockets below 1024 */
183 /* Allows binding to ATM VCIs below 32 */
184 
185 #define CAP_NET_BIND_SERVICE 10
186 
187 /* Allow broadcasting, listen to multicast */
188 
189 #define CAP_NET_BROADCAST    11
190 
191 /* Allow interface configuration */
192 /* Allow administration of IP firewall, masquerading and accounting */
193 /* Allow setting debug option on sockets */
194 /* Allow modification of routing tables */
195 /* Allow setting arbitrary process / process group ownership on
196    sockets */
197 /* Allow binding to any address for transparent proxying (also via NET_RAW) */
198 /* Allow setting TOS (type of service) */
199 /* Allow setting promiscuous mode */
200 /* Allow clearing driver statistics */
201 /* Allow multicasting */
202 /* Allow read/write of device-specific registers */
203 /* Allow activation of ATM control sockets */
204 
205 #define CAP_NET_ADMIN        12
206 
207 /* Allow use of RAW sockets */
208 /* Allow use of PACKET sockets */
209 /* Allow binding to any address for transparent proxying (also via NET_ADMIN) */
210 
211 #define CAP_NET_RAW          13
212 
213 /* Allow locking of shared memory segments */
214 /* Allow mlock and mlockall (which doesn't really have anything to do
215    with IPC) */
216 
217 #define CAP_IPC_LOCK         14
218 
219 /* Override IPC ownership checks */
220 
221 #define CAP_IPC_OWNER        15
222 
223 /* Insert and remove kernel modules - modify kernel without limit */
224 #define CAP_SYS_MODULE       16
225 
226 /* Allow ioperm/iopl access */
227 /* Allow sending USB messages to any device via /dev/bus/usb */
228 
229 #define CAP_SYS_RAWIO        17
230 
231 /* Allow use of chroot() */
232 
233 #define CAP_SYS_CHROOT       18
234 
235 /* Allow ptrace() of any process */
236 
237 #define CAP_SYS_PTRACE       19
238 
239 /* Allow configuration of process accounting */
240 
241 #define CAP_SYS_PACCT        20
242 
243 /* Allow configuration of the secure attention key */
244 /* Allow administration of the random device */
245 /* Allow examination and configuration of disk quotas */
246 /* Allow setting the domainname */
247 /* Allow setting the hostname */
248 /* Allow mount() and umount(), setting up new smb connection */
249 /* Allow some autofs root ioctls */
250 /* Allow nfsservctl */
251 /* Allow VM86_REQUEST_IRQ */
252 /* Allow to read/write pci config on alpha */
253 /* Allow irix_prctl on mips (setstacksize) */
254 /* Allow flushing all cache on m68k (sys_cacheflush) */
255 /* Allow removing semaphores */
256 /* Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores
257    and shared memory */
258 /* Allow locking/unlocking of shared memory segment */
259 /* Allow turning swap on/off */
260 /* Allow forged pids on socket credentials passing */
261 /* Allow setting readahead and flushing buffers on block devices */
262 /* Allow setting geometry in floppy driver */
263 /* Allow turning DMA on/off in xd driver */
264 /* Allow administration of md devices (mostly the above, but some
265    extra ioctls) */
266 /* Allow tuning the ide driver */
267 /* Allow access to the nvram device */
268 /* Allow administration of apm_bios, serial and bttv (TV) device */
269 /* Allow manufacturer commands in isdn CAPI support driver */
270 /* Allow reading non-standardized portions of pci configuration space */
271 /* Allow DDI debug ioctl on sbpcd driver */
272 /* Allow setting up serial ports */
273 /* Allow sending raw qic-117 commands */
274 /* Allow enabling/disabling tagged queuing on SCSI controllers and sending
275    arbitrary SCSI commands */
276 /* Allow setting encryption key on loopback filesystem */
277 /* Allow setting zone reclaim policy */
278 /* Allow everything under CAP_BPF and CAP_PERFMON for backward compatibility */
279 /* Allow setting hardware protection emergency action */
280 
281 #define CAP_SYS_ADMIN        21
282 
283 /* Allow use of reboot() */
284 
285 #define CAP_SYS_BOOT         22
286 
287 /* Allow raising priority and setting priority on other (different
288    UID) processes */
289 /* Allow use of FIFO and round-robin (realtime) scheduling on own
290    processes and setting the scheduling algorithm used by another
291    process. */
292 /* Allow setting cpu affinity on other processes */
293 /* Allow setting realtime ioprio class */
294 /* Allow setting ioprio class on other processes */
295 
296 #define CAP_SYS_NICE         23
297 
298 /* Override resource limits. Set resource limits. */
299 /* Override quota limits. */
300 /* Override reserved space on ext2 filesystem */
301 /* Modify data journaling mode on ext3 filesystem (uses journaling
302    resources) */
303 /* NOTE: ext2 honors fsuid when checking for resource overrides, so
304    you can override using fsuid too */
305 /* Override size restrictions on IPC message queues */
306 /* Allow more than 64hz interrupts from the real-time clock */
307 /* Override max number of consoles on console allocation */
308 /* Override max number of keymaps */
309 /* Control memory reclaim behavior */
310 
311 #define CAP_SYS_RESOURCE     24
312 
313 /* Allow manipulation of system clock */
314 /* Allow irix_stime on mips */
315 /* Allow setting the real-time clock */
316 
317 #define CAP_SYS_TIME         25
318 
319 /* Allow configuration of tty devices */
320 /* Allow vhangup() of tty */
321 
322 #define CAP_SYS_TTY_CONFIG   26
323 
324 /* Allow the privileged aspects of mknod() */
325 
326 #define CAP_MKNOD            27
327 
328 /* Allow taking of leases on files */
329 
330 #define CAP_LEASE            28
331 
332 /* Allow writing the audit log via unicast netlink socket */
333 
334 #define CAP_AUDIT_WRITE      29
335 
336 /* Allow configuration of audit via unicast netlink socket */
337 
338 #define CAP_AUDIT_CONTROL    30
339 
340 /* Set or remove capabilities on files.
341    Map uid=0 into a child user namespace. */
342 
343 #define CAP_SETFCAP	     31
344 
345 /* Override MAC access.
346    The base kernel enforces no MAC policy.
347    An LSM may enforce a MAC policy, and if it does and it chooses
348    to implement capability based overrides of that policy, this is
349    the capability it should use to do so. */
350 
351 #define CAP_MAC_OVERRIDE     32
352 
353 /* Allow MAC configuration or state changes.
354    The base kernel requires no MAC configuration.
355    An LSM may enforce a MAC policy, and if it does and it chooses
356    to implement capability based checks on modifications to that
357    policy or the data required to maintain it, this is the
358    capability it should use to do so. */
359 
360 #define CAP_MAC_ADMIN        33
361 
362 /* Allow configuring the kernel's syslog (printk behaviour) */
363 
364 #define CAP_SYSLOG           34
365 
366 /* Allow triggering something that will wake the system */
367 
368 #define CAP_WAKE_ALARM            35
369 
370 /* Allow preventing system suspends */
371 
372 #define CAP_BLOCK_SUSPEND    36
373 
374 /* Allow reading the audit log via multicast netlink socket */
375 
376 #define CAP_AUDIT_READ		37
377 
378 /*
379  * Allow system performance and observability privileged operations
380  * using perf_events, i915_perf and other kernel subsystems
381  */
382 
383 #define CAP_PERFMON		38
384 
385 /*
386  * CAP_BPF allows the following BPF operations:
387  * - Creating all types of BPF maps
388  * - Advanced verifier features
389  *   - Indirect variable access
390  *   - Bounded loops
391  *   - BPF to BPF function calls
392  *   - Scalar precision tracking
393  *   - Larger complexity limits
394  *   - Dead code elimination
395  *   - And potentially other features
396  * - Loading BPF Type Format (BTF) data
397  * - Retrieve xlated and JITed code of BPF programs
398  * - Use bpf_spin_lock() helper
399  *
400  * CAP_PERFMON relaxes the verifier checks further:
401  * - BPF progs can use of pointer-to-integer conversions
402  * - speculation attack hardening measures are bypassed
403  * - bpf_probe_read to read arbitrary kernel memory is allowed
404  * - bpf_trace_printk to print kernel memory is allowed
405  *
406  * CAP_SYS_ADMIN is required to use bpf_probe_write_user.
407  *
408  * CAP_SYS_ADMIN is required to iterate system wide loaded
409  * programs, maps, links, BTFs and convert their IDs to file descriptors.
410  *
411  * CAP_PERFMON and CAP_BPF are required to load tracing programs.
412  * CAP_NET_ADMIN and CAP_BPF are required to load networking programs.
413  */
414 #define CAP_BPF			39
415 
416 
417 /* Allow checkpoint/restore related operations */
418 /* Allow PID selection during clone3() */
419 /* Allow writing to ns_last_pid */
420 
421 #define CAP_CHECKPOINT_RESTORE	40
422 
423 #define CAP_LAST_CAP         CAP_CHECKPOINT_RESTORE
424 
425 #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
426 
427 /*
428  * Bit location of each capability (used by user-space library and kernel)
429  */
430 
431 #define CAP_TO_INDEX(x)     ((x) >> 5)        /* 1 << 5 == bits in __u32 */
432 #define CAP_TO_MASK(x)      (1U << ((x) & 31)) /* mask for indexed __u32 */
433 
434 
435 #endif /* _UAPI_LINUX_CAPABILITY_H */
436