2 * Copyright (c) 1999-2002, 2009 Robert N. M. Watson
3 * Copyright (c) 2001 Ilmar S. Habibulin
4 * Copyright (c) 2001-2005 McAfee, Inc.
5 * Copyright (c) 2005-2006 SPARTA, Inc.
6 * Copyright (c) 2008 Apple Inc.
9 * This software was developed by Robert Watson and Ilmar Habibulin for the
12 * This software was developed for the FreeBSD Project in part by McAfee
13 * Research, the Security Research Division of McAfee, Inc. under
14 * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
15 * CHATS research program.
17 * This software was enhanced by SPARTA ISSO under SPAWAR contract
18 * N66001-04-C-6019 ("SEFOS").
20 * This software was developed at the University of Cambridge Computer
21 * Laboratory with support from a grant from Google, Inc.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
32 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 #include <sys/cdefs.h>
46 __FBSDID("$FreeBSD$");
48 #include "opt_kdtrace.h"
51 #include <sys/param.h>
52 #include <sys/condvar.h>
53 #include <sys/extattr.h>
54 #include <sys/imgact.h>
55 #include <sys/kernel.h>
57 #include <sys/malloc.h>
58 #include <sys/mutex.h>
61 #include <sys/systm.h>
62 #include <sys/vnode.h>
63 #include <sys/mount.h>
65 #include <sys/namei.h>
67 #include <sys/sysctl.h>
71 #include <vm/vm_map.h>
72 #include <vm/vm_object.h>
74 #include <fs/devfs/devfs.h>
76 #include <security/mac/mac_framework.h>
77 #include <security/mac/mac_internal.h>
78 #include <security/mac/mac_policy.h>
81 * Warn about EA transactions only the first time they happen. No locking on
84 static int ea_warn_once = 0;
86 static int mac_vnode_setlabel_extattr(struct ucred *cred,
87 struct vnode *vp, struct label *intlabel);
90 mac_devfs_label_alloc(void)
94 label = mac_labelzone_alloc(M_WAITOK);
95 MAC_POLICY_PERFORM(devfs_init_label, label);
100 mac_devfs_init(struct devfs_dirent *de)
103 if (mac_labeled & MPC_OBJECT_DEVFS)
104 de->de_label = mac_devfs_label_alloc();
109 static struct label *
110 mac_mount_label_alloc(void)
114 label = mac_labelzone_alloc(M_WAITOK);
115 MAC_POLICY_PERFORM(mount_init_label, label);
120 mac_mount_init(struct mount *mp)
123 if (mac_labeled & MPC_OBJECT_MOUNT)
124 mp->mnt_label = mac_mount_label_alloc();
126 mp->mnt_label = NULL;
130 mac_vnode_label_alloc(void)
134 label = mac_labelzone_alloc(M_WAITOK);
135 MAC_POLICY_PERFORM(vnode_init_label, label);
140 mac_vnode_init(struct vnode *vp)
143 if (mac_labeled & MPC_OBJECT_VNODE)
144 vp->v_label = mac_vnode_label_alloc();
150 mac_devfs_label_free(struct label *label)
153 MAC_POLICY_PERFORM_NOSLEEP(devfs_destroy_label, label);
154 mac_labelzone_free(label);
158 mac_devfs_destroy(struct devfs_dirent *de)
161 if (de->de_label != NULL) {
162 mac_devfs_label_free(de->de_label);
168 mac_mount_label_free(struct label *label)
171 MAC_POLICY_PERFORM_NOSLEEP(mount_destroy_label, label);
172 mac_labelzone_free(label);
176 mac_mount_destroy(struct mount *mp)
179 if (mp->mnt_label != NULL) {
180 mac_mount_label_free(mp->mnt_label);
181 mp->mnt_label = NULL;
186 mac_vnode_label_free(struct label *label)
189 MAC_POLICY_PERFORM_NOSLEEP(vnode_destroy_label, label);
190 mac_labelzone_free(label);
194 mac_vnode_destroy(struct vnode *vp)
197 if (vp->v_label != NULL) {
198 mac_vnode_label_free(vp->v_label);
204 mac_vnode_copy_label(struct label *src, struct label *dest)
207 MAC_POLICY_PERFORM_NOSLEEP(vnode_copy_label, src, dest);
211 mac_vnode_externalize_label(struct label *label, char *elements,
212 char *outbuf, size_t outbuflen)
216 MAC_POLICY_EXTERNALIZE(vnode, label, elements, outbuf, outbuflen);
222 mac_vnode_internalize_label(struct label *label, char *string)
226 MAC_POLICY_INTERNALIZE(vnode, label, string);
232 mac_devfs_update(struct mount *mp, struct devfs_dirent *de, struct vnode *vp)
235 MAC_POLICY_PERFORM_NOSLEEP(devfs_update, mp, de, de->de_label, vp,
240 mac_devfs_vnode_associate(struct mount *mp, struct devfs_dirent *de,
244 MAC_POLICY_PERFORM_NOSLEEP(devfs_vnode_associate, mp, mp->mnt_label,
245 de, de->de_label, vp, vp->v_label);
249 mac_vnode_associate_extattr(struct mount *mp, struct vnode *vp)
253 ASSERT_VOP_LOCKED(vp, "mac_vnode_associate_extattr");
255 MAC_POLICY_CHECK(vnode_associate_extattr, mp, mp->mnt_label, vp,
262 mac_vnode_associate_singlelabel(struct mount *mp, struct vnode *vp)
265 MAC_POLICY_PERFORM_NOSLEEP(vnode_associate_singlelabel, mp,
266 mp->mnt_label, vp, vp->v_label);
270 * Functions implementing extended-attribute backed labels for file systems
273 * Where possible, we use EA transactions to make writes to multiple
274 * attributes across difference policies mutually atomic. We allow work to
275 * continue on file systems not supporting EA transactions, but generate a
279 mac_vnode_create_extattr(struct ucred *cred, struct mount *mp,
280 struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
284 ASSERT_VOP_LOCKED(dvp, "mac_vnode_create_extattr");
285 ASSERT_VOP_LOCKED(vp, "mac_vnode_create_extattr");
287 error = VOP_OPENEXTATTR(vp, cred, curthread);
288 if (error == EOPNOTSUPP) {
289 if (ea_warn_once == 0) {
290 printf("Warning: transactions not supported "
297 MAC_POLICY_CHECK(vnode_create_extattr, cred, mp, mp->mnt_label, dvp,
298 dvp->v_label, vp, vp->v_label, cnp);
301 VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
305 error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
306 if (error == EOPNOTSUPP)
313 mac_vnode_setlabel_extattr(struct ucred *cred, struct vnode *vp,
314 struct label *intlabel)
318 ASSERT_VOP_LOCKED(vp, "mac_vnode_setlabel_extattr");
320 error = VOP_OPENEXTATTR(vp, cred, curthread);
321 if (error == EOPNOTSUPP) {
322 if (ea_warn_once == 0) {
323 printf("Warning: transactions not supported "
330 MAC_POLICY_CHECK(vnode_setlabel_extattr, cred, vp, vp->v_label,
334 VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
338 error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
339 if (error == EOPNOTSUPP)
346 mac_vnode_execve_transition(struct ucred *old, struct ucred *new,
347 struct vnode *vp, struct label *interpvplabel, struct image_params *imgp)
350 ASSERT_VOP_LOCKED(vp, "mac_vnode_execve_transition");
352 MAC_POLICY_PERFORM(vnode_execve_transition, old, new, vp,
353 vp->v_label, interpvplabel, imgp, imgp->execlabel);
357 mac_vnode_execve_will_transition(struct ucred *old, struct vnode *vp,
358 struct label *interpvplabel, struct image_params *imgp)
362 ASSERT_VOP_LOCKED(vp, "mac_vnode_execve_will_transition");
365 /* No sleeping since the process lock will be held by the caller. */
366 MAC_POLICY_BOOLEAN_NOSLEEP(vnode_execve_will_transition, ||, old, vp,
367 vp->v_label, interpvplabel, imgp, imgp->execlabel);
372 MAC_CHECK_PROBE_DEFINE3(vnode_check_access, "struct ucred *",
373 "struct vnode *", "accmode_t");
376 mac_vnode_check_access(struct ucred *cred, struct vnode *vp, accmode_t accmode)
380 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_access");
382 MAC_POLICY_CHECK(vnode_check_access, cred, vp, vp->v_label, accmode);
383 MAC_CHECK_PROBE3(vnode_check_access, error, cred, vp, accmode);
388 MAC_CHECK_PROBE_DEFINE2(vnode_check_chdir, "struct ucred *",
392 mac_vnode_check_chdir(struct ucred *cred, struct vnode *dvp)
396 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_chdir");
398 MAC_POLICY_CHECK(vnode_check_chdir, cred, dvp, dvp->v_label);
399 MAC_CHECK_PROBE2(vnode_check_chdir, error, cred, dvp);
404 MAC_CHECK_PROBE_DEFINE2(vnode_check_chroot, "struct ucred *",
408 mac_vnode_check_chroot(struct ucred *cred, struct vnode *dvp)
412 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_chroot");
414 MAC_POLICY_CHECK(vnode_check_chroot, cred, dvp, dvp->v_label);
415 MAC_CHECK_PROBE2(vnode_check_chroot, error, cred, dvp);
420 MAC_CHECK_PROBE_DEFINE4(vnode_check_create, "struct ucred *",
421 "struct vnode *", "struct componentname *", "struct vattr *");
424 mac_vnode_check_create(struct ucred *cred, struct vnode *dvp,
425 struct componentname *cnp, struct vattr *vap)
429 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_create");
431 MAC_POLICY_CHECK(vnode_check_create, cred, dvp, dvp->v_label, cnp,
433 MAC_CHECK_PROBE4(vnode_check_create, error, cred, dvp, cnp, vap);
438 MAC_CHECK_PROBE_DEFINE3(vnode_check_deleteacl, "struct ucred *",
439 "struct vnode *", "acl_type_t");
442 mac_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp,
447 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_deleteacl");
449 MAC_POLICY_CHECK(vnode_check_deleteacl, cred, vp, vp->v_label, type);
450 MAC_CHECK_PROBE3(vnode_check_deleteacl, error, cred, vp, type);
455 MAC_CHECK_PROBE_DEFINE4(vnode_check_deleteextattr, "struct ucred *",
456 "struct vnode *", "int", "const char *");
459 mac_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp,
460 int attrnamespace, const char *name)
464 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_deleteextattr");
466 MAC_POLICY_CHECK(vnode_check_deleteextattr, cred, vp, vp->v_label,
467 attrnamespace, name);
468 MAC_CHECK_PROBE4(vnode_check_deleteextattr, error, cred, vp,
469 attrnamespace, name);
474 MAC_CHECK_PROBE_DEFINE3(vnode_check_exec, "struct ucred *", "struct vnode *",
475 "struct image_params *");
478 mac_vnode_check_exec(struct ucred *cred, struct vnode *vp,
479 struct image_params *imgp)
483 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_exec");
485 MAC_POLICY_CHECK(vnode_check_exec, cred, vp, vp->v_label, imgp,
487 MAC_CHECK_PROBE3(vnode_check_exec, error, cred, vp, imgp);
492 MAC_CHECK_PROBE_DEFINE3(vnode_check_getacl, "struct ucred *",
493 "struct vnode *", "acl_type_t");
496 mac_vnode_check_getacl(struct ucred *cred, struct vnode *vp, acl_type_t type)
500 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_getacl");
502 MAC_POLICY_CHECK(vnode_check_getacl, cred, vp, vp->v_label, type);
503 MAC_CHECK_PROBE3(vnode_check_getacl, error, cred, vp, type);
508 MAC_CHECK_PROBE_DEFINE4(vnode_check_getextattr, "struct ucred *",
509 "struct vnode *", "int", "const char *");
512 mac_vnode_check_getextattr(struct ucred *cred, struct vnode *vp,
513 int attrnamespace, const char *name)
517 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_getextattr");
519 MAC_POLICY_CHECK(vnode_check_getextattr, cred, vp, vp->v_label,
520 attrnamespace, name);
521 MAC_CHECK_PROBE4(vnode_check_getextattr, error, cred, vp,
522 attrnamespace, name);
527 MAC_CHECK_PROBE_DEFINE4(vnode_check_link, "struct ucred *", "struct vnode *",
528 "struct vnode *", "struct componentname *");
531 mac_vnode_check_link(struct ucred *cred, struct vnode *dvp,
532 struct vnode *vp, struct componentname *cnp)
536 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_link");
537 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_link");
539 MAC_POLICY_CHECK(vnode_check_link, cred, dvp, dvp->v_label, vp,
541 MAC_CHECK_PROBE4(vnode_check_link, error, cred, dvp, vp, cnp);
546 MAC_CHECK_PROBE_DEFINE3(vnode_check_listextattr, "struct ucred *",
547 "struct vnode *", "int");
550 mac_vnode_check_listextattr(struct ucred *cred, struct vnode *vp,
555 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_listextattr");
557 MAC_POLICY_CHECK(vnode_check_listextattr, cred, vp, vp->v_label,
559 MAC_CHECK_PROBE3(vnode_check_listextattr, error, cred, vp,
565 MAC_CHECK_PROBE_DEFINE3(vnode_check_lookup, "struct ucred *",
566 "struct vnode *", "struct componentname *");
569 mac_vnode_check_lookup(struct ucred *cred, struct vnode *dvp,
570 struct componentname *cnp)
574 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_lookup");
576 MAC_POLICY_CHECK(vnode_check_lookup, cred, dvp, dvp->v_label, cnp);
577 MAC_CHECK_PROBE3(vnode_check_lookup, error, cred, dvp, cnp);
582 MAC_CHECK_PROBE_DEFINE4(vnode_check_mmap, "struct ucred *", "struct vnode *",
586 mac_vnode_check_mmap(struct ucred *cred, struct vnode *vp, int prot,
591 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_mmap");
593 MAC_POLICY_CHECK(vnode_check_mmap, cred, vp, vp->v_label, prot, flags);
594 MAC_CHECK_PROBE4(vnode_check_mmap, error, cred, vp, prot, flags);
600 mac_vnode_check_mmap_downgrade(struct ucred *cred, struct vnode *vp,
605 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_mmap_downgrade");
607 MAC_POLICY_PERFORM(vnode_check_mmap_downgrade, cred, vp, vp->v_label,
613 MAC_CHECK_PROBE_DEFINE3(vnode_check_mprotect, "struct ucred *",
614 "struct vnode *", "int");
617 mac_vnode_check_mprotect(struct ucred *cred, struct vnode *vp, int prot)
621 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_mprotect");
623 MAC_POLICY_CHECK(vnode_check_mprotect, cred, vp, vp->v_label, prot);
624 MAC_CHECK_PROBE3(vnode_check_mprotect, error, cred, vp, prot);
629 MAC_CHECK_PROBE_DEFINE3(vnode_check_open, "struct ucred *", "struct vnode *",
633 mac_vnode_check_open(struct ucred *cred, struct vnode *vp, accmode_t accmode)
637 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_open");
639 MAC_POLICY_CHECK(vnode_check_open, cred, vp, vp->v_label, accmode);
640 MAC_CHECK_PROBE3(vnode_check_open, error, cred, vp, accmode);
645 MAC_CHECK_PROBE_DEFINE3(vnode_check_poll, "struct ucred *", "struct ucred *",
649 mac_vnode_check_poll(struct ucred *active_cred, struct ucred *file_cred,
654 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_poll");
656 MAC_POLICY_CHECK(vnode_check_poll, active_cred, file_cred, vp,
658 MAC_CHECK_PROBE3(vnode_check_poll, error, active_cred, file_cred,
664 MAC_CHECK_PROBE_DEFINE3(vnode_check_read, "struct ucred *", "struct ucred *",
668 mac_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred,
673 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_read");
675 MAC_POLICY_CHECK(vnode_check_read, active_cred, file_cred, vp,
677 MAC_CHECK_PROBE3(vnode_check_read, error, active_cred, file_cred,
683 MAC_CHECK_PROBE_DEFINE2(vnode_check_readdir, "struct ucred *",
687 mac_vnode_check_readdir(struct ucred *cred, struct vnode *dvp)
691 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_readdir");
693 MAC_POLICY_CHECK(vnode_check_readdir, cred, dvp, dvp->v_label);
694 MAC_CHECK_PROBE2(vnode_check_readdir, error, cred, dvp);
699 MAC_CHECK_PROBE_DEFINE2(vnode_check_readlink, "struct ucred *",
703 mac_vnode_check_readlink(struct ucred *cred, struct vnode *vp)
707 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_readlink");
709 MAC_POLICY_CHECK(vnode_check_readlink, cred, vp, vp->v_label);
710 MAC_CHECK_PROBE2(vnode_check_readlink, error, cred, vp);
715 MAC_CHECK_PROBE_DEFINE3(vnode_check_relabel, "struct ucred *",
716 "struct vnode *", "struct label *");
719 mac_vnode_check_relabel(struct ucred *cred, struct vnode *vp,
720 struct label *newlabel)
724 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_relabel");
726 MAC_POLICY_CHECK(vnode_check_relabel, cred, vp, vp->v_label, newlabel);
727 MAC_CHECK_PROBE3(vnode_check_relabel, error, cred, vp, newlabel);
732 MAC_CHECK_PROBE_DEFINE4(vnode_check_rename_from, "struct ucred *",
733 "struct vnode *", "struct vnode *", "struct componentname *");
736 mac_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp,
737 struct vnode *vp, struct componentname *cnp)
741 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_rename_from");
742 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_rename_from");
744 MAC_POLICY_CHECK(vnode_check_rename_from, cred, dvp, dvp->v_label, vp,
746 MAC_CHECK_PROBE4(vnode_check_rename_from, error, cred, dvp, vp, cnp);
751 MAC_CHECK_PROBE_DEFINE4(vnode_check_rename_to, "struct ucred *",
752 "struct vnode *", "struct vnode *", "struct componentname *");
755 mac_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp,
756 struct vnode *vp, int samedir, struct componentname *cnp)
760 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_rename_to");
761 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_rename_to");
763 MAC_POLICY_CHECK(vnode_check_rename_to, cred, dvp, dvp->v_label, vp,
764 vp != NULL ? vp->v_label : NULL, samedir, cnp);
765 MAC_CHECK_PROBE4(vnode_check_rename_to, error, cred, dvp, vp, cnp);
769 MAC_CHECK_PROBE_DEFINE2(vnode_check_revoke, "struct ucred *",
773 mac_vnode_check_revoke(struct ucred *cred, struct vnode *vp)
777 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_revoke");
779 MAC_POLICY_CHECK(vnode_check_revoke, cred, vp, vp->v_label);
780 MAC_CHECK_PROBE2(vnode_check_revoke, error, cred, vp);
785 MAC_CHECK_PROBE_DEFINE4(vnode_check_setacl, "struct ucred *",
786 "struct vnode *", "acl_type_t", "struct acl *");
789 mac_vnode_check_setacl(struct ucred *cred, struct vnode *vp, acl_type_t type,
794 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setacl");
796 MAC_POLICY_CHECK(vnode_check_setacl, cred, vp, vp->v_label, type, acl);
797 MAC_CHECK_PROBE4(vnode_check_setacl, error, cred, vp, type, acl);
802 MAC_CHECK_PROBE_DEFINE4(vnode_check_setextattr, "struct ucred *",
803 "struct vnode *", "int", "const char *");
806 mac_vnode_check_setextattr(struct ucred *cred, struct vnode *vp,
807 int attrnamespace, const char *name)
811 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setextattr");
813 MAC_POLICY_CHECK(vnode_check_setextattr, cred, vp, vp->v_label,
814 attrnamespace, name);
815 MAC_CHECK_PROBE4(vnode_check_setextattr, error, cred, vp,
816 attrnamespace, name);
821 MAC_CHECK_PROBE_DEFINE3(vnode_check_setflags, "struct ucred *",
822 "struct vnode *", "u_long");
825 mac_vnode_check_setflags(struct ucred *cred, struct vnode *vp, u_long flags)
829 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setflags");
831 MAC_POLICY_CHECK(vnode_check_setflags, cred, vp, vp->v_label, flags);
832 MAC_CHECK_PROBE3(vnode_check_setflags, error, cred, vp, flags);
837 MAC_CHECK_PROBE_DEFINE3(vnode_check_setmode, "struct ucred *",
838 "struct vnode *", "mode_t");
841 mac_vnode_check_setmode(struct ucred *cred, struct vnode *vp, mode_t mode)
845 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setmode");
847 MAC_POLICY_CHECK(vnode_check_setmode, cred, vp, vp->v_label, mode);
848 MAC_CHECK_PROBE3(vnode_check_setmode, error, cred, vp, mode);
853 MAC_CHECK_PROBE_DEFINE4(vnode_check_setowner, "struct ucred *",
854 "struct vnode *", "uid_t", "gid_t");
857 mac_vnode_check_setowner(struct ucred *cred, struct vnode *vp, uid_t uid,
862 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setowner");
864 MAC_POLICY_CHECK(vnode_check_setowner, cred, vp, vp->v_label, uid, gid);
865 MAC_CHECK_PROBE4(vnode_check_setowner, error, cred, vp, uid, gid);
870 MAC_CHECK_PROBE_DEFINE4(vnode_check_setutimes, "struct ucred *",
871 "struct vnode *", "struct timespec *", "struct timespec *");
874 mac_vnode_check_setutimes(struct ucred *cred, struct vnode *vp,
875 struct timespec atime, struct timespec mtime)
879 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setutimes");
881 MAC_POLICY_CHECK(vnode_check_setutimes, cred, vp, vp->v_label, atime,
883 MAC_CHECK_PROBE4(vnode_check_setutimes, error, cred, vp, &atime,
889 MAC_CHECK_PROBE_DEFINE3(vnode_check_stat, "struct ucred *", "struct ucred *",
893 mac_vnode_check_stat(struct ucred *active_cred, struct ucred *file_cred,
898 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_stat");
900 MAC_POLICY_CHECK(vnode_check_stat, active_cred, file_cred, vp,
902 MAC_CHECK_PROBE3(vnode_check_stat, error, active_cred, file_cred,
908 MAC_CHECK_PROBE_DEFINE4(vnode_check_unlink, "struct ucred *",
909 "struct vnode *", "struct vnode *", "struct componentname *");
912 mac_vnode_check_unlink(struct ucred *cred, struct vnode *dvp,
913 struct vnode *vp, struct componentname *cnp)
917 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_unlink");
918 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_unlink");
920 MAC_POLICY_CHECK(vnode_check_unlink, cred, dvp, dvp->v_label, vp,
922 MAC_CHECK_PROBE4(vnode_check_unlink, error, cred, dvp, vp, cnp);
927 MAC_CHECK_PROBE_DEFINE3(vnode_check_write, "struct ucred *",
928 "struct ucred *", "struct vnode *");
931 mac_vnode_check_write(struct ucred *active_cred, struct ucred *file_cred,
936 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_write");
938 MAC_POLICY_CHECK(vnode_check_write, active_cred, file_cred, vp,
940 MAC_CHECK_PROBE3(vnode_check_write, error, active_cred, file_cred,
947 mac_vnode_relabel(struct ucred *cred, struct vnode *vp,
948 struct label *newlabel)
951 MAC_POLICY_PERFORM(vnode_relabel, cred, vp, vp->v_label, newlabel);
955 mac_mount_create(struct ucred *cred, struct mount *mp)
958 MAC_POLICY_PERFORM(mount_create, cred, mp, mp->mnt_label);
961 MAC_CHECK_PROBE_DEFINE2(mount_check_stat, "struct ucred *",
965 mac_mount_check_stat(struct ucred *cred, struct mount *mount)
969 MAC_POLICY_CHECK_NOSLEEP(mount_check_stat, cred, mount, mount->mnt_label);
970 MAC_CHECK_PROBE2(mount_check_stat, error, cred, mount);
976 mac_devfs_create_device(struct ucred *cred, struct mount *mp,
977 struct cdev *dev, struct devfs_dirent *de)
980 MAC_POLICY_PERFORM_NOSLEEP(devfs_create_device, cred, mp, dev, de,
985 mac_devfs_create_symlink(struct ucred *cred, struct mount *mp,
986 struct devfs_dirent *dd, struct devfs_dirent *de)
989 MAC_POLICY_PERFORM_NOSLEEP(devfs_create_symlink, cred, mp, dd,
990 dd->de_label, de, de->de_label);
994 mac_devfs_create_directory(struct mount *mp, char *dirname, int dirnamelen,
995 struct devfs_dirent *de)
998 MAC_POLICY_PERFORM_NOSLEEP(devfs_create_directory, mp, dirname,
999 dirnamelen, de, de->de_label);
1003 * Implementation of VOP_SETLABEL() that relies on extended attributes to
1004 * store label data. Can be referenced by filesystems supporting extended
1008 vop_stdsetlabel_ea(struct vop_setlabel_args *ap)
1010 struct vnode *vp = ap->a_vp;
1011 struct label *intlabel = ap->a_label;
1014 ASSERT_VOP_LOCKED(vp, "vop_stdsetlabel_ea");
1016 if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
1017 return (EOPNOTSUPP);
1019 error = mac_vnode_setlabel_extattr(ap->a_cred, vp, intlabel);
1023 mac_vnode_relabel(ap->a_cred, vp, intlabel);
1029 vn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred)
1033 if (vp->v_mount == NULL) {
1034 /* printf("vn_setlabel: null v_mount\n"); */
1035 if (vp->v_type != VNON)
1036 printf("vn_setlabel: null v_mount with non-VNON\n");
1040 if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
1041 return (EOPNOTSUPP);
1044 * Multi-phase commit. First check the policies to confirm the
1045 * change is OK. Then commit via the filesystem. Finally, update
1046 * the actual vnode label.
1048 * Question: maybe the filesystem should update the vnode at the end
1049 * as part of VOP_SETLABEL()?
1051 error = mac_vnode_check_relabel(cred, vp, intlabel);
1056 * VADMIN provides the opportunity for the filesystem to make
1057 * decisions about who is and is not able to modify labels and
1058 * protections on files. This might not be right. We can't assume
1059 * VOP_SETLABEL() will do it, because we might implement that as part
1060 * of vop_stdsetlabel_ea().
1062 error = VOP_ACCESS(vp, VADMIN, cred, curthread);
1066 error = VOP_SETLABEL(vp, intlabel, cred, curthread);