blob: c3021105edc076ab2114e60bd7335c7e7144e2f8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This is <linux/capability.h>
3 *
Serge E. Hallynb5376772007-10-16 23:31:36 -07004 * Andrew G. Morgan <morgan@kernel.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Alexander Kjeldaas <astor@guardian.no>
6 * with help from Aleph1, Roland Buresund and Andrew Main.
7 *
8 * See here for the libcap library ("POSIX draft" compliance):
9 *
Serge E. Hallynb5376772007-10-16 23:31:36 -070010 * ftp://linux.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.6/
11 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13#ifndef _LINUX_CAPABILITY_H
14#define _LINUX_CAPABILITY_H
15
16#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Andrew Mortonb7add022007-05-23 13:57:39 -070018struct task_struct;
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/* 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
Andrew Morgane338d262008-02-04 22:29:42 -080025/* Note, cap_t, is defined by POSIX (draft) to be an "opaque" pointer to
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 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.. */
Serge E. Hallynb5376772007-10-16 23:31:36 -070030
Andrew Morgane338d262008-02-04 22:29:42 -080031#define _LINUX_CAPABILITY_VERSION_1 0x19980330
32#define _LINUX_CAPABILITY_U32S_1 1
33
Andrew G. Morganca05a992008-05-27 22:05:17 -070034#define _LINUX_CAPABILITY_VERSION_2 0x20071026 /* deprecated - use v3 */
Andrew Morgane338d262008-02-04 22:29:42 -080035#define _LINUX_CAPABILITY_U32S_2 2
36
Andrew G. Morganca05a992008-05-27 22:05:17 -070037#define _LINUX_CAPABILITY_VERSION_3 0x20080522
38#define _LINUX_CAPABILITY_U32S_3 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40typedef struct __user_cap_header_struct {
41 __u32 version;
42 int pid;
43} __user *cap_user_header_t;
Serge E. Hallynb5376772007-10-16 23:31:36 -070044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045typedef struct __user_cap_data_struct {
46 __u32 effective;
47 __u32 permitted;
48 __u32 inheritable;
49} __user *cap_user_data_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Andrew Morgane338d262008-02-04 22:29:42 -080051
Serge E. Hallynb5376772007-10-16 23:31:36 -070052#define XATTR_CAPS_SUFFIX "capability"
53#define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
54
Serge E. Hallynb5376772007-10-16 23:31:36 -070055#define VFS_CAP_REVISION_MASK 0xFF000000
Eric Paris851f7ff2008-11-11 21:48:14 +110056#define VFS_CAP_REVISION_SHIFT 24
Serge E. Hallynb5376772007-10-16 23:31:36 -070057#define VFS_CAP_FLAGS_MASK ~VFS_CAP_REVISION_MASK
58#define VFS_CAP_FLAGS_EFFECTIVE 0x000001
59
Andrew Morgane338d262008-02-04 22:29:42 -080060#define VFS_CAP_REVISION_1 0x01000000
61#define VFS_CAP_U32_1 1
62#define XATTR_CAPS_SZ_1 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_1))
63
64#define VFS_CAP_REVISION_2 0x02000000
65#define VFS_CAP_U32_2 2
66#define XATTR_CAPS_SZ_2 (sizeof(__le32)*(1 + 2*VFS_CAP_U32_2))
67
68#define XATTR_CAPS_SZ XATTR_CAPS_SZ_2
69#define VFS_CAP_U32 VFS_CAP_U32_2
70#define VFS_CAP_REVISION VFS_CAP_REVISION_2
71
Serge E. Hallynb5376772007-10-16 23:31:36 -070072struct vfs_cap_data {
Andrew Morgane338d262008-02-04 22:29:42 -080073 __le32 magic_etc; /* Little endian */
Andrew Morton8f6936f2008-02-04 22:29:41 -080074 struct {
Andrew Morgane338d262008-02-04 22:29:42 -080075 __le32 permitted; /* Little endian */
76 __le32 inheritable; /* Little endian */
77 } data[VFS_CAP_U32];
Serge E. Hallynb5376772007-10-16 23:31:36 -070078};
79
Andrew G. Morganca05a992008-05-27 22:05:17 -070080#ifndef __KERNEL__
81
82/*
83 * Backwardly compatible definition for source code - trapped in a
84 * 32-bit world. If you find you need this, please consider using
85 * libcap to untrap yourself...
86 */
87#define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_1
88#define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_1
89
90#else
91
92#define _KERNEL_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_3
93#define _KERNEL_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_3
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Jaswinder Singh Rajput9fa91d92009-01-30 20:39:30 +053095#ifdef CONFIG_SECURITY_FILE_CAPABILITIES
96extern int file_caps_enabled;
97#endif
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099typedef struct kernel_cap_struct {
Andrew G. Morganca05a992008-05-27 22:05:17 -0700100 __u32 cap[_KERNEL_CAPABILITY_U32S];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101} kernel_cap_t;
102
Eric Parisc0b00442008-11-11 21:48:10 +1100103/* exact same as vfs_cap_data but in cpu endian and always filled completely */
104struct cpu_vfs_cap_data {
105 __u32 magic_etc;
106 kernel_cap_t permitted;
107 kernel_cap_t inheritable;
108};
109
Andrew Morgane338d262008-02-04 22:29:42 -0800110#define _USER_CAP_HEADER_SIZE (sizeof(struct __user_cap_header_struct))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define _KERNEL_CAP_T_SIZE (sizeof(kernel_cap_t))
112
113#endif
114
115
116/**
Serge E. Hallynb5376772007-10-16 23:31:36 -0700117 ** POSIX-draft defined capabilities.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 **/
119
120/* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this
121 overrides the restriction of changing file ownership and group
122 ownership. */
123
124#define CAP_CHOWN 0
125
126/* Override all DAC access, including ACL execute access if
127 [_POSIX_ACL] is defined. Excluding DAC access covered by
128 CAP_LINUX_IMMUTABLE. */
129
130#define CAP_DAC_OVERRIDE 1
131
132/* Overrides all DAC restrictions regarding read and search on files
133 and directories, including ACL restrictions if [_POSIX_ACL] is
134 defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */
135
136#define CAP_DAC_READ_SEARCH 2
Serge E. Hallynb5376772007-10-16 23:31:36 -0700137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/* Overrides all restrictions about allowed operations on files, where
139 file owner ID must be equal to the user ID, except where CAP_FSETID
140 is applicable. It doesn't override MAC and DAC restrictions. */
141
142#define CAP_FOWNER 3
143
144/* Overrides the following restrictions that the effective user ID
145 shall match the file owner ID when setting the S_ISUID and S_ISGID
146 bits on that file; that the effective group ID (or one of the
147 supplementary group IDs) shall match the file owner ID when setting
148 the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are
149 cleared on successful return from chown(2) (not implemented). */
150
151#define CAP_FSETID 4
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153/* Overrides the restriction that the real or effective user ID of a
154 process sending a signal must match the real or effective user ID
155 of the process receiving the signal. */
156
157#define CAP_KILL 5
158
159/* Allows setgid(2) manipulation */
160/* Allows setgroups(2) */
161/* Allows forged gids on socket credentials passing. */
162
163#define CAP_SETGID 6
164
165/* Allows set*uid(2) manipulation (including fsuid). */
166/* Allows forged pids on socket credentials passing. */
167
168#define CAP_SETUID 7
169
170
171/**
172 ** Linux-specific capabilities
173 **/
174
Andrew Morgane338d262008-02-04 22:29:42 -0800175/* Without VFS support for capabilities:
176 * Transfer any capability in your permitted set to any pid,
177 * remove any capability in your permitted set from any pid
178 * With VFS support for capabilities (neither of above, but)
Serge E. Hallyn3b7391d2008-02-04 22:29:45 -0800179 * Add any capability from current's capability bounding set
180 * to the current process' inheritable set
181 * Allow taking bits out of capability bounding set
Andrew G. Morgan3898b1b2008-04-28 02:13:40 -0700182 * Allow modification of the securebits for a process
Andrew Morgane338d262008-02-04 22:29:42 -0800183 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185#define CAP_SETPCAP 8
186
187/* Allow modification of S_IMMUTABLE and S_APPEND file attributes */
188
189#define CAP_LINUX_IMMUTABLE 9
190
191/* Allows binding to TCP/UDP sockets below 1024 */
192/* Allows binding to ATM VCIs below 32 */
193
194#define CAP_NET_BIND_SERVICE 10
195
196/* Allow broadcasting, listen to multicast */
197
198#define CAP_NET_BROADCAST 11
199
200/* Allow interface configuration */
201/* Allow administration of IP firewall, masquerading and accounting */
202/* Allow setting debug option on sockets */
203/* Allow modification of routing tables */
204/* Allow setting arbitrary process / process group ownership on
205 sockets */
206/* Allow binding to any address for transparent proxying */
207/* Allow setting TOS (type of service) */
208/* Allow setting promiscuous mode */
209/* Allow clearing driver statistics */
210/* Allow multicasting */
211/* Allow read/write of device-specific registers */
212/* Allow activation of ATM control sockets */
213
214#define CAP_NET_ADMIN 12
215
216/* Allow use of RAW sockets */
217/* Allow use of PACKET sockets */
218
219#define CAP_NET_RAW 13
220
221/* Allow locking of shared memory segments */
222/* Allow mlock and mlockall (which doesn't really have anything to do
223 with IPC) */
224
225#define CAP_IPC_LOCK 14
226
227/* Override IPC ownership checks */
228
229#define CAP_IPC_OWNER 15
230
231/* Insert and remove kernel modules - modify kernel without limit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232#define CAP_SYS_MODULE 16
233
234/* Allow ioperm/iopl access */
235/* Allow sending USB messages to any device via /proc/bus/usb */
236
237#define CAP_SYS_RAWIO 17
238
239/* Allow use of chroot() */
240
241#define CAP_SYS_CHROOT 18
242
243/* Allow ptrace() of any process */
244
245#define CAP_SYS_PTRACE 19
246
247/* Allow configuration of process accounting */
248
249#define CAP_SYS_PACCT 20
250
251/* Allow configuration of the secure attention key */
252/* Allow administration of the random device */
253/* Allow examination and configuration of disk quotas */
254/* Allow configuring the kernel's syslog (printk behaviour) */
255/* Allow setting the domainname */
256/* Allow setting the hostname */
257/* Allow calling bdflush() */
258/* Allow mount() and umount(), setting up new smb connection */
259/* Allow some autofs root ioctls */
260/* Allow nfsservctl */
261/* Allow VM86_REQUEST_IRQ */
262/* Allow to read/write pci config on alpha */
263/* Allow irix_prctl on mips (setstacksize) */
264/* Allow flushing all cache on m68k (sys_cacheflush) */
265/* Allow removing semaphores */
266/* Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores
267 and shared memory */
268/* Allow locking/unlocking of shared memory segment */
269/* Allow turning swap on/off */
270/* Allow forged pids on socket credentials passing */
271/* Allow setting readahead and flushing buffers on block devices */
272/* Allow setting geometry in floppy driver */
273/* Allow turning DMA on/off in xd driver */
274/* Allow administration of md devices (mostly the above, but some
275 extra ioctls) */
276/* Allow tuning the ide driver */
277/* Allow access to the nvram device */
278/* Allow administration of apm_bios, serial and bttv (TV) device */
279/* Allow manufacturer commands in isdn CAPI support driver */
280/* Allow reading non-standardized portions of pci configuration space */
281/* Allow DDI debug ioctl on sbpcd driver */
282/* Allow setting up serial ports */
283/* Allow sending raw qic-117 commands */
284/* Allow enabling/disabling tagged queuing on SCSI controllers and sending
285 arbitrary SCSI commands */
286/* Allow setting encryption key on loopback filesystem */
Martin Hicksbce5f6ba2005-09-03 15:54:50 -0700287/* Allow setting zone reclaim policy */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289#define CAP_SYS_ADMIN 21
290
291/* Allow use of reboot() */
292
293#define CAP_SYS_BOOT 22
294
295/* Allow raising priority and setting priority on other (different
296 UID) processes */
297/* Allow use of FIFO and round-robin (realtime) scheduling on own
298 processes and setting the scheduling algorithm used by another
299 process. */
300/* Allow setting cpu affinity on other processes */
301
302#define CAP_SYS_NICE 23
303
304/* Override resource limits. Set resource limits. */
305/* Override quota limits. */
306/* Override reserved space on ext2 filesystem */
307/* Modify data journaling mode on ext3 filesystem (uses journaling
308 resources) */
Serge E. Hallynb5376772007-10-16 23:31:36 -0700309/* NOTE: ext2 honors fsuid when checking for resource overrides, so
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 you can override using fsuid too */
311/* Override size restrictions on IPC message queues */
312/* Allow more than 64hz interrupts from the real-time clock */
313/* Override max number of consoles on console allocation */
314/* Override max number of keymaps */
315
316#define CAP_SYS_RESOURCE 24
317
318/* Allow manipulation of system clock */
319/* Allow irix_stime on mips */
320/* Allow setting the real-time clock */
321
322#define CAP_SYS_TIME 25
323
324/* Allow configuration of tty devices */
325/* Allow vhangup() of tty */
326
327#define CAP_SYS_TTY_CONFIG 26
328
329/* Allow the privileged aspects of mknod() */
330
331#define CAP_MKNOD 27
332
333/* Allow taking of leases on files */
334
335#define CAP_LEASE 28
336
337#define CAP_AUDIT_WRITE 29
338
339#define CAP_AUDIT_CONTROL 30
340
Serge E. Hallynb5376772007-10-16 23:31:36 -0700341#define CAP_SETFCAP 31
342
Casey Schauflere114e472008-02-04 22:29:50 -0800343/* Override MAC access.
344 The base kernel enforces no MAC policy.
345 An LSM may enforce a MAC policy, and if it does and it chooses
346 to implement capability based overrides of that policy, this is
347 the capability it should use to do so. */
348
349#define CAP_MAC_OVERRIDE 32
350
351/* Allow MAC configuration or state changes.
352 The base kernel requires no MAC configuration.
353 An LSM may enforce a MAC policy, and if it does and it chooses
354 to implement capability based checks on modifications to that
355 policy or the data required to maintain it, this is the
356 capability it should use to do so. */
357
358#define CAP_MAC_ADMIN 33
359
360#define CAP_LAST_CAP CAP_MAC_ADMIN
Serge E. Hallyn3b7391d2008-02-04 22:29:45 -0800361
362#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
363
Andrew Morgane338d262008-02-04 22:29:42 -0800364/*
365 * Bit location of each capability (used by user-space library and kernel)
366 */
367
368#define CAP_TO_INDEX(x) ((x) >> 5) /* 1 << 5 == bits in __u32 */
369#define CAP_TO_MASK(x) (1 << ((x) & 31)) /* mask for indexed __u32 */
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373/*
374 * Internal kernel functions only
375 */
Serge E. Hallynb5376772007-10-16 23:31:36 -0700376
Andrew Morgane338d262008-02-04 22:29:42 -0800377#define CAP_FOR_EACH_U32(__capi) \
Andrew G. Morganca05a992008-05-27 22:05:17 -0700378 for (__capi = 0; __capi < _KERNEL_CAPABILITY_U32S; ++__capi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Serge E. Hallyn0ad30b82009-04-13 09:56:14 -0500380/*
381 * CAP_FS_MASK and CAP_NFSD_MASKS:
382 *
383 * The fs mask is all the privileges that fsuid==0 historically meant.
384 * At one time in the past, that included CAP_MKNOD and CAP_LINUX_IMMUTABLE.
385 *
386 * It has never meant setting security.* and trusted.* xattrs.
387 *
388 * We could also define fsmask as follows:
389 * 1. CAP_FS_MASK is the privilege to bypass all fs-related DAC permissions
390 * 2. The security.* and trusted.* xattrs are fs-related MAC permissions
391 */
392
Andrew Morgane338d262008-02-04 22:29:42 -0800393# define CAP_FS_MASK_B0 (CAP_TO_MASK(CAP_CHOWN) \
Serge E. Hallyn0ad30b82009-04-13 09:56:14 -0500394 | CAP_TO_MASK(CAP_MKNOD) \
Andrew Morgane338d262008-02-04 22:29:42 -0800395 | CAP_TO_MASK(CAP_DAC_OVERRIDE) \
396 | CAP_TO_MASK(CAP_DAC_READ_SEARCH) \
397 | CAP_TO_MASK(CAP_FOWNER) \
398 | CAP_TO_MASK(CAP_FSETID))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Casey Schauflere114e472008-02-04 22:29:50 -0800400# define CAP_FS_MASK_B1 (CAP_TO_MASK(CAP_MAC_OVERRIDE))
401
Andrew G. Morganca05a992008-05-27 22:05:17 -0700402#if _KERNEL_CAPABILITY_U32S != 2
Andrew Morgane338d262008-02-04 22:29:42 -0800403# error Fix up hand-coded capability macro initializers
404#else /* HAND-CODED capability initializers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
David Howells25f2ea92008-04-29 20:54:28 +0100406# define CAP_EMPTY_SET ((kernel_cap_t){{ 0, 0 }})
407# define CAP_FULL_SET ((kernel_cap_t){{ ~0, ~0 }})
408# define CAP_INIT_EFF_SET ((kernel_cap_t){{ ~CAP_TO_MASK(CAP_SETPCAP), ~0 }})
Serge E. Hallyn0ad30b82009-04-13 09:56:14 -0500409# define CAP_FS_SET ((kernel_cap_t){{ CAP_FS_MASK_B0 \
410 | CAP_TO_MASK(CAP_LINUX_IMMUTABLE), \
411 CAP_FS_MASK_B1 } })
J. Bruce Fields76a67ec2009-03-16 18:34:20 -0400412# define CAP_NFSD_SET ((kernel_cap_t){{ CAP_FS_MASK_B0 \
Serge E. Hallyn0ad30b82009-04-13 09:56:14 -0500413 | CAP_TO_MASK(CAP_SYS_RESOURCE), \
414 CAP_FS_MASK_B1 } })
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Andrew G. Morganca05a992008-05-27 22:05:17 -0700416#endif /* _KERNEL_CAPABILITY_U32S != 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Andrew Morgane338d262008-02-04 22:29:42 -0800418#define CAP_INIT_INH_SET CAP_EMPTY_SET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Andrew Morgane338d262008-02-04 22:29:42 -0800420# define cap_clear(c) do { (c) = __cap_empty_set; } while (0)
421# define cap_set_full(c) do { (c) = __cap_full_set; } while (0)
422# define cap_set_init_eff(c) do { (c) = __cap_init_eff_set; } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Andrew Morgane338d262008-02-04 22:29:42 -0800424#define cap_raise(c, flag) ((c).cap[CAP_TO_INDEX(flag)] |= CAP_TO_MASK(flag))
425#define cap_lower(c, flag) ((c).cap[CAP_TO_INDEX(flag)] &= ~CAP_TO_MASK(flag))
426#define cap_raised(c, flag) ((c).cap[CAP_TO_INDEX(flag)] & CAP_TO_MASK(flag))
427
428#define CAP_BOP_ALL(c, a, b, OP) \
429do { \
430 unsigned __capi; \
431 CAP_FOR_EACH_U32(__capi) { \
432 c.cap[__capi] = a.cap[__capi] OP b.cap[__capi]; \
433 } \
434} while (0)
435
436#define CAP_UOP_ALL(c, a, OP) \
437do { \
438 unsigned __capi; \
439 CAP_FOR_EACH_U32(__capi) { \
440 c.cap[__capi] = OP a.cap[__capi]; \
441 } \
442} while (0)
443
444static inline kernel_cap_t cap_combine(const kernel_cap_t a,
445 const kernel_cap_t b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
Andrew Morgane338d262008-02-04 22:29:42 -0800447 kernel_cap_t dest;
448 CAP_BOP_ALL(dest, a, b, |);
449 return dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450}
451
Andrew Morgane338d262008-02-04 22:29:42 -0800452static inline kernel_cap_t cap_intersect(const kernel_cap_t a,
453 const kernel_cap_t b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
Andrew Morgane338d262008-02-04 22:29:42 -0800455 kernel_cap_t dest;
456 CAP_BOP_ALL(dest, a, b, &);
457 return dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458}
459
Andrew Morgane338d262008-02-04 22:29:42 -0800460static inline kernel_cap_t cap_drop(const kernel_cap_t a,
461 const kernel_cap_t drop)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
Andrew Morgane338d262008-02-04 22:29:42 -0800463 kernel_cap_t dest;
464 CAP_BOP_ALL(dest, a, drop, &~);
465 return dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466}
467
Andrew Morgane338d262008-02-04 22:29:42 -0800468static inline kernel_cap_t cap_invert(const kernel_cap_t c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
Andrew Morgane338d262008-02-04 22:29:42 -0800470 kernel_cap_t dest;
471 CAP_UOP_ALL(dest, c, ~);
472 return dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473}
474
Andrew Morgane338d262008-02-04 22:29:42 -0800475static inline int cap_isclear(const kernel_cap_t a)
476{
477 unsigned __capi;
478 CAP_FOR_EACH_U32(__capi) {
479 if (a.cap[__capi] != 0)
480 return 0;
481 }
482 return 1;
483}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Eric Paris9d36be72008-11-11 21:48:07 +1100485/*
486 * Check if "a" is a subset of "set".
487 * return 1 if ALL of the capabilities in "a" are also in "set"
488 * cap_issubset(0101, 1111) will return 1
489 * return 0 if ANY of the capabilities in "a" are not in "set"
490 * cap_issubset(1111, 0101) will return 0
491 */
Andrew Morgane338d262008-02-04 22:29:42 -0800492static inline int cap_issubset(const kernel_cap_t a, const kernel_cap_t set)
493{
494 kernel_cap_t dest;
495 dest = cap_drop(a, set);
496 return cap_isclear(dest);
497}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Andrew Morgane338d262008-02-04 22:29:42 -0800499/* Used to decide between falling back on the old suser() or fsuser(). */
500
501static inline int cap_is_fs_cap(int cap)
502{
503 const kernel_cap_t __cap_fs_set = CAP_FS_SET;
504 return !!(CAP_TO_MASK(cap) & __cap_fs_set.cap[CAP_TO_INDEX(cap)]);
505}
506
507static inline kernel_cap_t cap_drop_fs_set(const kernel_cap_t a)
508{
509 const kernel_cap_t __cap_fs_set = CAP_FS_SET;
510 return cap_drop(a, __cap_fs_set);
511}
512
513static inline kernel_cap_t cap_raise_fs_set(const kernel_cap_t a,
514 const kernel_cap_t permitted)
515{
516 const kernel_cap_t __cap_fs_set = CAP_FS_SET;
517 return cap_combine(a,
518 cap_intersect(permitted, __cap_fs_set));
519}
520
521static inline kernel_cap_t cap_drop_nfsd_set(const kernel_cap_t a)
522{
523 const kernel_cap_t __cap_fs_set = CAP_NFSD_SET;
524 return cap_drop(a, __cap_fs_set);
525}
526
527static inline kernel_cap_t cap_raise_nfsd_set(const kernel_cap_t a,
528 const kernel_cap_t permitted)
529{
530 const kernel_cap_t __cap_nfsd_set = CAP_NFSD_SET;
531 return cap_combine(a,
532 cap_intersect(permitted, __cap_nfsd_set));
533}
534
535extern const kernel_cap_t __cap_empty_set;
536extern const kernel_cap_t __cap_full_set;
537extern const kernel_cap_t __cap_init_eff_set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
David Howells5cd9c582008-08-14 11:37:28 +0100539/**
540 * has_capability - Determine if a task has a superior capability available
541 * @t: The task in question
542 * @cap: The capability to be tested for
543 *
544 * Return true if the specified task has the given superior capability
545 * currently in effect, false if not.
546 *
547 * Note that this does not set PF_SUPERPRIV on the task.
548 */
David Howells3699c532009-01-06 22:27:01 +0000549#define has_capability(t, cap) (security_real_capable((t), (cap)) == 0)
550
551/**
552 * has_capability_noaudit - Determine if a task has a superior capability available (unaudited)
553 * @t: The task in question
554 * @cap: The capability to be tested for
555 *
556 * Return true if the specified task has the given superior capability
557 * currently in effect, false if not, but don't write an audit message for the
558 * check.
559 *
560 * Note that this does not set PF_SUPERPRIV on the task.
561 */
562#define has_capability_noaudit(t, cap) \
563 (security_real_capable_noaudit((t), (cap)) == 0)
David Howells5cd9c582008-08-14 11:37:28 +0100564
565extern int capable(int cap);
Randy.Dunlapc59ede72006-01-11 12:17:46 -0800566
Eric Paris851f7ff2008-11-11 21:48:14 +1100567/* audit system wants to get cap info from files as well */
568struct dentry;
569extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#endif /* __KERNEL__ */
572
573#endif /* !_LINUX_CAPABILITY_H */