1 /*- 2 * Copyright (c) 1999-2002 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 _SYS_SECURITY_MAC_MAC_FRAMEWORK_H_ 47 #define _SYS_SECURITY_MAC_MAC_FRAMEWORK_H_ 48 49 #ifndef _KERNEL 50 #error "no user-serviceable parts inside" 51 #endif 52 53 #include <sys/_label.h> 54 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 m_tag; 66 struct mac; 67 struct mbuf; 68 struct mount; 69 struct msg; 70 struct msqid_kernel; 71 struct proc; 72 struct semid_kernel; 73 struct shmid_kernel; 74 struct sockaddr; 75 struct socket; 76 struct sysctl_oid; 77 struct sysctl_req; 78 struct pipepair; 79 struct thread; 80 struct timespec; 81 struct ucred; 82 struct uio; 83 struct vattr; 84 struct vnode; 85 struct vop_setlabel_args; 86 87 #include <sys/acl.h> /* XXX acl_type_t */ 88 89 /* 90 * Kernel functions to manage and evaluate labels. 91 */ 92 void mac_init_bpfdesc(struct bpf_d *); 93 void mac_init_cred(struct ucred *); 94 void mac_init_devfsdirent(struct devfs_dirent *); 95 void mac_init_ifnet(struct ifnet *); 96 int mac_init_inpcb(struct inpcb *, int flag); 97 void mac_init_sysv_msgmsg(struct msg *); 98 void mac_init_sysv_msgqueue(struct msqid_kernel*); 99 void mac_init_sysv_sem(struct semid_kernel*); 100 void mac_init_sysv_shm(struct shmid_kernel*); 101 int mac_init_ipq(struct ipq *, int flag); 102 int mac_init_socket(struct socket *, int flag); 103 void mac_init_pipe(struct pipepair *); 104 void mac_init_posix_sem(struct ksem *); 105 int mac_init_mbuf(struct mbuf *mbuf, int flag); 106 int mac_init_mbuf_tag(struct m_tag *, int flag); 107 void mac_init_mount(struct mount *); 108 void mac_init_proc(struct proc *); 109 void mac_init_vnode(struct vnode *); 110 void mac_copy_mbuf(struct mbuf *m_from, struct mbuf *m_to); 111 void mac_copy_mbuf_tag(struct m_tag *, struct m_tag *); 112 void mac_copy_vnode_label(struct label *, struct label *label); 113 void mac_destroy_bpfdesc(struct bpf_d *); 114 void mac_destroy_cred(struct ucred *); 115 void mac_destroy_devfsdirent(struct devfs_dirent *); 116 void mac_destroy_ifnet(struct ifnet *); 117 void mac_destroy_inpcb(struct inpcb *); 118 void mac_destroy_sysv_msgmsg(struct msg *); 119 void mac_destroy_sysv_msgqueue(struct msqid_kernel *); 120 void mac_destroy_sysv_sem(struct semid_kernel *); 121 void mac_destroy_sysv_shm(struct shmid_kernel *); 122 void mac_destroy_ipq(struct ipq *); 123 void mac_destroy_socket(struct socket *); 124 void mac_destroy_pipe(struct pipepair *); 125 void mac_destroy_posix_sem(struct ksem *); 126 void mac_destroy_proc(struct proc *); 127 void mac_destroy_mbuf_tag(struct m_tag *); 128 void mac_destroy_mount(struct mount *); 129 void mac_destroy_vnode(struct vnode *); 130 131 struct label *mac_cred_label_alloc(void); 132 void mac_cred_label_free(struct label *label); 133 struct label *mac_vnode_label_alloc(void); 134 void mac_vnode_label_free(struct label *label); 135 136 /* 137 * Labeling event operations: file system objects, and things that look a lot 138 * like file system objects. 139 */ 140 void mac_associate_vnode_devfs(struct mount *mp, struct devfs_dirent *de, 141 struct vnode *vp); 142 int mac_associate_vnode_extattr(struct mount *mp, struct vnode *vp); 143 void mac_associate_vnode_singlelabel(struct mount *mp, struct vnode *vp); 144 void mac_create_devfs_device(struct ucred *cred, struct mount *mp, 145 struct cdev *dev, struct devfs_dirent *de); 146 void mac_create_devfs_directory(struct mount *mp, char *dirname, 147 int dirnamelen, struct devfs_dirent *de); 148 void mac_create_devfs_symlink(struct ucred *cred, struct mount *mp, 149 struct devfs_dirent *dd, struct devfs_dirent *de); 150 int mac_create_vnode_extattr(struct ucred *cred, struct mount *mp, 151 struct vnode *dvp, struct vnode *vp, struct componentname *cnp); 152 void mac_create_mount(struct ucred *cred, struct mount *mp); 153 void mac_relabel_vnode(struct ucred *cred, struct vnode *vp, 154 struct label *newlabel); 155 void mac_update_devfsdirent(struct mount *mp, struct devfs_dirent *de, 156 struct vnode *vp); 157 158 /* 159 * Labeling event operations: IPC objects. 160 */ 161 void mac_create_mbuf_from_socket(struct socket *so, struct mbuf *m); 162 void mac_create_socket(struct ucred *cred, struct socket *socket); 163 void mac_create_socket_from_socket(struct socket *oldsocket, 164 struct socket *newsocket); 165 void mac_set_socket_peer_from_mbuf(struct mbuf *mbuf, 166 struct socket *socket); 167 void mac_set_socket_peer_from_socket(struct socket *oldsocket, 168 struct socket *newsocket); 169 void mac_create_pipe(struct ucred *cred, struct pipepair *pp); 170 171 /* 172 * Labeling event operations: System V IPC primitives 173 */ 174 void mac_create_sysv_msgmsg(struct ucred *cred, 175 struct msqid_kernel *msqkptr, struct msg *msgptr); 176 void mac_create_sysv_msgqueue(struct ucred *cred, 177 struct msqid_kernel *msqkptr); 178 void mac_create_sysv_sem(struct ucred *cred, 179 struct semid_kernel *semakptr); 180 void mac_create_sysv_shm(struct ucred *cred, 181 struct shmid_kernel *shmsegptr); 182 183 /* 184 * Labeling event operations: POSIX (global/inter-process) semaphores. 185 */ 186 void mac_create_posix_sem(struct ucred *cred, struct ksem *ksemptr); 187 188 /* 189 * Labeling event operations: network objects. 190 */ 191 void mac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d); 192 void mac_create_ifnet(struct ifnet *ifp); 193 void mac_create_inpcb_from_socket(struct socket *so, struct inpcb *inp); 194 void mac_create_ipq(struct mbuf *fragment, struct ipq *ipq); 195 void mac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram); 196 void mac_create_fragment(struct mbuf *datagram, struct mbuf *fragment); 197 void mac_create_mbuf_from_inpcb(struct inpcb *inp, struct mbuf *m); 198 void mac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *m); 199 void mac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *m); 200 void mac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *m); 201 void mac_create_mbuf_multicast_encap(struct mbuf *oldmbuf, 202 struct ifnet *ifnet, struct mbuf *newmbuf); 203 void mac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf); 204 int mac_fragment_match(struct mbuf *fragment, struct ipq *ipq); 205 void mac_reflect_mbuf_icmp(struct mbuf *m); 206 void mac_reflect_mbuf_tcp(struct mbuf *m); 207 void mac_update_ipq(struct mbuf *fragment, struct ipq *ipq); 208 void mac_inpcb_sosetlabel(struct socket *so, struct inpcb *inp); 209 void mac_create_mbuf_from_firewall(struct mbuf *m); 210 void mac_destroy_syncache(struct label **label); 211 int mac_init_syncache(struct label **label); 212 void mac_init_syncache_from_inpcb(struct label *label, struct inpcb *inp); 213 void mac_create_mbuf_from_syncache(struct label *sc_label, struct mbuf *m); 214 215 /* 216 * Labeling event operations: processes. 217 */ 218 void mac_copy_cred(struct ucred *cr1, struct ucred *cr2); 219 int mac_execve_enter(struct image_params *imgp, struct mac *mac_p); 220 void mac_execve_exit(struct image_params *imgp); 221 void mac_execve_transition(struct ucred *old, struct ucred *new, 222 struct vnode *vp, struct label *interpvnodelabel, 223 struct image_params *imgp); 224 int mac_execve_will_transition(struct ucred *old, struct vnode *vp, 225 struct label *interpvnodelabel, struct image_params *imgp); 226 void mac_create_proc0(struct ucred *cred); 227 void mac_create_proc1(struct ucred *cred); 228 void mac_thread_userret(struct thread *td); 229 230 /* 231 * Label cleanup operation: This is the inverse complement for the mac_create 232 * and associate type of hooks. This hook lets the policy module(s) perform a 233 * cleanup/flushing operation on the label associated with the objects, 234 * without freeing up the space allocated. This hook is useful in cases 235 * where it is desirable to remove any labeling reference when recycling any 236 * object to a pool. This hook does not replace the mac_destroy hooks. 237 * 238 * XXXRW: These object methods are inconsistent with the life cycles of other 239 * objects, and likely should be revised to be more consistent. 240 */ 241 void mac_cleanup_sysv_msgmsg(struct msg *msgptr); 242 void mac_cleanup_sysv_msgqueue(struct msqid_kernel *msqkptr); 243 void mac_cleanup_sysv_sem(struct semid_kernel *semakptr); 244 void mac_cleanup_sysv_shm(struct shmid_kernel *shmsegptr); 245 246 /* 247 * Access control checks. 248 */ 249 int mac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet); 250 int mac_check_cred_visible(struct ucred *u1, struct ucred *u2); 251 int mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *m); 252 int mac_check_inpcb_deliver(struct inpcb *inp, struct mbuf *m); 253 int mac_check_sysv_msgmsq(struct ucred *cred, struct msg *msgptr, 254 struct msqid_kernel *msqkptr); 255 int mac_check_sysv_msgrcv(struct ucred *cred, struct msg *msgptr); 256 int mac_check_sysv_msgrmid(struct ucred *cred, struct msg *msgptr); 257 int mac_check_sysv_msqget(struct ucred *cred, 258 struct msqid_kernel *msqkptr); 259 int mac_check_sysv_msqsnd(struct ucred *cred, 260 struct msqid_kernel *msqkptr); 261 int mac_check_sysv_msqrcv(struct ucred *cred, 262 struct msqid_kernel *msqkptr); 263 int mac_check_sysv_msqctl(struct ucred *cred, 264 struct msqid_kernel *msqkptr, int cmd); 265 int mac_check_sysv_semctl(struct ucred *cred, 266 struct semid_kernel *semakptr, int cmd); 267 int mac_check_sysv_semget(struct ucred *cred, 268 struct semid_kernel *semakptr); 269 int mac_check_sysv_semop(struct ucred *cred,struct semid_kernel *semakptr, 270 size_t accesstype); 271 int mac_check_sysv_shmat(struct ucred *cred, 272 struct shmid_kernel *shmsegptr, int shmflg); 273 int mac_check_sysv_shmctl(struct ucred *cred, 274 struct shmid_kernel *shmsegptr, int cmd); 275 int mac_check_sysv_shmdt(struct ucred *cred, 276 struct shmid_kernel *shmsegptr); 277 int mac_check_sysv_shmget(struct ucred *cred, 278 struct shmid_kernel *shmsegptr, int shmflg); 279 int mac_check_kenv_dump(struct ucred *cred); 280 int mac_check_kenv_get(struct ucred *cred, char *name); 281 int mac_check_kenv_set(struct ucred *cred, char *name, char *value); 282 int mac_check_kenv_unset(struct ucred *cred, char *name); 283 int mac_check_kld_load(struct ucred *cred, struct vnode *vp); 284 int mac_check_kld_stat(struct ucred *cred); 285 int mac_check_kld_unload(struct ucred *cred); 286 int mac_check_mount_stat(struct ucred *cred, struct mount *mp); 287 int mac_check_pipe_ioctl(struct ucred *cred, struct pipepair *pp, 288 unsigned long cmd, void *data); 289 int mac_check_pipe_poll(struct ucred *cred, struct pipepair *pp); 290 int mac_check_pipe_read(struct ucred *cred, struct pipepair *pp); 291 int mac_check_pipe_stat(struct ucred *cred, struct pipepair *pp); 292 int mac_check_pipe_write(struct ucred *cred, struct pipepair *pp); 293 int mac_check_posix_sem_destroy(struct ucred *cred, struct ksem *ksemptr); 294 int mac_check_posix_sem_getvalue(struct ucred *cred,struct ksem *ksemptr); 295 int mac_check_posix_sem_open(struct ucred *cred, struct ksem *ksemptr); 296 int mac_check_posix_sem_post(struct ucred *cred, struct ksem *ksemptr); 297 int mac_check_posix_sem_unlink(struct ucred *cred, struct ksem *ksemptr); 298 int mac_check_posix_sem_wait(struct ucred *cred, struct ksem *ksemptr); 299 int mac_check_proc_debug(struct ucred *cred, struct proc *proc); 300 int mac_check_proc_sched(struct ucred *cred, struct proc *proc); 301 int mac_check_proc_setuid(struct proc *proc, struct ucred *cred, 302 uid_t uid); 303 int mac_check_proc_seteuid(struct proc *proc, struct ucred *cred, 304 uid_t euid); 305 int mac_check_proc_setgid(struct proc *proc, struct ucred *cred, 306 gid_t gid); 307 int mac_check_proc_setegid(struct proc *proc, struct ucred *cred, 308 gid_t egid); 309 int mac_check_proc_setgroups(struct proc *proc, struct ucred *cred, 310 int ngroups, gid_t *gidset); 311 int mac_check_proc_setreuid(struct proc *proc, struct ucred *cred, 312 uid_t ruid, uid_t euid); 313 int mac_check_proc_setregid(struct proc *proc, struct ucred *cred, 314 gid_t rgid, gid_t egid); 315 int mac_check_proc_setresuid(struct proc *proc, struct ucred *cred, 316 uid_t ruid, uid_t euid, uid_t suid); 317 int mac_check_proc_setresgid(struct proc *proc, struct ucred *cred, 318 gid_t rgid, gid_t egid, gid_t sgid); 319 int mac_check_proc_signal(struct ucred *cred, struct proc *proc, 320 int signum); 321 int mac_check_proc_wait(struct ucred *cred, struct proc *proc); 322 int mac_check_socket_accept(struct ucred *cred, struct socket *so); 323 int mac_check_socket_bind(struct ucred *cred, struct socket *so, 324 struct sockaddr *sockaddr); 325 int mac_check_socket_connect(struct ucred *cred, struct socket *so, 326 struct sockaddr *sockaddr); 327 int mac_check_socket_create(struct ucred *cred, int domain, int type, 328 int protocol); 329 int mac_check_socket_deliver(struct socket *so, struct mbuf *m); 330 int mac_check_socket_listen(struct ucred *cred, struct socket *so); 331 int mac_check_socket_poll(struct ucred *cred, struct socket *so); 332 int mac_check_socket_receive(struct ucred *cred, struct socket *so); 333 int mac_check_socket_send(struct ucred *cred, struct socket *so); 334 int mac_check_socket_stat(struct ucred *cred, struct socket *so); 335 int mac_check_socket_visible(struct ucred *cred, struct socket *so); 336 int mac_check_sysarch_ioperm(struct ucred *cred); 337 int mac_check_system_acct(struct ucred *cred, struct vnode *vp); 338 int mac_check_system_nfsd(struct ucred *cred); 339 int mac_check_system_reboot(struct ucred *cred, int howto); 340 int mac_check_system_settime(struct ucred *cred); 341 int mac_check_system_swapon(struct ucred *cred, struct vnode *vp); 342 int mac_check_system_swapoff(struct ucred *cred, struct vnode *vp); 343 int mac_check_system_sysctl(struct ucred *cred, struct sysctl_oid *oidp, 344 void *arg1, int arg2, struct sysctl_req *req); 345 int mac_check_vnode_access(struct ucred *cred, struct vnode *vp, 346 int acc_mode); 347 int mac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp); 348 int mac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp); 349 int mac_check_vnode_create(struct ucred *cred, struct vnode *dvp, 350 struct componentname *cnp, struct vattr *vap); 351 int mac_check_vnode_delete(struct ucred *cred, struct vnode *dvp, 352 struct vnode *vp, struct componentname *cnp); 353 int mac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp, 354 acl_type_t type); 355 int mac_check_vnode_deleteextattr(struct ucred *cred, struct vnode *vp, 356 int attrnamespace, const char *name); 357 int mac_check_vnode_exec(struct ucred *cred, struct vnode *vp, 358 struct image_params *imgp); 359 int mac_check_vnode_getacl(struct ucred *cred, struct vnode *vp, 360 acl_type_t type); 361 int mac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp, 362 int attrnamespace, const char *name, struct uio *uio); 363 int mac_check_vnode_link(struct ucred *cred, struct vnode *dvp, 364 struct vnode *vp, struct componentname *cnp); 365 int mac_check_vnode_listextattr(struct ucred *cred, struct vnode *vp, 366 int attrnamespace); 367 int mac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp, 368 struct componentname *cnp); 369 int mac_check_vnode_mmap(struct ucred *cred, struct vnode *vp, 370 int prot, int flags); 371 int mac_check_vnode_mprotect(struct ucred *cred, struct vnode *vp, 372 int prot); 373 int mac_check_vnode_open(struct ucred *cred, struct vnode *vp, 374 int acc_mode); 375 int mac_check_vnode_poll(struct ucred *active_cred, 376 struct ucred *file_cred, struct vnode *vp); 377 int mac_check_vnode_read(struct ucred *active_cred, 378 struct ucred *file_cred, struct vnode *vp); 379 int mac_check_vnode_readdir(struct ucred *cred, struct vnode *vp); 380 int mac_check_vnode_readlink(struct ucred *cred, struct vnode *vp); 381 int mac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp, 382 struct vnode *vp, struct componentname *cnp); 383 int mac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp, 384 struct vnode *vp, int samedir, struct componentname *cnp); 385 int mac_check_vnode_revoke(struct ucred *cred, struct vnode *vp); 386 int mac_check_vnode_setacl(struct ucred *cred, struct vnode *vp, 387 acl_type_t type, struct acl *acl); 388 int mac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp, 389 int attrnamespace, const char *name, struct uio *uio); 390 int mac_check_vnode_setflags(struct ucred *cred, struct vnode *vp, 391 u_long flags); 392 int mac_check_vnode_setmode(struct ucred *cred, struct vnode *vp, 393 mode_t mode); 394 int mac_check_vnode_setowner(struct ucred *cred, struct vnode *vp, 395 uid_t uid, gid_t gid); 396 int mac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp, 397 struct timespec atime, struct timespec mtime); 398 int mac_check_vnode_stat(struct ucred *active_cred, 399 struct ucred *file_cred, struct vnode *vp); 400 int mac_check_vnode_write(struct ucred *active_cred, 401 struct ucred *file_cred, struct vnode *vp); 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_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr, 407 struct ifnet *ifnet); 408 int mac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr, 409 struct ifnet *ifnet); 410 int mac_setsockopt_label(struct ucred *cred, struct socket *so, 411 struct mac *extmac); 412 int mac_pipe_label_set(struct ucred *cred, struct pipepair *pp, 413 struct label *label); 414 void mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred); 415 void mac_associate_nfsd_label(struct ucred *cred); 416 int mac_priv_check(struct ucred *cred, int priv); 417 int mac_priv_grant(struct ucred *cred, int priv); 418 419 /* 420 * Calls to help various file systems implement labeling functionality using 421 * their existing EA implementation. 422 */ 423 int vop_stdsetlabel_ea(struct vop_setlabel_args *ap); 424 425 #endif /* !_SYS_SECURITY_MAC_MAC_FRAMEWORK_H_ */ 426