2 * Copyright (c) 2008-2010 Robert N. M. Watson
5 * This software was developed at the University of Cambridge Computer
6 * Laboratory with support from a grant from Google, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Definitions for FreeBSD capabilities facility.
35 #ifndef _SYS_CAPABILITY_H_
36 #define _SYS_CAPABILITY_H_
38 #include <sys/cdefs.h>
39 #include <sys/types.h>
44 * Possible rights on capabilities.
47 * Some system calls don't require a capability in order to perform an
48 * operation on an fd. These include: close, dup, dup2.
50 * sendfile is authorized using CAP_READ on the file and CAP_WRITE on the
53 * mmap() and aio*() system calls will need special attention as they may
54 * involve reads or writes depending a great deal on context.
57 /* General file I/O. */
58 #define CAP_READ 0x0000000000000001ULL /* read/recv */
59 #define CAP_WRITE 0x0000000000000002ULL /* write/send */
60 #define CAP_MMAP 0x0000000000000004ULL /* mmap */
61 #define CAP_MAPEXEC 0x0000000000000008ULL /* mmap(2) as exec */
62 #define CAP_FEXECVE 0x0000000000000010ULL
63 #define CAP_FSYNC 0x0000000000000020ULL
64 #define CAP_FTRUNCATE 0x0000000000000040ULL
65 #define CAP_SEEK 0x0000000000000080ULL
68 #define CAP_FCHFLAGS 0x0000000000000100ULL
69 #define CAP_FCHDIR 0x0000000000000200ULL
70 #define CAP_FCHMOD 0x0000000000000400ULL
71 #define CAP_FCHOWN 0x0000000000000800ULL
72 #define CAP_FCNTL 0x0000000000001000ULL
73 #define CAP_FPATHCONF 0x0000000000002000ULL
74 #define CAP_FLOCK 0x0000000000004000ULL
75 #define CAP_FSCK 0x0000000000008000ULL
76 #define CAP_FSTAT 0x0000000000010000ULL
77 #define CAP_FSTATFS 0x0000000000020000ULL
78 #define CAP_FUTIMES 0x0000000000040000ULL
79 #define CAP_CREATE 0x0000000000080000ULL
80 #define CAP_DELETE 0x0000000000100000ULL
81 #define CAP_MKDIR 0x0000000000200000ULL
82 #define CAP_RMDIR 0x0000000000400000ULL
83 #define CAP_MKFIFO 0x0000000000800000ULL
85 /* Lookups - used to constrain *at() calls. */
86 #define CAP_LOOKUP 0x0000000001000000ULL
88 /* Extended attributes. */
89 #define CAP_EXTATTR_DELETE 0x0000000002000000ULL
90 #define CAP_EXTATTR_GET 0x0000000004000000ULL
91 #define CAP_EXTATTR_LIST 0x0000000008000000ULL
92 #define CAP_EXTATTR_SET 0x0000000010000000ULL
94 /* Access Control Lists. */
95 #define CAP_ACL_CHECK 0x0000000020000000ULL
96 #define CAP_ACL_DELETE 0x0000000040000000ULL
97 #define CAP_ACL_GET 0x0000000080000000ULL
98 #define CAP_ACL_SET 0x0000000100000000ULL
100 /* Socket operations. */
101 #define CAP_ACCEPT 0x0000000200000000ULL
102 #define CAP_BIND 0x0000000400000000ULL
103 #define CAP_CONNECT 0x0000000800000000ULL
104 #define CAP_GETPEERNAME 0x0000001000000000ULL
105 #define CAP_GETSOCKNAME 0x0000002000000000ULL
106 #define CAP_GETSOCKOPT 0x0000004000000000ULL
107 #define CAP_LISTEN 0x0000008000000000ULL
108 #define CAP_PEELOFF 0x0000010000000000ULL
109 #define CAP_SETSOCKOPT 0x0000020000000000ULL
110 #define CAP_SHUTDOWN 0x0000040000000000ULL
112 #define CAP_SOCK_ALL \
113 (CAP_ACCEPT | CAP_BIND | CAP_CONNECT \
114 | CAP_GETPEERNAME | CAP_GETSOCKNAME | CAP_GETSOCKOPT \
115 | CAP_LISTEN | CAP_PEELOFF | CAP_SETSOCKOPT | CAP_SHUTDOWN)
117 /* Mandatory Access Control. */
118 #define CAP_MAC_GET 0x0000080000000000ULL
119 #define CAP_MAC_SET 0x0000100000000000ULL
121 /* Methods on semaphores. */
122 #define CAP_SEM_GETVALUE 0x0000200000000000ULL
123 #define CAP_SEM_POST 0x0000400000000000ULL
124 #define CAP_SEM_WAIT 0x0000800000000000ULL
127 #define CAP_POLL_EVENT 0x0001000000000000ULL
128 #define CAP_POST_EVENT 0x0002000000000000ULL
130 /* Strange and powerful rights that should not be given lightly. */
131 #define CAP_IOCTL 0x0004000000000000ULL
132 #define CAP_TTYHOOK 0x0008000000000000ULL
134 /* Process management via process descriptors. */
135 #define CAP_PDGETPID 0x0010000000000000ULL
136 #define CAP_PDWAIT 0x0020000000000000ULL
137 #define CAP_PDKILL 0x0040000000000000ULL
139 /* The mask of all valid method rights. */
140 #define CAP_MASK_VALID 0x007fffffffffffffULL
144 #define IN_CAPABILITY_MODE(td) (td->td_ucred->cr_flags & CRED_FLAG_CAPMODE)
147 * Create a capability to wrap a file object.
149 int kern_capwrap(struct thread *td, struct file *fp, cap_rights_t rights,
153 * Unwrap a capability if its rights mask is a superset of 'rights'.
155 * Unwrapping a non-capability is effectively a no-op; the value of fp_cap
156 * is simply copied into fpp.
158 int cap_funwrap(struct file *fp_cap, cap_rights_t rights,
160 int cap_funwrap_mmap(struct file *fp_cap, cap_rights_t rights,
161 u_char *maxprotp, struct file **fpp);
164 * For the purposes of procstat(1) and similar tools, allow kern_descrip.c to
165 * extract the rights from a capability. However, this should not be used by
166 * kernel code generally, instead cap_funwrap() should be used in order to
167 * keep all access control in one place.
169 cap_rights_t cap_rights(struct file *fp_cap);
176 * cap_enter(): Cause the process to enter capability mode, which will
177 * prevent it from directly accessing global namespaces. System calls will
178 * be limited to process-local, process-inherited, or file descriptor
179 * operations. If already in capability mode, a no-op.
181 * Currently, process-inherited operations are not properly handled -- in
182 * particular, we're interested in things like waitpid(2), kill(2), etc,
183 * being properly constrained. One possible solution is to introduce process
189 * cap_getmode(): Are we in capability mode?
191 int cap_getmode(u_int* modep);
194 * cap_new(): Create a new capability derived from an existing file
195 * descriptor with the specified rights. If the existing file descriptor is
196 * a capability, then the new rights must be a subset of the existing rights.
198 int cap_new(int fd, cap_rights_t rights);
201 * cap_getrights(): Query the rights on a capability.
203 int cap_getrights(int fd, cap_rights_t *rightsp);
207 #endif /* !_KERNEL */
209 #endif /* !_SYS_CAPABILITY_H_ */