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);
643 MAC_CHECK_PROBE_DEFINE3(vnode_check_poll, "struct ucred *", "struct ucred *",
647 mac_vnode_check_poll(struct ucred *active_cred, struct ucred *file_cred,
652 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_poll");
654 MAC_POLICY_CHECK(vnode_check_poll, active_cred, file_cred, vp,
656 MAC_CHECK_PROBE3(vnode_check_poll, error, active_cred, file_cred,
662 MAC_CHECK_PROBE_DEFINE3(vnode_check_read, "struct ucred *", "struct ucred *",
666 mac_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred,
671 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_read");
673 MAC_POLICY_CHECK(vnode_check_read, active_cred, file_cred, vp,
675 MAC_CHECK_PROBE3(vnode_check_read, error, active_cred, file_cred,
681 MAC_CHECK_PROBE_DEFINE2(vnode_check_readdir, "struct ucred *",
685 mac_vnode_check_readdir(struct ucred *cred, struct vnode *dvp)
689 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_readdir");
691 MAC_POLICY_CHECK(vnode_check_readdir, cred, dvp, dvp->v_label);
692 MAC_CHECK_PROBE2(vnode_check_readdir, error, cred, dvp);
697 MAC_CHECK_PROBE_DEFINE2(vnode_check_readlink, "struct ucred *",
701 mac_vnode_check_readlink(struct ucred *cred, struct vnode *vp)
705 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_readlink");
707 MAC_POLICY_CHECK(vnode_check_readlink, cred, vp, vp->v_label);
708 MAC_CHECK_PROBE2(vnode_check_readlink, error, cred, vp);
713 MAC_CHECK_PROBE_DEFINE3(vnode_check_relabel, "struct ucred *",
714 "struct vnode *", "struct label *");
717 mac_vnode_check_relabel(struct ucred *cred, struct vnode *vp,
718 struct label *newlabel)
722 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_relabel");
724 MAC_POLICY_CHECK(vnode_check_relabel, cred, vp, vp->v_label, newlabel);
725 MAC_CHECK_PROBE3(vnode_check_relabel, error, cred, vp, newlabel);
730 MAC_CHECK_PROBE_DEFINE4(vnode_check_rename_from, "struct ucred *",
731 "struct vnode *", "struct vnode *", "struct componentname *");
734 mac_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp,
735 struct vnode *vp, struct componentname *cnp)
739 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_rename_from");
740 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_rename_from");
742 MAC_POLICY_CHECK(vnode_check_rename_from, cred, dvp, dvp->v_label, vp,
744 MAC_CHECK_PROBE4(vnode_check_rename_from, error, cred, dvp, vp, cnp);
749 MAC_CHECK_PROBE_DEFINE4(vnode_check_rename_to, "struct ucred *",
750 "struct vnode *", "struct vnode *", "struct componentname *");
753 mac_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp,
754 struct vnode *vp, int samedir, struct componentname *cnp)
758 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_rename_to");
759 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_rename_to");
761 MAC_POLICY_CHECK(vnode_check_rename_to, cred, dvp, dvp->v_label, vp,
762 vp != NULL ? vp->v_label : NULL, samedir, cnp);
763 MAC_CHECK_PROBE4(vnode_check_rename_to, error, cred, dvp, vp, cnp);
767 MAC_CHECK_PROBE_DEFINE2(vnode_check_revoke, "struct ucred *",
771 mac_vnode_check_revoke(struct ucred *cred, struct vnode *vp)
775 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_revoke");
777 MAC_POLICY_CHECK(vnode_check_revoke, cred, vp, vp->v_label);
778 MAC_CHECK_PROBE2(vnode_check_revoke, error, cred, vp);
783 MAC_CHECK_PROBE_DEFINE4(vnode_check_setacl, "struct ucred *",
784 "struct vnode *", "acl_tpe_t", "struct acl *");
787 mac_vnode_check_setacl(struct ucred *cred, struct vnode *vp, acl_type_t type,
792 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setacl");
794 MAC_POLICY_CHECK(vnode_check_setacl, cred, vp, vp->v_label, type, acl);
795 MAC_CHECK_PROBE4(vnode_check_setacl, error, cred, vp, type, acl);
800 MAC_CHECK_PROBE_DEFINE4(vnode_check_setextattr, "struct ucred *",
801 "struct vnode *", "int", "const char *");
804 mac_vnode_check_setextattr(struct ucred *cred, struct vnode *vp,
805 int attrnamespace, const char *name)
809 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setextattr");
811 MAC_POLICY_CHECK(vnode_check_setextattr, cred, vp, vp->v_label,
812 attrnamespace, name);
813 MAC_CHECK_PROBE4(vnode_check_setextattr, error, cred, vp,
814 attrnamespace, name);
819 MAC_CHECK_PROBE_DEFINE3(vnode_check_setflags, "struct ucred *",
820 "struct vnode *", "u_long");
823 mac_vnode_check_setflags(struct ucred *cred, struct vnode *vp, u_long flags)
827 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setflags");
829 MAC_POLICY_CHECK(vnode_check_setflags, cred, vp, vp->v_label, flags);
830 MAC_CHECK_PROBE3(vnode_check_setflags, error, cred, vp, flags);
835 MAC_CHECK_PROBE_DEFINE3(vnode_check_setmode, "struct ucred *",
836 "struct vnode *", "mode_t");
839 mac_vnode_check_setmode(struct ucred *cred, struct vnode *vp, mode_t mode)
843 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setmode");
845 MAC_POLICY_CHECK(vnode_check_setmode, cred, vp, vp->v_label, mode);
846 MAC_CHECK_PROBE3(vnode_check_setmode, error, cred, vp, mode);
851 MAC_CHECK_PROBE_DEFINE4(vnode_check_setowner, "struct ucred *",
852 "struct vnode *", "uid_t", "gid_t");
855 mac_vnode_check_setowner(struct ucred *cred, struct vnode *vp, uid_t uid,
860 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setowner");
862 MAC_POLICY_CHECK(vnode_check_setowner, cred, vp, vp->v_label, uid, gid);
863 MAC_CHECK_PROBE4(vnode_check_setowner, error, cred, vp, uid, gid);
868 MAC_CHECK_PROBE_DEFINE4(vnode_check_setutimes, "struct ucred *",
869 "struct vnode *", "struct timespec *", "struct timespec *");
872 mac_vnode_check_setutimes(struct ucred *cred, struct vnode *vp,
873 struct timespec atime, struct timespec mtime)
877 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setutimes");
879 MAC_POLICY_CHECK(vnode_check_setutimes, cred, vp, vp->v_label, atime,
881 MAC_CHECK_PROBE4(vnode_check_setutimes, error, cred, vp, &atime,
887 MAC_CHECK_PROBE_DEFINE3(vnode_check_stat, "struct ucred *", "struct ucred *",
891 mac_vnode_check_stat(struct ucred *active_cred, struct ucred *file_cred,
896 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_stat");
898 MAC_POLICY_CHECK(vnode_check_stat, active_cred, file_cred, vp,
900 MAC_CHECK_PROBE3(vnode_check_stat, error, active_cred, file_cred,
906 MAC_CHECK_PROBE_DEFINE4(vnode_check_unlink, "struct ucred *",
907 "struct vnode *", "struct vnode *", "struct componentname *");
910 mac_vnode_check_unlink(struct ucred *cred, struct vnode *dvp,
911 struct vnode *vp, struct componentname *cnp)
915 ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_unlink");
916 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_unlink");
918 MAC_POLICY_CHECK(vnode_check_unlink, cred, dvp, dvp->v_label, vp,
920 MAC_CHECK_PROBE4(vnode_check_unlink, error, cred, dvp, vp, cnp);
925 MAC_CHECK_PROBE_DEFINE3(vnode_check_write, "struct ucred *",
926 "struct ucred *", "struct vnode *");
929 mac_vnode_check_write(struct ucred *active_cred, struct ucred *file_cred,
934 ASSERT_VOP_LOCKED(vp, "mac_vnode_check_write");
936 MAC_POLICY_CHECK(vnode_check_write, active_cred, file_cred, vp,
938 MAC_CHECK_PROBE3(vnode_check_write, error, active_cred, file_cred,
945 mac_vnode_relabel(struct ucred *cred, struct vnode *vp,
946 struct label *newlabel)
949 MAC_POLICY_PERFORM(vnode_relabel, cred, vp, vp->v_label, newlabel);
953 mac_mount_create(struct ucred *cred, struct mount *mp)
956 MAC_POLICY_PERFORM(mount_create, cred, mp, mp->mnt_label);
959 MAC_CHECK_PROBE_DEFINE2(mount_check_stat, "struct ucred *",
963 mac_mount_check_stat(struct ucred *cred, struct mount *mount)
967 MAC_POLICY_CHECK_NOSLEEP(mount_check_stat, cred, mount, mount->mnt_label);
968 MAC_CHECK_PROBE2(mount_check_stat, error, cred, mount);
974 mac_devfs_create_device(struct ucred *cred, struct mount *mp,
975 struct cdev *dev, struct devfs_dirent *de)
978 MAC_POLICY_PERFORM_NOSLEEP(devfs_create_device, cred, mp, dev, de,
983 mac_devfs_create_symlink(struct ucred *cred, struct mount *mp,
984 struct devfs_dirent *dd, struct devfs_dirent *de)
987 MAC_POLICY_PERFORM_NOSLEEP(devfs_create_symlink, cred, mp, dd,
988 dd->de_label, de, de->de_label);
992 mac_devfs_create_directory(struct mount *mp, char *dirname, int dirnamelen,
993 struct devfs_dirent *de)
996 MAC_POLICY_PERFORM_NOSLEEP(devfs_create_directory, mp, dirname,
997 dirnamelen, de, de->de_label);
1001 * Implementation of VOP_SETLABEL() that relies on extended attributes to
1002 * store label data. Can be referenced by filesystems supporting extended
1006 vop_stdsetlabel_ea(struct vop_setlabel_args *ap)
1008 struct vnode *vp = ap->a_vp;
1009 struct label *intlabel = ap->a_label;
1012 ASSERT_VOP_LOCKED(vp, "vop_stdsetlabel_ea");
1014 if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
1015 return (EOPNOTSUPP);
1017 error = mac_vnode_setlabel_extattr(ap->a_cred, vp, intlabel);
1021 mac_vnode_relabel(ap->a_cred, vp, intlabel);
1027 vn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred)
1031 if (vp->v_mount == NULL) {
1032 /* printf("vn_setlabel: null v_mount\n"); */
1033 if (vp->v_type != VNON)
1034 printf("vn_setlabel: null v_mount with non-VNON\n");
1038 if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0)
1039 return (EOPNOTSUPP);
1042 * Multi-phase commit. First check the policies to confirm the
1043 * change is OK. Then commit via the filesystem. Finally, update
1044 * the actual vnode label.
1046 * Question: maybe the filesystem should update the vnode at the end
1047 * as part of VOP_SETLABEL()?
1049 error = mac_vnode_check_relabel(cred, vp, intlabel);
1054 * VADMIN provides the opportunity for the filesystem to make
1055 * decisions about who is and is not able to modify labels and
1056 * protections on files. This might not be right. We can't assume
1057 * VOP_SETLABEL() will do it, because we might implement that as part
1058 * of vop_stdsetlabel_ea().
1060 error = VOP_ACCESS(vp, VADMIN, cred, curthread);
1064 error = VOP_SETLABEL(vp, intlabel, cred, curthread);