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