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 false 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 false 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 false 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 false 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_impl(struct ucred *cred, struct pipepair *pp); 275 #ifdef MAC 276 extern bool mac_pipe_check_read_fp_flag; 277 #else 278 #define mac_pipe_check_read_fp_flag false 279 #endif 280 #define mac_pipe_check_read_enabled() __predict_false(mac_pipe_check_read_fp_flag) 281 static inline int 282 mac_pipe_check_read(struct ucred *cred, struct pipepair *pp) 283 { 284 285 if (mac_pipe_check_read_enabled()) 286 return (mac_pipe_check_read_impl(cred, pp)); 287 return (0); 288 } 289 290 int mac_pipe_check_write(struct ucred *cred, struct pipepair *pp); 291 void mac_pipe_create(struct ucred *cred, struct pipepair *pp); 292 void mac_pipe_destroy(struct pipepair *); 293 void mac_pipe_init(struct pipepair *); 294 int mac_pipe_label_set(struct ucred *cred, struct pipepair *pp, 295 struct label *label); 296 297 int mac_posixsem_check_getvalue(struct ucred *active_cred, 298 struct ucred *file_cred, struct ksem *ks); 299 int mac_posixsem_check_open(struct ucred *cred, struct ksem *ks); 300 int mac_posixsem_check_post(struct ucred *active_cred, 301 struct ucred *file_cred, struct ksem *ks); 302 int mac_posixsem_check_setmode(struct ucred *cred, struct ksem *ks, 303 mode_t mode); 304 int mac_posixsem_check_setowner(struct ucred *cred, struct ksem *ks, 305 uid_t uid, gid_t gid); 306 int mac_posixsem_check_stat(struct ucred *active_cred, 307 struct ucred *file_cred, struct ksem *ks); 308 int mac_posixsem_check_unlink(struct ucred *cred, struct ksem *ks); 309 int mac_posixsem_check_wait(struct ucred *active_cred, 310 struct ucred *file_cred, struct ksem *ks); 311 void mac_posixsem_create(struct ucred *cred, struct ksem *ks); 312 void mac_posixsem_destroy(struct ksem *); 313 void mac_posixsem_init(struct ksem *); 314 315 int mac_posixshm_check_create(struct ucred *cred, const char *path); 316 int mac_posixshm_check_mmap(struct ucred *cred, struct shmfd *shmfd, 317 int prot, int flags); 318 int mac_posixshm_check_open(struct ucred *cred, struct shmfd *shmfd, 319 accmode_t accmode); 320 int mac_posixshm_check_read(struct ucred *active_cred, 321 struct ucred *file_cred, struct shmfd *shmfd); 322 int mac_posixshm_check_setmode(struct ucred *cred, struct shmfd *shmfd, 323 mode_t mode); 324 int mac_posixshm_check_setowner(struct ucred *cred, struct shmfd *shmfd, 325 uid_t uid, gid_t gid); 326 int mac_posixshm_check_stat(struct ucred *active_cred, 327 struct ucred *file_cred, struct shmfd *shmfd); 328 int mac_posixshm_check_truncate(struct ucred *active_cred, 329 struct ucred *file_cred, struct shmfd *shmfd); 330 int mac_posixshm_check_unlink(struct ucred *cred, struct shmfd *shmfd); 331 int mac_posixshm_check_write(struct ucred *active_cred, 332 struct ucred *file_cred, struct shmfd *shmfd); 333 void mac_posixshm_create(struct ucred *cred, struct shmfd *shmfd); 334 void mac_posixshm_destroy(struct shmfd *); 335 void mac_posixshm_init(struct shmfd *); 336 337 int mac_priv_check_impl(struct ucred *cred, int priv); 338 #ifdef MAC 339 extern bool mac_priv_check_fp_flag; 340 #else 341 #define mac_priv_check_fp_flag false 342 #endif 343 #define mac_priv_check_enabled() __predict_false(mac_priv_check_fp_flag) 344 static inline int 345 mac_priv_check(struct ucred *cred, int priv) 346 { 347 348 if (mac_priv_check_enabled()) 349 return (mac_priv_check_impl(cred, priv)); 350 return (0); 351 } 352 353 int mac_priv_grant_impl(struct ucred *cred, int priv); 354 #ifdef MAC 355 extern bool mac_priv_grant_fp_flag; 356 #else 357 #define mac_priv_grant_fp_flag false 358 #endif 359 #define mac_priv_grant_enabled() __predict_false(mac_priv_grant_fp_flag) 360 static inline int 361 mac_priv_grant(struct ucred *cred, int priv) 362 { 363 364 if (mac_priv_grant_enabled()) 365 return (mac_priv_grant_impl(cred, priv)); 366 return (EPERM); 367 } 368 369 int mac_proc_check_debug(struct ucred *cred, struct proc *p); 370 int mac_proc_check_sched(struct ucred *cred, struct proc *p); 371 int mac_proc_check_signal(struct ucred *cred, struct proc *p, 372 int signum); 373 int mac_proc_check_wait(struct ucred *cred, struct proc *p); 374 void mac_proc_destroy(struct proc *); 375 void mac_proc_init(struct proc *); 376 void mac_proc_vm_revoke(struct thread *td); 377 int mac_execve_enter(struct image_params *imgp, struct mac *mac_p); 378 void mac_execve_exit(struct image_params *imgp); 379 void mac_execve_interpreter_enter(struct vnode *interpvp, 380 struct label **interplabel); 381 void mac_execve_interpreter_exit(struct label *interpvplabel); 382 383 int mac_socket_check_accept(struct ucred *cred, struct socket *so); 384 int mac_socket_check_bind(struct ucred *cred, struct socket *so, 385 struct sockaddr *sa); 386 int mac_socket_check_connect(struct ucred *cred, struct socket *so, 387 struct sockaddr *sa); 388 int mac_socket_check_create(struct ucred *cred, int domain, int type, 389 int proto); 390 int mac_socket_check_deliver(struct socket *so, struct mbuf *m); 391 int mac_socket_check_listen(struct ucred *cred, struct socket *so); 392 int mac_socket_check_poll(struct ucred *cred, struct socket *so); 393 int mac_socket_check_receive(struct ucred *cred, struct socket *so); 394 int mac_socket_check_send(struct ucred *cred, struct socket *so); 395 int mac_socket_check_stat(struct ucred *cred, struct socket *so); 396 int mac_socket_check_visible(struct ucred *cred, struct socket *so); 397 void mac_socket_create_mbuf(struct socket *so, struct mbuf *m); 398 void mac_socket_create(struct ucred *cred, struct socket *so); 399 void mac_socket_destroy(struct socket *); 400 int mac_socket_init(struct socket *, int); 401 void mac_socket_newconn(struct socket *oldso, struct socket *newso); 402 int mac_getsockopt_label(struct ucred *cred, struct socket *so, 403 struct mac *extmac); 404 int mac_getsockopt_peerlabel(struct ucred *cred, struct socket *so, 405 struct mac *extmac); 406 int mac_setsockopt_label(struct ucred *cred, struct socket *so, 407 struct mac *extmac); 408 409 void mac_socketpeer_set_from_mbuf(struct mbuf *m, struct socket *so); 410 void mac_socketpeer_set_from_socket(struct socket *oldso, 411 struct socket *newso); 412 413 void mac_syncache_create(struct label *l, struct inpcb *inp); 414 void mac_syncache_create_mbuf(struct label *l, struct mbuf *m); 415 void mac_syncache_destroy(struct label **l); 416 int mac_syncache_init(struct label **l); 417 418 int mac_system_check_acct(struct ucred *cred, struct vnode *vp); 419 int mac_system_check_audit(struct ucred *cred, void *record, int length); 420 int mac_system_check_auditctl(struct ucred *cred, struct vnode *vp); 421 int mac_system_check_auditon(struct ucred *cred, int cmd); 422 int mac_system_check_reboot(struct ucred *cred, int howto); 423 int mac_system_check_swapon(struct ucred *cred, struct vnode *vp); 424 int mac_system_check_swapoff(struct ucred *cred, struct vnode *vp); 425 int mac_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp, 426 void *arg1, int arg2, struct sysctl_req *req); 427 428 void mac_sysvmsg_cleanup(struct msg *msgptr); 429 void mac_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr, 430 struct msg *msgptr); 431 void mac_sysvmsg_destroy(struct msg *); 432 void mac_sysvmsg_init(struct msg *); 433 434 int mac_sysvmsq_check_msgmsq(struct ucred *cred, struct msg *msgptr, 435 struct msqid_kernel *msqkptr); 436 int mac_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr); 437 int mac_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr); 438 int mac_sysvmsq_check_msqctl(struct ucred *cred, 439 struct msqid_kernel *msqkptr, int cmd); 440 int mac_sysvmsq_check_msqget(struct ucred *cred, 441 struct msqid_kernel *msqkptr); 442 int mac_sysvmsq_check_msqrcv(struct ucred *cred, 443 struct msqid_kernel *msqkptr); 444 int mac_sysvmsq_check_msqsnd(struct ucred *cred, 445 struct msqid_kernel *msqkptr); 446 void mac_sysvmsq_cleanup(struct msqid_kernel *msqkptr); 447 void mac_sysvmsq_create(struct ucred *cred, struct msqid_kernel *msqkptr); 448 void mac_sysvmsq_destroy(struct msqid_kernel *); 449 void mac_sysvmsq_init(struct msqid_kernel *); 450 451 int mac_sysvsem_check_semctl(struct ucred *cred, 452 struct semid_kernel *semakptr, int cmd); 453 int mac_sysvsem_check_semget(struct ucred *cred, 454 struct semid_kernel *semakptr); 455 int mac_sysvsem_check_semop(struct ucred *cred, 456 struct semid_kernel *semakptr, size_t accesstype); 457 void mac_sysvsem_cleanup(struct semid_kernel *semakptr); 458 void mac_sysvsem_create(struct ucred *cred, 459 struct semid_kernel *semakptr); 460 void mac_sysvsem_destroy(struct semid_kernel *); 461 void mac_sysvsem_init(struct semid_kernel *); 462 463 int mac_sysvshm_check_shmat(struct ucred *cred, 464 struct shmid_kernel *shmsegptr, int shmflg); 465 int mac_sysvshm_check_shmctl(struct ucred *cred, 466 struct shmid_kernel *shmsegptr, int cmd); 467 int mac_sysvshm_check_shmdt(struct ucred *cred, 468 struct shmid_kernel *shmsegptr); 469 int mac_sysvshm_check_shmget(struct ucred *cred, 470 struct shmid_kernel *shmsegptr, int shmflg); 471 void mac_sysvshm_cleanup(struct shmid_kernel *shmsegptr); 472 void mac_sysvshm_create(struct ucred *cred, 473 struct shmid_kernel *shmsegptr); 474 void mac_sysvshm_destroy(struct shmid_kernel *); 475 void mac_sysvshm_init(struct shmid_kernel *); 476 477 void mac_thread_userret(struct thread *td); 478 479 #if defined(MAC) && defined(DEBUG_VFS_LOCKS) 480 void mac_vnode_assert_locked(struct vnode *vp, const char *func); 481 #else 482 #define mac_vnode_assert_locked(vp, func) do { } while (0) 483 #endif 484 485 int mac_vnode_associate_extattr(struct mount *mp, struct vnode *vp); 486 void mac_vnode_associate_singlelabel(struct mount *mp, struct vnode *vp); 487 int mac_vnode_check_access_impl(struct ucred *cred, struct vnode *dvp, 488 accmode_t accmode); 489 extern bool mac_vnode_check_access_fp_flag; 490 #define mac_vnode_check_access_enabled() __predict_false(mac_vnode_check_access_fp_flag) 491 static inline int 492 mac_vnode_check_access(struct ucred *cred, struct vnode *dvp, 493 accmode_t accmode) 494 { 495 496 mac_vnode_assert_locked(dvp, "mac_vnode_check_access"); 497 if (mac_vnode_check_access_enabled()) 498 return (mac_vnode_check_access_impl(cred, dvp, accmode)); 499 return (0); 500 } 501 int mac_vnode_check_chdir(struct ucred *cred, struct vnode *dvp); 502 int mac_vnode_check_chroot(struct ucred *cred, struct vnode *dvp); 503 int mac_vnode_check_create(struct ucred *cred, struct vnode *dvp, 504 struct componentname *cnp, struct vattr *vap); 505 int mac_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp, 506 acl_type_t type); 507 int mac_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp, 508 int attrnamespace, const char *name); 509 int mac_vnode_check_exec(struct ucred *cred, struct vnode *vp, 510 struct image_params *imgp); 511 int mac_vnode_check_getacl(struct ucred *cred, struct vnode *vp, 512 acl_type_t type); 513 int mac_vnode_check_getextattr(struct ucred *cred, struct vnode *vp, 514 int attrnamespace, const char *name); 515 int mac_vnode_check_link(struct ucred *cred, struct vnode *dvp, 516 struct vnode *vp, struct componentname *cnp); 517 int mac_vnode_check_listextattr(struct ucred *cred, struct vnode *vp, 518 int attrnamespace); 519 520 int mac_vnode_check_lookup_impl(struct ucred *cred, struct vnode *dvp, 521 struct componentname *cnp); 522 #ifdef MAC 523 extern bool mac_vnode_check_lookup_fp_flag; 524 #else 525 #define mac_vnode_check_lookup_fp_flag false 526 #endif 527 #define mac_vnode_check_lookup_enabled() __predict_false(mac_vnode_check_lookup_fp_flag) 528 static inline int 529 mac_vnode_check_lookup(struct ucred *cred, struct vnode *dvp, 530 struct componentname *cnp) 531 { 532 533 mac_vnode_assert_locked(dvp, "mac_vnode_check_lookup"); 534 if (mac_vnode_check_lookup_enabled()) 535 return (mac_vnode_check_lookup_impl(cred, dvp, cnp)); 536 return (0); 537 } 538 539 int mac_vnode_check_mmap_impl(struct ucred *cred, struct vnode *vp, int prot, 540 int flags); 541 #ifdef MAC 542 extern bool mac_vnode_check_mmap_fp_flag; 543 #else 544 #define mac_vnode_check_mmap_fp_flag false 545 #endif 546 #define mac_vnode_check_mmap_enabled() __predict_false(mac_vnode_check_mmap_fp_flag) 547 static inline int 548 mac_vnode_check_mmap(struct ucred *cred, struct vnode *vp, int prot, 549 int flags) 550 { 551 552 mac_vnode_assert_locked(vp, "mac_vnode_check_mmap"); 553 if (mac_vnode_check_mmap_enabled()) 554 return (mac_vnode_check_mmap_impl(cred, vp, prot, flags)); 555 return (0); 556 } 557 558 int mac_vnode_check_open_impl(struct ucred *cred, struct vnode *vp, 559 accmode_t accmode); 560 #ifdef MAC 561 extern bool mac_vnode_check_open_fp_flag; 562 #else 563 #define mac_vnode_check_open_fp_flag false 564 #endif 565 #define mac_vnode_check_open_enabled() __predict_false(mac_vnode_check_open_fp_flag) 566 static inline int 567 mac_vnode_check_open(struct ucred *cred, struct vnode *vp, 568 accmode_t accmode) 569 { 570 571 mac_vnode_assert_locked(vp, "mac_vnode_check_open"); 572 if (mac_vnode_check_open_enabled()) 573 return (mac_vnode_check_open_impl(cred, vp, accmode)); 574 return (0); 575 } 576 577 int mac_vnode_check_mprotect(struct ucred *cred, struct vnode *vp, 578 int prot); 579 580 #define mac_vnode_check_poll_enabled() __predict_false(mac_vnode_check_poll_fp_flag) 581 #ifdef MAC 582 extern bool mac_vnode_check_poll_fp_flag; 583 int mac_vnode_check_poll(struct ucred *active_cred, 584 struct ucred *file_cred, struct vnode *vp); 585 #else 586 #define mac_vnode_check_poll_fp_flag false 587 static inline int 588 mac_vnode_check_poll(struct ucred *active_cred, struct ucred *file_cred, 589 struct vnode *vp) 590 { 591 592 return (0); 593 } 594 #endif 595 int mac_vnode_check_readdir(struct ucred *cred, struct vnode *vp); 596 int mac_vnode_check_readlink_impl(struct ucred *cred, struct vnode *dvp); 597 #ifdef MAC 598 extern bool mac_vnode_check_readlink_fp_flag; 599 #else 600 #define mac_vnode_check_readlink_fp_flag false 601 #endif 602 #define mac_vnode_check_readlink_enabled() __predict_false(mac_vnode_check_readlink_fp_flag) 603 static inline int 604 mac_vnode_check_readlink(struct ucred *cred, struct vnode *vp) 605 { 606 607 mac_vnode_assert_locked(vp, "mac_vnode_check_readlink"); 608 if (mac_vnode_check_readlink_enabled()) 609 return (mac_vnode_check_readlink_impl(cred, vp)); 610 return (0); 611 } 612 #define mac_vnode_check_rename_from_enabled() __predict_false(mac_vnode_check_rename_from_fp_flag) 613 #ifdef MAC 614 extern bool mac_vnode_check_rename_from_fp_flag; 615 #endif 616 int mac_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp, 617 struct vnode *vp, struct componentname *cnp); 618 int mac_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp, 619 struct vnode *vp, int samedir, struct componentname *cnp); 620 int mac_vnode_check_revoke(struct ucred *cred, struct vnode *vp); 621 int mac_vnode_check_setacl(struct ucred *cred, struct vnode *vp, 622 acl_type_t type, struct acl *acl); 623 int mac_vnode_check_setextattr(struct ucred *cred, struct vnode *vp, 624 int attrnamespace, const char *name); 625 int mac_vnode_check_setflags(struct ucred *cred, struct vnode *vp, 626 u_long flags); 627 int mac_vnode_check_setmode(struct ucred *cred, struct vnode *vp, 628 mode_t mode); 629 int mac_vnode_check_setowner(struct ucred *cred, struct vnode *vp, 630 uid_t uid, gid_t gid); 631 int mac_vnode_check_setutimes(struct ucred *cred, struct vnode *vp, 632 struct timespec atime, struct timespec mtime); 633 634 int mac_vnode_check_stat_impl(struct ucred *active_cred, 635 struct ucred *file_cred, struct vnode *vp); 636 #ifdef MAC 637 extern bool mac_vnode_check_stat_fp_flag; 638 #else 639 #define mac_vnode_check_stat_fp_flag false 640 #endif 641 #define mac_vnode_check_stat_enabled() __predict_false(mac_vnode_check_stat_fp_flag) 642 static inline int 643 mac_vnode_check_stat(struct ucred *active_cred, struct ucred *file_cred, 644 struct vnode *vp) 645 { 646 647 mac_vnode_assert_locked(vp, "mac_vnode_check_stat"); 648 if (mac_vnode_check_stat_enabled()) 649 return (mac_vnode_check_stat_impl(active_cred, file_cred, vp)); 650 return (0); 651 } 652 653 int mac_vnode_check_read_impl(struct ucred *active_cred, 654 struct ucred *file_cred, struct vnode *vp); 655 #ifdef MAC 656 extern bool mac_vnode_check_read_fp_flag; 657 #else 658 #define mac_vnode_check_read_fp_flag false 659 #endif 660 #define mac_vnode_check_read_enabled() __predict_false(mac_vnode_check_read_fp_flag) 661 static inline int 662 mac_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred, 663 struct vnode *vp) 664 { 665 666 mac_vnode_assert_locked(vp, "mac_vnode_check_read"); 667 if (mac_vnode_check_read_enabled()) 668 return (mac_vnode_check_read_impl(active_cred, file_cred, vp)); 669 return (0); 670 } 671 672 int mac_vnode_check_write_impl(struct ucred *active_cred, 673 struct ucred *file_cred, struct vnode *vp); 674 #ifdef MAC 675 extern bool mac_vnode_check_write_fp_flag; 676 #else 677 #define mac_vnode_check_write_fp_flag false 678 #endif 679 #define mac_vnode_check_write_enabled() __predict_false(mac_vnode_check_write_fp_flag) 680 static inline int 681 mac_vnode_check_write(struct ucred *active_cred, struct ucred *file_cred, 682 struct vnode *vp) 683 { 684 685 mac_vnode_assert_locked(vp, "mac_vnode_check_write"); 686 if (mac_vnode_check_write_enabled()) 687 return (mac_vnode_check_write_impl(active_cred, file_cred, vp)); 688 return (0); 689 } 690 691 int mac_vnode_check_unlink(struct ucred *cred, struct vnode *dvp, 692 struct vnode *vp, struct componentname *cnp); 693 void mac_vnode_copy_label(struct label *, struct label *); 694 void mac_vnode_init(struct vnode *); 695 int mac_vnode_create_extattr(struct ucred *cred, struct mount *mp, 696 struct vnode *dvp, struct vnode *vp, struct componentname *cnp); 697 void mac_vnode_destroy(struct vnode *); 698 void mac_vnode_execve_transition(struct ucred *oldcred, 699 struct ucred *newcred, struct vnode *vp, 700 struct label *interpvplabel, struct image_params *imgp); 701 int mac_vnode_execve_will_transition(struct ucred *cred, 702 struct vnode *vp, struct label *interpvplabel, 703 struct image_params *imgp); 704 void mac_vnode_relabel(struct ucred *cred, struct vnode *vp, 705 struct label *newlabel); 706 707 /* 708 * Calls to help various file systems implement labeling functionality using 709 * their existing EA implementation. 710 */ 711 int vop_stdsetlabel_ea(struct vop_setlabel_args *ap); 712 713 #endif /* !_SECURITY_MAC_MAC_FRAMEWORK_H_ */ 714