V3 file capabilities: alter behavior of cap_setpcap
[linux-2.6/x86.git] / include / linux / capability.h
blob7a8d7ade28a035b106cf025c4faa74c18ee8b229
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>
17 #include <linux/compiler.h>
19 struct task_struct;
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
24 it. */
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
30 etc.. */
32 #define _LINUX_CAPABILITY_VERSION 0x19980330
34 typedef struct __user_cap_header_struct {
35 __u32 version;
36 int pid;
37 } __user *cap_user_header_t;
39 typedef struct __user_cap_data_struct {
40 __u32 effective;
41 __u32 permitted;
42 __u32 inheritable;
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
57 struct vfs_cap_data {
58 __u32 magic_etc; /* Little endian */
59 struct {
60 __u32 permitted; /* Little endian */
61 __u32 inheritable; /* Little endian */
62 } data[1];
65 #ifdef __KERNEL__
67 /* #define STRICT_CAP_T_TYPECHECKS */
69 #ifdef STRICT_CAP_T_TYPECHECKS
71 typedef struct kernel_cap_struct {
72 __u32 cap;
73 } kernel_cap_t;
75 #else
77 typedef __u32 kernel_cap_t;
79 #endif
81 #define _USER_CAP_HEADER_SIZE (2*sizeof(__u32))
82 #define _KERNEL_CAP_T_SIZE (sizeof(kernel_cap_t))
84 #endif
87 /**
88 ** POSIX-draft defined capabilities.
89 **/
91 /* In a system with the [_POSIX_CHOWN_RESTRICTED] option defined, this
92 overrides the restriction of changing file ownership and group
93 ownership. */
95 #define CAP_CHOWN 0
97 /* Override all DAC access, including ACL execute access if
98 [_POSIX_ACL] is defined. Excluding DAC access covered by
99 CAP_LINUX_IMMUTABLE. */
101 #define CAP_DAC_OVERRIDE 1
103 /* Overrides all DAC restrictions regarding read and search on files
104 and directories, including ACL restrictions if [_POSIX_ACL] is
105 defined. Excluding DAC access covered by CAP_LINUX_IMMUTABLE. */
107 #define CAP_DAC_READ_SEARCH 2
109 /* Overrides all restrictions about allowed operations on files, where
110 file owner ID must be equal to the user ID, except where CAP_FSETID
111 is applicable. It doesn't override MAC and DAC restrictions. */
113 #define CAP_FOWNER 3
115 /* Overrides the following restrictions that the effective user ID
116 shall match the file owner ID when setting the S_ISUID and S_ISGID
117 bits on that file; that the effective group ID (or one of the
118 supplementary group IDs) shall match the file owner ID when setting
119 the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are
120 cleared on successful return from chown(2) (not implemented). */
122 #define CAP_FSETID 4
124 /* Used to decide between falling back on the old suser() or fsuser(). */
126 #define CAP_FS_MASK 0x1f
128 /* Overrides the restriction that the real or effective user ID of a
129 process sending a signal must match the real or effective user ID
130 of the process receiving the signal. */
132 #define CAP_KILL 5
134 /* Allows setgid(2) manipulation */
135 /* Allows setgroups(2) */
136 /* Allows forged gids on socket credentials passing. */
138 #define CAP_SETGID 6
140 /* Allows set*uid(2) manipulation (including fsuid). */
141 /* Allows forged pids on socket credentials passing. */
143 #define CAP_SETUID 7
147 ** Linux-specific capabilities
150 /* Transfer any capability in your permitted set to any pid,
151 remove any capability in your permitted set from any pid */
153 #define CAP_SETPCAP 8
155 /* Allow modification of S_IMMUTABLE and S_APPEND file attributes */
157 #define CAP_LINUX_IMMUTABLE 9
159 /* Allows binding to TCP/UDP sockets below 1024 */
160 /* Allows binding to ATM VCIs below 32 */
162 #define CAP_NET_BIND_SERVICE 10
164 /* Allow broadcasting, listen to multicast */
166 #define CAP_NET_BROADCAST 11
168 /* Allow interface configuration */
169 /* Allow administration of IP firewall, masquerading and accounting */
170 /* Allow setting debug option on sockets */
171 /* Allow modification of routing tables */
172 /* Allow setting arbitrary process / process group ownership on
173 sockets */
174 /* Allow binding to any address for transparent proxying */
175 /* Allow setting TOS (type of service) */
176 /* Allow setting promiscuous mode */
177 /* Allow clearing driver statistics */
178 /* Allow multicasting */
179 /* Allow read/write of device-specific registers */
180 /* Allow activation of ATM control sockets */
182 #define CAP_NET_ADMIN 12
184 /* Allow use of RAW sockets */
185 /* Allow use of PACKET sockets */
187 #define CAP_NET_RAW 13
189 /* Allow locking of shared memory segments */
190 /* Allow mlock and mlockall (which doesn't really have anything to do
191 with IPC) */
193 #define CAP_IPC_LOCK 14
195 /* Override IPC ownership checks */
197 #define CAP_IPC_OWNER 15
199 /* Insert and remove kernel modules - modify kernel without limit */
200 /* Modify cap_bset */
201 #define CAP_SYS_MODULE 16
203 /* Allow ioperm/iopl access */
204 /* Allow sending USB messages to any device via /proc/bus/usb */
206 #define CAP_SYS_RAWIO 17
208 /* Allow use of chroot() */
210 #define CAP_SYS_CHROOT 18
212 /* Allow ptrace() of any process */
214 #define CAP_SYS_PTRACE 19
216 /* Allow configuration of process accounting */
218 #define CAP_SYS_PACCT 20
220 /* Allow configuration of the secure attention key */
221 /* Allow administration of the random device */
222 /* Allow examination and configuration of disk quotas */
223 /* Allow configuring the kernel's syslog (printk behaviour) */
224 /* Allow setting the domainname */
225 /* Allow setting the hostname */
226 /* Allow calling bdflush() */
227 /* Allow mount() and umount(), setting up new smb connection */
228 /* Allow some autofs root ioctls */
229 /* Allow nfsservctl */
230 /* Allow VM86_REQUEST_IRQ */
231 /* Allow to read/write pci config on alpha */
232 /* Allow irix_prctl on mips (setstacksize) */
233 /* Allow flushing all cache on m68k (sys_cacheflush) */
234 /* Allow removing semaphores */
235 /* Used instead of CAP_CHOWN to "chown" IPC message queues, semaphores
236 and shared memory */
237 /* Allow locking/unlocking of shared memory segment */
238 /* Allow turning swap on/off */
239 /* Allow forged pids on socket credentials passing */
240 /* Allow setting readahead and flushing buffers on block devices */
241 /* Allow setting geometry in floppy driver */
242 /* Allow turning DMA on/off in xd driver */
243 /* Allow administration of md devices (mostly the above, but some
244 extra ioctls) */
245 /* Allow tuning the ide driver */
246 /* Allow access to the nvram device */
247 /* Allow administration of apm_bios, serial and bttv (TV) device */
248 /* Allow manufacturer commands in isdn CAPI support driver */
249 /* Allow reading non-standardized portions of pci configuration space */
250 /* Allow DDI debug ioctl on sbpcd driver */
251 /* Allow setting up serial ports */
252 /* Allow sending raw qic-117 commands */
253 /* Allow enabling/disabling tagged queuing on SCSI controllers and sending
254 arbitrary SCSI commands */
255 /* Allow setting encryption key on loopback filesystem */
256 /* Allow setting zone reclaim policy */
258 #define CAP_SYS_ADMIN 21
260 /* Allow use of reboot() */
262 #define CAP_SYS_BOOT 22
264 /* Allow raising priority and setting priority on other (different
265 UID) processes */
266 /* Allow use of FIFO and round-robin (realtime) scheduling on own
267 processes and setting the scheduling algorithm used by another
268 process. */
269 /* Allow setting cpu affinity on other processes */
271 #define CAP_SYS_NICE 23
273 /* Override resource limits. Set resource limits. */
274 /* Override quota limits. */
275 /* Override reserved space on ext2 filesystem */
276 /* Modify data journaling mode on ext3 filesystem (uses journaling
277 resources) */
278 /* NOTE: ext2 honors fsuid when checking for resource overrides, so
279 you can override using fsuid too */
280 /* Override size restrictions on IPC message queues */
281 /* Allow more than 64hz interrupts from the real-time clock */
282 /* Override max number of consoles on console allocation */
283 /* Override max number of keymaps */
285 #define CAP_SYS_RESOURCE 24
287 /* Allow manipulation of system clock */
288 /* Allow irix_stime on mips */
289 /* Allow setting the real-time clock */
291 #define CAP_SYS_TIME 25
293 /* Allow configuration of tty devices */
294 /* Allow vhangup() of tty */
296 #define CAP_SYS_TTY_CONFIG 26
298 /* Allow the privileged aspects of mknod() */
300 #define CAP_MKNOD 27
302 /* Allow taking of leases on files */
304 #define CAP_LEASE 28
306 #define CAP_AUDIT_WRITE 29
308 #define CAP_AUDIT_CONTROL 30
310 #define CAP_SETFCAP 31
312 #ifdef __KERNEL__
315 * Internal kernel functions only
318 #ifdef STRICT_CAP_T_TYPECHECKS
320 #define to_cap_t(x) { x }
321 #define cap_t(x) (x).cap
323 #else
325 #define to_cap_t(x) (x)
326 #define cap_t(x) (x)
328 #endif
330 #define CAP_EMPTY_SET to_cap_t(0)
331 #define CAP_FULL_SET to_cap_t(~0)
332 #define CAP_INIT_EFF_SET to_cap_t(~0 & ~CAP_TO_MASK(CAP_SETPCAP))
333 #define CAP_INIT_INH_SET to_cap_t(0)
335 #define CAP_TO_MASK(x) (1 << (x))
336 #define cap_raise(c, flag) (cap_t(c) |= CAP_TO_MASK(flag))
337 #define cap_lower(c, flag) (cap_t(c) &= ~CAP_TO_MASK(flag))
338 #define cap_raised(c, flag) (cap_t(c) & CAP_TO_MASK(flag))
340 static inline kernel_cap_t cap_combine(kernel_cap_t a, kernel_cap_t b)
342 kernel_cap_t dest;
343 cap_t(dest) = cap_t(a) | cap_t(b);
344 return dest;
347 static inline kernel_cap_t cap_intersect(kernel_cap_t a, kernel_cap_t b)
349 kernel_cap_t dest;
350 cap_t(dest) = cap_t(a) & cap_t(b);
351 return dest;
354 static inline kernel_cap_t cap_drop(kernel_cap_t a, kernel_cap_t drop)
356 kernel_cap_t dest;
357 cap_t(dest) = cap_t(a) & ~cap_t(drop);
358 return dest;
361 static inline kernel_cap_t cap_invert(kernel_cap_t c)
363 kernel_cap_t dest;
364 cap_t(dest) = ~cap_t(c);
365 return dest;
368 #define cap_isclear(c) (!cap_t(c))
369 #define cap_issubset(a,set) (!(cap_t(a) & ~cap_t(set)))
371 #define cap_clear(c) do { cap_t(c) = 0; } while(0)
372 #define cap_set_full(c) do { cap_t(c) = ~0; } while(0)
373 #define cap_mask(c,mask) do { cap_t(c) &= cap_t(mask); } while(0)
375 #define cap_is_fs_cap(c) (CAP_TO_MASK(c) & CAP_FS_MASK)
377 int capable(int cap);
378 int __capable(struct task_struct *t, int cap);
380 #endif /* __KERNEL__ */
382 #endif /* !_LINUX_CAPABILITY_H */