1 /*- 2 * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson 3 * Copyright (c) 2001, 2002 Networks Associates Technology, Inc. 4 * All rights reserved. 5 * 6 * This software was developed by Robert Watson for the TrustedBSD Project. 7 * 8 * This software was developed for the FreeBSD Project in part by NAI Labs, 9 * the Security Research Division of Network Associates, Inc. under 10 * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA 11 * CHATS research program. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. The names of the authors may not be used to endorse or promote 22 * products derived from this software without specific prior written 23 * permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * $FreeBSD$ 38 */ 39 /* 40 * Kernel interface for MAC policy modules. 41 */ 42 #ifndef _SYS_MAC_POLICY_H 43 #define _SYS_MAC_POLICY_H 44 45 /*- 46 * Pluggable access control policy definition structure. 47 * 48 * List of operations that are performed as part of the implementation 49 * of a MAC policy. Policy implementors declare operations with a 50 * mac_policy_ops structure, and using the MAC_POLICY_SET() macro. 51 * If an entry point is not declared, then then the policy will be ignored 52 * during evaluation of that event or check. 53 * 54 * Operations are sorted first by general class of operation, then 55 * alphabetically. 56 */ 57 struct mac_policy_conf; 58 struct mac_policy_ops { 59 /* 60 * Policy module operations. 61 */ 62 void (*mpo_destroy)(struct mac_policy_conf *mpc); 63 void (*mpo_init)(struct mac_policy_conf *mpc); 64 65 /* 66 * General policy-directed security system call so that policies 67 * may implement new services without reserving explicit 68 * system call numbers. 69 */ 70 int (*mpo_syscall)(struct thread *td, int call, void *arg); 71 72 /* 73 * Label operations. 74 */ 75 void (*mpo_init_bpfdesc_label)(struct label *label); 76 void (*mpo_init_cred_label)(struct label *label); 77 void (*mpo_init_devfsdirent_label)(struct label *label); 78 void (*mpo_init_ifnet_label)(struct label *label); 79 void (*mpo_init_ipq_label)(struct label *label); 80 int (*mpo_init_mbuf_label)(struct label *label, int flag); 81 void (*mpo_init_mount_label)(struct label *label); 82 void (*mpo_init_mount_fs_label)(struct label *label); 83 int (*mpo_init_socket_label)(struct label *label, int flag); 84 int (*mpo_init_socket_peer_label)(struct label *label, int flag); 85 void (*mpo_init_pipe_label)(struct label *label); 86 void (*mpo_init_vnode_label)(struct label *label); 87 void (*mpo_destroy_bpfdesc_label)(struct label *label); 88 void (*mpo_destroy_cred_label)(struct label *label); 89 void (*mpo_destroy_devfsdirent_label)(struct label *label); 90 void (*mpo_destroy_ifnet_label)(struct label *label); 91 void (*mpo_destroy_ipq_label)(struct label *label); 92 void (*mpo_destroy_mbuf_label)(struct label *label); 93 void (*mpo_destroy_mount_label)(struct label *label); 94 void (*mpo_destroy_mount_fs_label)(struct label *label); 95 void (*mpo_destroy_socket_label)(struct label *label); 96 void (*mpo_destroy_socket_peer_label)(struct label *label); 97 void (*mpo_destroy_pipe_label)(struct label *label); 98 void (*mpo_destroy_vnode_label)(struct label *label); 99 void (*mpo_copy_pipe_label)(struct label *src, 100 struct label *dest); 101 void (*mpo_copy_vnode_label)(struct label *src, 102 struct label *dest); 103 int (*mpo_externalize_cred_label)(struct label *label, 104 char *element_name, char *buffer, size_t buflen, 105 size_t *len, int *claimed); 106 int (*mpo_externalize_ifnet_label)(struct label *label, 107 char *element_name, char *buffer, size_t buflen, 108 size_t *len, int *claimed); 109 int (*mpo_externalize_pipe_label)(struct label *label, 110 char *element_name, char *buffer, size_t buflen, 111 size_t *len, int *claimed); 112 int (*mpo_externalize_socket_label)(struct label *label, 113 char *element_name, char *buffer, size_t buflen, 114 size_t *len, int *claimed); 115 int (*mpo_externalize_socket_peer_label)(struct label *label, 116 char *element_name, char *buffer, size_t buflen, 117 size_t *len, int *claimed); 118 int (*mpo_externalize_vnode_label)(struct label *label, 119 char *element_name, char *buffer, size_t buflen, 120 size_t *len, int *claimed); 121 int (*mpo_externalize_vnode_oldmac)(struct label *label, 122 struct oldmac *extmac); 123 int (*mpo_internalize_cred_label)(struct label *label, 124 char *element_name, char *element_data, int *claimed); 125 int (*mpo_internalize_ifnet_label)(struct label *label, 126 char *element_name, char *element_data, int *claimed); 127 int (*mpo_internalize_pipe_label)(struct label *label, 128 char *element_name, char *element_data, int *claimed); 129 int (*mpo_internalize_socket_label)(struct label *label, 130 char *element_name, char *element_data, int *claimed); 131 int (*mpo_internalize_vnode_label)(struct label *label, 132 char *element_name, char *element_data, int *claimed); 133 134 /* 135 * Labeling event operations: file system objects, and things that 136 * look a lot like file system objects. 137 */ 138 void (*mpo_create_devfs_device)(dev_t dev, struct devfs_dirent *de, 139 struct label *label); 140 void (*mpo_create_devfs_directory)(char *dirname, int dirnamelen, 141 struct devfs_dirent *de, struct label *label); 142 void (*mpo_create_devfs_symlink)(struct ucred *cred, 143 struct devfs_dirent *dd, struct label *ddlabel, 144 struct devfs_dirent *de, struct label *delabel); 145 void (*mpo_create_devfs_vnode)(struct devfs_dirent *de, 146 struct label *direntlabel, struct vnode *vp, 147 struct label *vnodelabel); 148 void (*mpo_create_vnode)(struct ucred *cred, struct vnode *parent, 149 struct label *parentlabel, struct vnode *child, 150 struct label *childlabel); 151 void (*mpo_create_mount)(struct ucred *cred, struct mount *mp, 152 struct label *mntlabel, struct label *fslabel); 153 void (*mpo_create_root_mount)(struct ucred *cred, struct mount *mp, 154 struct label *mountlabel, struct label *fslabel); 155 void (*mpo_relabel_vnode)(struct ucred *cred, struct vnode *vp, 156 struct label *vnodelabel, struct label *label); 157 int (*mpo_stdcreatevnode_ea)(struct vnode *vp, 158 struct label *vnodelabel); 159 void (*mpo_update_devfsdirent)(struct devfs_dirent *devfs_dirent, 160 struct label *direntlabel, struct vnode *vp, 161 struct label *vnodelabel); 162 void (*mpo_update_procfsvnode)(struct vnode *vp, 163 struct label *vnodelabel, struct ucred *cred); 164 int (*mpo_update_vnode_from_extattr)(struct vnode *vp, 165 struct label *vnodelabel, struct mount *mp, 166 struct label *fslabel); 167 int (*mpo_update_vnode_from_externalized)(struct vnode *vp, 168 struct label *vnodelabel, struct oldmac *extmac); 169 void (*mpo_update_vnode_from_mount)(struct vnode *vp, 170 struct label *vnodelabel, struct mount *mp, 171 struct label *fslabel); 172 173 /* 174 * Labeling event operations: IPC objects. 175 */ 176 void (*mpo_create_mbuf_from_socket)(struct socket *so, 177 struct label *socketlabel, struct mbuf *m, 178 struct label *mbuflabel); 179 void (*mpo_create_socket)(struct ucred *cred, struct socket *so, 180 struct label *socketlabel); 181 void (*mpo_create_socket_from_socket)(struct socket *oldsocket, 182 struct label *oldsocketlabel, struct socket *newsocket, 183 struct label *newsocketlabel); 184 void (*mpo_relabel_socket)(struct ucred *cred, struct socket *so, 185 struct label *oldlabel, struct label *newlabel); 186 void (*mpo_relabel_pipe)(struct ucred *cred, struct pipe *pipe, 187 struct label *oldlabel, struct label *newlabel); 188 void (*mpo_set_socket_peer_from_mbuf)(struct mbuf *mbuf, 189 struct label *mbuflabel, struct socket *so, 190 struct label *socketpeerlabel); 191 void (*mpo_set_socket_peer_from_socket)(struct socket *oldsocket, 192 struct label *oldsocketlabel, struct socket *newsocket, 193 struct label *newsocketpeerlabel); 194 void (*mpo_create_pipe)(struct ucred *cred, struct pipe *pipe, 195 struct label *pipelabel); 196 197 /* 198 * Labeling event operations: network objects. 199 */ 200 void (*mpo_create_bpfdesc)(struct ucred *cred, struct bpf_d *bpf_d, 201 struct label *bpflabel); 202 void (*mpo_create_ifnet)(struct ifnet *ifnet, 203 struct label *ifnetlabel); 204 void (*mpo_create_ipq)(struct mbuf *fragment, 205 struct label *fragmentlabel, struct ipq *ipq, 206 struct label *ipqlabel); 207 void (*mpo_create_datagram_from_ipq) 208 (struct ipq *ipq, struct label *ipqlabel, 209 struct mbuf *datagram, struct label *datagramlabel); 210 void (*mpo_create_fragment)(struct mbuf *datagram, 211 struct label *datagramlabel, struct mbuf *fragment, 212 struct label *fragmentlabel); 213 void (*mpo_create_mbuf_from_mbuf)(struct mbuf *oldmbuf, 214 struct label *oldlabel, struct mbuf *newmbuf, 215 struct label *newlabel); 216 void (*mpo_create_mbuf_linklayer)(struct ifnet *ifnet, 217 struct label *ifnetlabel, struct mbuf *mbuf, 218 struct label *mbuflabel); 219 void (*mpo_create_mbuf_from_bpfdesc)(struct bpf_d *bpf_d, 220 struct label *bpflabel, struct mbuf *mbuf, 221 struct label *mbuflabel); 222 void (*mpo_create_mbuf_from_ifnet)(struct ifnet *ifnet, 223 struct label *ifnetlabel, struct mbuf *mbuf, 224 struct label *mbuflabel); 225 void (*mpo_create_mbuf_multicast_encap)(struct mbuf *oldmbuf, 226 struct label *oldmbuflabel, struct ifnet *ifnet, 227 struct label *ifnetlabel, struct mbuf *newmbuf, 228 struct label *newmbuflabel); 229 void (*mpo_create_mbuf_netlayer)(struct mbuf *oldmbuf, 230 struct label *oldmbuflabel, struct mbuf *newmbuf, 231 struct label *newmbuflabel); 232 int (*mpo_fragment_match)(struct mbuf *fragment, 233 struct label *fragmentlabel, struct ipq *ipq, 234 struct label *ipqlabel); 235 void (*mpo_relabel_ifnet)(struct ucred *cred, struct ifnet *ifnet, 236 struct label *ifnetlabel, struct label *newlabel); 237 void (*mpo_update_ipq)(struct mbuf *fragment, 238 struct label *fragmentlabel, struct ipq *ipq, 239 struct label *ipqlabel); 240 241 /* 242 * Labeling event operations: processes. 243 */ 244 void (*mpo_create_cred)(struct ucred *parent_cred, 245 struct ucred *child_cred); 246 void (*mpo_execve_transition)(struct ucred *old, struct ucred *new, 247 struct vnode *vp, struct label *vnodelabel); 248 int (*mpo_execve_will_transition)(struct ucred *old, 249 struct vnode *vp, struct label *vnodelabel); 250 void (*mpo_create_proc0)(struct ucred *cred); 251 void (*mpo_create_proc1)(struct ucred *cred); 252 void (*mpo_relabel_cred)(struct ucred *cred, 253 struct label *newlabel); 254 void (*mpo_thread_userret)(struct thread *thread); 255 256 /* 257 * Access control checks. 258 */ 259 int (*mpo_check_bpfdesc_receive)(struct bpf_d *bpf_d, 260 struct label *bpflabel, struct ifnet *ifnet, 261 struct label *ifnetlabel); 262 int (*mpo_check_cred_relabel)(struct ucred *cred, 263 struct label *newlabel); 264 int (*mpo_check_cred_visible)(struct ucred *u1, struct ucred *u2); 265 int (*mpo_check_ifnet_relabel)(struct ucred *cred, 266 struct ifnet *ifnet, struct label *ifnetlabel, 267 struct label *newlabel); 268 int (*mpo_check_ifnet_transmit)(struct ifnet *ifnet, 269 struct label *ifnetlabel, struct mbuf *m, 270 struct label *mbuflabel); 271 int (*mpo_check_mount_stat)(struct ucred *cred, struct mount *mp, 272 struct label *mntlabel); 273 int (*mpo_check_pipe_ioctl)(struct ucred *cred, struct pipe *pipe, 274 struct label *pipelabel, unsigned long cmd, void *data); 275 int (*mpo_check_pipe_poll)(struct ucred *cred, struct pipe *pipe, 276 struct label *pipelabel); 277 int (*mpo_check_pipe_read)(struct ucred *cred, struct pipe *pipe, 278 struct label *pipelabel); 279 int (*mpo_check_pipe_relabel)(struct ucred *cred, 280 struct pipe *pipe, struct label *pipelabel, 281 struct label *newlabel); 282 int (*mpo_check_pipe_stat)(struct ucred *cred, struct pipe *pipe, 283 struct label *pipelabel); 284 int (*mpo_check_pipe_write)(struct ucred *cred, struct pipe *pipe, 285 struct label *pipelabel); 286 int (*mpo_check_proc_debug)(struct ucred *cred, 287 struct proc *proc); 288 int (*mpo_check_proc_sched)(struct ucred *cred, 289 struct proc *proc); 290 int (*mpo_check_proc_signal)(struct ucred *cred, 291 struct proc *proc, int signum); 292 int (*mpo_check_socket_bind)(struct ucred *cred, 293 struct socket *so, struct label *socketlabel, 294 struct sockaddr *sockaddr); 295 int (*mpo_check_socket_connect)(struct ucred *cred, 296 struct socket *so, struct label *socketlabel, 297 struct sockaddr *sockaddr); 298 int (*mpo_check_socket_deliver)(struct socket *so, 299 struct label *socketlabel, struct mbuf *m, 300 struct label *mbuflabel); 301 int (*mpo_check_socket_listen)(struct ucred *cred, 302 struct socket *so, struct label *socketlabel); 303 int (*mpo_check_socket_receive)(struct ucred *cred, 304 struct socket *so, struct label *socketlabel); 305 int (*mpo_check_socket_relabel)(struct ucred *cred, 306 struct socket *so, struct label *socketlabel, 307 struct label *newlabel); 308 int (*mpo_check_socket_send)(struct ucred *cred, 309 struct socket *so, struct label *socketlabel); 310 int (*mpo_check_socket_visible)(struct ucred *cred, 311 struct socket *so, struct label *socketlabel); 312 int (*mpo_check_vnode_access)(struct ucred *cred, 313 struct vnode *vp, struct label *label, int flags); 314 int (*mpo_check_vnode_chdir)(struct ucred *cred, 315 struct vnode *dvp, struct label *dlabel); 316 int (*mpo_check_vnode_chroot)(struct ucred *cred, 317 struct vnode *dvp, struct label *dlabel); 318 int (*mpo_check_vnode_create)(struct ucred *cred, 319 struct vnode *dvp, struct label *dlabel, 320 struct componentname *cnp, struct vattr *vap); 321 int (*mpo_check_vnode_delete)(struct ucred *cred, 322 struct vnode *dvp, struct label *dlabel, 323 struct vnode *vp, void *label, struct componentname *cnp); 324 int (*mpo_check_vnode_deleteacl)(struct ucred *cred, 325 struct vnode *vp, struct label *label, acl_type_t type); 326 int (*mpo_check_vnode_exec)(struct ucred *cred, struct vnode *vp, 327 struct label *label); 328 int (*mpo_check_vnode_getacl)(struct ucred *cred, 329 struct vnode *vp, struct label *label, acl_type_t type); 330 int (*mpo_check_vnode_getextattr)(struct ucred *cred, 331 struct vnode *vp, struct label *label, int attrnamespace, 332 const char *name, struct uio *uio); 333 int (*mpo_check_vnode_link)(struct ucred *cred, struct vnode *dvp, 334 struct label *dlabel, struct vnode *vp, 335 struct label *label, struct componentname *cnp); 336 int (*mpo_check_vnode_lookup)(struct ucred *cred, 337 struct vnode *dvp, struct label *dlabel, 338 struct componentname *cnp); 339 int (*mpo_check_vnode_mmap)(struct ucred *cred, struct vnode *vp, 340 struct label *label, int prot); 341 void (*mpo_check_vnode_mmap_downgrade)(struct ucred *cred, 342 struct vnode *vp, struct label *label, int *prot); 343 int (*mpo_check_vnode_mprotect)(struct ucred *cred, 344 struct vnode *vp, struct label *label, int prot); 345 int (*mpo_check_vnode_open)(struct ucred *cred, struct vnode *vp, 346 struct label *label, mode_t acc_mode); 347 int (*mpo_check_vnode_poll)(struct ucred *active_cred, 348 struct ucred *file_cred, struct vnode *vp, 349 struct label *label); 350 int (*mpo_check_vnode_read)(struct ucred *active_cred, 351 struct ucred *file_cred, struct vnode *vp, 352 struct label *label); 353 int (*mpo_check_vnode_readdir)(struct ucred *cred, 354 struct vnode *dvp, struct label *dlabel); 355 int (*mpo_check_vnode_readlink)(struct ucred *cred, 356 struct vnode *vp, struct label *label); 357 int (*mpo_check_vnode_relabel)(struct ucred *cred, 358 struct vnode *vp, struct label *vnodelabel, 359 struct label *newlabel); 360 int (*mpo_check_vnode_rename_from)(struct ucred *cred, 361 struct vnode *dvp, struct label *dlabel, struct vnode *vp, 362 struct label *label, struct componentname *cnp); 363 int (*mpo_check_vnode_rename_to)(struct ucred *cred, 364 struct vnode *dvp, struct label *dlabel, struct vnode *vp, 365 struct label *label, int samedir, 366 struct componentname *cnp); 367 int (*mpo_check_vnode_revoke)(struct ucred *cred, 368 struct vnode *vp, struct label *label); 369 int (*mpo_check_vnode_setacl)(struct ucred *cred, 370 struct vnode *vp, struct label *label, acl_type_t type, 371 struct acl *acl); 372 int (*mpo_check_vnode_setextattr)(struct ucred *cred, 373 struct vnode *vp, struct label *label, int attrnamespace, 374 const char *name, struct uio *uio); 375 int (*mpo_check_vnode_setflags)(struct ucred *cred, 376 struct vnode *vp, struct label *label, u_long flags); 377 int (*mpo_check_vnode_setmode)(struct ucred *cred, 378 struct vnode *vp, struct label *label, mode_t mode); 379 int (*mpo_check_vnode_setowner)(struct ucred *cred, 380 struct vnode *vp, struct label *label, uid_t uid, 381 gid_t gid); 382 int (*mpo_check_vnode_setutimes)(struct ucred *cred, 383 struct vnode *vp, struct label *label, 384 struct timespec atime, struct timespec mtime); 385 int (*mpo_check_vnode_stat)(struct ucred *active_cred, 386 struct ucred *file_cred, struct vnode *vp, 387 struct label *label); 388 int (*mpo_check_vnode_swapon)(struct ucred *cred, 389 struct vnode *vp, struct label *label); 390 int (*mpo_check_vnode_write)(struct ucred *active_cred, 391 struct ucred *file_cred, struct vnode *vp, 392 struct label *label); 393 }; 394 395 typedef const void *macop_t; 396 397 enum mac_op_constant { 398 MAC_OP_LAST, 399 MAC_DESTROY, 400 MAC_INIT, 401 MAC_SYSCALL, 402 MAC_INIT_BPFDESC_LABEL, 403 MAC_INIT_CRED_LABEL, 404 MAC_INIT_DEVFSDIRENT_LABEL, 405 MAC_INIT_IFNET_LABEL, 406 MAC_INIT_IPQ_LABEL, 407 MAC_INIT_MBUF_LABEL, 408 MAC_INIT_MOUNT_LABEL, 409 MAC_INIT_MOUNT_FS_LABEL, 410 MAC_INIT_PIPE_LABEL, 411 MAC_INIT_SOCKET_LABEL, 412 MAC_INIT_SOCKET_PEER_LABEL, 413 MAC_INIT_VNODE_LABEL, 414 MAC_DESTROY_BPFDESC_LABEL, 415 MAC_DESTROY_CRED_LABEL, 416 MAC_DESTROY_DEVFSDIRENT_LABEL, 417 MAC_DESTROY_IFNET_LABEL, 418 MAC_DESTROY_IPQ_LABEL, 419 MAC_DESTROY_MBUF_LABEL, 420 MAC_DESTROY_MOUNT_LABEL, 421 MAC_DESTROY_MOUNT_FS_LABEL, 422 MAC_DESTROY_PIPE_LABEL, 423 MAC_DESTROY_SOCKET_LABEL, 424 MAC_DESTROY_SOCKET_PEER_LABEL, 425 MAC_DESTROY_VNODE_LABEL, 426 MAC_COPY_PIPE_LABEL, 427 MAC_COPY_VNODE_LABEL, 428 MAC_EXTERNALIZE_CRED_LABEL, 429 MAC_EXTERNALIZE_IFNET_LABEL, 430 MAC_EXTERNALIZE_PIPE_LABEL, 431 MAC_EXTERNALIZE_SOCKET_LABEL, 432 MAC_EXTERNALIZE_SOCKET_PEER_LABEL, 433 MAC_EXTERNALIZE_VNODE_LABEL, 434 MAC_EXTERNALIZE_VNODE_OLDMAC, 435 MAC_INTERNALIZE_CRED_LABEL, 436 MAC_INTERNALIZE_IFNET_LABEL, 437 MAC_INTERNALIZE_PIPE_LABEL, 438 MAC_INTERNALIZE_SOCKET_LABEL, 439 MAC_INTERNALIZE_VNODE_LABEL, 440 MAC_CREATE_DEVFS_DEVICE, 441 MAC_CREATE_DEVFS_DIRECTORY, 442 MAC_CREATE_DEVFS_SYMLINK, 443 MAC_CREATE_DEVFS_VNODE, 444 MAC_CREATE_VNODE, 445 MAC_CREATE_MOUNT, 446 MAC_CREATE_ROOT_MOUNT, 447 MAC_RELABEL_VNODE, 448 MAC_STDCREATEVNODE_EA, 449 MAC_UPDATE_DEVFSDIRENT, 450 MAC_UPDATE_PROCFSVNODE, 451 MAC_UPDATE_VNODE_FROM_EXTATTR, 452 MAC_UPDATE_VNODE_FROM_EXTERNALIZED, 453 MAC_UPDATE_VNODE_FROM_MOUNT, 454 MAC_CREATE_MBUF_FROM_SOCKET, 455 MAC_CREATE_PIPE, 456 MAC_CREATE_SOCKET, 457 MAC_CREATE_SOCKET_FROM_SOCKET, 458 MAC_RELABEL_PIPE, 459 MAC_RELABEL_SOCKET, 460 MAC_SET_SOCKET_PEER_FROM_MBUF, 461 MAC_SET_SOCKET_PEER_FROM_SOCKET, 462 MAC_CREATE_BPFDESC, 463 MAC_CREATE_DATAGRAM_FROM_IPQ, 464 MAC_CREATE_IFNET, 465 MAC_CREATE_IPQ, 466 MAC_CREATE_FRAGMENT, 467 MAC_CREATE_MBUF_FROM_MBUF, 468 MAC_CREATE_MBUF_LINKLAYER, 469 MAC_CREATE_MBUF_FROM_BPFDESC, 470 MAC_CREATE_MBUF_FROM_IFNET, 471 MAC_CREATE_MBUF_MULTICAST_ENCAP, 472 MAC_CREATE_MBUF_NETLAYER, 473 MAC_FRAGMENT_MATCH, 474 MAC_RELABEL_IFNET, 475 MAC_UPDATE_IPQ, 476 MAC_CREATE_CRED, 477 MAC_EXECVE_TRANSITION, 478 MAC_EXECVE_WILL_TRANSITION, 479 MAC_CREATE_PROC0, 480 MAC_CREATE_PROC1, 481 MAC_RELABEL_CRED, 482 MAC_THREAD_USERRET, 483 MAC_CHECK_BPFDESC_RECEIVE, 484 MAC_CHECK_CRED_RELABEL, 485 MAC_CHECK_CRED_VISIBLE, 486 MAC_CHECK_IFNET_RELABEL, 487 MAC_CHECK_IFNET_TRANSMIT, 488 MAC_CHECK_MOUNT_STAT, 489 MAC_CHECK_PIPE_IOCTL, 490 MAC_CHECK_PIPE_POLL, 491 MAC_CHECK_PIPE_READ, 492 MAC_CHECK_PIPE_RELABEL, 493 MAC_CHECK_PIPE_STAT, 494 MAC_CHECK_PIPE_WRITE, 495 MAC_CHECK_PROC_DEBUG, 496 MAC_CHECK_PROC_SCHED, 497 MAC_CHECK_PROC_SIGNAL, 498 MAC_CHECK_SOCKET_BIND, 499 MAC_CHECK_SOCKET_CONNECT, 500 MAC_CHECK_SOCKET_DELIVER, 501 MAC_CHECK_SOCKET_LISTEN, 502 MAC_CHECK_SOCKET_RECEIVE, 503 MAC_CHECK_SOCKET_RELABEL, 504 MAC_CHECK_SOCKET_SEND, 505 MAC_CHECK_SOCKET_VISIBLE, 506 MAC_CHECK_VNODE_ACCESS, 507 MAC_CHECK_VNODE_CHDIR, 508 MAC_CHECK_VNODE_CHROOT, 509 MAC_CHECK_VNODE_CREATE, 510 MAC_CHECK_VNODE_DELETE, 511 MAC_CHECK_VNODE_DELETEACL, 512 MAC_CHECK_VNODE_EXEC, 513 MAC_CHECK_VNODE_GETACL, 514 MAC_CHECK_VNODE_GETEXTATTR, 515 MAC_CHECK_VNODE_LINK, 516 MAC_CHECK_VNODE_LOOKUP, 517 MAC_CHECK_VNODE_MMAP, 518 MAC_CHECK_VNODE_MMAP_DOWNGRADE, 519 MAC_CHECK_VNODE_MPROTECT, 520 MAC_CHECK_VNODE_OPEN, 521 MAC_CHECK_VNODE_POLL, 522 MAC_CHECK_VNODE_READ, 523 MAC_CHECK_VNODE_READDIR, 524 MAC_CHECK_VNODE_READLINK, 525 MAC_CHECK_VNODE_RELABEL, 526 MAC_CHECK_VNODE_RENAME_FROM, 527 MAC_CHECK_VNODE_RENAME_TO, 528 MAC_CHECK_VNODE_REVOKE, 529 MAC_CHECK_VNODE_SETACL, 530 MAC_CHECK_VNODE_SETEXTATTR, 531 MAC_CHECK_VNODE_SETFLAGS, 532 MAC_CHECK_VNODE_SETMODE, 533 MAC_CHECK_VNODE_SETOWNER, 534 MAC_CHECK_VNODE_SETUTIMES, 535 MAC_CHECK_VNODE_STAT, 536 MAC_CHECK_VNODE_SWAPON, 537 MAC_CHECK_VNODE_WRITE, 538 }; 539 540 struct mac_policy_op_entry { 541 enum mac_op_constant mpe_constant; /* what this hook implements */ 542 macop_t mpe_function; /* hook's implementation */ 543 }; 544 545 struct mac_policy_conf { 546 char *mpc_name; /* policy name */ 547 char *mpc_fullname; /* policy full name */ 548 struct mac_policy_ops *mpc_ops; /* policy operations */ 549 struct mac_policy_op_entry *mpc_entries; /* ops to fill in */ 550 int mpc_loadtime_flags; /* flags */ 551 int *mpc_field_off; /* security field */ 552 int mpc_runtime_flags; /* flags */ 553 LIST_ENTRY(mac_policy_conf) mpc_list; /* global list */ 554 }; 555 556 /* Flags for the mpc_loadtime_flags field. */ 557 #define MPC_LOADTIME_FLAG_NOTLATE 0x00000001 558 #define MPC_LOADTIME_FLAG_UNLOADOK 0x00000002 559 560 /* Flags for the mpc_runtime_flags field. */ 561 #define MPC_RUNTIME_FLAG_REGISTERED 0x00000001 562 563 #define MAC_POLICY_SET(mpents, mpname, mpfullname, mpflags, privdata_wanted) \ 564 static struct mac_policy_conf mpname##_mac_policy_conf = { \ 565 #mpname, \ 566 mpfullname, \ 567 NULL, \ 568 mpents, \ 569 mpflags, \ 570 privdata_wanted, \ 571 0, \ 572 }; \ 573 static moduledata_t mpname##_mod = { \ 574 #mpname, \ 575 mac_policy_modevent, \ 576 &mpname##_mac_policy_conf \ 577 }; \ 578 MODULE_DEPEND(mpname, kernel_mac_support, 1, 1, 1); \ 579 DECLARE_MODULE(mpname, mpname##_mod, SI_SUB_MAC_POLICY, \ 580 SI_ORDER_MIDDLE) 581 582 int mac_policy_modevent(module_t mod, int type, void *data); 583 584 #define LABEL_TO_SLOT(l, s) (l)->l_perpolicy[s] 585 586 #endif /* !_SYS_MAC_POLICY_H */ 587