move wm8400-regulator's probe function to .devinit.text
[linux-2.6/sactl.git] / include / linux / capability.h
blob02bdb768d43b8dc980bdabd38e0784355f71eaf1
1 /*
2 * This is <linux/capability.h>
4 * Andrew G. Morgan <morgan@kernel.org>
5 * Alexander Kjeldaas <astor@guardian.no>
6 * with help from Aleph1, Roland Buresund and Andrew Main.
8 * See here for the libcap library ("POSIX draft" compliance):
10 * ftp://linux.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.6/
13 #ifndef _LINUX_CAPABILITY_H
14 #define _LINUX_CAPABILITY_H
16 #include <linux/types.h>
18 struct task_struct;
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. */
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.. */
31 #define _LINUX_CAPABILITY_VERSION_1 0x19980330
32 #define _LINUX_CAPABILITY_U32S_1 1
34 #define _LINUX_CAPABILITY_VERSION_2 0x20071026 /* deprecated - use v3 */
35 #define _LINUX_CAPABILITY_U32S_2 2
37 #define _LINUX_CAPABILITY_VERSION_3 0x20080522
38 #define _LINUX_CAPABILITY_U32S_3 2
40 typedef struct __user_cap_header_struct {
41 __u32 version;
42 int pid;
43 } __user *cap_user_header_t;
45 typedef struct __user_cap_data_struct {
46 __u32 effective;
47 __u32 permitted;
48 __u32 inheritable;
49 } __user *cap_user_data_t;
52 #define XATTR_CAPS_SUFFIX "capability"
53 #define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
55 #define VFS_CAP_REVISION_MASK 0xFF000000
56 #define VFS_CAP_REVISION_SHIFT 24
57 #define VFS_CAP_FLAGS_MASK ~VFS_CAP_REVISION_MASK
58 #define VFS_CAP_FLAGS_EFFECTIVE 0x000001
60 #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))
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))
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
72 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
73 extern int file_caps_enabled;
74 #endif
76 struct vfs_cap_data {
77 __le32 magic_etc; /* Little endian */
78 struct {
79 __le32 permitted; /* Little endian */
80 __le32 inheritable; /* Little endian */
81 } data[VFS_CAP_U32];
84 #ifndef __KERNEL__
87 * Backwardly compatible definition for source code - trapped in a
88 * 32-bit world. If you find you need this, please consider using
89 * libcap to untrap yourself...
91 #define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_1
92 #define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_1
94 #else
96 #define _KERNEL_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_3
97 #define _KERNEL_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_3
99 typedef struct kernel_cap_struct {
100 __u32 cap[_KERNEL_CAPABILITY_U32S];
101 } kernel_cap_t;
103 /* exact same as vfs_cap_data but in cpu endian and always filled completely */
104 struct cpu_vfs_cap_data {
105 __u32 magic_etc;
106 kernel_cap_t permitted;
107 kernel_cap_t inheritable;
110 #define _USER_CAP_HEADER_SIZE (sizeof(struct __user_cap_header_struct))
111 #define _KERNEL_CAP_T_SIZE (sizeof(kernel_cap_t))
113 #endif
117 ** POSIX-draft defined capabilities.
120 /* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this
121 overrides the restriction of changing file ownership and group
122 ownership. */
124 #define CAP_CHOWN 0
126 /* Override all DAC access, including ACL execute access if
127 [_POSIX_ACL] is defined. Excluding DAC access covered by
128 CAP_LINUX_IMMUTABLE. */
130 #define CAP_DAC_OVERRIDE 1
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. */
136 #define CAP_DAC_READ_SEARCH 2
138 /* 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. */
142 #define CAP_FOWNER 3
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). */
151 #define CAP_FSETID 4
153 /* 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. */
157 #define CAP_KILL 5
159 /* Allows setgid(2) manipulation */
160 /* Allows setgroups(2) */
161 /* Allows forged gids on socket credentials passing. */
163 #define CAP_SETGID 6
165 /* Allows set*uid(2) manipulation (including fsuid). */
166 /* Allows forged pids on socket credentials passing. */
168 #define CAP_SETUID 7
172 ** Linux-specific capabilities
175 /* 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)
179 * 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
182 * Allow modification of the securebits for a process
185 #define CAP_SETPCAP 8
187 /* Allow modification of S_IMMUTABLE and S_APPEND file attributes */
189 #define CAP_LINUX_IMMUTABLE 9
191 /* Allows binding to TCP/UDP sockets below 1024 */
192 /* Allows binding to ATM VCIs below 32 */
194 #define CAP_NET_BIND_SERVICE 10
196 /* Allow broadcasting, listen to multicast */
198 #define CAP_NET_BROADCAST 11
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 */
214 #define CAP_NET_ADMIN 12
216 /* Allow use of RAW sockets */
217 /* Allow use of PACKET sockets */
219 #define CAP_NET_RAW 13
221 /* Allow locking of shared memory segments */
222 /* Allow mlock and mlockall (which doesn't really have anything to do
223 with IPC) */
225 #define CAP_IPC_LOCK 14
227 /* Override IPC ownership checks */
229 #define CAP_IPC_OWNER 15
231 /* Insert and remove kernel modules - modify kernel without limit */
232 #define CAP_SYS_MODULE 16
234 /* Allow ioperm/iopl access */
235 /* Allow sending USB messages to any device via /proc/bus/usb */
237 #define CAP_SYS_RAWIO 17
239 /* Allow use of chroot() */
241 #define CAP_SYS_CHROOT 18
243 /* Allow ptrace() of any process */
245 #define CAP_SYS_PTRACE 19
247 /* Allow configuration of process accounting */
249 #define CAP_SYS_PACCT 20
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 */
287 /* Allow setting zone reclaim policy */
289 #define CAP_SYS_ADMIN 21
291 /* Allow use of reboot() */
293 #define CAP_SYS_BOOT 22
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 */
302 #define CAP_SYS_NICE 23
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) */
309 /* NOTE: ext2 honors fsuid when checking for resource overrides, so
310 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 */
316 #define CAP_SYS_RESOURCE 24
318 /* Allow manipulation of system clock */
319 /* Allow irix_stime on mips */
320 /* Allow setting the real-time clock */
322 #define CAP_SYS_TIME 25
324 /* Allow configuration of tty devices */
325 /* Allow vhangup() of tty */
327 #define CAP_SYS_TTY_CONFIG 26
329 /* Allow the privileged aspects of mknod() */
331 #define CAP_MKNOD 27
333 /* Allow taking of leases on files */
335 #define CAP_LEASE 28
337 #define CAP_AUDIT_WRITE 29
339 #define CAP_AUDIT_CONTROL 30
341 #define CAP_SETFCAP 31
343 /* 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. */
349 #define CAP_MAC_OVERRIDE 32
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. */
358 #define CAP_MAC_ADMIN 33
360 #define CAP_LAST_CAP CAP_MAC_ADMIN
362 #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
365 * Bit location of each capability (used by user-space library and kernel)
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 */
371 #ifdef __KERNEL__
374 * Internal kernel functions only
377 #define CAP_FOR_EACH_U32(__capi) \
378 for (__capi = 0; __capi < _KERNEL_CAPABILITY_U32S; ++__capi)
380 # define CAP_FS_MASK_B0 (CAP_TO_MASK(CAP_CHOWN) \
381 | CAP_TO_MASK(CAP_DAC_OVERRIDE) \
382 | CAP_TO_MASK(CAP_DAC_READ_SEARCH) \
383 | CAP_TO_MASK(CAP_FOWNER) \
384 | CAP_TO_MASK(CAP_FSETID))
386 # define CAP_FS_MASK_B1 (CAP_TO_MASK(CAP_MAC_OVERRIDE))
388 #if _KERNEL_CAPABILITY_U32S != 2
389 # error Fix up hand-coded capability macro initializers
390 #else /* HAND-CODED capability initializers */
392 # define CAP_EMPTY_SET ((kernel_cap_t){{ 0, 0 }})
393 # define CAP_FULL_SET ((kernel_cap_t){{ ~0, ~0 }})
394 # define CAP_INIT_EFF_SET ((kernel_cap_t){{ ~CAP_TO_MASK(CAP_SETPCAP), ~0 }})
395 # define CAP_FS_SET ((kernel_cap_t){{ CAP_FS_MASK_B0, CAP_FS_MASK_B1 } })
396 # define CAP_NFSD_SET ((kernel_cap_t){{ CAP_FS_MASK_B0|CAP_TO_MASK(CAP_SYS_RESOURCE), \
397 CAP_FS_MASK_B1 } })
399 #endif /* _KERNEL_CAPABILITY_U32S != 2 */
401 #define CAP_INIT_INH_SET CAP_EMPTY_SET
403 # define cap_clear(c) do { (c) = __cap_empty_set; } while (0)
404 # define cap_set_full(c) do { (c) = __cap_full_set; } while (0)
405 # define cap_set_init_eff(c) do { (c) = __cap_init_eff_set; } while (0)
407 #define cap_raise(c, flag) ((c).cap[CAP_TO_INDEX(flag)] |= CAP_TO_MASK(flag))
408 #define cap_lower(c, flag) ((c).cap[CAP_TO_INDEX(flag)] &= ~CAP_TO_MASK(flag))
409 #define cap_raised(c, flag) ((c).cap[CAP_TO_INDEX(flag)] & CAP_TO_MASK(flag))
411 #define CAP_BOP_ALL(c, a, b, OP) \
412 do { \
413 unsigned __capi; \
414 CAP_FOR_EACH_U32(__capi) { \
415 c.cap[__capi] = a.cap[__capi] OP b.cap[__capi]; \
417 } while (0)
419 #define CAP_UOP_ALL(c, a, OP) \
420 do { \
421 unsigned __capi; \
422 CAP_FOR_EACH_U32(__capi) { \
423 c.cap[__capi] = OP a.cap[__capi]; \
425 } while (0)
427 static inline kernel_cap_t cap_combine(const kernel_cap_t a,
428 const kernel_cap_t b)
430 kernel_cap_t dest;
431 CAP_BOP_ALL(dest, a, b, |);
432 return dest;
435 static inline kernel_cap_t cap_intersect(const kernel_cap_t a,
436 const kernel_cap_t b)
438 kernel_cap_t dest;
439 CAP_BOP_ALL(dest, a, b, &);
440 return dest;
443 static inline kernel_cap_t cap_drop(const kernel_cap_t a,
444 const kernel_cap_t drop)
446 kernel_cap_t dest;
447 CAP_BOP_ALL(dest, a, drop, &~);
448 return dest;
451 static inline kernel_cap_t cap_invert(const kernel_cap_t c)
453 kernel_cap_t dest;
454 CAP_UOP_ALL(dest, c, ~);
455 return dest;
458 static inline int cap_isclear(const kernel_cap_t a)
460 unsigned __capi;
461 CAP_FOR_EACH_U32(__capi) {
462 if (a.cap[__capi] != 0)
463 return 0;
465 return 1;
469 * Check if "a" is a subset of "set".
470 * return 1 if ALL of the capabilities in "a" are also in "set"
471 * cap_issubset(0101, 1111) will return 1
472 * return 0 if ANY of the capabilities in "a" are not in "set"
473 * cap_issubset(1111, 0101) will return 0
475 static inline int cap_issubset(const kernel_cap_t a, const kernel_cap_t set)
477 kernel_cap_t dest;
478 dest = cap_drop(a, set);
479 return cap_isclear(dest);
482 /* Used to decide between falling back on the old suser() or fsuser(). */
484 static inline int cap_is_fs_cap(int cap)
486 const kernel_cap_t __cap_fs_set = CAP_FS_SET;
487 return !!(CAP_TO_MASK(cap) & __cap_fs_set.cap[CAP_TO_INDEX(cap)]);
490 static inline kernel_cap_t cap_drop_fs_set(const kernel_cap_t a)
492 const kernel_cap_t __cap_fs_set = CAP_FS_SET;
493 return cap_drop(a, __cap_fs_set);
496 static inline kernel_cap_t cap_raise_fs_set(const kernel_cap_t a,
497 const kernel_cap_t permitted)
499 const kernel_cap_t __cap_fs_set = CAP_FS_SET;
500 return cap_combine(a,
501 cap_intersect(permitted, __cap_fs_set));
504 static inline kernel_cap_t cap_drop_nfsd_set(const kernel_cap_t a)
506 const kernel_cap_t __cap_fs_set = CAP_NFSD_SET;
507 return cap_drop(a, __cap_fs_set);
510 static inline kernel_cap_t cap_raise_nfsd_set(const kernel_cap_t a,
511 const kernel_cap_t permitted)
513 const kernel_cap_t __cap_nfsd_set = CAP_NFSD_SET;
514 return cap_combine(a,
515 cap_intersect(permitted, __cap_nfsd_set));
518 extern const kernel_cap_t __cap_empty_set;
519 extern const kernel_cap_t __cap_full_set;
520 extern const kernel_cap_t __cap_init_eff_set;
523 * has_capability - Determine if a task has a superior capability available
524 * @t: The task in question
525 * @cap: The capability to be tested for
527 * Return true if the specified task has the given superior capability
528 * currently in effect, false if not.
530 * Note that this does not set PF_SUPERPRIV on the task.
532 #define has_capability(t, cap) (security_real_capable((t), (cap)) == 0)
535 * has_capability_noaudit - Determine if a task has a superior capability available (unaudited)
536 * @t: The task in question
537 * @cap: The capability to be tested for
539 * Return true if the specified task has the given superior capability
540 * currently in effect, false if not, but don't write an audit message for the
541 * check.
543 * Note that this does not set PF_SUPERPRIV on the task.
545 #define has_capability_noaudit(t, cap) \
546 (security_real_capable_noaudit((t), (cap)) == 0)
548 extern int capable(int cap);
550 /* audit system wants to get cap info from files as well */
551 struct dentry;
552 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
554 #endif /* __KERNEL__ */
556 #endif /* !_LINUX_CAPABILITY_H */