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$");
50 #include <sys/param.h>
51 #include <sys/condvar.h>
52 #include <sys/extattr.h>
53 #include <sys/imgact.h>
54 #include <sys/kernel.h>
56 #include <sys/malloc.h>
57 #include <sys/mutex.h>
60 #include <sys/systm.h>
61 #include <sys/vnode.h>
62 #include <sys/mount.h>
64 #include <sys/namei.h>
66 #include <sys/sysctl.h>
70 #include <vm/vm_map.h>
71 #include <vm/vm_object.h>
73 #include <fs/devfs/devfs.h>
75 #include <security/mac/mac_framework.h>
76 #include <security/mac/mac_internal.h>
77 #include <security/mac/mac_policy.h>
80 * Warn about EA transactions only the first time they happen. No locking on
83 static int ea_warn_once = 0;
85 static int mac_vnode_setlabel_extattr(struct ucred *cred,
86 struct vnode *vp, struct label *intlabel);
89 mac_devfs_label_alloc(void)
93 label = mac_labelzone_alloc(M_WAITOK);
94 MAC_POLICY_PERFORM(devfs_init_label, label);
99 mac_devfs_init(struct devfs_dirent *de)
102 if (mac_labeled & MPC_OBJECT_DEVFS)
103 de->de_label = mac_devfs_label_alloc();
108 static struct label *
109 mac_mount_label_alloc(void)
113 label = mac_labelzone_alloc(M_WAITOK);
114 MAC_POLICY_PERFORM(mount_init_label, label);
119 mac_mount_init(struct mount *mp)
122 if (mac_labeled & MPC_OBJECT_MOUNT)
123 mp->mnt_label = mac_mount_label_alloc();
125 mp->mnt_label = NULL;
129 mac_vnode_label_alloc(void)
133 label = mac_labelzone_alloc(M_WAITOK);
134 MAC_POLICY_PERFORM(vnode_init_label, label);
139 mac_vnode_init(struct vnode *vp)
142 if (mac_labeled & MPC_OBJECT_VNODE)
143 vp->v_label = mac_vnode_label_alloc();
149 mac_devfs_label_free(struct label *label)
152 MAC_POLICY_PERFORM_NOSLEEP(devfs_destroy_label, label);
153 mac_labelzone_free(label);
157 mac_devfs_destroy(struct devfs_dirent *de)
160 if (de->de_label != NULL) {
161 mac_devfs_label_free(de->de_label);
167 mac_mount_label_free(struct label *label)
170 MAC_POLICY_PERFORM_NOSLEEP(mount_destroy_label, label);
171 mac_labelzone_free(label);
175 mac_mount_destroy(struct mount *mp)
178 if (mp->mnt_label != NULL) {
179 mac_mount_label_free(mp->mnt_label);
180 mp->mnt_label = NULL;
185 mac_vnode_label_free(struct label *label)
188 MAC_POLICY_PERFORM_NOSLEEP(vnode_destroy_label, label);
189 mac_labelzone_free(label);
193 mac_vnode_destroy(struct vnode *vp)
196 if (vp->v_label != NULL) {
197 mac_vnode_label_free(vp->v_label);
203 mac_vnode_copy_label(struct label *src, struct label *dest)
206 MAC_POLICY_PERFORM_NOSLEEP(vnode_copy_label, src, dest);
210 mac_vnode_externalize_label(struct label *label, char *elements,
211 char *outbuf, size_t outbuflen)
215 MAC_POLICY_EXTERNALIZE(vnode, label, elements, outbuf, outbuflen);
221 mac_vnode_internalize_label(struct label *label, char *string)
225 MAC_POLICY_INTERNALIZE(vnode, label, string);
231 mac_devfs_update(struct mount *mp, struct devfs_dirent *de, struct vnode *vp)
234 MAC_POLICY_PERFORM_NOSLEEP(devfs_update, mp, de, de->de_label, vp,
239 mac_devfs_vnode_associate(struct mount *mp, struct devfs_dirent *de,
243 MAC_POLICY_PERFORM_NOSLEEP(devfs_vnode_associate, mp, mp->mnt_label,
244 de, de->de_label, vp, vp->v_label);
248 mac_vnode_associate_extattr(struct mount *mp, struct vnode *vp)
252 ASSERT_VOP_LOCKED(vp, "mac_vnode_associate_extattr");
254 MAC_POLICY_CHECK(vnode_associate_extattr, mp, mp->mnt_label, vp,
261 mac_vnode_associate_singlelabel(struct mount *mp, struct vnode *vp)
264 MAC_POLICY_PERFORM_NOSLEEP(vnode_associate_singlelabel, mp,
265 mp->mnt_label, vp, vp->v_label);
269 * Functions implementing extended-attribute backed labels for file systems
272 * Where possible, we use EA transactions to make writes to multiple
273 * attributes across difference policies mutually atomic. We allow work to
274 * continue on file systems not supporting EA transactions, but generate a
278 mac_vnode_create_extattr(struct ucred *cred, struct mount *mp,
279 struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
283 ASSERT_VOP_LOCKED(dvp, "mac_vnode_create_extattr");
284 ASSERT_VOP_LOCKED(vp, "mac_vnode_create_extattr");
286 error = VOP_OPENEXTATTR(vp, cred, curthread);
287 if (error == EOPNOTSUPP) {
288 if (ea_warn_once == 0) {
289 printf("Warning: transactions not supported "
296 MAC_POLICY_CHECK(vnode_create_extattr, cred, mp, mp->mnt_label, dvp,
297 dvp->v_label, vp, vp->v_label, cnp);
300 VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
304 error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
305 if (error == EOPNOTSUPP)
312 mac_vnode_setlabel_extattr(struct ucred *cred, struct vnode *vp,
313 struct label *intlabel)
317 ASSERT_VOP_LOCKED(vp, "mac_vnode_setlabel_extattr");
319 error = VOP_OPENEXTATTR(vp, cred, curthread);
320 if (error == EOPNOTSUPP) {
321 if (ea_warn_once == 0) {
322 printf("Warning: transactions not supported "
329 MAC_POLICY_CHECK(vnode_setlabel_extattr, cred, vp, vp->v_label,
333 VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread);
337 error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread);
338 if (error == EOPNOTSUPP)
345 mac_vnode_execve_transition(struct ucred *old, struct ucred *new,
346 struct vnode *vp, struct label *interpvplabel, struct image_params *imgp)
349 ASSERT_VOP_LOCKED(vp, "mac_vnode_execve_transition");
351 MAC_POLICY_PERFORM(vnode_execve_transition, old, new, vp,
352 vp->v_label, interpvplabel, imgp, imgp->execlabel);
356 mac_vnode_execve_will_transition(struct ucred *old, struct vnode *vp,
357 struct label *interpvplabel, struct image_params *imgp)
361 ASSERT_VOP_LOCKED(vp, "mac_vnode_execve_will_transition");
364 /* No sleeping since the process lock will be held by the caller. */
365 MAC_POLICY_BOOLEAN_NOSLEEP(vnode_execve_will_transition, ||, old, vp,
366 vp->v_label, interpvplabel, imgp, imgp->execlabel);
371 MAC_CHECK_PROBE_DEFINE3(vnode_check_access, "struct ucred *",
372 "struct vnode *", "accmode_t");
375 mac_vnode_check_access(struct ucred *cred, struct vnode *vp, accmode_t accmode)
379 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_access");
381 MAC_POLICY_CHECK(vnode_check_access, cred, vp, vp->v_label, accmode);
382 MAC_CHECK_PROBE3(vnode_check_access, error, cred, vp, accmode);
387 MAC_CHECK_PROBE_DEFINE2(vnode_check_chdir, "struct ucred *",
391 mac_vnode_check_chdir(struct ucred *cred, struct vnode *dvp)
395 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_chdir");
397 MAC_POLICY_CHECK(vnode_check_chdir, cred, dvp, dvp->v_label);
398 MAC_CHECK_PROBE2(vnode_check_chdir, error, cred, dvp);
403 MAC_CHECK_PROBE_DEFINE2(vnode_check_chroot, "struct ucred *",
407 mac_vnode_check_chroot(struct ucred *cred, struct vnode *dvp)
411 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_chroot");
413 MAC_POLICY_CHECK(vnode_check_chroot, cred, dvp, dvp->v_label);
414 MAC_CHECK_PROBE2(vnode_check_chroot, error, cred, dvp);
419 MAC_CHECK_PROBE_DEFINE4(vnode_check_create, "struct ucred *",
420 "struct vnode *", "struct componentname *", "struct vattr *");
423 mac_vnode_check_create(struct ucred *cred, struct vnode *dvp,
424 struct componentname *cnp, struct vattr *vap)
428 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_create");
430 MAC_POLICY_CHECK(vnode_check_create, cred, dvp, dvp->v_label, cnp,
432 MAC_CHECK_PROBE4(vnode_check_create, error, cred, dvp, cnp, vap);
437 MAC_CHECK_PROBE_DEFINE3(vnode_check_deleteacl, "struct ucred *",
438 "struct vnode *", "acl_type_t");
441 mac_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp,
446 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_deleteacl");
448 MAC_POLICY_CHECK(vnode_check_deleteacl, cred, vp, vp->v_label, type);
449 MAC_CHECK_PROBE3(vnode_check_deleteacl, error, cred, vp, type);
454 MAC_CHECK_PROBE_DEFINE4(vnode_check_deleteextattr, "struct ucred *",
455 "struct vnode *", "int", "const char *");
458 mac_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp,
459 int attrnamespace, const char *name)
463 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_deleteextattr");
465 MAC_POLICY_CHECK(vnode_check_deleteextattr, cred, vp, vp->v_label,
466 attrnamespace, name);
467 MAC_CHECK_PROBE4(vnode_check_deleteextattr, error, cred, vp,
468 attrnamespace, name);
473 MAC_CHECK_PROBE_DEFINE3(vnode_check_exec, "struct ucred *", "struct vnode *",
474 "struct image_params *");
477 mac_vnode_check_exec(struct ucred *cred, struct vnode *vp,
478 struct image_params *imgp)
482 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_exec");
484 MAC_POLICY_CHECK(vnode_check_exec, cred, vp, vp->v_label, imgp,
486 MAC_CHECK_PROBE3(vnode_check_exec, error, cred, vp, imgp);
491 MAC_CHECK_PROBE_DEFINE3(vnode_check_getacl, "struct ucred *",
492 "struct vnode *", "acl_type_t");
495 mac_vnode_check_getacl(struct ucred *cred, struct vnode *vp, acl_type_t type)
499 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_getacl");
501 MAC_POLICY_CHECK(vnode_check_getacl, cred, vp, vp->v_label, type);
502 MAC_CHECK_PROBE3(vnode_check_getacl, error, cred, vp, type);
507 MAC_CHECK_PROBE_DEFINE4(vnode_check_getextattr, "struct ucred *",
508 "struct vnode *", "int", "const char *");
511 mac_vnode_check_getextattr(struct ucred *cred, struct vnode *vp,
512 int attrnamespace, const char *name)
516 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_getextattr");
518 MAC_POLICY_CHECK(vnode_check_getextattr, cred, vp, vp->v_label,
519 attrnamespace, name);
520 MAC_CHECK_PROBE4(vnode_check_getextattr, error, cred, vp,
521 attrnamespace, name);
526 MAC_CHECK_PROBE_DEFINE4(vnode_check_link, "struct ucred *", "struct vnode *",
527 "struct vnode *", "struct componentname *");
530 mac_vnode_check_link(struct ucred *cred, struct vnode *dvp,
531 struct vnode *vp, struct componentname *cnp)
535 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_link");
536 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_link");
538 MAC_POLICY_CHECK(vnode_check_link, cred, dvp, dvp->v_label, vp,
540 MAC_CHECK_PROBE4(vnode_check_link, error, cred, dvp, vp, cnp);
545 MAC_CHECK_PROBE_DEFINE3(vnode_check_listextattr, "struct ucred *",
546 "struct vnode *", "int");
549 mac_vnode_check_listextattr(struct ucred *cred, struct vnode *vp,
554 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_listextattr");
556 MAC_POLICY_CHECK(vnode_check_listextattr, cred, vp, vp->v_label,
558 MAC_CHECK_PROBE3(vnode_check_listextattr, error, cred, vp,
564 MAC_CHECK_PROBE_DEFINE3(vnode_check_lookup, "struct ucred *",
565 "struct vnode *", "struct componentname *");
568 mac_vnode_check_lookup(struct ucred *cred, struct vnode *dvp,
569 struct componentname *cnp)
573 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_lookup");
575 MAC_POLICY_CHECK(vnode_check_lookup, cred, dvp, dvp->v_label, cnp);
576 MAC_CHECK_PROBE3(vnode_check_lookup, error, cred, dvp, cnp);
581 MAC_CHECK_PROBE_DEFINE4(vnode_check_mmap, "struct ucred *", "struct vnode *",
585 mac_vnode_check_mmap(struct ucred *cred, struct vnode *vp, int prot,
590 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_mmap");
592 MAC_POLICY_CHECK(vnode_check_mmap, cred, vp, vp->v_label, prot, flags);
593 MAC_CHECK_PROBE4(vnode_check_mmap, error, cred, vp, prot, flags);
599 mac_vnode_check_mmap_downgrade(struct ucred *cred, struct vnode *vp,
604 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_mmap_downgrade");
606 MAC_POLICY_PERFORM(vnode_check_mmap_downgrade, cred, vp, vp->v_label,
612 MAC_CHECK_PROBE_DEFINE3(vnode_check_mprotect, "struct ucred *",
613 "struct vnode *", "int");
616 mac_vnode_check_mprotect(struct ucred *cred, struct vnode *vp, int prot)
620 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_mprotect");
622 MAC_POLICY_CHECK(vnode_check_mprotect, cred, vp, vp->v_label, prot);
623 MAC_CHECK_PROBE3(vnode_check_mprotect, error, cred, vp, prot);
628 MAC_CHECK_PROBE_DEFINE3(vnode_check_open, "struct ucred *", "struct vnode *",
632 mac_vnode_check_open(struct ucred *cred, struct vnode *vp, accmode_t accmode)
636 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_open");
638 MAC_POLICY_CHECK(vnode_check_open, cred, vp, vp->v_label, accmode);
639 MAC_CHECK_PROBE3(vnode_check_open, error, cred, vp, accmode);
644 MAC_CHECK_PROBE_DEFINE3(vnode_check_poll, "struct ucred *", "struct ucred *",
648 mac_vnode_check_poll(struct ucred *active_cred, struct ucred *file_cred,
653 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_poll");
655 MAC_POLICY_CHECK(vnode_check_poll, active_cred, file_cred, vp,
657 MAC_CHECK_PROBE3(vnode_check_poll, error, active_cred, file_cred,
663 MAC_CHECK_PROBE_DEFINE3(vnode_check_read, "struct ucred *", "struct ucred *",
667 mac_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred,
672 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_read");
674 MAC_POLICY_CHECK(vnode_check_read, active_cred, file_cred, vp,
676 MAC_CHECK_PROBE3(vnode_check_read, error, active_cred, file_cred,
682 MAC_CHECK_PROBE_DEFINE2(vnode_check_readdir, "struct ucred *",
686 mac_vnode_check_readdir(struct ucred *cred, struct vnode *dvp)
690 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_readdir");
692 MAC_POLICY_CHECK(vnode_check_readdir, cred, dvp, dvp->v_label);
693 MAC_CHECK_PROBE2(vnode_check_readdir, error, cred, dvp);
698 MAC_CHECK_PROBE_DEFINE2(vnode_check_readlink, "struct ucred *",
702 mac_vnode_check_readlink(struct ucred *cred, struct vnode *vp)
706 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_readlink");
708 MAC_POLICY_CHECK(vnode_check_readlink, cred, vp, vp->v_label);
709 MAC_CHECK_PROBE2(vnode_check_readlink, error, cred, vp);
714 MAC_CHECK_PROBE_DEFINE3(vnode_check_relabel, "struct ucred *",
715 "struct vnode *", "struct label *");
718 mac_vnode_check_relabel(struct ucred *cred, struct vnode *vp,
719 struct label *newlabel)
723 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_relabel");
725 MAC_POLICY_CHECK(vnode_check_relabel, cred, vp, vp->v_label, newlabel);
726 MAC_CHECK_PROBE3(vnode_check_relabel, error, cred, vp, newlabel);
731 MAC_CHECK_PROBE_DEFINE4(vnode_check_rename_from, "struct ucred *",
732 "struct vnode *", "struct vnode *", "struct componentname *");
735 mac_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp,
736 struct vnode *vp, struct componentname *cnp)
740 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_rename_from");
741 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_rename_from");
743 MAC_POLICY_CHECK(vnode_check_rename_from, cred, dvp, dvp->v_label, vp,
745 MAC_CHECK_PROBE4(vnode_check_rename_from, error, cred, dvp, vp, cnp);
750 MAC_CHECK_PROBE_DEFINE4(vnode_check_rename_to, "struct ucred *",
751 "struct vnode *", "struct vnode *", "struct componentname *");
754 mac_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp,
755 struct vnode *vp, int samedir, struct componentname *cnp)
759 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_rename_to");
760 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_rename_to");
762 MAC_POLICY_CHECK(vnode_check_rename_to, cred, dvp, dvp->v_label, vp,
763 vp != NULL ? vp->v_label : NULL, samedir, cnp);
764 MAC_CHECK_PROBE4(vnode_check_rename_to, error, cred, dvp, vp, cnp);
768 MAC_CHECK_PROBE_DEFINE2(vnode_check_revoke, "struct ucred *",
772 mac_vnode_check_revoke(struct ucred *cred, struct vnode *vp)
776 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_revoke");
778 MAC_POLICY_CHECK(vnode_check_revoke, cred, vp, vp->v_label);
779 MAC_CHECK_PROBE2(vnode_check_revoke, error, cred, vp);
784 MAC_CHECK_PROBE_DEFINE4(vnode_check_setacl, "struct ucred *",
785 "struct vnode *", "acl_type_t", "struct acl *");
788 mac_vnode_check_setacl(struct ucred *cred, struct vnode *vp, acl_type_t type,
793 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setacl");
795 MAC_POLICY_CHECK(vnode_check_setacl, cred, vp, vp->v_label, type, acl);
796 MAC_CHECK_PROBE4(vnode_check_setacl, error, cred, vp, type, acl);
801 MAC_CHECK_PROBE_DEFINE4(vnode_check_setextattr, "struct ucred *",
802 "struct vnode *", "int", "const char *");
805 mac_vnode_check_setextattr(struct ucred *cred, struct vnode *vp,
806 int attrnamespace, const char *name)
810 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setextattr");
812 MAC_POLICY_CHECK(vnode_check_setextattr, cred, vp, vp->v_label,
813 attrnamespace, name);
814 MAC_CHECK_PROBE4(vnode_check_setextattr, error, cred, vp,
815 attrnamespace, name);
820 MAC_CHECK_PROBE_DEFINE3(vnode_check_setflags, "struct ucred *",
821 "struct vnode *", "u_long");
824 mac_vnode_check_setflags(struct ucred *cred, struct vnode *vp, u_long flags)
828 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setflags");
830 MAC_POLICY_CHECK(vnode_check_setflags, cred, vp, vp->v_label, flags);
831 MAC_CHECK_PROBE3(vnode_check_setflags, error, cred, vp, flags);
836 MAC_CHECK_PROBE_DEFINE3(vnode_check_setmode, "struct ucred *",
837 "struct vnode *", "mode_t");
840 mac_vnode_check_setmode(struct ucred *cred, struct vnode *vp, mode_t mode)
844 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setmode");
846 MAC_POLICY_CHECK(vnode_check_setmode, cred, vp, vp->v_label, mode);
847 MAC_CHECK_PROBE3(vnode_check_setmode, error, cred, vp, mode);
852 MAC_CHECK_PROBE_DEFINE4(vnode_check_setowner, "struct ucred *",
853 "struct vnode *", "uid_t", "gid_t");
856 mac_vnode_check_setowner(struct ucred *cred, struct vnode *vp, uid_t uid,
861 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setowner");
863 MAC_POLICY_CHECK(vnode_check_setowner, cred, vp, vp->v_label, uid, gid);
864 MAC_CHECK_PROBE4(vnode_check_setowner, error, cred, vp, uid, gid);
869 MAC_CHECK_PROBE_DEFINE4(vnode_check_setutimes, "struct ucred *",
870 "struct vnode *", "struct timespec *", "struct timespec *");
873 mac_vnode_check_setutimes(struct ucred *cred, struct vnode *vp,
874 struct timespec atime, struct timespec mtime)
878 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setutimes");
880 MAC_POLICY_CHECK(vnode_check_setutimes, cred, vp, vp->v_label, atime,
882 MAC_CHECK_PROBE4(vnode_check_setutimes, error, cred, vp, &atime,
888 MAC_CHECK_PROBE_DEFINE3(vnode_check_stat, "struct ucred *", "struct ucred *",
892 mac_vnode_check_stat(struct ucred *active_cred, struct ucred *file_cred,
897 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_stat");
899 MAC_POLICY_CHECK(vnode_check_stat, active_cred, file_cred, vp,
901 MAC_CHECK_PROBE3(vnode_check_stat, error, active_cred, file_cred,
907 MAC_CHECK_PROBE_DEFINE4(vnode_check_unlink, "struct ucred *",
908 "struct vnode *", "struct vnode *", "struct componentname *");
911 mac_vnode_check_unlink(struct ucred *cred, struct vnode *dvp,
912 struct vnode *vp, struct componentname *cnp)
916 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_unlink");
917 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_unlink");
919 MAC_POLICY_CHECK(vnode_check_unlink, cred, dvp, dvp->v_label, vp,
921 MAC_CHECK_PROBE4(vnode_check_unlink, error, cred, dvp, vp, cnp);
926 MAC_CHECK_PROBE_DEFINE3(vnode_check_write, "struct ucred *",
927 "struct ucred *", "struct vnode *");
930 mac_vnode_check_write(struct ucred *active_cred, struct ucred *file_cred,
935 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_write");
937 MAC_POLICY_CHECK(vnode_check_write, active_cred, file_cred, vp,
939 MAC_CHECK_PROBE3(vnode_check_write, error, active_cred, file_cred,
946 mac_vnode_relabel(struct ucred *cred, struct vnode *vp,
947 struct label *newlabel)
950 MAC_POLICY_PERFORM(vnode_relabel, cred, vp, vp->v_label, newlabel);
954 mac_mount_create(struct ucred *cred, struct mount *mp)
957 MAC_POLICY_PERFORM(mount_create, cred, mp, mp->mnt_label);
960 MAC_CHECK_PROBE_DEFINE2(mount_check_stat, "struct ucred *",
964 mac_mount_check_stat(struct ucred *cred, struct mount *mount)
968 MAC_POLICY_CHECK_NOSLEEP(mount_check_stat, cred, mount, mount->mnt_label);
969 MAC_CHECK_PROBE2(mount_check_stat, error, cred, mount);
975 mac_devfs_create_device(struct ucred *cred, struct mount *mp,
976 struct cdev *dev, struct devfs_dirent *de)
979 MAC_POLICY_PERFORM_NOSLEEP(devfs_create_device, cred, mp, dev, de,
984 mac_devfs_create_symlink(struct ucred *cred, struct mount *mp,
985 struct devfs_dirent *dd, struct devfs_dirent *de)
988 MAC_POLICY_PERFORM_NOSLEEP(devfs_create_symlink, cred, mp, dd,
989 dd->de_label, de, de->de_label);
993 mac_devfs_create_directory(struct mount *mp, char *dirname, int dirnamelen,
994 struct devfs_dirent *de)
997 MAC_POLICY_PERFORM_NOSLEEP(devfs_create_directory, mp, dirname,
998 dirnamelen, de, de->de_label);
1002 * Implementation of VOP_SETLABEL() that relies on extended attributes to
1003 * store label data. Can be referenced by filesystems supporting extended
1007 vop_stdsetlabel_ea(struct vop_setlabel_args *ap)
1009 struct vnode *vp = ap->a_vp;
1010 struct label *intlabel = ap->a_label;
1013 ASSERT_VOP_LOCKED(vp, "vop_stdsetlabel_ea");
1015 if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
1016 return (EOPNOTSUPP);
1018 error = mac_vnode_setlabel_extattr(ap->a_cred, vp, intlabel);
1022 mac_vnode_relabel(ap->a_cred, vp, intlabel);
1028 vn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred)
1032 if (vp->v_mount == NULL) {
1033 /* printf("vn_setlabel: null v_mount\n"); */
1034 if (vp->v_type != VNON)
1035 printf("vn_setlabel: null v_mount with non-VNON\n");
1039 if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
1040 return (EOPNOTSUPP);
1043 * Multi-phase commit. First check the policies to confirm the
1044 * change is OK. Then commit via the filesystem. Finally, update
1045 * the actual vnode label.
1047 * Question: maybe the filesystem should update the vnode at the end
1048 * as part of VOP_SETLABEL()?
1050 error = mac_vnode_check_relabel(cred, vp, intlabel);
1055 * VADMIN provides the opportunity for the filesystem to make
1056 * decisions about who is and is not able to modify labels and
1057 * protections on files. This might not be right. We can't assume
1058 * VOP_SETLABEL() will do it, because we might implement that as part
1059 * of vop_stdsetlabel_ea().
1061 error = VOP_ACCESS(vp, VADMIN, cred, curthread);
1065 error = VOP_SETLABEL(vp, intlabel, cred, curthread);