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>
17 #include <linux/compiler.h>
21 /* User-level do most of the mapping between kernel and user
22 capabilities based on the version tag given by the kernel. The
23 kernel might be somewhat backwards compatible, but don't bet on
26 /* XXX - Note, cap_t, is defined by POSIX to be an "opaque" pointer to
27 a set of three capability sets. The transposition of 3*the
28 following structure to such a composite is better handled in a user
29 library since the draft standard requires the use of malloc/free
32 #define _LINUX_CAPABILITY_VERSION 0x19980330
34 typedef struct __user_cap_header_struct {
37 } __user *cap_user_header_t;
39 typedef struct __user_cap_data_struct {
43 } __user *cap_user_data_t;
45 #define XATTR_CAPS_SUFFIX "capability"
46 #define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
48 #define XATTR_CAPS_SZ (3*sizeof(__le32))
49 #define VFS_CAP_REVISION_MASK 0xFF000000
50 #define VFS_CAP_REVISION_1 0x01000000
52 #define VFS_CAP_REVISION VFS_CAP_REVISION_1
54 #define VFS_CAP_FLAGS_MASK ~VFS_CAP_REVISION_MASK
55 #define VFS_CAP_FLAGS_EFFECTIVE 0x000001
58 __u32 magic_etc; /* Little endian */
59 __u32 permitted; /* Little endian */
60 __u32 inheritable; /* Little endian */
65 /* #define STRICT_CAP_T_TYPECHECKS */
67 #ifdef STRICT_CAP_T_TYPECHECKS
69 typedef struct kernel_cap_struct {
75 typedef __u32 kernel_cap_t;
79 #define _USER_CAP_HEADER_SIZE (2*sizeof(__u32))
80 #define _KERNEL_CAP_T_SIZE (sizeof(kernel_cap_t))
86 ** POSIX-draft defined capabilities.
89 /* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this
90 overrides the restriction of changing file ownership and group
95 /* Override all DAC access, including ACL execute access if
96 [_POSIX_ACL] is defined. Excluding DAC access covered by
97 CAP_LINUX_IMMUTABLE. */
99 #define CAP_DAC_OVERRIDE 1
101 /* Overrides all DAC restrictions regarding read and search on files
102 and directories, including ACL restrictions if [_POSIX_ACL] is
103 defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */
105 #define CAP_DAC_READ_SEARCH 2
107 /* Overrides all restrictions about allowed operations on files, where
108 file owner ID must be equal to the user ID, except where CAP_FSETID
109 is applicable. It doesn't override MAC and DAC restrictions. */
113 /* Overrides the following restrictions that the effective user ID
114 shall match the file owner ID when setting the S_ISUID and S_ISGID
115 bits on that file; that the effective group ID (or one of the
116 supplementary group IDs) shall match the file owner ID when setting
117 the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are
118 cleared on successful return from chown(2) (not implemented). */
122 /* Used to decide between falling back on the old suser() or fsuser(). */
124 #define CAP_FS_MASK 0x1f
126 /* Overrides the restriction that the real or effective user ID of a
127 process sending a signal must match the real or effective user ID
128 of the process receiving the signal. */
132 /* Allows setgid(2) manipulation */
133 /* Allows setgroups(2) */
134 /* Allows forged gids on socket credentials passing. */
138 /* Allows set*uid(2) manipulation (including fsuid). */
139 /* Allows forged pids on socket credentials passing. */
145 ** Linux-specific capabilities
148 /* Transfer any capability in your permitted set to any pid,
149 remove any capability in your permitted set from any pid */
151 #define CAP_SETPCAP 8
153 /* Allow modification of S_IMMUTABLE and S_APPEND file attributes */
155 #define CAP_LINUX_IMMUTABLE 9
157 /* Allows binding to TCP/UDP sockets below 1024 */
158 /* Allows binding to ATM VCIs below 32 */
160 #define CAP_NET_BIND_SERVICE 10
162 /* Allow broadcasting, listen to multicast */
164 #define CAP_NET_BROADCAST 11
166 /* Allow interface configuration */
167 /* Allow administration of IP firewall, masquerading and accounting */
168 /* Allow setting debug option on sockets */
169 /* Allow modification of routing tables */
170 /* Allow setting arbitrary process / process group ownership on
172 /* Allow binding to any address for transparent proxying */
173 /* Allow setting TOS (type of service) */
174 /* Allow setting promiscuous mode */
175 /* Allow clearing driver statistics */
176 /* Allow multicasting */
177 /* Allow read/write of device-specific registers */
178 /* Allow activation of ATM control sockets */
180 #define CAP_NET_ADMIN 12
182 /* Allow use of RAW sockets */
183 /* Allow use of PACKET sockets */
185 #define CAP_NET_RAW 13
187 /* Allow locking of shared memory segments */
188 /* Allow mlock and mlockall (which doesn't really have anything to do
191 #define CAP_IPC_LOCK 14
193 /* Override IPC ownership checks */
195 #define CAP_IPC_OWNER 15
197 /* Insert and remove kernel modules - modify kernel without limit */
198 /* Modify cap_bset */
199 #define CAP_SYS_MODULE 16
201 /* Allow ioperm/iopl access */
202 /* Allow sending USB messages to any device via /proc/bus/usb */
204 #define CAP_SYS_RAWIO 17
206 /* Allow use of chroot() */
208 #define CAP_SYS_CHROOT 18
210 /* Allow ptrace() of any process */
212 #define CAP_SYS_PTRACE 19
214 /* Allow configuration of process accounting */
216 #define CAP_SYS_PACCT 20
218 /* Allow configuration of the secure attention key */
219 /* Allow administration of the random device */
220 /* Allow examination and configuration of disk quotas */
221 /* Allow configuring the kernel's syslog (printk behaviour) */
222 /* Allow setting the domainname */
223 /* Allow setting the hostname */
224 /* Allow calling bdflush() */
225 /* Allow mount() and umount(), setting up new smb connection */
226 /* Allow some autofs root ioctls */
227 /* Allow nfsservctl */
228 /* Allow VM86_REQUEST_IRQ */
229 /* Allow to read/write pci config on alpha */
230 /* Allow irix_prctl on mips (setstacksize) */
231 /* Allow flushing all cache on m68k (sys_cacheflush) */
232 /* Allow removing semaphores */
233 /* Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores
235 /* Allow locking/unlocking of shared memory segment */
236 /* Allow turning swap on/off */
237 /* Allow forged pids on socket credentials passing */
238 /* Allow setting readahead and flushing buffers on block devices */
239 /* Allow setting geometry in floppy driver */
240 /* Allow turning DMA on/off in xd driver */
241 /* Allow administration of md devices (mostly the above, but some
243 /* Allow tuning the ide driver */
244 /* Allow access to the nvram device */
245 /* Allow administration of apm_bios, serial and bttv (TV) device */
246 /* Allow manufacturer commands in isdn CAPI support driver */
247 /* Allow reading non-standardized portions of pci configuration space */
248 /* Allow DDI debug ioctl on sbpcd driver */
249 /* Allow setting up serial ports */
250 /* Allow sending raw qic-117 commands */
251 /* Allow enabling/disabling tagged queuing on SCSI controllers and sending
252 arbitrary SCSI commands */
253 /* Allow setting encryption key on loopback filesystem */
254 /* Allow setting zone reclaim policy */
256 #define CAP_SYS_ADMIN 21
258 /* Allow use of reboot() */
260 #define CAP_SYS_BOOT 22
262 /* Allow raising priority and setting priority on other (different
264 /* Allow use of FIFO and round-robin (realtime) scheduling on own
265 processes and setting the scheduling algorithm used by another
267 /* Allow setting cpu affinity on other processes */
269 #define CAP_SYS_NICE 23
271 /* Override resource limits. Set resource limits. */
272 /* Override quota limits. */
273 /* Override reserved space on ext2 filesystem */
274 /* Modify data journaling mode on ext3 filesystem (uses journaling
276 /* NOTE: ext2 honors fsuid when checking for resource overrides, so
277 you can override using fsuid too */
278 /* Override size restrictions on IPC message queues */
279 /* Allow more than 64hz interrupts from the real-time clock */
280 /* Override max number of consoles on console allocation */
281 /* Override max number of keymaps */
283 #define CAP_SYS_RESOURCE 24
285 /* Allow manipulation of system clock */
286 /* Allow irix_stime on mips */
287 /* Allow setting the real-time clock */
289 #define CAP_SYS_TIME 25
291 /* Allow configuration of tty devices */
292 /* Allow vhangup() of tty */
294 #define CAP_SYS_TTY_CONFIG 26
296 /* Allow the privileged aspects of mknod() */
300 /* Allow taking of leases on files */
304 #define CAP_AUDIT_WRITE 29
306 #define CAP_AUDIT_CONTROL 30
308 #define CAP_SETFCAP 31
313 * Internal kernel functions only
316 #ifdef STRICT_CAP_T_TYPECHECKS
318 #define to_cap_t(x) { x }
319 #define cap_t(x) (x).cap
323 #define to_cap_t(x) (x)
328 #define CAP_EMPTY_SET to_cap_t(0)
329 #define CAP_FULL_SET to_cap_t(~0)
330 #define CAP_INIT_EFF_SET to_cap_t(~0 & ~CAP_TO_MASK(CAP_SETPCAP))
331 #define CAP_INIT_INH_SET to_cap_t(0)
333 #define CAP_TO_MASK(x) (1 << (x))
334 #define cap_raise(c, flag) (cap_t(c) |= CAP_TO_MASK(flag))
335 #define cap_lower(c, flag) (cap_t(c) &= ~CAP_TO_MASK(flag))
336 #define cap_raised(c, flag) (cap_t(c) & CAP_TO_MASK(flag))
338 static inline kernel_cap_t cap_combine(kernel_cap_t a, kernel_cap_t b)
341 cap_t(dest) = cap_t(a) | cap_t(b);
345 static inline kernel_cap_t cap_intersect(kernel_cap_t a, kernel_cap_t b)
348 cap_t(dest) = cap_t(a) & cap_t(b);
352 static inline kernel_cap_t cap_drop(kernel_cap_t a, kernel_cap_t drop)
355 cap_t(dest) = cap_t(a) & ~cap_t(drop);
359 static inline kernel_cap_t cap_invert(kernel_cap_t c)
362 cap_t(dest) = ~cap_t(c);
366 #define cap_isclear(c) (!cap_t(c))
367 #define cap_issubset(a,set) (!(cap_t(a) & ~cap_t(set)))
369 #define cap_clear(c) do { cap_t(c) = 0; } while(0)
370 #define cap_set_full(c) do { cap_t(c) = ~0; } while(0)
371 #define cap_mask(c,mask) do { cap_t(c) &= cap_t(mask); } while(0)
373 #define cap_is_fs_cap(c) (CAP_TO_MASK(c) & CAP_FS_MASK)
375 int capable(int cap);
376 int __capable(struct task_struct *t, int cap);
378 #endif /* __KERNEL__ */
380 #endif /* !_LINUX_CAPABILITY_H */