1 /*- 2 * Copyright (c) 1999-2002, 2007-2011 Robert N. M. Watson 3 * Copyright (c) 2001-2005 Networks Associates Technology, Inc. 4 * Copyright (c) 2005-2006 SPARTA, Inc. 5 * All rights reserved. 6 * 7 * This software was developed by Robert Watson for the TrustedBSD Project. 8 * 9 * This software was developed for the FreeBSD Project in part by Network 10 * Associates Laboratories, the Security Research Division of Network 11 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), 12 * as part of the DARPA CHATS research program. 13 * 14 * This software was enhanced by SPARTA ISSO under SPAWAR contract 15 * N66001-04-C-6019 ("SEFOS"). 16 * 17 * This software was developed at the University of Cambridge Computer 18 * Laboratory with support from a grant from Google, Inc. 19 * 20 * Redistribution and use in source and binary forms, with or without 21 * modification, are permitted provided that the following conditions 22 * are met: 23 * 1. Redistributions of source code must retain the above copyright 24 * notice, this list of conditions and the following disclaimer. 25 * 2. Redistributions in binary form must reproduce the above copyright 26 * notice, this list of conditions and the following disclaimer in the 27 * documentation and/or other materials provided with the distribution. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 * 41 * $FreeBSD$ 42 */ 43 44 /* 45 * Kernel interface for Mandatory Access Control -- how kernel services 46 * interact with the TrustedBSD MAC Framework. 47 */ 48 49 #ifndef _SECURITY_MAC_MAC_FRAMEWORK_H_ 50 #define _SECURITY_MAC_MAC_FRAMEWORK_H_ 51 52 #ifndef _KERNEL 53 #error "no user-serviceable parts inside" 54 #endif 55 56 struct auditinfo; 57 struct auditinfo_addr; 58 struct bpf_d; 59 struct cdev; 60 struct componentname; 61 struct devfs_dirent; 62 struct ifnet; 63 struct ifreq; 64 struct image_params; 65 struct inpcb; 66 struct ip6q; 67 struct ipq; 68 struct kdb_dbbe; 69 struct ksem; 70 struct label; 71 struct m_tag; 72 struct mac; 73 struct mbuf; 74 struct mount; 75 struct msg; 76 struct msqid_kernel; 77 struct proc; 78 struct semid_kernel; 79 struct shmfd; 80 struct shmid_kernel; 81 struct sockaddr; 82 struct socket; 83 struct sysctl_oid; 84 struct sysctl_req; 85 struct pipepair; 86 struct thread; 87 struct timespec; 88 struct ucred; 89 struct vattr; 90 struct vnode; 91 struct vop_setlabel_args; 92 93 #include <sys/acl.h> /* XXX acl_type_t */ 94 #include <sys/types.h> /* accmode_t */ 95 96 #include <ddb/ddb.h> /* db_expr_t */ 97 98 /* 99 * Entry points to the TrustedBSD MAC Framework from the remainder of the 100 * kernel: entry points are named based on a principle object type and an 101 * action relating to it. They are sorted alphabetically first by object 102 * type and then action. In some situations, the principle object type is 103 * obvious, and in other cases, less so as multiple objects may be inolved 104 * in the operation. 105 */ 106 int mac_bpfdesc_check_receive(struct bpf_d *d, struct ifnet *ifp); 107 void mac_bpfdesc_create(struct ucred *cred, struct bpf_d *d); 108 void mac_bpfdesc_create_mbuf(struct bpf_d *d, struct mbuf *m); 109 void mac_bpfdesc_destroy(struct bpf_d *); 110 void mac_bpfdesc_init(struct bpf_d *); 111 112 void mac_cred_associate_nfsd(struct ucred *cred); 113 int mac_cred_check_setaudit(struct ucred *cred, struct auditinfo *ai); 114 int mac_cred_check_setaudit_addr(struct ucred *cred, 115 struct auditinfo_addr *aia); 116 int mac_cred_check_setauid(struct ucred *cred, uid_t auid); 117 int mac_cred_check_setegid(struct ucred *cred, gid_t egid); 118 int mac_cred_check_seteuid(struct ucred *cred, uid_t euid); 119 int mac_cred_check_setgid(struct ucred *cred, gid_t gid); 120 int mac_cred_check_setgroups(struct ucred *cred, int ngroups, 121 gid_t *gidset); 122 int mac_cred_check_setregid(struct ucred *cred, gid_t rgid, gid_t egid); 123 int mac_cred_check_setresgid(struct ucred *cred, gid_t rgid, gid_t egid, 124 gid_t sgid); 125 int mac_cred_check_setresuid(struct ucred *cred, uid_t ruid, uid_t euid, 126 uid_t suid); 127 int mac_cred_check_setreuid(struct ucred *cred, uid_t ruid, uid_t euid); 128 int mac_cred_check_setuid(struct ucred *cred, uid_t uid); 129 int mac_cred_check_visible(struct ucred *cr1, struct ucred *cr2); 130 void mac_cred_copy(struct ucred *cr1, struct ucred *cr2); 131 void mac_cred_create_init(struct ucred *cred); 132 void mac_cred_create_swapper(struct ucred *cred); 133 void mac_cred_destroy(struct ucred *); 134 void mac_cred_init(struct ucred *); 135 136 int mac_ddb_command_register(struct db_command_table *table, 137 struct db_command *cmd); 138 int mac_ddb_command_exec(struct db_command *cmd, db_expr_t addr, 139 bool have_addr, db_expr_t count, char *modif); 140 141 void mac_devfs_create_device(struct ucred *cred, struct mount *mp, 142 struct cdev *dev, struct devfs_dirent *de); 143 void mac_devfs_create_directory(struct mount *mp, char *dirname, 144 int dirnamelen, struct devfs_dirent *de); 145 void mac_devfs_create_symlink(struct ucred *cred, struct mount *mp, 146 struct devfs_dirent *dd, struct devfs_dirent *de); 147 void mac_devfs_destroy(struct devfs_dirent *); 148 void mac_devfs_init(struct devfs_dirent *); 149 void mac_devfs_update(struct mount *mp, struct devfs_dirent *de, 150 struct vnode *vp); 151 void mac_devfs_vnode_associate(struct mount *mp, struct devfs_dirent *de, 152 struct vnode *vp); 153 154 int mac_ifnet_check_transmit_impl(struct ifnet *ifp, struct mbuf *m); 155 #ifdef MAC 156 extern bool mac_ifnet_check_transmit_fp_flag; 157 #else 158 #define mac_ifnet_check_transmit_fp_flag 0 159 #endif 160 #define mac_ifnet_check_transmit_enabled() __predict_false(mac_ifnet_check_transmit_fp_flag) 161 static inline int 162 mac_ifnet_check_transmit(struct ifnet *ifp, struct mbuf *m) 163 { 164 165 if (mac_ifnet_check_transmit_enabled()) 166 return (mac_ifnet_check_transmit_impl(ifp, m)); 167 return (0); 168 } 169 170 void mac_ifnet_create(struct ifnet *ifp); 171 172 void mac_ifnet_create_mbuf_impl(struct ifnet *ifp, struct mbuf *m); 173 #ifdef MAC 174 extern bool mac_ifnet_create_mbuf_fp_flag; 175 #else 176 #define mac_ifnet_create_mbuf_fp_flag 0 177 #endif 178 #define mac_ifnet_create_mbuf_enabled() __predict_false(mac_ifnet_create_mbuf_fp_flag) 179 static inline void 180 mac_ifnet_create_mbuf(struct ifnet *ifp, struct mbuf *m) 181 { 182 183 if (mac_ifnet_create_mbuf_enabled()) 184 mac_ifnet_create_mbuf_impl(ifp, m); 185 } 186 187 void mac_ifnet_destroy(struct ifnet *); 188 void mac_ifnet_init(struct ifnet *); 189 int mac_ifnet_ioctl_get(struct ucred *cred, struct ifreq *ifr, 190 struct ifnet *ifp); 191 int mac_ifnet_ioctl_set(struct ucred *cred, struct ifreq *ifr, 192 struct ifnet *ifp); 193 194 int mac_inpcb_check_deliver(struct inpcb *inp, struct mbuf *m); 195 int mac_inpcb_check_visible(struct ucred *cred, struct inpcb *inp); 196 void mac_inpcb_create(struct socket *so, struct inpcb *inp); 197 void mac_inpcb_create_mbuf(struct inpcb *inp, struct mbuf *m); 198 void mac_inpcb_destroy(struct inpcb *); 199 int mac_inpcb_init(struct inpcb *, int); 200 void mac_inpcb_sosetlabel(struct socket *so, struct inpcb *inp); 201 202 void mac_ip6q_create(struct mbuf *m, struct ip6q *q6); 203 void mac_ip6q_destroy(struct ip6q *q6); 204 int mac_ip6q_init(struct ip6q *q6, int); 205 int mac_ip6q_match(struct mbuf *m, struct ip6q *q6); 206 void mac_ip6q_reassemble(struct ip6q *q6, struct mbuf *m); 207 void mac_ip6q_update(struct mbuf *m, struct ip6q *q6); 208 209 void mac_ipq_create(struct mbuf *m, struct ipq *q); 210 void mac_ipq_destroy(struct ipq *q); 211 int mac_ipq_init(struct ipq *q, int); 212 int mac_ipq_match(struct mbuf *m, struct ipq *q); 213 void mac_ipq_reassemble(struct ipq *q, struct mbuf *m); 214 void mac_ipq_update(struct mbuf *m, struct ipq *q); 215 216 int mac_kdb_check_backend(struct kdb_dbbe *be); 217 218 int mac_kenv_check_dump(struct ucred *cred); 219 int mac_kenv_check_get(struct ucred *cred, char *name); 220 int mac_kenv_check_set(struct ucred *cred, char *name, char *value); 221 int mac_kenv_check_unset(struct ucred *cred, char *name); 222 223 int mac_kld_check_load(struct ucred *cred, struct vnode *vp); 224 int mac_kld_check_stat(struct ucred *cred); 225 226 void mac_mbuf_copy(struct mbuf *, struct mbuf *); 227 int mac_mbuf_init(struct mbuf *, int); 228 229 void mac_mbuf_tag_copy(struct m_tag *, struct m_tag *); 230 void mac_mbuf_tag_destroy(struct m_tag *); 231 int mac_mbuf_tag_init(struct m_tag *, int); 232 233 int mac_mount_check_stat(struct ucred *cred, struct mount *mp); 234 void mac_mount_create(struct ucred *cred, struct mount *mp); 235 void mac_mount_destroy(struct mount *); 236 void mac_mount_init(struct mount *); 237 238 void mac_netinet_arp_send(struct ifnet *ifp, struct mbuf *m); 239 void mac_netinet_firewall_reply(struct mbuf *mrecv, struct mbuf *msend); 240 void mac_netinet_firewall_send(struct mbuf *m); 241 void mac_netinet_fragment(struct mbuf *m, struct mbuf *frag); 242 void mac_netinet_icmp_reply(struct mbuf *mrecv, struct mbuf *msend); 243 void mac_netinet_icmp_replyinplace(struct mbuf *m); 244 void mac_netinet_igmp_send(struct ifnet *ifp, struct mbuf *m); 245 void mac_netinet_tcp_reply(struct mbuf *m); 246 247 void mac_netinet6_nd6_send(struct ifnet *ifp, struct mbuf *m); 248 249 int mac_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp, 250 unsigned long cmd, void *data); 251 int mac_pipe_check_poll_impl(struct ucred *cred, struct pipepair *pp); 252 #ifdef MAC 253 extern bool mac_pipe_check_poll_fp_flag; 254 #else 255 #define mac_pipe_check_poll_fp_flag 0 256 #endif 257 #define mac_pipe_check_poll_enabled() __predict_false(mac_pipe_check_poll_fp_flag) 258 static inline int 259 mac_pipe_check_poll(struct ucred *cred, struct pipepair *pp) 260 { 261 262 if (mac_pipe_check_poll_enabled()) 263 return (mac_pipe_check_poll_impl(cred, pp)); 264 return (0); 265 } 266 267 #ifdef MAC 268 extern bool mac_pipe_check_stat_fp_flag; 269 #else 270 #define mac_pipe_check_stat_fp_flag 0 271 #endif 272 #define mac_pipe_check_stat_enabled() __predict_false(mac_pipe_check_stat_fp_flag) 273 int mac_pipe_check_stat(struct ucred *cred, struct pipepair *pp); 274 int mac_pipe_check_read(struct ucred *cred, struct pipepair *pp); 275 int mac_pipe_check_write(struct ucred *cred, struct pipepair *pp); 276 void mac_pipe_create(struct ucred *cred, struct pipepair *pp); 277 void mac_pipe_destroy(struct pipepair *); 278 void mac_pipe_init(struct pipepair *); 279 int mac_pipe_label_set(struct ucred *cred, struct pipepair *pp, 280 struct label *label); 281 282 int mac_posixsem_check_getvalue(struct ucred *active_cred, 283 struct ucred *file_cred, struct ksem *ks); 284 int mac_posixsem_check_open(struct ucred *cred, struct ksem *ks); 285 int mac_posixsem_check_post(struct ucred *active_cred, 286 struct ucred *file_cred, struct ksem *ks); 287 int mac_posixsem_check_setmode(struct ucred *cred, struct ksem *ks, 288 mode_t mode); 289 int mac_posixsem_check_setowner(struct ucred *cred, struct ksem *ks, 290 uid_t uid, gid_t gid); 291 int mac_posixsem_check_stat(struct ucred *active_cred, 292 struct ucred *file_cred, struct ksem *ks); 293 int mac_posixsem_check_unlink(struct ucred *cred, struct ksem *ks); 294 int mac_posixsem_check_wait(struct ucred *active_cred, 295 struct ucred *file_cred, struct ksem *ks); 296 void mac_posixsem_create(struct ucred *cred, struct ksem *ks); 297 void mac_posixsem_destroy(struct ksem *); 298 void mac_posixsem_init(struct ksem *); 299 300 int mac_posixshm_check_create(struct ucred *cred, const char *path); 301 int mac_posixshm_check_mmap(struct ucred *cred, struct shmfd *shmfd, 302 int prot, int flags); 303 int mac_posixshm_check_open(struct ucred *cred, struct shmfd *shmfd, 304 accmode_t accmode); 305 int mac_posixshm_check_read(struct ucred *active_cred, 306 struct ucred *file_cred, struct shmfd *shmfd); 307 int mac_posixshm_check_setmode(struct ucred *cred, struct shmfd *shmfd, 308 mode_t mode); 309 int mac_posixshm_check_setowner(struct ucred *cred, struct shmfd *shmfd, 310 uid_t uid, gid_t gid); 311 int mac_posixshm_check_stat(struct ucred *active_cred, 312 struct ucred *file_cred, struct shmfd *shmfd); 313 int mac_posixshm_check_truncate(struct ucred *active_cred, 314 struct ucred *file_cred, struct shmfd *shmfd); 315 int mac_posixshm_check_unlink(struct ucred *cred, struct shmfd *shmfd); 316 int mac_posixshm_check_write(struct ucred *active_cred, 317 struct ucred *file_cred, struct shmfd *shmfd); 318 void mac_posixshm_create(struct ucred *cred, struct shmfd *shmfd); 319 void mac_posixshm_destroy(struct shmfd *); 320 void mac_posixshm_init(struct shmfd *); 321 322 int mac_priv_check_impl(struct ucred *cred, int priv); 323 #ifdef MAC 324 extern bool mac_priv_check_fp_flag; 325 #else 326 #define mac_priv_check_fp_flag 0 327 #endif 328 #define mac_priv_check_enabled() __predict_false(mac_priv_check_fp_flag) 329 static inline int 330 mac_priv_check(struct ucred *cred, int priv) 331 { 332 333 if (mac_priv_check_enabled()) 334 return (mac_priv_check_impl(cred, priv)); 335 return (0); 336 } 337 338 int mac_priv_grant_impl(struct ucred *cred, int priv); 339 #ifdef MAC 340 extern bool mac_priv_grant_fp_flag; 341 #else 342 #define mac_priv_grant_fp_flag 0 343 #endif 344 #define mac_priv_grant_enabled() __predict_false(mac_priv_grant_fp_flag) 345 static inline int 346 mac_priv_grant(struct ucred *cred, int priv) 347 { 348 349 if (mac_priv_grant_enabled()) 350 return (mac_priv_grant_impl(cred, priv)); 351 return (EPERM); 352 } 353 354 int mac_proc_check_debug(struct ucred *cred, struct proc *p); 355 int mac_proc_check_sched(struct ucred *cred, struct proc *p); 356 int mac_proc_check_signal(struct ucred *cred, struct proc *p, 357 int signum); 358 int mac_proc_check_wait(struct ucred *cred, struct proc *p); 359 void mac_proc_destroy(struct proc *); 360 void mac_proc_init(struct proc *); 361 void mac_proc_vm_revoke(struct thread *td); 362 int mac_execve_enter(struct image_params *imgp, struct mac *mac_p); 363 void mac_execve_exit(struct image_params *imgp); 364 void mac_execve_interpreter_enter(struct vnode *interpvp, 365 struct label **interplabel); 366 void mac_execve_interpreter_exit(struct label *interpvplabel); 367 368 int mac_socket_check_accept(struct ucred *cred, struct socket *so); 369 int mac_socket_check_bind(struct ucred *cred, struct socket *so, 370 struct sockaddr *sa); 371 int mac_socket_check_connect(struct ucred *cred, struct socket *so, 372 struct sockaddr *sa); 373 int mac_socket_check_create(struct ucred *cred, int domain, int type, 374 int proto); 375 int mac_socket_check_deliver(struct socket *so, struct mbuf *m); 376 int mac_socket_check_listen(struct ucred *cred, struct socket *so); 377 int mac_socket_check_poll(struct ucred *cred, struct socket *so); 378 int mac_socket_check_receive(struct ucred *cred, struct socket *so); 379 int mac_socket_check_send(struct ucred *cred, struct socket *so); 380 int mac_socket_check_stat(struct ucred *cred, struct socket *so); 381 int mac_socket_check_visible(struct ucred *cred, struct socket *so); 382 void mac_socket_create_mbuf(struct socket *so, struct mbuf *m); 383 void mac_socket_create(struct ucred *cred, struct socket *so); 384 void mac_socket_destroy(struct socket *); 385 int mac_socket_init(struct socket *, int); 386 void mac_socket_newconn(struct socket *oldso, struct socket *newso); 387 int mac_getsockopt_label(struct ucred *cred, struct socket *so, 388 struct mac *extmac); 389 int mac_getsockopt_peerlabel(struct ucred *cred, struct socket *so, 390 struct mac *extmac); 391 int mac_setsockopt_label(struct ucred *cred, struct socket *so, 392 struct mac *extmac); 393 394 void mac_socketpeer_set_from_mbuf(struct mbuf *m, struct socket *so); 395 void mac_socketpeer_set_from_socket(struct socket *oldso, 396 struct socket *newso); 397 398 void mac_syncache_create(struct label *l, struct inpcb *inp); 399 void mac_syncache_create_mbuf(struct label *l, struct mbuf *m); 400 void mac_syncache_destroy(struct label **l); 401 int mac_syncache_init(struct label **l); 402 403 int mac_system_check_acct(struct ucred *cred, struct vnode *vp); 404 int mac_system_check_audit(struct ucred *cred, void *record, int length); 405 int mac_system_check_auditctl(struct ucred *cred, struct vnode *vp); 406 int mac_system_check_auditon(struct ucred *cred, int cmd); 407 int mac_system_check_reboot(struct ucred *cred, int howto); 408 int mac_system_check_swapon(struct ucred *cred, struct vnode *vp); 409 int mac_system_check_swapoff(struct ucred *cred, struct vnode *vp); 410 int mac_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp, 411 void *arg1, int arg2, struct sysctl_req *req); 412 413 void mac_sysvmsg_cleanup(struct msg *msgptr); 414 void mac_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr, 415 struct msg *msgptr); 416 void mac_sysvmsg_destroy(struct msg *); 417 void mac_sysvmsg_init(struct msg *); 418 419 int mac_sysvmsq_check_msgmsq(struct ucred *cred, struct msg *msgptr, 420 struct msqid_kernel *msqkptr); 421 int mac_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr); 422 int mac_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr); 423 int mac_sysvmsq_check_msqctl(struct ucred *cred, 424 struct msqid_kernel *msqkptr, int cmd); 425 int mac_sysvmsq_check_msqget(struct ucred *cred, 426 struct msqid_kernel *msqkptr); 427 int mac_sysvmsq_check_msqrcv(struct ucred *cred, 428 struct msqid_kernel *msqkptr); 429 int mac_sysvmsq_check_msqsnd(struct ucred *cred, 430 struct msqid_kernel *msqkptr); 431 void mac_sysvmsq_cleanup(struct msqid_kernel *msqkptr); 432 void mac_sysvmsq_create(struct ucred *cred, struct msqid_kernel *msqkptr); 433 void mac_sysvmsq_destroy(struct msqid_kernel *); 434 void mac_sysvmsq_init(struct msqid_kernel *); 435 436 int mac_sysvsem_check_semctl(struct ucred *cred, 437 struct semid_kernel *semakptr, int cmd); 438 int mac_sysvsem_check_semget(struct ucred *cred, 439 struct semid_kernel *semakptr); 440 int mac_sysvsem_check_semop(struct ucred *cred, 441 struct semid_kernel *semakptr, size_t accesstype); 442 void mac_sysvsem_cleanup(struct semid_kernel *semakptr); 443 void mac_sysvsem_create(struct ucred *cred, 444 struct semid_kernel *semakptr); 445 void mac_sysvsem_destroy(struct semid_kernel *); 446 void mac_sysvsem_init(struct semid_kernel *); 447 448 int mac_sysvshm_check_shmat(struct ucred *cred, 449 struct shmid_kernel *shmsegptr, int shmflg); 450 int mac_sysvshm_check_shmctl(struct ucred *cred, 451 struct shmid_kernel *shmsegptr, int cmd); 452 int mac_sysvshm_check_shmdt(struct ucred *cred, 453 struct shmid_kernel *shmsegptr); 454 int mac_sysvshm_check_shmget(struct ucred *cred, 455 struct shmid_kernel *shmsegptr, int shmflg); 456 void mac_sysvshm_cleanup(struct shmid_kernel *shmsegptr); 457 void mac_sysvshm_create(struct ucred *cred, 458 struct shmid_kernel *shmsegptr); 459 void mac_sysvshm_destroy(struct shmid_kernel *); 460 void mac_sysvshm_init(struct shmid_kernel *); 461 462 void mac_thread_userret(struct thread *td); 463 464 #if defined(MAC) && defined(DEBUG_VFS_LOCKS) 465 void mac_vnode_assert_locked(struct vnode *vp, const char *func); 466 #else 467 #define mac_vnode_assert_locked(vp, func) do { } while (0) 468 #endif 469 470 int mac_vnode_associate_extattr(struct mount *mp, struct vnode *vp); 471 void mac_vnode_associate_singlelabel(struct mount *mp, struct vnode *vp); 472 int mac_vnode_check_access_impl(struct ucred *cred, struct vnode *dvp, 473 accmode_t accmode); 474 extern bool mac_vnode_check_access_fp_flag; 475 #define mac_vnode_check_access_enabled() __predict_false(mac_vnode_check_access_fp_flag) 476 static inline int 477 mac_vnode_check_access(struct ucred *cred, struct vnode *dvp, 478 accmode_t accmode) 479 { 480 481 mac_vnode_assert_locked(dvp, "mac_vnode_check_access"); 482 if (mac_vnode_check_access_enabled()) 483 return (mac_vnode_check_access_impl(cred, dvp, accmode)); 484 return (0); 485 } 486 int mac_vnode_check_chdir(struct ucred *cred, struct vnode *dvp); 487 int mac_vnode_check_chroot(struct ucred *cred, struct vnode *dvp); 488 int mac_vnode_check_create(struct ucred *cred, struct vnode *dvp, 489 struct componentname *cnp, struct vattr *vap); 490 int mac_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp, 491 acl_type_t type); 492 int mac_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp, 493 int attrnamespace, const char *name); 494 int mac_vnode_check_exec(struct ucred *cred, struct vnode *vp, 495 struct image_params *imgp); 496 int mac_vnode_check_getacl(struct ucred *cred, struct vnode *vp, 497 acl_type_t type); 498 int mac_vnode_check_getextattr(struct ucred *cred, struct vnode *vp, 499 int attrnamespace, const char *name); 500 int mac_vnode_check_link(struct ucred *cred, struct vnode *dvp, 501 struct vnode *vp, struct componentname *cnp); 502 int mac_vnode_check_listextattr(struct ucred *cred, struct vnode *vp, 503 int attrnamespace); 504 505 int mac_vnode_check_lookup_impl(struct ucred *cred, struct vnode *dvp, 506 struct componentname *cnp); 507 #ifdef MAC 508 extern bool mac_vnode_check_lookup_fp_flag; 509 #else 510 #define mac_vnode_check_lookup_fp_flag 0 511 #endif 512 #define mac_vnode_check_lookup_enabled() __predict_false(mac_vnode_check_lookup_fp_flag) 513 static inline int 514 mac_vnode_check_lookup(struct ucred *cred, struct vnode *dvp, 515 struct componentname *cnp) 516 { 517 518 mac_vnode_assert_locked(dvp, "mac_vnode_check_lookup"); 519 if (mac_vnode_check_lookup_enabled()) 520 return (mac_vnode_check_lookup_impl(cred, dvp, cnp)); 521 return (0); 522 } 523 524 int mac_vnode_check_mmap_impl(struct ucred *cred, struct vnode *vp, int prot, 525 int flags); 526 #ifdef MAC 527 extern bool mac_vnode_check_mmap_fp_flag; 528 #else 529 #define mac_vnode_check_mmap_fp_flag 0 530 #endif 531 #define mac_vnode_check_mmap_enabled() __predict_false(mac_vnode_check_mmap_fp_flag) 532 static inline int 533 mac_vnode_check_mmap(struct ucred *cred, struct vnode *vp, int prot, 534 int flags) 535 { 536 537 mac_vnode_assert_locked(vp, "mac_vnode_check_mmap"); 538 if (mac_vnode_check_mmap_enabled()) 539 return (mac_vnode_check_mmap_impl(cred, vp, prot, flags)); 540 return (0); 541 } 542 543 int mac_vnode_check_open_impl(struct ucred *cred, struct vnode *vp, 544 accmode_t accmode); 545 #ifdef MAC 546 extern bool mac_vnode_check_open_fp_flag; 547 #else 548 #define mac_vnode_check_open_fp_flag 0 549 #endif 550 #define mac_vnode_check_open_enabled() __predict_false(mac_vnode_check_open_fp_flag) 551 static inline int 552 mac_vnode_check_open(struct ucred *cred, struct vnode *vp, 553 accmode_t accmode) 554 { 555 556 mac_vnode_assert_locked(vp, "mac_vnode_check_open"); 557 if (mac_vnode_check_open_enabled()) 558 return (mac_vnode_check_open_impl(cred, vp, accmode)); 559 return (0); 560 } 561 562 int mac_vnode_check_mprotect(struct ucred *cred, struct vnode *vp, 563 int prot); 564 565 #define mac_vnode_check_poll_enabled() __predict_false(mac_vnode_check_poll_fp_flag) 566 #ifdef MAC 567 extern bool mac_vnode_check_poll_fp_flag; 568 int mac_vnode_check_poll(struct ucred *active_cred, 569 struct ucred *file_cred, struct vnode *vp); 570 #else 571 #define mac_vnode_check_poll_fp_flag 0 572 static inline int 573 mac_vnode_check_poll(struct ucred *active_cred, struct ucred *file_cred, 574 struct vnode *vp) 575 { 576 577 return (0); 578 } 579 #endif 580 int mac_vnode_check_readdir(struct ucred *cred, struct vnode *vp); 581 int mac_vnode_check_readlink_impl(struct ucred *cred, struct vnode *dvp); 582 #ifdef MAC 583 extern bool mac_vnode_check_readlink_fp_flag; 584 #else 585 #define mac_vnode_check_readlink_fp_flag 0 586 #endif 587 #define mac_vnode_check_readlink_enabled() __predict_false(mac_vnode_check_readlink_fp_flag) 588 static inline int 589 mac_vnode_check_readlink(struct ucred *cred, struct vnode *vp) 590 { 591 592 mac_vnode_assert_locked(vp, "mac_vnode_check_readlink"); 593 if (mac_vnode_check_readlink_enabled()) 594 return (mac_vnode_check_readlink_impl(cred, vp)); 595 return (0); 596 } 597 #define mac_vnode_check_rename_from_enabled() __predict_false(mac_vnode_check_rename_from_fp_flag) 598 #ifdef MAC 599 extern bool mac_vnode_check_rename_from_fp_flag; 600 #endif 601 int mac_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp, 602 struct vnode *vp, struct componentname *cnp); 603 int mac_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp, 604 struct vnode *vp, int samedir, struct componentname *cnp); 605 int mac_vnode_check_revoke(struct ucred *cred, struct vnode *vp); 606 int mac_vnode_check_setacl(struct ucred *cred, struct vnode *vp, 607 acl_type_t type, struct acl *acl); 608 int mac_vnode_check_setextattr(struct ucred *cred, struct vnode *vp, 609 int attrnamespace, const char *name); 610 int mac_vnode_check_setflags(struct ucred *cred, struct vnode *vp, 611 u_long flags); 612 int mac_vnode_check_setmode(struct ucred *cred, struct vnode *vp, 613 mode_t mode); 614 int mac_vnode_check_setowner(struct ucred *cred, struct vnode *vp, 615 uid_t uid, gid_t gid); 616 int mac_vnode_check_setutimes(struct ucred *cred, struct vnode *vp, 617 struct timespec atime, struct timespec mtime); 618 619 int mac_vnode_check_stat_impl(struct ucred *active_cred, 620 struct ucred *file_cred, struct vnode *vp); 621 #ifdef MAC 622 extern bool mac_vnode_check_stat_fp_flag; 623 #else 624 #define mac_vnode_check_stat_fp_flag 0 625 #endif 626 #define mac_vnode_check_stat_enabled() __predict_false(mac_vnode_check_stat_fp_flag) 627 static inline int 628 mac_vnode_check_stat(struct ucred *active_cred, struct ucred *file_cred, 629 struct vnode *vp) 630 { 631 632 mac_vnode_assert_locked(vp, "mac_vnode_check_stat"); 633 if (mac_vnode_check_stat_enabled()) 634 return (mac_vnode_check_stat_impl(active_cred, file_cred, vp)); 635 return (0); 636 } 637 638 int mac_vnode_check_read_impl(struct ucred *active_cred, 639 struct ucred *file_cred, struct vnode *vp); 640 #ifdef MAC 641 extern bool mac_vnode_check_read_fp_flag; 642 #else 643 #define mac_vnode_check_read_fp_flag 0 644 #endif 645 #define mac_vnode_check_read_enabled() __predict_false(mac_vnode_check_read_fp_flag) 646 static inline int 647 mac_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred, 648 struct vnode *vp) 649 { 650 651 mac_vnode_assert_locked(vp, "mac_vnode_check_read"); 652 if (mac_vnode_check_read_enabled()) 653 return (mac_vnode_check_read_impl(active_cred, file_cred, vp)); 654 return (0); 655 } 656 657 int mac_vnode_check_write_impl(struct ucred *active_cred, 658 struct ucred *file_cred, struct vnode *vp); 659 #ifdef MAC 660 extern bool mac_vnode_check_write_fp_flag; 661 #else 662 #define mac_vnode_check_write_fp_flag 0 663 #endif 664 #define mac_vnode_check_write_enabled() __predict_false(mac_vnode_check_write_fp_flag) 665 static inline int 666 mac_vnode_check_write(struct ucred *active_cred, struct ucred *file_cred, 667 struct vnode *vp) 668 { 669 670 mac_vnode_assert_locked(vp, "mac_vnode_check_write"); 671 if (mac_vnode_check_write_enabled()) 672 return (mac_vnode_check_write_impl(active_cred, file_cred, vp)); 673 return (0); 674 } 675 676 int mac_vnode_check_unlink(struct ucred *cred, struct vnode *dvp, 677 struct vnode *vp, struct componentname *cnp); 678 void mac_vnode_copy_label(struct label *, struct label *); 679 void mac_vnode_init(struct vnode *); 680 int mac_vnode_create_extattr(struct ucred *cred, struct mount *mp, 681 struct vnode *dvp, struct vnode *vp, struct componentname *cnp); 682 void mac_vnode_destroy(struct vnode *); 683 void mac_vnode_execve_transition(struct ucred *oldcred, 684 struct ucred *newcred, struct vnode *vp, 685 struct label *interpvplabel, struct image_params *imgp); 686 int mac_vnode_execve_will_transition(struct ucred *cred, 687 struct vnode *vp, struct label *interpvplabel, 688 struct image_params *imgp); 689 void mac_vnode_relabel(struct ucred *cred, struct vnode *vp, 690 struct label *newlabel); 691 692 /* 693 * Calls to help various file systems implement labeling functionality using 694 * their existing EA implementation. 695 */ 696 int vop_stdsetlabel_ea(struct vop_setlabel_args *ap); 697 698 #endif /* !_SECURITY_MAC_MAC_FRAMEWORK_H_ */ 699