1 /*- 2 * Copyright (c) 1999-2002, 2007 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 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions 19 * are met: 20 * 1. Redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer. 22 * 2. Redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * $FreeBSD$ 39 */ 40 41 /* 42 * Kernel interface for Mandatory Access Control -- how kernel services 43 * interact with the TrustedBSD MAC Framework. 44 */ 45 46 #ifndef _SECURITY_MAC_MAC_FRAMEWORK_H_ 47 #define _SECURITY_MAC_MAC_FRAMEWORK_H_ 48 49 #ifndef _KERNEL 50 #error "no user-serviceable parts inside" 51 #endif 52 53 struct auditinfo; 54 struct auditinfo_addr; 55 struct bpf_d; 56 struct cdev; 57 struct componentname; 58 struct devfs_dirent; 59 struct ifnet; 60 struct ifreq; 61 struct image_params; 62 struct inpcb; 63 struct ipq; 64 struct ksem; 65 struct label; 66 struct m_tag; 67 struct mac; 68 struct mbuf; 69 struct mount; 70 struct msg; 71 struct msqid_kernel; 72 struct proc; 73 struct semid_kernel; 74 struct shmfd; 75 struct shmid_kernel; 76 struct sockaddr; 77 struct socket; 78 struct sysctl_oid; 79 struct sysctl_req; 80 struct pipepair; 81 struct thread; 82 struct timespec; 83 struct ucred; 84 struct uio; 85 struct vattr; 86 struct vnode; 87 struct vop_setlabel_args; 88 89 #include <sys/acl.h> /* XXX acl_type_t */ 90 91 /* 92 * Entry points to the TrustedBSD MAC Framework from the remainder of the 93 * kernel: entry points are named based on a principle object type and an 94 * action relating to it. They are sorted alphabetically first by object 95 * type and then action. In some situations, the principle object type is 96 * obvious, and in other cases, less so as multiple objects may be inolved 97 * in the operation. 98 */ 99 int mac_bpfdesc_check_receive(struct bpf_d *d, struct ifnet *ifp); 100 void mac_bpfdesc_create(struct ucred *cred, struct bpf_d *d); 101 void mac_bpfdesc_create_mbuf(struct bpf_d *d, struct mbuf *m); 102 void mac_bpfdesc_destroy(struct bpf_d *); 103 void mac_bpfdesc_init(struct bpf_d *); 104 105 int mac_cred_check_visible(struct ucred *cr1, struct ucred *cr2); 106 void mac_cred_copy(struct ucred *cr1, struct ucred *cr2); 107 void mac_cred_destroy(struct ucred *); 108 void mac_cred_init(struct ucred *); 109 110 void mac_devfs_create_device(struct ucred *cred, struct mount *mp, 111 struct cdev *dev, struct devfs_dirent *de); 112 void mac_devfs_create_directory(struct mount *mp, char *dirname, 113 int dirnamelen, struct devfs_dirent *de); 114 void mac_devfs_create_symlink(struct ucred *cred, struct mount *mp, 115 struct devfs_dirent *dd, struct devfs_dirent *de); 116 void mac_devfs_destroy(struct devfs_dirent *); 117 void mac_devfs_init(struct devfs_dirent *); 118 void mac_devfs_update(struct mount *mp, struct devfs_dirent *de, 119 struct vnode *vp); 120 void mac_devfs_vnode_associate(struct mount *mp, struct devfs_dirent *de, 121 struct vnode *vp); 122 123 int mac_ifnet_check_transmit(struct ifnet *ifp, struct mbuf *m); 124 void mac_ifnet_create(struct ifnet *ifp); 125 void mac_ifnet_create_mbuf(struct ifnet *ifp, struct mbuf *m); 126 void mac_ifnet_destroy(struct ifnet *); 127 void mac_ifnet_init(struct ifnet *); 128 int mac_ifnet_ioctl_get(struct ucred *cred, struct ifreq *ifr, 129 struct ifnet *ifp); 130 int mac_ifnet_ioctl_set(struct ucred *cred, struct ifreq *ifr, 131 struct ifnet *ifp); 132 133 int mac_inpcb_check_deliver(struct inpcb *inp, struct mbuf *m); 134 void mac_inpcb_create(struct socket *so, struct inpcb *inp); 135 void mac_inpcb_create_mbuf(struct inpcb *inp, struct mbuf *m); 136 void mac_inpcb_destroy(struct inpcb *); 137 int mac_inpcb_init(struct inpcb *, int); 138 void mac_inpcb_sosetlabel(struct socket *so, struct inpcb *inp); 139 140 void mac_ipq_create(struct mbuf *m, struct ipq *q); 141 void mac_ipq_destroy(struct ipq *q); 142 int mac_ipq_init(struct ipq *q, int); 143 int mac_ipq_match(struct mbuf *m, struct ipq *q); 144 void mac_ipq_reassemble(struct ipq *q, struct mbuf *m); 145 void mac_ipq_update(struct mbuf *m, struct ipq *q); 146 147 int mac_kenv_check_dump(struct ucred *cred); 148 int mac_kenv_check_get(struct ucred *cred, char *name); 149 int mac_kenv_check_set(struct ucred *cred, char *name, char *value); 150 int mac_kenv_check_unset(struct ucred *cred, char *name); 151 152 int mac_kld_check_load(struct ucred *cred, struct vnode *vp); 153 int mac_kld_check_stat(struct ucred *cred); 154 155 void mac_mbuf_copy(struct mbuf *, struct mbuf *); 156 int mac_mbuf_init(struct mbuf *, int); 157 158 void mac_mbuf_tag_copy(struct m_tag *, struct m_tag *); 159 void mac_mbuf_tag_destroy(struct m_tag *); 160 int mac_mbuf_tag_init(struct m_tag *, int); 161 162 int mac_mount_check_stat(struct ucred *cred, struct mount *mp); 163 void mac_mount_create(struct ucred *cred, struct mount *mp); 164 void mac_mount_destroy(struct mount *); 165 void mac_mount_init(struct mount *); 166 167 void mac_netatalk_aarp_send(struct ifnet *ifp, struct mbuf *m); 168 169 void mac_netinet_arp_send(struct ifnet *ifp, struct mbuf *m); 170 void mac_netinet_firewall_reply(struct mbuf *mrecv, struct mbuf *msend); 171 void mac_netinet_firewall_send(struct mbuf *m); 172 void mac_netinet_fragment(struct mbuf *m, struct mbuf *frag); 173 void mac_netinet_icmp_reply(struct mbuf *mrecv, struct mbuf *msend); 174 void mac_netinet_icmp_replyinplace(struct mbuf *m); 175 void mac_netinet_igmp_send(struct ifnet *ifp, struct mbuf *m); 176 void mac_netinet_tcp_reply(struct mbuf *m); 177 178 void mac_netinet6_nd6_send(struct ifnet *ifp, struct mbuf *m); 179 180 int mac_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp, 181 unsigned long cmd, void *data); 182 int mac_pipe_check_poll(struct ucred *cred, struct pipepair *pp); 183 int mac_pipe_check_read(struct ucred *cred, struct pipepair *pp); 184 int mac_pipe_check_stat(struct ucred *cred, struct pipepair *pp); 185 int mac_pipe_check_write(struct ucred *cred, struct pipepair *pp); 186 void mac_pipe_create(struct ucred *cred, struct pipepair *pp); 187 void mac_pipe_destroy(struct pipepair *); 188 void mac_pipe_init(struct pipepair *); 189 int mac_pipe_label_set(struct ucred *cred, struct pipepair *pp, 190 struct label *label); 191 192 int mac_posixsem_check_getvalue(struct ucred *active_cred, 193 struct ucred *file_cred, struct ksem *ks); 194 int mac_posixsem_check_open(struct ucred *cred, struct ksem *ks); 195 int mac_posixsem_check_post(struct ucred *active_cred, 196 struct ucred *file_cred, struct ksem *ks); 197 int mac_posixsem_check_stat(struct ucred *active_cred, 198 struct ucred *file_cred, struct ksem *ks); 199 int mac_posixsem_check_unlink(struct ucred *cred, struct ksem *ks); 200 int mac_posixsem_check_wait(struct ucred *active_cred, 201 struct ucred *file_cred, struct ksem *ks); 202 void mac_posixsem_create(struct ucred *cred, struct ksem *ks); 203 void mac_posixsem_destroy(struct ksem *); 204 void mac_posixsem_init(struct ksem *); 205 206 int mac_posixshm_check_mmap(struct ucred *cred, struct shmfd *shmfd, 207 int prot, int flags); 208 int mac_posixshm_check_open(struct ucred *cred, struct shmfd *shmfd); 209 int mac_posixshm_check_stat(struct ucred *active_cred, 210 struct ucred *file_cred, struct shmfd *shmfd); 211 int mac_posixshm_check_truncate(struct ucred *active_cred, 212 struct ucred *file_cred, struct shmfd *shmfd); 213 int mac_posixshm_check_unlink(struct ucred *cred, struct shmfd *shmfd); 214 void mac_posixshm_create(struct ucred *cred, struct shmfd *shmfd); 215 void mac_posixshm_destroy(struct shmfd *); 216 void mac_posixshm_init(struct shmfd *); 217 218 int mac_priv_check(struct ucred *cred, int priv); 219 int mac_priv_grant(struct ucred *cred, int priv); 220 221 void mac_proc_associate_nfsd(struct ucred *cred); 222 int mac_proc_check_debug(struct ucred *cred, struct proc *p); 223 int mac_proc_check_sched(struct ucred *cred, struct proc *p); 224 int mac_proc_check_setaudit(struct ucred *cred, struct auditinfo *ai); 225 int mac_proc_check_setaudit_addr(struct ucred *cred, 226 struct auditinfo_addr *aia); 227 int mac_proc_check_setauid(struct ucred *cred, uid_t auid); 228 int mac_proc_check_setegid(struct proc *p, struct ucred *cred, 229 gid_t egid); 230 int mac_proc_check_seteuid(struct proc *p, struct ucred *cred, 231 uid_t euid); 232 int mac_proc_check_setgid(struct proc *p, struct ucred *cred, 233 gid_t gid); 234 int mac_proc_check_setgroups(struct proc *p, struct ucred *cred, 235 int ngroups, gid_t *gidset); 236 int mac_proc_check_setregid(struct proc *p, struct ucred *cred, 237 gid_t rgid, gid_t egid); 238 int mac_proc_check_setresgid(struct proc *p, struct ucred *cred, 239 gid_t rgid, gid_t egid, gid_t sgid); 240 int mac_proc_check_setresuid(struct proc *p, struct ucred *cred, 241 uid_t ruid, uid_t euid, uid_t suid); 242 int mac_proc_check_setreuid(struct proc *p, struct ucred *cred, 243 uid_t ruid, uid_t euid); 244 int mac_proc_check_setuid(struct proc *p, struct ucred *cred, 245 uid_t uid); 246 int mac_proc_check_signal(struct ucred *cred, struct proc *p, 247 int signum); 248 int mac_proc_check_wait(struct ucred *cred, struct proc *p); 249 void mac_proc_create_init(struct ucred *cred); 250 void mac_proc_create_swapper(struct ucred *cred); 251 void mac_proc_destroy(struct proc *); 252 void mac_proc_init(struct proc *); 253 int mac_execve_enter(struct image_params *imgp, struct mac *mac_p); 254 void mac_execve_exit(struct image_params *imgp); 255 void mac_execve_interpreter_enter(struct vnode *interpvp, 256 struct label **interplabel); 257 void mac_execve_interpreter_exit(struct label *interpvplabel); 258 259 int mac_socket_check_accept(struct ucred *cred, struct socket *so); 260 int mac_socket_check_bind(struct ucred *cred, struct socket *so, 261 struct sockaddr *sa); 262 int mac_socket_check_connect(struct ucred *cred, struct socket *so, 263 struct sockaddr *sa); 264 int mac_socket_check_create(struct ucred *cred, int domain, int type, 265 int proto); 266 int mac_socket_check_deliver(struct socket *so, struct mbuf *m); 267 int mac_socket_check_listen(struct ucred *cred, struct socket *so); 268 int mac_socket_check_poll(struct ucred *cred, struct socket *so); 269 int mac_socket_check_receive(struct ucred *cred, struct socket *so); 270 int mac_socket_check_send(struct ucred *cred, struct socket *so); 271 int mac_socket_check_stat(struct ucred *cred, struct socket *so); 272 int mac_socket_check_visible(struct ucred *cred, struct socket *so); 273 void mac_socket_create_mbuf(struct socket *so, struct mbuf *m); 274 void mac_socket_create(struct ucred *cred, struct socket *so); 275 void mac_socket_destroy(struct socket *); 276 int mac_socket_init(struct socket *, int); 277 void mac_socket_newconn(struct socket *oldso, struct socket *newso); 278 int mac_getsockopt_label(struct ucred *cred, struct socket *so, 279 struct mac *extmac); 280 int mac_getsockopt_peerlabel(struct ucred *cred, struct socket *so, 281 struct mac *extmac); 282 int mac_setsockopt_label(struct ucred *cred, struct socket *so, 283 struct mac *extmac); 284 285 void mac_socketpeer_set_from_mbuf(struct mbuf *m, struct socket *so); 286 void mac_socketpeer_set_from_socket(struct socket *oldso, 287 struct socket *newso); 288 289 void mac_syncache_create(struct label *l, struct inpcb *inp); 290 void mac_syncache_create_mbuf(struct label *l, struct mbuf *m); 291 void mac_syncache_destroy(struct label **l); 292 int mac_syncache_init(struct label **l); 293 294 int mac_system_check_acct(struct ucred *cred, struct vnode *vp); 295 int mac_system_check_audit(struct ucred *cred, void *record, int length); 296 int mac_system_check_auditctl(struct ucred *cred, struct vnode *vp); 297 int mac_system_check_auditon(struct ucred *cred, int cmd); 298 int mac_system_check_reboot(struct ucred *cred, int howto); 299 int mac_system_check_swapon(struct ucred *cred, struct vnode *vp); 300 int mac_system_check_swapoff(struct ucred *cred, struct vnode *vp); 301 int mac_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp, 302 void *arg1, int arg2, struct sysctl_req *req); 303 304 void mac_sysvmsg_cleanup(struct msg *msgptr); 305 void mac_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr, 306 struct msg *msgptr); 307 void mac_sysvmsg_destroy(struct msg *); 308 void mac_sysvmsg_init(struct msg *); 309 310 int mac_sysvmsq_check_msgmsq(struct ucred *cred, struct msg *msgptr, 311 struct msqid_kernel *msqkptr); 312 int mac_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr); 313 int mac_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr); 314 int mac_sysvmsq_check_msqctl(struct ucred *cred, 315 struct msqid_kernel *msqkptr, int cmd); 316 int mac_sysvmsq_check_msqget(struct ucred *cred, 317 struct msqid_kernel *msqkptr); 318 int mac_sysvmsq_check_msqrcv(struct ucred *cred, 319 struct msqid_kernel *msqkptr); 320 int mac_sysvmsq_check_msqsnd(struct ucred *cred, 321 struct msqid_kernel *msqkptr); 322 void mac_sysvmsq_cleanup(struct msqid_kernel *msqkptr); 323 void mac_sysvmsq_create(struct ucred *cred, struct msqid_kernel *msqkptr); 324 void mac_sysvmsq_destroy(struct msqid_kernel *); 325 void mac_sysvmsq_init(struct msqid_kernel *); 326 327 int mac_sysvsem_check_semctl(struct ucred *cred, 328 struct semid_kernel *semakptr, int cmd); 329 int mac_sysvsem_check_semget(struct ucred *cred, 330 struct semid_kernel *semakptr); 331 int mac_sysvsem_check_semop(struct ucred *cred, 332 struct semid_kernel *semakptr, size_t accesstype); 333 void mac_sysvsem_cleanup(struct semid_kernel *semakptr); 334 void mac_sysvsem_create(struct ucred *cred, 335 struct semid_kernel *semakptr); 336 void mac_sysvsem_destroy(struct semid_kernel *); 337 void mac_sysvsem_init(struct semid_kernel *); 338 339 int mac_sysvshm_check_shmat(struct ucred *cred, 340 struct shmid_kernel *shmsegptr, int shmflg); 341 int mac_sysvshm_check_shmctl(struct ucred *cred, 342 struct shmid_kernel *shmsegptr, int cmd); 343 int mac_sysvshm_check_shmdt(struct ucred *cred, 344 struct shmid_kernel *shmsegptr); 345 int mac_sysvshm_check_shmget(struct ucred *cred, 346 struct shmid_kernel *shmsegptr, int shmflg); 347 void mac_sysvshm_cleanup(struct shmid_kernel *shmsegptr); 348 void mac_sysvshm_create(struct ucred *cred, 349 struct shmid_kernel *shmsegptr); 350 void mac_sysvshm_destroy(struct shmid_kernel *); 351 void mac_sysvshm_init(struct shmid_kernel *); 352 353 void mac_thread_userret(struct thread *td); 354 355 int mac_vnode_associate_extattr(struct mount *mp, struct vnode *vp); 356 void mac_vnode_associate_singlelabel(struct mount *mp, struct vnode *vp); 357 int mac_vnode_check_access(struct ucred *cred, struct vnode *vp, 358 int acc_mode); 359 int mac_vnode_check_chdir(struct ucred *cred, struct vnode *dvp); 360 int mac_vnode_check_chroot(struct ucred *cred, struct vnode *dvp); 361 int mac_vnode_check_create(struct ucred *cred, struct vnode *dvp, 362 struct componentname *cnp, struct vattr *vap); 363 int mac_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp, 364 acl_type_t type); 365 int mac_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp, 366 int attrnamespace, const char *name); 367 int mac_vnode_check_exec(struct ucred *cred, struct vnode *vp, 368 struct image_params *imgp); 369 int mac_vnode_check_getacl(struct ucred *cred, struct vnode *vp, 370 acl_type_t type); 371 int mac_vnode_check_getextattr(struct ucred *cred, struct vnode *vp, 372 int attrnamespace, const char *name, struct uio *uio); 373 int mac_vnode_check_link(struct ucred *cred, struct vnode *dvp, 374 struct vnode *vp, struct componentname *cnp); 375 int mac_vnode_check_listextattr(struct ucred *cred, struct vnode *vp, 376 int attrnamespace); 377 int mac_vnode_check_lookup(struct ucred *cred, struct vnode *dvp, 378 struct componentname *cnp); 379 int mac_vnode_check_mmap(struct ucred *cred, struct vnode *vp, int prot, 380 int flags); 381 int mac_vnode_check_mprotect(struct ucred *cred, struct vnode *vp, 382 int prot); 383 int mac_vnode_check_open(struct ucred *cred, struct vnode *vp, 384 int acc_mode); 385 int mac_vnode_check_poll(struct ucred *active_cred, 386 struct ucred *file_cred, struct vnode *vp); 387 int mac_vnode_check_read(struct ucred *active_cred, 388 struct ucred *file_cred, struct vnode *vp); 389 int mac_vnode_check_readdir(struct ucred *cred, struct vnode *vp); 390 int mac_vnode_check_readlink(struct ucred *cred, struct vnode *vp); 391 int mac_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp, 392 struct vnode *vp, struct componentname *cnp); 393 int mac_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp, 394 struct vnode *vp, int samedir, struct componentname *cnp); 395 int mac_vnode_check_revoke(struct ucred *cred, struct vnode *vp); 396 int mac_vnode_check_setacl(struct ucred *cred, struct vnode *vp, 397 acl_type_t type, struct acl *acl); 398 int mac_vnode_check_setextattr(struct ucred *cred, struct vnode *vp, 399 int attrnamespace, const char *name, struct uio *uio); 400 int mac_vnode_check_setflags(struct ucred *cred, struct vnode *vp, 401 u_long flags); 402 int mac_vnode_check_setmode(struct ucred *cred, struct vnode *vp, 403 mode_t mode); 404 int mac_vnode_check_setowner(struct ucred *cred, struct vnode *vp, 405 uid_t uid, gid_t gid); 406 int mac_vnode_check_setutimes(struct ucred *cred, struct vnode *vp, 407 struct timespec atime, struct timespec mtime); 408 int mac_vnode_check_stat(struct ucred *active_cred, 409 struct ucred *file_cred, struct vnode *vp); 410 int mac_vnode_check_unlink(struct ucred *cred, struct vnode *dvp, 411 struct vnode *vp, struct componentname *cnp); 412 int mac_vnode_check_write(struct ucred *active_cred, 413 struct ucred *file_cred, struct vnode *vp); 414 void mac_vnode_copy_label(struct label *, struct label *); 415 void mac_vnode_init(struct vnode *); 416 int mac_vnode_create_extattr(struct ucred *cred, struct mount *mp, 417 struct vnode *dvp, struct vnode *vp, struct componentname *cnp); 418 void mac_vnode_destroy(struct vnode *); 419 void mac_vnode_execve_transition(struct ucred *oldcred, 420 struct ucred *newcred, struct vnode *vp, 421 struct label *interpvplabel, struct image_params *imgp); 422 int mac_vnode_execve_will_transition(struct ucred *cred, 423 struct vnode *vp, struct label *interpvplabel, 424 struct image_params *imgp); 425 void mac_vnode_relabel(struct ucred *cred, struct vnode *vp, 426 struct label *newlabel); 427 428 void mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred); 429 430 /* 431 * Calls to help various file systems implement labeling functionality using 432 * their existing EA implementation. 433 */ 434 int vop_stdsetlabel_ea(struct vop_setlabel_args *ap); 435 436 #endif /* !_SECURITY_MAC_MAC_FRAMEWORK_H_ */ 437