2 * This is <linux/capability.h>
4 * Andrew G. Morgan <morgan@transmeta.com>
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.2/
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;
47 #include <asm/current.h>
49 /* #define STRICT_CAP_T_TYPECHECKS */
51 #ifdef STRICT_CAP_T_TYPECHECKS
53 typedef struct kernel_cap_struct {
59 typedef __u32 kernel_cap_t;
63 #define _USER_CAP_HEADER_SIZE (2*sizeof(__u32))
64 #define _KERNEL_CAP_T_SIZE (sizeof(kernel_cap_t))
70 ** POSIX-draft defined capabilities.
73 /* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this
74 overrides the restriction of changing file ownership and group
79 /* Override all DAC access, including ACL execute access if
80 [_POSIX_ACL] is defined. Excluding DAC access covered by
81 CAP_LINUX_IMMUTABLE. */
83 #define CAP_DAC_OVERRIDE 1
85 /* Overrides all DAC restrictions regarding read and search on files
86 and directories, including ACL restrictions if [_POSIX_ACL] is
87 defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */
89 #define CAP_DAC_READ_SEARCH 2
91 /* Overrides all restrictions about allowed operations on files, where
92 file owner ID must be equal to the user ID, except where CAP_FSETID
93 is applicable. It doesn't override MAC and DAC restrictions. */
97 /* Overrides the following restrictions that the effective user ID
98 shall match the file owner ID when setting the S_ISUID and S_ISGID
99 bits on that file; that the effective group ID (or one of the
100 supplementary group IDs) shall match the file owner ID when setting
101 the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are
102 cleared on successful return from chown(2) (not implemented). */
106 /* Used to decide between falling back on the old suser() or fsuser(). */
108 #define CAP_FS_MASK 0x1f
110 /* Overrides the restriction that the real or effective user ID of a
111 process sending a signal must match the real or effective user ID
112 of the process receiving the signal. */
116 /* Allows setgid(2) manipulation */
117 /* Allows setgroups(2) */
118 /* Allows forged gids on socket credentials passing. */
122 /* Allows set*uid(2) manipulation (including fsuid). */
123 /* Allows forged pids on socket credentials passing. */
129 ** Linux-specific capabilities
132 /* Transfer any capability in your permitted set to any pid,
133 remove any capability in your permitted set from any pid */
135 #define CAP_SETPCAP 8
137 /* Allow modification of S_IMMUTABLE and S_APPEND file attributes */
139 #define CAP_LINUX_IMMUTABLE 9
141 /* Allows binding to TCP/UDP sockets below 1024 */
142 /* Allows binding to ATM VCIs below 32 */
144 #define CAP_NET_BIND_SERVICE 10
146 /* Allow broadcasting, listen to multicast */
148 #define CAP_NET_BROADCAST 11
150 /* Allow interface configuration */
151 /* Allow administration of IP firewall, masquerading and accounting */
152 /* Allow setting debug option on sockets */
153 /* Allow modification of routing tables */
154 /* Allow setting arbitrary process / process group ownership on
156 /* Allow binding to any address for transparent proxying */
157 /* Allow setting TOS (type of service) */
158 /* Allow setting promiscuous mode */
159 /* Allow clearing driver statistics */
160 /* Allow multicasting */
161 /* Allow read/write of device-specific registers */
162 /* Allow activation of ATM control sockets */
164 #define CAP_NET_ADMIN 12
166 /* Allow use of RAW sockets */
167 /* Allow use of PACKET sockets */
169 #define CAP_NET_RAW 13
171 /* Allow locking of shared memory segments */
172 /* Allow mlock and mlockall (which doesn't really have anything to do
175 #define CAP_IPC_LOCK 14
177 /* Override IPC ownership checks */
179 #define CAP_IPC_OWNER 15
181 /* Insert and remove kernel modules - modify kernel without limit */
182 /* Modify cap_bset */
183 #define CAP_SYS_MODULE 16
185 /* Allow ioperm/iopl access */
186 /* Allow sending USB messages to any device via /proc/bus/usb */
188 #define CAP_SYS_RAWIO 17
190 /* Allow use of chroot() */
192 #define CAP_SYS_CHROOT 18
194 /* Allow ptrace() of any process */
196 #define CAP_SYS_PTRACE 19
198 /* Allow configuration of process accounting */
200 #define CAP_SYS_PACCT 20
202 /* Allow configuration of the secure attention key */
203 /* Allow administration of the random device */
204 /* Allow examination and configuration of disk quotas */
205 /* Allow configuring the kernel's syslog (printk behaviour) */
206 /* Allow setting the domainname */
207 /* Allow setting the hostname */
208 /* Allow calling bdflush() */
209 /* Allow mount() and umount(), setting up new smb connection */
210 /* Allow some autofs root ioctls */
211 /* Allow nfsservctl */
212 /* Allow VM86_REQUEST_IRQ */
213 /* Allow to read/write pci config on alpha */
214 /* Allow irix_prctl on mips (setstacksize) */
215 /* Allow flushing all cache on m68k (sys_cacheflush) */
216 /* Allow removing semaphores */
217 /* Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores
219 /* Allow locking/unlocking of shared memory segment */
220 /* Allow turning swap on/off */
221 /* Allow forged pids on socket credentials passing */
222 /* Allow setting readahead and flushing buffers on block devices */
223 /* Allow setting geometry in floppy driver */
224 /* Allow turning DMA on/off in xd driver */
225 /* Allow administration of md devices (mostly the above, but some
227 /* Allow tuning the ide driver */
228 /* Allow access to the nvram device */
229 /* Allow administration of apm_bios, serial and bttv (TV) device */
230 /* Allow manufacturer commands in isdn CAPI support driver */
231 /* Allow reading non-standardized portions of pci configuration space */
232 /* Allow DDI debug ioctl on sbpcd driver */
233 /* Allow setting up serial ports */
234 /* Allow sending raw qic-117 commands */
235 /* Allow enabling/disabling tagged queuing on SCSI controllers and sending
236 arbitrary SCSI commands */
237 /* Allow setting encryption key on loopback filesystem */
238 /* Allow setting zone reclaim policy */
240 #define CAP_SYS_ADMIN 21
242 /* Allow use of reboot() */
244 #define CAP_SYS_BOOT 22
246 /* Allow raising priority and setting priority on other (different
248 /* Allow use of FIFO and round-robin (realtime) scheduling on own
249 processes and setting the scheduling algorithm used by another
251 /* Allow setting cpu affinity on other processes */
253 #define CAP_SYS_NICE 23
255 /* Override resource limits. Set resource limits. */
256 /* Override quota limits. */
257 /* Override reserved space on ext2 filesystem */
258 /* Modify data journaling mode on ext3 filesystem (uses journaling
260 /* NOTE: ext2 honors fsuid when checking for resource overrides, so
261 you can override using fsuid too */
262 /* Override size restrictions on IPC message queues */
263 /* Allow more than 64hz interrupts from the real-time clock */
264 /* Override max number of consoles on console allocation */
265 /* Override max number of keymaps */
267 #define CAP_SYS_RESOURCE 24
269 /* Allow manipulation of system clock */
270 /* Allow irix_stime on mips */
271 /* Allow setting the real-time clock */
273 #define CAP_SYS_TIME 25
275 /* Allow configuration of tty devices */
276 /* Allow vhangup() of tty */
278 #define CAP_SYS_TTY_CONFIG 26
280 /* Allow the privileged aspects of mknod() */
284 /* Allow taking of leases on files */
288 #define CAP_AUDIT_WRITE 29
290 #define CAP_AUDIT_CONTROL 30
296 extern kernel_cap_t cap_bset;
299 * Internal kernel functions only
302 #ifdef STRICT_CAP_T_TYPECHECKS
304 #define to_cap_t(x) { x }
305 #define cap_t(x) (x).cap
309 #define to_cap_t(x) (x)
314 #define CAP_EMPTY_SET to_cap_t(0)
315 #define CAP_FULL_SET to_cap_t(~0)
316 #define CAP_INIT_EFF_SET to_cap_t(~0 & ~CAP_TO_MASK(CAP_SETPCAP))
317 #define CAP_INIT_INH_SET to_cap_t(0)
319 #define CAP_TO_MASK(x) (1 << (x))
320 #define cap_raise(c, flag) (cap_t(c) |= CAP_TO_MASK(flag))
321 #define cap_lower(c, flag) (cap_t(c) &= ~CAP_TO_MASK(flag))
322 #define cap_raised(c, flag) (cap_t(c) & CAP_TO_MASK(flag))
324 static inline kernel_cap_t cap_combine(kernel_cap_t a, kernel_cap_t b)
327 cap_t(dest) = cap_t(a) | cap_t(b);
331 static inline kernel_cap_t cap_intersect(kernel_cap_t a, kernel_cap_t b)
334 cap_t(dest) = cap_t(a) & cap_t(b);
338 static inline kernel_cap_t cap_drop(kernel_cap_t a, kernel_cap_t drop)
341 cap_t(dest) = cap_t(a) & ~cap_t(drop);
345 static inline kernel_cap_t cap_invert(kernel_cap_t c)
348 cap_t(dest) = ~cap_t(c);
352 #define cap_isclear(c) (!cap_t(c))
353 #define cap_issubset(a,set) (!(cap_t(a) & ~cap_t(set)))
355 #define cap_clear(c) do { cap_t(c) = 0; } while(0)
356 #define cap_set_full(c) do { cap_t(c) = ~0; } while(0)
357 #define cap_mask(c,mask) do { cap_t(c) &= cap_t(mask); } while(0)
359 #define cap_is_fs_cap(c) (CAP_TO_MASK(c) & CAP_FS_MASK)
361 int capable(int cap);
362 int __capable(struct task_struct *t, int cap);
364 #endif /* __KERNEL__ */
366 #endif /* !_LINUX_CAPABILITY_H */