2 * Copyright (c) 2007-2016 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
30 * Copyright (c) 2001 Ilmar S. Habibulin
31 * Copyright (c) 2001, 2002, 2003, 2004 Networks Associates Technology, Inc.
32 * Copyright (c) 2005 SPARTA, Inc.
34 * This software was developed by Robert Watson and Ilmar Habibulin for the
37 * This software was developed for the FreeBSD Project in part by Network
38 * Associates Laboratories, the Security Research Division of Network
39 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
40 * as part of the DARPA CHATS research program.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 #include <kern/kalloc.h>
66 #include <libkern/OSAtomic.h>
68 #include <sys/param.h>
69 #include <sys/systm.h>
70 #include <sys/kernel.h>
72 #include <sys/kauth.h>
74 #include <sys/file_internal.h>
75 #include <sys/imgact.h>
76 #include <sys/namei.h>
77 #include <sys/mount_internal.h>
79 #include <sys/posix_sem.h>
80 #include <sys/posix_shm.h>
81 #include <sys/reason.h>
82 #include <sys/uio_internal.h>
83 #include <sys/vnode_internal.h>
84 #include <sys/kdebug.h>
87 #include <miscfs/devfs/devfsdefs.h>
88 #include <miscfs/devfs/fdesc.h>
90 #include <security/mac_internal.h>
92 /* convert {R,W,X}_OK values to V{READ,WRITE,EXEC} */
93 #define ACCESS_MODE_TO_VNODE_MASK(m) (m << 6)
97 * Optional tracing of policy operations. Define VFS_TRACE_POLICY_OPS to trace the operations.
99 * Along with DBG_FSYSTEM and DBG_VFS, dcode in the macros below is used to construct
100 * KDBG_EVENTID(DBG_FSYSTEM, DBG_VFS, dcode) global event id, see bsd/sys/kdebug.h.
101 * Note that dcode is multiplied by 4 and ORed as part of the construction. See bsd/kern/trace_codes
102 * for list of system-wide {global event id, name} pairs. Currently DBG_VFS event ids are in range
103 * [0x3130000, 0x313016C].
106 //#define VFS_TRACE_POLICY_OPS
108 #ifdef VFS_TRACE_POLICY_OPS
109 #define DBG_VFS_CODE(dcode) FSDBG_CODE(DBG_VFS, dcode)
110 #define VFS_KERNEL_DEBUG_START0(dcode) KERNEL_DEBUG_CONSTANT(DBG_VFS_CODE(dcode) | DBG_FUNC_START, 0, 0, 0, 0, 0)
111 #define VFS_KERNEL_DEBUG_END0(dcode) KERNEL_DEBUG_CONSTANT(DBG_VFS_CODE(dcode) | DBG_FUNC_END, 0, 0, 0, 0, 0)
112 #define VFS_KERNEL_DEBUG_START1(dcode, darg) KERNEL_DEBUG_CONSTANT(DBG_VFS_CODE(dcode) | DBG_FUNC_START, darg, 0, 0, 0, 0)
113 #define VFS_KERNEL_DEBUG_END1(dcode, darg) KERNEL_DEBUG_CONSTANT(DBG_VFS_CODE(dcode) | DBG_FUNC_END, darg, 0, 0, 0, 0)
115 #define VFS_KERNEL_DEBUG_START0(dcode) do {} while (0)
116 #define VFS_KERNEL_DEBUG_END0(dcode) do {} while (0)
117 #define VFS_KERNEL_DEBUG_START1(dcode, darg) do {} while (0)
118 #define VFS_KERNEL_DEBUG_END1(dcode, darg) do {} while (0)
121 static struct label
*
122 mac_devfsdirent_label_alloc(void)
126 label
= mac_labelzone_alloc(MAC_WAITOK
);
130 VFS_KERNEL_DEBUG_START0(0);
131 MAC_PERFORM(devfs_label_init
, label
);
132 VFS_KERNEL_DEBUG_END0(0);
137 mac_devfs_label_init(struct devnode
*de
)
139 de
->dn_label
= mac_devfsdirent_label_alloc();
142 static struct label
*
143 mac_mount_label_alloc(void)
147 label
= mac_labelzone_alloc(MAC_WAITOK
);
151 VFS_KERNEL_DEBUG_START0(1);
152 MAC_PERFORM(mount_label_init
, label
);
153 VFS_KERNEL_DEBUG_END0(1);
158 mac_mount_label_init(struct mount
*mp
)
160 mp
->mnt_mntlabel
= mac_mount_label_alloc();
164 mac_vnode_label_alloc(void)
168 label
= mac_labelzone_alloc(MAC_WAITOK
);
172 VFS_KERNEL_DEBUG_START0(2);
173 MAC_PERFORM(vnode_label_init
, label
);
174 VFS_KERNEL_DEBUG_END0(2);
175 OSIncrementAtomic(&mac_vnode_label_count
);
180 mac_vnode_label_init(vnode_t vp
)
182 vp
->v_label
= mac_vnode_label_alloc();
186 mac_vnode_label_init_needed(vnode_t vp
)
188 #if CONFIG_MACF_LAZY_VNODE_LABELS
192 return mac_label_vnodes
!= 0 && vp
->v_label
== NULL
;
197 mac_vnode_label_allocate(vnode_t vp
)
199 if (mac_vnode_label_init_needed(vp
)) {
200 vp
->v_label
= mac_vnode_label_alloc();
206 * vnode labels are allocated at the same time as vnodes, but vnodes are never
207 * freed. Instead, we want to remove any sensitive information before putting
208 * them on the free list for reuse.
211 mac_vnode_label_recycle(vnode_t vp
)
213 MAC_PERFORM(vnode_label_recycle
, vp
->v_label
);
214 #if CONFIG_MACF_LAZY_VNODE_LABELS
216 mac_vnode_label_destroy(vp
);
218 vp
->v_lflag
&= ~VL_LABELED
;
224 mac_devfs_label_free(struct label
*label
)
226 VFS_KERNEL_DEBUG_START1(3, label
);
227 MAC_PERFORM(devfs_label_destroy
, label
);
228 VFS_KERNEL_DEBUG_END1(3, label
);
229 mac_labelzone_free(label
);
233 mac_devfs_label_destroy(struct devnode
*de
)
235 if (de
->dn_label
!= NULL
) {
236 mac_devfs_label_free(de
->dn_label
);
242 mac_mount_label_free(struct label
*label
)
244 VFS_KERNEL_DEBUG_START1(4, label
);
245 MAC_PERFORM(mount_label_destroy
, label
);
246 VFS_KERNEL_DEBUG_END1(4, label
);
247 mac_labelzone_free(label
);
251 mac_mount_label_destroy(struct mount
*mp
)
253 if (mp
->mnt_mntlabel
!= NULL
) {
254 mac_mount_label_free(mp
->mnt_mntlabel
);
255 mp
->mnt_mntlabel
= NULL
;
260 mac_vnode_label_free(struct label
*label
)
263 VFS_KERNEL_DEBUG_START1(5, label
);
264 MAC_PERFORM(vnode_label_destroy
, label
);
265 VFS_KERNEL_DEBUG_END1(5, label
);
266 mac_labelzone_free(label
);
267 OSDecrementAtomic(&mac_vnode_label_count
);
272 mac_vnode_label_destroy(struct vnode
*vp
)
274 if (vp
->v_label
!= NULL
) {
275 mac_vnode_label_free(vp
->v_label
);
281 mac_vnode_label_copy(struct label
*src
, struct label
*dest
)
283 VFS_KERNEL_DEBUG_START1(6, src
);
285 MAC_PERFORM(vnode_label_init
, dest
);
287 MAC_PERFORM(vnode_label_copy
, src
, dest
);
289 VFS_KERNEL_DEBUG_END1(6, src
);
293 mac_vnode_label_externalize_audit(struct vnode
*vp
, struct mac
*mac
)
297 /* It is assumed that any necessary vnode locking is done on entry */
298 error
= MAC_EXTERNALIZE_AUDIT(vnode
, vp
->v_label
,
299 mac
->m_string
, mac
->m_buflen
);
305 mac_vnode_label_externalize(struct label
*label
, char *elements
,
306 char *outbuf
, size_t outbuflen
, int flags __unused
)
310 error
= MAC_EXTERNALIZE(vnode
, label
, elements
, outbuf
, outbuflen
);
316 mac_vnode_label_internalize(struct label
*label
, char *string
)
320 error
= MAC_INTERNALIZE(vnode
, label
, string
);
326 mac_mount_label_internalize(struct label
*label
, char *string
)
330 error
= MAC_INTERNALIZE(mount
, label
, string
);
336 mac_mount_label_externalize(struct label
*label
, char *elements
,
337 char *outbuf
, size_t outbuflen
)
341 error
= MAC_EXTERNALIZE(mount
, label
, elements
, outbuf
, outbuflen
);
347 mac_devfs_label_copy(struct label
*src
, struct label
*dest
)
349 #if SECURITY_MAC_CHECK_ENFORCE
350 /* 21167099 - only check if we allow write */
351 if (!mac_device_enforce
) {
356 VFS_KERNEL_DEBUG_START1(7, src
);
357 MAC_PERFORM(devfs_label_copy
, src
, dest
);
358 VFS_KERNEL_DEBUG_END1(7, src
);
362 mac_devfs_label_update(struct mount
*mp
, struct devnode
*de
,
365 #if SECURITY_MAC_CHECK_ENFORCE
366 /* 21167099 - only check if we allow write */
367 if (!mac_device_enforce
) {
372 VFS_KERNEL_DEBUG_START1(8, vp
);
373 MAC_PERFORM(devfs_label_update
, mp
, de
, de
->dn_label
, vp
,
375 VFS_KERNEL_DEBUG_END1(8, vp
);
379 mac_vnode_label_associate(struct mount
*mp
, struct vnode
*vp
, vfs_context_t ctx
)
382 struct fdescnode
*fnp
;
385 #if SECURITY_MAC_CHECK_ENFORCE
386 /* 21167099 - only check if we allow write */
387 if (!mac_vnode_enforce
) {
392 /* XXX: should not inspect v_tag in kernel! */
396 mac_vnode_label_associate_devfs(mp
, dnp
, vp
);
400 error
= mac_vnode_label_associate_fdesc(mp
, fnp
, vp
, ctx
);
403 error
= mac_vnode_label_associate_extattr(mp
, vp
);
411 mac_vnode_label_associate_devfs(struct mount
*mp
, struct devnode
*de
,
414 #if SECURITY_MAC_CHECK_ENFORCE
415 /* 21167099 - only check if we allow write */
416 if (!mac_device_enforce
) {
421 VFS_KERNEL_DEBUG_START1(9, vp
);
422 MAC_PERFORM(vnode_label_associate_devfs
,
423 mp
, mp
? mp
->mnt_mntlabel
: NULL
,
426 VFS_KERNEL_DEBUG_END1(9, vp
);
430 mac_vnode_label_associate_extattr(struct mount
*mp
, struct vnode
*vp
)
434 VFS_KERNEL_DEBUG_START1(10, vp
);
435 MAC_CHECK(vnode_label_associate_extattr
, mp
, mp
->mnt_mntlabel
, vp
,
437 VFS_KERNEL_DEBUG_END1(10, vp
);
443 mac_vnode_label_associate_singlelabel(struct mount
*mp
, struct vnode
*vp
)
445 #if SECURITY_MAC_CHECK_ENFORCE
446 /* 21167099 - only check if we allow write */
447 if (!mac_vnode_enforce
) {
451 if (!mac_label_vnodes
) {
455 VFS_KERNEL_DEBUG_START1(11, vp
);
456 MAC_PERFORM(vnode_label_associate_singlelabel
, mp
,
457 mp
? mp
->mnt_mntlabel
: NULL
, vp
, vp
->v_label
);
458 VFS_KERNEL_DEBUG_END1(11, vp
);
462 mac_vnode_notify_create(vfs_context_t ctx
, struct mount
*mp
,
463 struct vnode
*dvp
, struct vnode
*vp
, struct componentname
*cnp
)
468 #if SECURITY_MAC_CHECK_ENFORCE
469 /* 21167099 - only check if we allow write */
470 if (!mac_vnode_enforce
) {
474 cred
= vfs_context_ucred(ctx
);
475 if (!mac_cred_check_enforce(cred
)) {
478 VFS_KERNEL_DEBUG_START1(12, vp
);
479 MAC_CHECK(vnode_notify_create
, cred
, mp
, mp
->mnt_mntlabel
,
480 dvp
, dvp
->v_label
, vp
, vp
->v_label
, cnp
);
481 VFS_KERNEL_DEBUG_END1(12, vp
);
487 mac_vnode_notify_rename(vfs_context_t ctx
, struct vnode
*vp
,
488 struct vnode
*dvp
, struct componentname
*cnp
)
492 #if SECURITY_MAC_CHECK_ENFORCE
493 /* 21167099 - only check if we allow write */
494 if (!mac_vnode_enforce
) {
498 cred
= vfs_context_ucred(ctx
);
499 if (!mac_cred_check_enforce(cred
)) {
502 VFS_KERNEL_DEBUG_START1(13, vp
);
503 MAC_PERFORM(vnode_notify_rename
, cred
, vp
, vp
->v_label
,
504 dvp
, dvp
->v_label
, cnp
);
505 VFS_KERNEL_DEBUG_END1(13, vp
);
509 mac_vnode_notify_open(vfs_context_t ctx
, struct vnode
*vp
, int acc_flags
)
513 #if SECURITY_MAC_CHECK_ENFORCE
514 /* 21167099 - only check if we allow write */
515 if (!mac_vnode_enforce
) {
519 cred
= vfs_context_ucred(ctx
);
520 if (!mac_cred_check_enforce(cred
)) {
523 VFS_KERNEL_DEBUG_START1(14, vp
);
524 MAC_PERFORM(vnode_notify_open
, cred
, vp
, vp
->v_label
, acc_flags
);
525 VFS_KERNEL_DEBUG_END1(14, vp
);
529 mac_vnode_notify_link(vfs_context_t ctx
, struct vnode
*vp
,
530 struct vnode
*dvp
, struct componentname
*cnp
)
534 #if SECURITY_MAC_CHECK_ENFORCE
535 /* 21167099 - only check if we allow write */
536 if (!mac_vnode_enforce
) {
540 cred
= vfs_context_ucred(ctx
);
541 if (!mac_cred_check_enforce(cred
)) {
544 VFS_KERNEL_DEBUG_START1(15, vp
);
545 MAC_PERFORM(vnode_notify_link
, cred
, dvp
, dvp
->v_label
, vp
, vp
->v_label
, cnp
);
546 VFS_KERNEL_DEBUG_END1(15, vp
);
550 mac_vnode_notify_deleteextattr(vfs_context_t ctx
, struct vnode
*vp
, const char *name
)
554 #if SECURITY_MAC_CHECK_ENFORCE
555 /* 21167099 - only check if we allow write */
556 if (!mac_vnode_enforce
) {
560 cred
= vfs_context_ucred(ctx
);
561 if (!mac_cred_check_enforce(cred
)) {
564 VFS_KERNEL_DEBUG_START1(16, vp
);
565 MAC_PERFORM(vnode_notify_deleteextattr
, cred
, vp
, vp
->v_label
, name
);
566 VFS_KERNEL_DEBUG_END1(16, vp
);
570 mac_vnode_notify_setacl(vfs_context_t ctx
, struct vnode
*vp
, struct kauth_acl
*acl
)
574 #if SECURITY_MAC_CHECK_ENFORCE
575 /* 21167099 - only check if we allow write */
576 if (!mac_vnode_enforce
) {
580 cred
= vfs_context_ucred(ctx
);
581 if (!mac_cred_check_enforce(cred
)) {
584 VFS_KERNEL_DEBUG_START1(17, vp
);
585 MAC_PERFORM(vnode_notify_setacl
, cred
, vp
, vp
->v_label
, acl
);
586 VFS_KERNEL_DEBUG_END1(17, vp
);
590 mac_vnode_notify_setattrlist(vfs_context_t ctx
, struct vnode
*vp
, struct attrlist
*alist
)
594 #if SECURITY_MAC_CHECK_ENFORCE
595 /* 21167099 - only check if we allow write */
596 if (!mac_vnode_enforce
) {
600 cred
= vfs_context_ucred(ctx
);
601 if (!mac_cred_check_enforce(cred
)) {
604 VFS_KERNEL_DEBUG_START1(18, vp
);
605 MAC_PERFORM(vnode_notify_setattrlist
, cred
, vp
, vp
->v_label
, alist
);
606 VFS_KERNEL_DEBUG_END1(18, vp
);
610 mac_vnode_notify_setextattr(vfs_context_t ctx
, struct vnode
*vp
, const char *name
, struct uio
*uio
)
614 #if SECURITY_MAC_CHECK_ENFORCE
615 /* 21167099 - only check if we allow write */
616 if (!mac_vnode_enforce
) {
620 cred
= vfs_context_ucred(ctx
);
621 if (!mac_cred_check_enforce(cred
)) {
624 VFS_KERNEL_DEBUG_START1(19, vp
);
625 MAC_PERFORM(vnode_notify_setextattr
, cred
, vp
, vp
->v_label
, name
, uio
);
626 VFS_KERNEL_DEBUG_END1(19, vp
);
630 mac_vnode_notify_setflags(vfs_context_t ctx
, struct vnode
*vp
, u_long flags
)
634 #if SECURITY_MAC_CHECK_ENFORCE
635 /* 21167099 - only check if we allow write */
636 if (!mac_vnode_enforce
) {
640 cred
= vfs_context_ucred(ctx
);
641 if (!mac_cred_check_enforce(cred
)) {
644 VFS_KERNEL_DEBUG_START1(20, vp
);
645 MAC_PERFORM(vnode_notify_setflags
, cred
, vp
, vp
->v_label
, flags
);
646 VFS_KERNEL_DEBUG_END1(20, vp
);
650 mac_vnode_notify_setmode(vfs_context_t ctx
, struct vnode
*vp
, mode_t mode
)
654 #if SECURITY_MAC_CHECK_ENFORCE
655 /* 21167099 - only check if we allow write */
656 if (!mac_vnode_enforce
) {
660 cred
= vfs_context_ucred(ctx
);
661 if (!mac_cred_check_enforce(cred
)) {
664 VFS_KERNEL_DEBUG_START1(21, vp
);
665 MAC_PERFORM(vnode_notify_setmode
, cred
, vp
, vp
->v_label
, mode
);
666 VFS_KERNEL_DEBUG_END1(21, vp
);
670 mac_vnode_notify_setowner(vfs_context_t ctx
, struct vnode
*vp
, uid_t uid
, gid_t gid
)
674 #if SECURITY_MAC_CHECK_ENFORCE
675 /* 21167099 - only check if we allow write */
676 if (!mac_vnode_enforce
) {
680 cred
= vfs_context_ucred(ctx
);
681 if (!mac_cred_check_enforce(cred
)) {
684 VFS_KERNEL_DEBUG_START1(22, vp
);
685 MAC_PERFORM(vnode_notify_setowner
, cred
, vp
, vp
->v_label
, uid
, gid
);
686 VFS_KERNEL_DEBUG_END1(22, vp
);
690 mac_vnode_notify_setutimes(vfs_context_t ctx
, struct vnode
*vp
, struct timespec atime
, struct timespec mtime
)
694 #if SECURITY_MAC_CHECK_ENFORCE
695 /* 21167099 - only check if we allow write */
696 if (!mac_vnode_enforce
) {
700 cred
= vfs_context_ucred(ctx
);
701 if (!mac_cred_check_enforce(cred
)) {
704 VFS_KERNEL_DEBUG_START1(23, vp
);
705 MAC_PERFORM(vnode_notify_setutimes
, cred
, vp
, vp
->v_label
, atime
, mtime
);
706 VFS_KERNEL_DEBUG_END1(23, vp
);
710 mac_vnode_notify_truncate(vfs_context_t ctx
, kauth_cred_t file_cred
, struct vnode
*vp
)
714 #if SECURITY_MAC_CHECK_ENFORCE
715 /* 21167099 - only check if we allow write */
716 if (!mac_vnode_enforce
) {
720 cred
= vfs_context_ucred(ctx
);
721 if (!mac_cred_check_enforce(cred
)) {
724 VFS_KERNEL_DEBUG_START1(24, vp
);
725 MAC_PERFORM(vnode_notify_truncate
, cred
, file_cred
, vp
, vp
->v_label
);
726 VFS_KERNEL_DEBUG_END1(24, vp
);
730 * Extended attribute 'name' was updated via
731 * vn_setxattr() or vn_removexattr(). Allow the
732 * policy to update the vnode label.
735 mac_vnode_label_update_extattr(struct mount
*mp
, struct vnode
*vp
,
740 #if SECURITY_MAC_CHECK_ENFORCE
741 /* 21167099 - only check if we allow write */
742 if (!mac_vnode_enforce
) {
746 if (!mac_label_vnodes
) {
750 VFS_KERNEL_DEBUG_START1(25, vp
);
751 MAC_PERFORM(vnode_label_update_extattr
, mp
, mp
->mnt_mntlabel
, vp
,
753 VFS_KERNEL_DEBUG_END1(25, vp
);
765 mac_vnode_label_store(vfs_context_t ctx
, struct vnode
*vp
,
766 struct label
*intlabel
)
771 #if SECURITY_MAC_CHECK_ENFORCE
772 /* 21167099 - only check if we allow write */
773 if (!mac_vnode_enforce
) {
777 if (!mac_label_vnodes
) {
781 cred
= vfs_context_ucred(ctx
);
782 if (!mac_cred_check_enforce(cred
)) {
785 VFS_KERNEL_DEBUG_START1(26, vp
);
786 MAC_CHECK(vnode_label_store
, cred
, vp
, vp
->v_label
, intlabel
);
787 VFS_KERNEL_DEBUG_END1(26, vp
);
793 mac_cred_label_update_execve(vfs_context_t ctx
, kauth_cred_t
new, struct vnode
*vp
, off_t offset
,
794 struct vnode
*scriptvp
, struct label
*scriptvnodelabel
, struct label
*execl
, u_int
*csflags
,
795 void *macextensions
, int *disjoint
, int *labelupdateerror
)
800 posix_cred_t pcred
= posix_cred_get(new);
802 #if SECURITY_MAC_CHECK_ENFORCE
803 /* 21167099 - only check if we allow write */
804 if (!mac_proc_enforce
|| !mac_vnode_enforce
) {
809 /* mark the new cred to indicate "matching" includes the label */
810 pcred
->cr_flags
|= CRF_MAC_ENFORCE
;
812 cred
= vfs_context_ucred(ctx
);
815 * NB: Cannot use MAC_CHECK macro because we need a sequence point after
816 * calling exec_spawnattr_getmacpolicyinfo() and before passing the
817 * spawnattrlen as an argument to the hook.
819 VFS_KERNEL_DEBUG_START1(27, vp
);
821 struct mac_policy_conf
*mpc
;
825 for (i
= 0; i
< mac_policy_list
.staticmax
; i
++) {
826 mpc
= mac_policy_list
.entries
[i
].mpc
;
831 mpo_cred_label_update_execve_t
*hook
= mpc
->mpc_ops
->mpo_cred_label_update_execve
;
836 size_t spawnattrlen
= 0;
837 void *spawnattr
= exec_spawnattr_getmacpolicyinfo(macextensions
, mpc
->mpc_name
, &spawnattrlen
);
839 error
= mac_error_select(hook(cred
, new, vfs_context_proc(ctx
), vp
, offset
, scriptvp
,
840 vp
->v_label
, scriptvnodelabel
, execl
, csflags
, spawnattr
, spawnattrlen
, disjoint
),
843 if (mac_policy_list_conditional_busy() != 0) {
844 for (; i
<= mac_policy_list
.maxindex
; i
++) {
845 mpc
= mac_policy_list
.entries
[i
].mpc
;
850 mpo_cred_label_update_execve_t
*hook
= mpc
->mpc_ops
->mpo_cred_label_update_execve
;
855 size_t spawnattrlen
= 0;
856 void *spawnattr
= exec_spawnattr_getmacpolicyinfo(macextensions
, mpc
->mpc_name
, &spawnattrlen
);
858 error
= mac_error_select(hook(cred
, new, vfs_context_proc(ctx
), vp
, offset
, scriptvp
,
859 vp
->v_label
, scriptvnodelabel
, execl
, csflags
, spawnattr
, spawnattrlen
, disjoint
),
862 mac_policy_list_unbusy();
865 *labelupdateerror
= error
;
866 VFS_KERNEL_DEBUG_END1(27, vp
);
870 mac_cred_check_label_update_execve(vfs_context_t ctx
, struct vnode
*vp
, off_t offset
,
871 struct vnode
*scriptvp
, struct label
*scriptvnodelabel
, struct label
*execlabel
,
872 struct proc
*p
, void *macextensions
)
877 #if SECURITY_MAC_CHECK_ENFORCE
878 /* 21167099 - only check if we allow write */
879 if (!mac_proc_enforce
|| !mac_vnode_enforce
) {
884 cred
= vfs_context_ucred(ctx
);
886 VFS_KERNEL_DEBUG_START1(28, vp
);
888 * NB: Cannot use MAC_BOOLEAN macro because we need a sequence point after
889 * calling exec_spawnattr_getmacpolicyinfo() and before passing the
890 * spawnattrlen as an argument to the hook.
893 struct mac_policy_conf
*mpc
;
896 for (i
= 0; i
< mac_policy_list
.staticmax
; i
++) {
897 mpc
= mac_policy_list
.entries
[i
].mpc
;
902 mpo_cred_check_label_update_execve_t
*hook
= mpc
->mpc_ops
->mpo_cred_check_label_update_execve
;
907 size_t spawnattrlen
= 0;
908 void *spawnattr
= exec_spawnattr_getmacpolicyinfo(macextensions
, mpc
->mpc_name
, &spawnattrlen
);
910 result
= result
|| hook(cred
, vp
, offset
, scriptvp
, vp
->v_label
, scriptvnodelabel
, execlabel
, p
, spawnattr
, spawnattrlen
);
912 if (mac_policy_list_conditional_busy() != 0) {
913 for (; i
<= mac_policy_list
.maxindex
; i
++) {
914 mpc
= mac_policy_list
.entries
[i
].mpc
;
919 mpo_cred_check_label_update_execve_t
*hook
= mpc
->mpc_ops
->mpo_cred_check_label_update_execve
;
924 size_t spawnattrlen
= 0;
925 void *spawnattr
= exec_spawnattr_getmacpolicyinfo(macextensions
, mpc
->mpc_name
, &spawnattrlen
);
927 result
= result
|| hook(cred
, vp
, offset
, scriptvp
, vp
->v_label
, scriptvnodelabel
, execlabel
, p
, spawnattr
, spawnattrlen
);
929 mac_policy_list_unbusy();
932 VFS_KERNEL_DEBUG_END1(28, vp
);
938 mac_vnode_check_access(vfs_context_t ctx
, struct vnode
*vp
,
945 #if SECURITY_MAC_CHECK_ENFORCE
946 /* 21167099 - only check if we allow write */
947 if (!mac_vnode_enforce
) {
951 cred
= vfs_context_ucred(ctx
);
952 if (!mac_cred_check_enforce(cred
)) {
955 /* Convert {R,W,X}_OK values to V{READ,WRITE,EXEC} for entry points */
956 mask
= ACCESS_MODE_TO_VNODE_MASK(acc_mode
);
957 VFS_KERNEL_DEBUG_START1(29, vp
);
958 MAC_CHECK(vnode_check_access
, cred
, vp
, vp
->v_label
, mask
);
959 VFS_KERNEL_DEBUG_END1(29, vp
);
964 mac_vnode_check_chdir(vfs_context_t ctx
, struct vnode
*dvp
)
969 #if SECURITY_MAC_CHECK_ENFORCE
970 /* 21167099 - only check if we allow write */
971 if (!mac_vnode_enforce
) {
975 cred
= vfs_context_ucred(ctx
);
976 if (!mac_cred_check_enforce(cred
)) {
979 VFS_KERNEL_DEBUG_START1(30, dvp
);
980 MAC_CHECK(vnode_check_chdir
, cred
, dvp
, dvp
->v_label
);
981 VFS_KERNEL_DEBUG_END1(30, dvp
);
986 mac_vnode_check_chroot(vfs_context_t ctx
, struct vnode
*dvp
,
987 struct componentname
*cnp
)
992 #if SECURITY_MAC_CHECK_ENFORCE
993 /* 21167099 - only check if we allow write */
994 if (!mac_vnode_enforce
) {
998 cred
= vfs_context_ucred(ctx
);
999 if (!mac_cred_check_enforce(cred
)) {
1002 VFS_KERNEL_DEBUG_START1(31, dvp
);
1003 MAC_CHECK(vnode_check_chroot
, cred
, dvp
, dvp
->v_label
, cnp
);
1004 VFS_KERNEL_DEBUG_END1(31, dvp
);
1009 mac_vnode_check_clone(vfs_context_t ctx
, struct vnode
*dvp
,
1010 struct vnode
*vp
, struct componentname
*cnp
)
1015 #if SECURITY_MAC_CHECK_ENFORCE
1016 /* 21167099 - only check if we allow write */
1017 if (!mac_vnode_enforce
) {
1021 cred
= vfs_context_ucred(ctx
);
1022 if (!mac_cred_check_enforce(cred
)) {
1025 VFS_KERNEL_DEBUG_START1(32, dvp
);
1026 MAC_CHECK(vnode_check_clone
, cred
, dvp
, dvp
->v_label
, vp
,
1028 VFS_KERNEL_DEBUG_END1(32, dvp
);
1032 mac_vnode_check_create(vfs_context_t ctx
, struct vnode
*dvp
,
1033 struct componentname
*cnp
, struct vnode_attr
*vap
)
1038 #if SECURITY_MAC_CHECK_ENFORCE
1039 /* 21167099 - only check if we allow write */
1040 if (!mac_vnode_enforce
) {
1044 cred
= vfs_context_ucred(ctx
);
1045 if (!mac_cred_check_enforce(cred
)) {
1048 VFS_KERNEL_DEBUG_START1(33, dvp
);
1049 MAC_CHECK(vnode_check_create
, cred
, dvp
, dvp
->v_label
, cnp
, vap
);
1050 VFS_KERNEL_DEBUG_END1(33, dvp
);
1055 mac_vnode_check_unlink(vfs_context_t ctx
, struct vnode
*dvp
, struct vnode
*vp
,
1056 struct componentname
*cnp
)
1061 #if SECURITY_MAC_CHECK_ENFORCE
1062 /* 21167099 - only check if we allow write */
1063 if (!mac_vnode_enforce
) {
1067 cred
= vfs_context_ucred(ctx
);
1068 if (!mac_cred_check_enforce(cred
)) {
1071 VFS_KERNEL_DEBUG_START1(34, dvp
);
1072 MAC_CHECK(vnode_check_unlink
, cred
, dvp
, dvp
->v_label
, vp
,
1074 VFS_KERNEL_DEBUG_END1(34, dvp
);
1079 mac_vnode_check_deleteacl(vfs_context_t ctx
, struct vnode
*vp
,
1085 #if SECURITY_MAC_CHECK_ENFORCE
1086 /* 21167099 - only check if we allow write */
1087 if (!mac_vnode_enforce
) {
1091 cred
= vfs_context_ucred(ctx
);
1092 if (!mac_cred_check_enforce(cred
)) {
1095 VFS_KERNEL_DEBUG_START1(35, dvp
);
1096 MAC_CHECK(vnode_check_deleteacl
, cred
, vp
, vp
->v_label
, type
);
1097 VFS_KERNEL_DEBUG_END1(35, dvp
);
1103 mac_vnode_check_deleteextattr(vfs_context_t ctx
, struct vnode
*vp
,
1109 #if SECURITY_MAC_CHECK_ENFORCE
1110 /* 21167099 - only check if we allow write */
1111 if (!mac_vnode_enforce
) {
1115 cred
= vfs_context_ucred(ctx
);
1116 if (!mac_cred_check_enforce(cred
)) {
1119 VFS_KERNEL_DEBUG_START1(36, vp
);
1120 MAC_CHECK(vnode_check_deleteextattr
, cred
, vp
, vp
->v_label
, name
);
1121 VFS_KERNEL_DEBUG_END1(36, vp
);
1125 mac_vnode_check_exchangedata(vfs_context_t ctx
,
1126 struct vnode
*v1
, struct vnode
*v2
)
1131 #if SECURITY_MAC_CHECK_ENFORCE
1132 /* 21167099 - only check if we allow write */
1133 if (!mac_vnode_enforce
) {
1137 cred
= vfs_context_ucred(ctx
);
1138 if (!mac_cred_check_enforce(cred
)) {
1141 VFS_KERNEL_DEBUG_START1(37, v1
);
1142 MAC_CHECK(vnode_check_exchangedata
, cred
, v1
, v1
->v_label
,
1144 VFS_KERNEL_DEBUG_END1(37, v1
);
1151 mac_vnode_check_getacl(vfs_context_t ctx
, struct vnode
*vp
, acl_type_t type
)
1156 #if SECURITY_MAC_CHECK_ENFORCE
1157 /* 21167099 - only check if we allow write */
1158 if (!mac_vnode_enforce
) {
1162 cred
= vfs_context_ucred(ctx
);
1163 if (!mac_cred_check_enforce(cred
)) {
1166 VFS_KERNEL_DEBUG_START1(38, vp
);
1167 MAC_CHECK(vnode_check_getacl
, cred
, vp
, vp
->v_label
, type
);
1168 VFS_KERNEL_DEBUG_END1(38, vp
);
1174 mac_vnode_check_getattr(vfs_context_t ctx
, struct ucred
*file_cred
,
1175 struct vnode
*vp
, struct vnode_attr
*va
)
1180 #if SECURITY_MAC_CHECK_ENFORCE
1181 /* 21167099 - only check if we allow write */
1182 if (!mac_vnode_enforce
) {
1186 cred
= vfs_context_ucred(ctx
);
1187 if (!mac_cred_check_enforce(cred
)) {
1190 VFS_KERNEL_DEBUG_START1(39, vp
);
1191 MAC_CHECK(vnode_check_getattr
, cred
, file_cred
, vp
, vp
->v_label
, va
);
1192 VFS_KERNEL_DEBUG_END1(39, vp
);
1197 mac_vnode_check_getattrlist(vfs_context_t ctx
, struct vnode
*vp
,
1198 struct attrlist
*alist
)
1203 #if SECURITY_MAC_CHECK_ENFORCE
1204 /* 21167099 - only check if we allow write */
1205 if (!mac_vnode_enforce
) {
1209 cred
= vfs_context_ucred(ctx
);
1210 if (!mac_cred_check_enforce(cred
)) {
1213 VFS_KERNEL_DEBUG_START1(40, vp
);
1214 MAC_CHECK(vnode_check_getattrlist
, cred
, vp
, vp
->v_label
, alist
);
1215 VFS_KERNEL_DEBUG_END1(40, vp
);
1217 /* Falsify results instead of returning error? */
1222 mac_vnode_check_exec(vfs_context_t ctx
, struct vnode
*vp
,
1223 struct image_params
*imgp
)
1228 #if SECURITY_MAC_CHECK_ENFORCE
1229 /* 21167099 - only check if we allow write */
1230 if (!mac_proc_enforce
|| !mac_vnode_enforce
) {
1235 cred
= vfs_context_ucred(ctx
);
1238 * NB: Cannot use MAC_CHECK macro because we need a sequence point after
1239 * calling exec_spawnattr_getmacpolicyinfo() and before passing the
1240 * spawnattrlen as an argument to the hook.
1242 VFS_KERNEL_DEBUG_START1(41, vp
);
1244 struct mac_policy_conf
*mpc
;
1247 for (i
= 0; i
< mac_policy_list
.staticmax
; i
++) {
1248 mpc
= mac_policy_list
.entries
[i
].mpc
;
1253 mpo_vnode_check_exec_t
*hook
= mpc
->mpc_ops
->mpo_vnode_check_exec
;
1258 size_t spawnattrlen
= 0;
1259 void *spawnattr
= exec_spawnattr_getmacpolicyinfo(imgp
->ip_px_smpx
, mpc
->mpc_name
, &spawnattrlen
);
1261 error
= mac_error_select(
1263 vp
, imgp
->ip_scriptvp
, vp
->v_label
, imgp
->ip_scriptlabelp
,
1264 imgp
->ip_execlabelp
, &imgp
->ip_ndp
->ni_cnd
, &imgp
->ip_csflags
,
1265 spawnattr
, spawnattrlen
), error
);
1267 if (mac_policy_list_conditional_busy() != 0) {
1268 for (; i
<= mac_policy_list
.maxindex
; i
++) {
1269 mpc
= mac_policy_list
.entries
[i
].mpc
;
1274 mpo_vnode_check_exec_t
*hook
= mpc
->mpc_ops
->mpo_vnode_check_exec
;
1279 size_t spawnattrlen
= 0;
1280 void *spawnattr
= exec_spawnattr_getmacpolicyinfo(imgp
->ip_px_smpx
, mpc
->mpc_name
, &spawnattrlen
);
1282 error
= mac_error_select(
1284 vp
, imgp
->ip_scriptvp
, vp
->v_label
, imgp
->ip_scriptlabelp
,
1285 imgp
->ip_execlabelp
, &imgp
->ip_ndp
->ni_cnd
, &imgp
->ip_csflags
,
1286 spawnattr
, spawnattrlen
), error
);
1288 mac_policy_list_unbusy();
1291 VFS_KERNEL_DEBUG_END1(41, vp
);
1297 mac_vnode_check_fsgetpath(vfs_context_t ctx
, struct vnode
*vp
)
1302 #if SECURITY_MAC_CHECK_ENFORCE
1303 /* 21167099 - only check if we allow write */
1304 if (!mac_vnode_enforce
) {
1308 cred
= vfs_context_ucred(ctx
);
1309 if (!mac_cred_check_enforce(cred
)) {
1312 VFS_KERNEL_DEBUG_START1(42, vp
);
1313 MAC_CHECK(vnode_check_fsgetpath
, cred
, vp
, vp
->v_label
);
1314 VFS_KERNEL_DEBUG_END1(42, vp
);
1319 mac_vnode_check_signature(struct vnode
*vp
, struct cs_blob
*cs_blob
,
1320 struct image_params
*imgp
,
1321 unsigned int *cs_flags
, unsigned int *signer_type
,
1325 char *fatal_failure_desc
= NULL
;
1326 size_t fatal_failure_desc_len
= 0;
1328 char *vn_path
= NULL
;
1329 vm_size_t vn_pathlen
= MAXPATHLEN
;
1330 cpu_type_t cpu_type
= (imgp
== NULL
) ? CPU_TYPE_ANY
: imgp
->ip_origcputype
;
1333 #if SECURITY_MAC_CHECK_ENFORCE
1334 /* 21167099 - only check if we allow write */
1335 if (!mac_proc_enforce
|| !mac_vnode_enforce
) {
1340 VFS_KERNEL_DEBUG_START1(43, vp
);
1341 MAC_CHECK(vnode_check_signature
, vp
, vp
->v_label
, cpu_type
, cs_blob
,
1342 cs_flags
, signer_type
, flags
, &fatal_failure_desc
, &fatal_failure_desc_len
);
1343 VFS_KERNEL_DEBUG_END1(43, vp
);
1345 if (fatal_failure_desc_len
) {
1346 // A fatal code signature validation failure occured, formulate a crash
1349 char const *path
= NULL
;
1351 vn_path
= (char *)kalloc(MAXPATHLEN
);
1352 if (vn_path
!= NULL
) {
1353 if (vn_getpath(vp
, vn_path
, (int*)&vn_pathlen
) == 0) {
1356 path
= "(get vnode path failed)";
1359 path
= "(path alloc failed)";
1363 panic("mac_vnode_check_signature: MAC hook returned no error, "
1364 "but status is claimed to be fatal? "
1365 "path: '%s', fatal_failure_desc_len: %ld, fatal_failure_desc:\n%s\n",
1366 path
, fatal_failure_desc_len
, fatal_failure_desc
);
1369 printf("mac_vnode_check_signature: %s: code signature validation failed fatally: %s",
1370 path
, fatal_failure_desc
);
1376 os_reason_t reason
= os_reason_create(OS_REASON_CODESIGNING
,
1377 CODESIGNING_EXIT_REASON_TASKGATED_INVALID_SIG
);
1379 if (reason
== OS_REASON_NULL
) {
1380 printf("mac_vnode_check_signature: %s: failure to allocate exit reason for validation failure: %s\n",
1381 path
, fatal_failure_desc
);
1385 imgp
->ip_cs_error
= reason
;
1386 reason
->osr_flags
= (OS_REASON_FLAG_GENERATE_CRASH_REPORT
|
1387 OS_REASON_FLAG_CONSISTENT_FAILURE
);
1389 if (fatal_failure_desc
== NULL
) {
1390 // This may happen if allocation for the buffer failed.
1391 printf("mac_vnode_check_signature: %s: fatal failure is missing its description.\n", path
);
1393 mach_vm_address_t data_addr
= 0;
1395 int reason_error
= 0;
1396 int kcdata_error
= 0;
1398 if ((reason_error
= os_reason_alloc_buffer_noblock(reason
, kcdata_estimate_required_buffer_size
1399 (1, fatal_failure_desc_len
))) == 0 &&
1400 (kcdata_error
= kcdata_get_memory_addr(&reason
->osr_kcd_descriptor
,
1401 EXIT_REASON_USER_DESC
, fatal_failure_desc_len
,
1402 &data_addr
)) == KERN_SUCCESS
) {
1403 kern_return_t mc_error
= kcdata_memcpy(&reason
->osr_kcd_descriptor
, (mach_vm_address_t
)data_addr
,
1404 fatal_failure_desc
, fatal_failure_desc_len
);
1406 if (mc_error
!= KERN_SUCCESS
) {
1407 printf("mac_vnode_check_signature: %s: failed to copy reason string "
1408 "(kcdata_memcpy error: %d, length: %ld)\n",
1409 path
, mc_error
, fatal_failure_desc_len
);
1412 printf("mac_vnode_check_signature: %s: failed to allocate space for reason string "
1413 "(os_reason_alloc_buffer error: %d, kcdata error: %d, length: %ld)\n",
1414 path
, reason_error
, kcdata_error
, fatal_failure_desc_len
);
1421 kfree(vn_path
, MAXPATHLEN
);
1424 if (fatal_failure_desc_len
> 0 && fatal_failure_desc
!= NULL
) {
1425 kfree(fatal_failure_desc
, fatal_failure_desc_len
);
1433 mac_vnode_check_getacl(vfs_context_t ctx
, struct vnode
*vp
, acl_type_t type
)
1438 #if SECURITY_MAC_CHECK_ENFORCE
1439 /* 21167099 - only check if we allow write */
1440 if (!mac_vnode_enforce
) {
1444 cred
= vfs_context_ucred(ctx
);
1445 if (!mac_cred_check_enforce(cred
)) {
1448 VFS_KERNEL_DEBUG_START1(44, vp
);
1449 MAC_CHECK(vnode_check_getacl
, cred
, vp
, vp
->v_label
, type
);
1450 VFS_KERNEL_DEBUG_END1(44, vp
);
1456 mac_vnode_check_getextattr(vfs_context_t ctx
, struct vnode
*vp
,
1457 const char *name
, struct uio
*uio
)
1462 #if SECURITY_MAC_CHECK_ENFORCE
1463 /* 21167099 - only check if we allow write */
1464 if (!mac_vnode_enforce
) {
1468 cred
= vfs_context_ucred(ctx
);
1469 if (!mac_cred_check_enforce(cred
)) {
1472 VFS_KERNEL_DEBUG_START1(45, vp
);
1473 MAC_CHECK(vnode_check_getextattr
, cred
, vp
, vp
->v_label
,
1475 VFS_KERNEL_DEBUG_END1(45, vp
);
1480 mac_vnode_check_ioctl(vfs_context_t ctx
, struct vnode
*vp
, u_int cmd
)
1485 #if SECURITY_MAC_CHECK_ENFORCE
1486 /* 21167099 - only check if we allow write */
1487 if (!mac_vnode_enforce
) {
1491 cred
= vfs_context_ucred(ctx
);
1492 if (!mac_cred_check_enforce(cred
)) {
1495 VFS_KERNEL_DEBUG_START1(46, vp
);
1496 MAC_CHECK(vnode_check_ioctl
, cred
, vp
, vp
->v_label
, cmd
);
1497 VFS_KERNEL_DEBUG_END1(46, vp
);
1502 mac_vnode_check_kqfilter(vfs_context_t ctx
, kauth_cred_t file_cred
,
1503 struct knote
*kn
, struct vnode
*vp
)
1508 #if SECURITY_MAC_CHECK_ENFORCE
1509 /* 21167099 - only check if we allow write */
1510 if (!mac_vnode_enforce
) {
1514 cred
= vfs_context_ucred(ctx
);
1515 if (!mac_cred_check_enforce(cred
)) {
1518 VFS_KERNEL_DEBUG_START1(47, vp
);
1519 MAC_CHECK(vnode_check_kqfilter
, cred
, file_cred
, kn
, vp
,
1521 VFS_KERNEL_DEBUG_END1(47, vp
);
1527 mac_vnode_check_link(vfs_context_t ctx
, struct vnode
*dvp
,
1528 struct vnode
*vp
, struct componentname
*cnp
)
1533 #if SECURITY_MAC_CHECK_ENFORCE
1534 /* 21167099 - only check if we allow write */
1535 if (!mac_vnode_enforce
) {
1539 cred
= vfs_context_ucred(ctx
);
1540 if (!mac_cred_check_enforce(cred
)) {
1543 VFS_KERNEL_DEBUG_START1(48, vp
);
1544 MAC_CHECK(vnode_check_link
, cred
, dvp
, dvp
->v_label
, vp
,
1546 VFS_KERNEL_DEBUG_END1(48, vp
);
1551 mac_vnode_check_listextattr(vfs_context_t ctx
, struct vnode
*vp
)
1556 #if SECURITY_MAC_CHECK_ENFORCE
1557 /* 21167099 - only check if we allow write */
1558 if (!mac_vnode_enforce
) {
1562 cred
= vfs_context_ucred(ctx
);
1563 if (!mac_cred_check_enforce(cred
)) {
1566 VFS_KERNEL_DEBUG_START1(49, vp
);
1567 MAC_CHECK(vnode_check_listextattr
, cred
, vp
, vp
->v_label
);
1568 VFS_KERNEL_DEBUG_END1(49, vp
);
1573 mac_vnode_check_lookup_preflight(vfs_context_t ctx
, struct vnode
*dvp
,
1574 const char *path
, size_t pathlen
)
1579 #if SECURITY_MAC_CHECK_ENFORCE
1580 /* 21167099 - only check if we allow write */
1581 if (!mac_vnode_enforce
) {
1585 cred
= vfs_context_ucred(ctx
);
1586 if (!mac_cred_check_enforce(cred
)) {
1589 VFS_KERNEL_DEBUG_START1(50, dvp
);
1590 MAC_CHECK(vnode_check_lookup_preflight
, cred
, dvp
, dvp
->v_label
, path
, pathlen
);
1591 VFS_KERNEL_DEBUG_END1(50, dvp
);
1596 mac_vnode_check_lookup(vfs_context_t ctx
, struct vnode
*dvp
,
1597 struct componentname
*cnp
)
1602 #if SECURITY_MAC_CHECK_ENFORCE
1603 /* 21167099 - only check if we allow write */
1604 if (!mac_vnode_enforce
) {
1608 cred
= vfs_context_ucred(ctx
);
1609 if (!mac_cred_check_enforce(cred
)) {
1612 VFS_KERNEL_DEBUG_START1(51, dvp
);
1613 MAC_CHECK(vnode_check_lookup
, cred
, dvp
, dvp
->v_label
, cnp
);
1614 VFS_KERNEL_DEBUG_END1(51, dvp
);
1619 mac_vnode_check_open(vfs_context_t ctx
, struct vnode
*vp
, int acc_mode
)
1624 #if SECURITY_MAC_CHECK_ENFORCE
1625 /* 21167099 - only check if we allow write */
1626 if (!mac_vnode_enforce
) {
1630 cred
= vfs_context_ucred(ctx
);
1631 if (!mac_cred_check_enforce(cred
)) {
1634 VFS_KERNEL_DEBUG_START1(52, vp
);
1635 MAC_CHECK(vnode_check_open
, cred
, vp
, vp
->v_label
, acc_mode
);
1636 VFS_KERNEL_DEBUG_END1(52, vp
);
1641 mac_vnode_check_read(vfs_context_t ctx
, struct ucred
*file_cred
,
1647 #if SECURITY_MAC_CHECK_ENFORCE
1648 /* 21167099 - only check if we allow write */
1649 if (!mac_vnode_enforce
) {
1653 cred
= vfs_context_ucred(ctx
);
1654 if (!mac_cred_check_enforce(cred
)) {
1657 VFS_KERNEL_DEBUG_START1(53, vp
);
1658 MAC_CHECK(vnode_check_read
, cred
, file_cred
, vp
,
1660 VFS_KERNEL_DEBUG_END1(53, vp
);
1666 mac_vnode_check_readdir(vfs_context_t ctx
, struct vnode
*dvp
)
1671 #if SECURITY_MAC_CHECK_ENFORCE
1672 /* 21167099 - only check if we allow write */
1673 if (!mac_vnode_enforce
) {
1677 cred
= vfs_context_ucred(ctx
);
1678 if (!mac_cred_check_enforce(cred
)) {
1681 VFS_KERNEL_DEBUG_START1(54, dvp
);
1682 MAC_CHECK(vnode_check_readdir
, cred
, dvp
, dvp
->v_label
);
1683 VFS_KERNEL_DEBUG_END1(54, dvp
);
1688 mac_vnode_check_readlink(vfs_context_t ctx
, struct vnode
*vp
)
1693 #if SECURITY_MAC_CHECK_ENFORCE
1694 /* 21167099 - only check if we allow write */
1695 if (!mac_vnode_enforce
) {
1699 cred
= vfs_context_ucred(ctx
);
1700 if (!mac_cred_check_enforce(cred
)) {
1703 VFS_KERNEL_DEBUG_START1(55, vp
);
1704 MAC_CHECK(vnode_check_readlink
, cred
, vp
, vp
->v_label
);
1705 VFS_KERNEL_DEBUG_END1(55, vp
);
1710 mac_vnode_check_label_update(vfs_context_t ctx
, struct vnode
*vp
,
1711 struct label
*newlabel
)
1716 #if SECURITY_MAC_CHECK_ENFORCE
1717 /* 21167099 - only check if we allow write */
1718 if (!mac_vnode_enforce
) {
1722 cred
= vfs_context_ucred(ctx
);
1723 if (!mac_cred_check_enforce(cred
)) {
1726 VFS_KERNEL_DEBUG_START1(56, vp
);
1727 MAC_CHECK(vnode_check_label_update
, cred
, vp
, vp
->v_label
, newlabel
);
1728 VFS_KERNEL_DEBUG_END1(56, vp
);
1734 mac_vnode_check_rename(vfs_context_t ctx
, struct vnode
*dvp
,
1735 struct vnode
*vp
, struct componentname
*cnp
, struct vnode
*tdvp
,
1736 struct vnode
*tvp
, struct componentname
*tcnp
)
1741 #if SECURITY_MAC_CHECK_ENFORCE
1742 /* 21167099 - only check if we allow write */
1743 if (!mac_vnode_enforce
) {
1747 cred
= vfs_context_ucred(ctx
);
1748 if (!mac_cred_check_enforce(cred
)) {
1752 VFS_KERNEL_DEBUG_START1(57, vp
);
1753 MAC_CHECK(vnode_check_rename_from
, cred
, dvp
, dvp
->v_label
, vp
,
1756 VFS_KERNEL_DEBUG_END1(57, vp
);
1760 MAC_CHECK(vnode_check_rename_to
, cred
, tdvp
, tdvp
->v_label
, tvp
,
1761 tvp
!= NULL
? tvp
->v_label
: NULL
, dvp
== tdvp
, tcnp
);
1763 VFS_KERNEL_DEBUG_END1(57, vp
);
1767 MAC_CHECK(vnode_check_rename
, cred
, dvp
, dvp
->v_label
, vp
,
1768 vp
->v_label
, cnp
, tdvp
, tdvp
->v_label
, tvp
,
1769 tvp
!= NULL
? tvp
->v_label
: NULL
, tcnp
);
1770 VFS_KERNEL_DEBUG_END1(57, vp
);
1775 mac_vnode_check_revoke(vfs_context_t ctx
, struct vnode
*vp
)
1780 #if SECURITY_MAC_CHECK_ENFORCE
1781 /* 21167099 - only check if we allow write */
1782 if (!mac_vnode_enforce
) {
1786 cred
= vfs_context_ucred(ctx
);
1787 if (!mac_cred_check_enforce(cred
)) {
1790 VFS_KERNEL_DEBUG_START1(58, vp
);
1791 MAC_CHECK(vnode_check_revoke
, cred
, vp
, vp
->v_label
);
1792 VFS_KERNEL_DEBUG_END1(58, vp
);
1797 mac_vnode_check_searchfs(vfs_context_t ctx
, struct vnode
*vp
, struct attrlist
*alist
)
1802 #if SECURITY_MAC_CHECK_ENFORCE
1803 /* 21167099 - only check if we allow write */
1804 if (!mac_vnode_enforce
) {
1808 cred
= vfs_context_ucred(ctx
);
1809 if (!mac_cred_check_enforce(cred
)) {
1812 VFS_KERNEL_DEBUG_START1(59, vp
);
1813 MAC_CHECK(vnode_check_searchfs
, cred
, vp
, vp
->v_label
, alist
);
1814 VFS_KERNEL_DEBUG_END1(59, vp
);
1819 mac_vnode_check_select(vfs_context_t ctx
, struct vnode
*vp
, int which
)
1824 #if SECURITY_MAC_CHECK_ENFORCE
1825 /* 21167099 - only check if we allow write */
1826 if (!mac_vnode_enforce
) {
1830 cred
= vfs_context_ucred(ctx
);
1831 if (!mac_cred_check_enforce(cred
)) {
1834 VFS_KERNEL_DEBUG_START1(60, vp
);
1835 MAC_CHECK(vnode_check_select
, cred
, vp
, vp
->v_label
, which
);
1836 VFS_KERNEL_DEBUG_END1(60, vp
);
1841 mac_vnode_check_setacl(vfs_context_t ctx
, struct vnode
*vp
,
1842 struct kauth_acl
*acl
)
1847 #if SECURITY_MAC_CHECK_ENFORCE
1848 /* 21167099 - only check if we allow write */
1849 if (!mac_vnode_enforce
) {
1853 cred
= vfs_context_ucred(ctx
);
1854 if (!mac_cred_check_enforce(cred
)) {
1857 VFS_KERNEL_DEBUG_START1(61, vp
);
1858 MAC_CHECK(vnode_check_setacl
, cred
, vp
, vp
->v_label
, acl
);
1859 VFS_KERNEL_DEBUG_END1(61, vp
);
1864 mac_vnode_check_setattrlist(vfs_context_t ctx
, struct vnode
*vp
,
1865 struct attrlist
*alist
)
1870 #if SECURITY_MAC_CHECK_ENFORCE
1871 /* 21167099 - only check if we allow write */
1872 if (!mac_vnode_enforce
) {
1876 cred
= vfs_context_ucred(ctx
);
1877 if (!mac_cred_check_enforce(cred
)) {
1880 VFS_KERNEL_DEBUG_START1(62, vp
);
1881 MAC_CHECK(vnode_check_setattrlist
, cred
, vp
, vp
->v_label
, alist
);
1882 VFS_KERNEL_DEBUG_END1(62, vp
);
1887 mac_vnode_check_setextattr(vfs_context_t ctx
, struct vnode
*vp
,
1888 const char *name
, struct uio
*uio
)
1893 #if SECURITY_MAC_CHECK_ENFORCE
1894 /* 21167099 - only check if we allow write */
1895 if (!mac_vnode_enforce
) {
1899 cred
= vfs_context_ucred(ctx
);
1900 if (!mac_cred_check_enforce(cred
)) {
1903 VFS_KERNEL_DEBUG_START1(63, vp
);
1904 MAC_CHECK(vnode_check_setextattr
, cred
, vp
, vp
->v_label
,
1906 VFS_KERNEL_DEBUG_END1(63, vp
);
1911 mac_vnode_check_setflags(vfs_context_t ctx
, struct vnode
*vp
, u_long flags
)
1916 #if SECURITY_MAC_CHECK_ENFORCE
1917 /* 21167099 - only check if we allow write */
1918 if (!mac_vnode_enforce
) {
1922 cred
= vfs_context_ucred(ctx
);
1923 if (!mac_cred_check_enforce(cred
)) {
1926 VFS_KERNEL_DEBUG_START1(64, vp
);
1927 MAC_CHECK(vnode_check_setflags
, cred
, vp
, vp
->v_label
, flags
);
1928 VFS_KERNEL_DEBUG_END1(64, vp
);
1933 mac_vnode_check_setmode(vfs_context_t ctx
, struct vnode
*vp
, mode_t mode
)
1938 #if SECURITY_MAC_CHECK_ENFORCE
1939 /* 21167099 - only check if we allow write */
1940 if (!mac_vnode_enforce
) {
1944 cred
= vfs_context_ucred(ctx
);
1945 if (!mac_cred_check_enforce(cred
)) {
1948 VFS_KERNEL_DEBUG_START1(65, vp
);
1949 MAC_CHECK(vnode_check_setmode
, cred
, vp
, vp
->v_label
, mode
);
1950 VFS_KERNEL_DEBUG_END1(65, vp
);
1955 mac_vnode_check_setowner(vfs_context_t ctx
, struct vnode
*vp
, uid_t uid
,
1961 #if SECURITY_MAC_CHECK_ENFORCE
1962 /* 21167099 - only check if we allow write */
1963 if (!mac_vnode_enforce
) {
1967 cred
= vfs_context_ucred(ctx
);
1968 if (!mac_cred_check_enforce(cred
)) {
1971 VFS_KERNEL_DEBUG_START1(66, vp
);
1972 MAC_CHECK(vnode_check_setowner
, cred
, vp
, vp
->v_label
, uid
, gid
);
1973 VFS_KERNEL_DEBUG_END1(66, vp
);
1978 mac_vnode_check_setutimes(vfs_context_t ctx
, struct vnode
*vp
,
1979 struct timespec atime
, struct timespec mtime
)
1984 #if SECURITY_MAC_CHECK_ENFORCE
1985 /* 21167099 - only check if we allow write */
1986 if (!mac_vnode_enforce
) {
1990 cred
= vfs_context_ucred(ctx
);
1991 if (!mac_cred_check_enforce(cred
)) {
1994 VFS_KERNEL_DEBUG_START1(67, vp
);
1995 MAC_CHECK(vnode_check_setutimes
, cred
, vp
, vp
->v_label
, atime
,
1997 VFS_KERNEL_DEBUG_END1(67, vp
);
2002 mac_vnode_check_stat(vfs_context_t ctx
, struct ucred
*file_cred
,
2008 #if SECURITY_MAC_CHECK_ENFORCE
2009 /* 21167099 - only check if we allow write */
2010 if (!mac_vnode_enforce
) {
2014 cred
= vfs_context_ucred(ctx
);
2015 if (!mac_cred_check_enforce(cred
)) {
2018 VFS_KERNEL_DEBUG_START1(68, vp
);
2019 MAC_CHECK(vnode_check_stat
, cred
, file_cred
, vp
,
2021 VFS_KERNEL_DEBUG_END1(68, vp
);
2026 mac_vnode_check_trigger_resolve(vfs_context_t ctx
, struct vnode
*dvp
,
2027 struct componentname
*cnp
)
2032 #if SECURITY_MAC_CHECK_ENFORCE
2033 /* 21167099 - only check if we allow write */
2034 if (!mac_vnode_enforce
) {
2038 cred
= vfs_context_ucred(ctx
);
2039 if (!mac_cred_check_enforce(cred
)) {
2042 VFS_KERNEL_DEBUG_START1(69, dvp
);
2043 MAC_CHECK(vnode_check_trigger_resolve
, cred
, dvp
, dvp
->v_label
, cnp
);
2044 VFS_KERNEL_DEBUG_END1(69, dvp
);
2049 mac_vnode_check_truncate(vfs_context_t ctx
, struct ucred
*file_cred
,
2055 #if SECURITY_MAC_CHECK_ENFORCE
2056 /* 21167099 - only check if we allow write */
2057 if (!mac_vnode_enforce
) {
2061 cred
= vfs_context_ucred(ctx
);
2062 if (!mac_cred_check_enforce(cred
)) {
2065 VFS_KERNEL_DEBUG_START1(70, vp
);
2066 MAC_CHECK(vnode_check_truncate
, cred
, file_cred
, vp
,
2068 VFS_KERNEL_DEBUG_END1(70, vp
);
2074 mac_vnode_check_write(vfs_context_t ctx
, struct ucred
*file_cred
,
2080 #if SECURITY_MAC_CHECK_ENFORCE
2081 /* 21167099 - only check if we allow write */
2082 if (!mac_vnode_enforce
) {
2086 cred
= vfs_context_ucred(ctx
);
2087 if (!mac_cred_check_enforce(cred
)) {
2090 VFS_KERNEL_DEBUG_START1(71, vp
);
2091 MAC_CHECK(vnode_check_write
, cred
, file_cred
, vp
, vp
->v_label
);
2092 VFS_KERNEL_DEBUG_END1(71, vp
);
2098 mac_vnode_check_uipc_bind(vfs_context_t ctx
, struct vnode
*dvp
,
2099 struct componentname
*cnp
, struct vnode_attr
*vap
)
2104 #if SECURITY_MAC_CHECK_ENFORCE
2105 /* 21167099 - only check if we allow write */
2106 if (!mac_vnode_enforce
) {
2110 cred
= vfs_context_ucred(ctx
);
2111 if (!mac_cred_check_enforce(cred
)) {
2114 VFS_KERNEL_DEBUG_START1(72, dvp
);
2115 MAC_CHECK(vnode_check_uipc_bind
, cred
, dvp
, dvp
->v_label
, cnp
, vap
);
2116 VFS_KERNEL_DEBUG_END1(72, dvp
);
2121 mac_vnode_check_uipc_connect(vfs_context_t ctx
, struct vnode
*vp
, struct socket
*so
)
2126 #if SECURITY_MAC_CHECK_ENFORCE
2127 /* 21167099 - only check if we allow write */
2128 if (!mac_vnode_enforce
) {
2132 cred
= vfs_context_ucred(ctx
);
2133 if (!mac_cred_check_enforce(cred
)) {
2136 VFS_KERNEL_DEBUG_START1(73, vp
);
2137 MAC_CHECK(vnode_check_uipc_connect
, cred
, vp
, vp
->v_label
, (socket_t
) so
);
2138 VFS_KERNEL_DEBUG_END1(73, vp
);
2143 mac_vnode_label_update(vfs_context_t ctx
, struct vnode
*vp
, struct label
*newlabel
)
2145 kauth_cred_t cred
= vfs_context_ucred(ctx
);
2146 struct label
*tmpl
= NULL
;
2148 if (vp
->v_label
== NULL
) {
2149 tmpl
= mac_vnode_label_alloc();
2154 /* recheck after lock */
2155 if (vp
->v_label
== NULL
) {
2160 VFS_KERNEL_DEBUG_START1(74, vp
);
2161 MAC_PERFORM(vnode_label_update
, cred
, vp
, vp
->v_label
, newlabel
);
2162 VFS_KERNEL_DEBUG_END1(74, vp
);
2166 mac_vnode_label_free(tmpl
);
2171 mac_vnode_find_sigs(struct proc
*p
, struct vnode
*vp
, off_t offset
)
2175 #if SECURITY_MAC_CHECK_ENFORCE
2176 /* 21167099 - only check if we allow write */
2177 if (!mac_proc_enforce
|| !mac_vnode_enforce
) {
2182 VFS_KERNEL_DEBUG_START1(75, vp
);
2183 MAC_CHECK(vnode_find_sigs
, p
, vp
, offset
, vp
->v_label
);
2184 VFS_KERNEL_DEBUG_END1(75, vp
);
2190 mac_mount_label_associate(vfs_context_t ctx
, struct mount
*mp
)
2192 kauth_cred_t cred
= vfs_context_ucred(ctx
);
2194 /* XXX: eventually this logic may be handled by the policy? */
2196 /* We desire MULTILABEL for the root filesystem. */
2197 if ((mp
->mnt_flag
& MNT_ROOTFS
) &&
2198 (strcmp(mp
->mnt_vfsstat
.f_fstypename
, "hfs") == 0)) {
2199 mp
->mnt_flag
|= MNT_MULTILABEL
;
2202 /* MULTILABEL on DEVFS. */
2203 if (strcmp(mp
->mnt_vfsstat
.f_fstypename
, "devfs") == 0) {
2204 mp
->mnt_flag
|= MNT_MULTILABEL
;
2207 /* MULTILABEL on FDESC pseudo-filesystem. */
2208 if (strcmp(mp
->mnt_vfsstat
.f_fstypename
, "fdesc") == 0) {
2209 mp
->mnt_flag
|= MNT_MULTILABEL
;
2212 /* MULTILABEL on all NFS filesystems. */
2213 if (strcmp(mp
->mnt_vfsstat
.f_fstypename
, "nfs") == 0) {
2214 mp
->mnt_flag
|= MNT_MULTILABEL
;
2217 /* MULTILABEL on all AFP filesystems. */
2218 if (strcmp(mp
->mnt_vfsstat
.f_fstypename
, "afpfs") == 0) {
2219 mp
->mnt_flag
|= MNT_MULTILABEL
;
2222 if (mp
->mnt_vtable
!= NULL
) {
2223 /* Any filesystem that supports native XATTRs. */
2224 if ((mp
->mnt_vtable
->vfc_vfsflags
& VFC_VFSNATIVEXATTR
)) {
2225 mp
->mnt_flag
|= MNT_MULTILABEL
;
2228 /* Filesystem does not support multilabel. */
2229 if ((mp
->mnt_vtable
->vfc_vfsflags
& VFC_VFSNOMACLABEL
) &&
2230 (mp
->mnt_flag
& MNT_MULTILABEL
)) {
2231 mp
->mnt_flag
&= ~MNT_MULTILABEL
;
2235 VFS_KERNEL_DEBUG_START1(76, mp
);
2236 MAC_PERFORM(mount_label_associate
, cred
, mp
, mp
->mnt_mntlabel
);
2237 VFS_KERNEL_DEBUG_END1(76, mp
);
2239 printf("MAC Framework enabling %s support: %s -> %s (%s)\n",
2240 mp
->mnt_flag
& MNT_MULTILABEL
? "multilabel" : "singlelabel",
2241 mp
->mnt_vfsstat
.f_mntfromname
,
2242 mp
->mnt_vfsstat
.f_mntonname
,
2243 mp
->mnt_vfsstat
.f_fstypename
);
2248 mac_mount_check_mount(vfs_context_t ctx
, struct vnode
*vp
,
2249 struct componentname
*cnp
, const char *vfc_name
)
2254 #if SECURITY_MAC_CHECK_ENFORCE
2255 /* 21167099 - only check if we allow write */
2256 if (!mac_vnode_enforce
) {
2260 cred
= vfs_context_ucred(ctx
);
2261 if (!mac_cred_check_enforce(cred
)) {
2264 VFS_KERNEL_DEBUG_START1(77, vp
);
2265 MAC_CHECK(mount_check_mount
, cred
, vp
, vp
->v_label
, cnp
, vfc_name
);
2266 VFS_KERNEL_DEBUG_END1(77, vp
);
2272 mac_mount_check_mount_late(vfs_context_t ctx
, struct mount
*mp
)
2277 #if SECURITY_MAC_CHECK_ENFORCE
2278 /* 21167099 - only check if we allow write */
2279 if (!mac_vnode_enforce
) {
2283 cred
= vfs_context_ucred(ctx
);
2284 if (!mac_cred_check_enforce(cred
)) {
2287 VFS_KERNEL_DEBUG_START1(78, mp
);
2288 MAC_CHECK(mount_check_mount_late
, cred
, mp
);
2289 VFS_KERNEL_DEBUG_END1(78, mp
);
2295 mac_mount_check_snapshot_create(vfs_context_t ctx
, struct mount
*mp
,
2301 #if SECURITY_MAC_CHECK_ENFORCE
2302 /* 21167099 - only check if we allow write */
2303 if (!mac_vnode_enforce
) {
2307 cred
= vfs_context_ucred(ctx
);
2308 if (!mac_cred_check_enforce(cred
)) {
2311 VFS_KERNEL_DEBUG_START1(79, mp
);
2312 MAC_CHECK(mount_check_snapshot_create
, cred
, mp
, name
);
2313 VFS_KERNEL_DEBUG_END1(79, mp
);
2318 mac_mount_check_snapshot_delete(vfs_context_t ctx
, struct mount
*mp
,
2324 #if SECURITY_MAC_CHECK_ENFORCE
2325 /* 21167099 - only check if we allow write */
2326 if (!mac_vnode_enforce
) {
2330 cred
= vfs_context_ucred(ctx
);
2331 if (!mac_cred_check_enforce(cred
)) {
2334 VFS_KERNEL_DEBUG_START1(80, mp
);
2335 MAC_CHECK(mount_check_snapshot_delete
, cred
, mp
, name
);
2336 VFS_KERNEL_DEBUG_END1(80, mp
);
2341 mac_mount_check_snapshot_revert(vfs_context_t ctx
, struct mount
*mp
,
2347 #if SECURITY_MAC_CHECK_ENFORCE
2348 /* 21167099 - only check if we allow write */
2349 if (!mac_vnode_enforce
) {
2353 cred
= vfs_context_ucred(ctx
);
2354 if (!mac_cred_check_enforce(cred
)) {
2357 VFS_KERNEL_DEBUG_START1(81, mp
);
2358 MAC_CHECK(mount_check_snapshot_revert
, cred
, mp
, name
);
2359 VFS_KERNEL_DEBUG_END1(81, mp
);
2364 mac_mount_check_remount(vfs_context_t ctx
, struct mount
*mp
)
2369 #if SECURITY_MAC_CHECK_ENFORCE
2370 /* 21167099 - only check if we allow write */
2371 if (!mac_vnode_enforce
) {
2375 cred
= vfs_context_ucred(ctx
);
2376 if (!mac_cred_check_enforce(cred
)) {
2379 VFS_KERNEL_DEBUG_START1(82, mp
);
2380 MAC_CHECK(mount_check_remount
, cred
, mp
, mp
->mnt_mntlabel
);
2381 VFS_KERNEL_DEBUG_END1(82, mp
);
2387 mac_mount_check_umount(vfs_context_t ctx
, struct mount
*mp
)
2392 #if SECURITY_MAC_CHECK_ENFORCE
2393 /* 21167099 - only check if we allow write */
2394 if (!mac_vnode_enforce
) {
2398 cred
= vfs_context_ucred(ctx
);
2399 if (!mac_cred_check_enforce(cred
)) {
2402 VFS_KERNEL_DEBUG_START1(83, mp
);
2403 MAC_CHECK(mount_check_umount
, cred
, mp
, mp
->mnt_mntlabel
);
2404 VFS_KERNEL_DEBUG_END1(83, mp
);
2410 mac_mount_check_getattr(vfs_context_t ctx
, struct mount
*mp
,
2411 struct vfs_attr
*vfa
)
2416 #if SECURITY_MAC_CHECK_ENFORCE
2417 /* 21167099 - only check if we allow write */
2418 if (!mac_vnode_enforce
) {
2422 cred
= vfs_context_ucred(ctx
);
2423 if (!mac_cred_check_enforce(cred
)) {
2426 VFS_KERNEL_DEBUG_START1(84, mp
);
2427 MAC_CHECK(mount_check_getattr
, cred
, mp
, mp
->mnt_mntlabel
, vfa
);
2428 VFS_KERNEL_DEBUG_END1(84, mp
);
2433 mac_mount_check_setattr(vfs_context_t ctx
, struct mount
*mp
,
2434 struct vfs_attr
*vfa
)
2439 #if SECURITY_MAC_CHECK_ENFORCE
2440 /* 21167099 - only check if we allow write */
2441 if (!mac_vnode_enforce
) {
2445 cred
= vfs_context_ucred(ctx
);
2446 if (!mac_cred_check_enforce(cred
)) {
2449 VFS_KERNEL_DEBUG_START1(85, mp
);
2450 MAC_CHECK(mount_check_setattr
, cred
, mp
, mp
->mnt_mntlabel
, vfa
);
2451 VFS_KERNEL_DEBUG_END1(85, mp
);
2456 mac_mount_check_stat(vfs_context_t ctx
, struct mount
*mount
)
2461 #if SECURITY_MAC_CHECK_ENFORCE
2462 /* 21167099 - only check if we allow write */
2463 if (!mac_vnode_enforce
) {
2467 cred
= vfs_context_ucred(ctx
);
2468 if (!mac_cred_check_enforce(cred
)) {
2471 VFS_KERNEL_DEBUG_START1(86, mount
);
2472 MAC_CHECK(mount_check_stat
, cred
, mount
, mount
->mnt_mntlabel
);
2473 VFS_KERNEL_DEBUG_END1(86, mount
);
2479 mac_mount_check_label_update(vfs_context_t ctx
, struct mount
*mount
)
2484 #if SECURITY_MAC_CHECK_ENFORCE
2485 /* 21167099 - only check if we allow write */
2486 if (!mac_vnode_enforce
) {
2490 cred
= vfs_context_ucred(ctx
);
2491 if (!mac_cred_check_enforce(cred
)) {
2494 VFS_KERNEL_DEBUG_START1(87, mount
);
2495 MAC_CHECK(mount_check_label_update
, cred
, mount
, mount
->mnt_mntlabel
);
2496 VFS_KERNEL_DEBUG_END1(87, mount
);
2502 mac_mount_check_fsctl(vfs_context_t ctx
, struct mount
*mp
, u_int cmd
)
2507 #if SECURITY_MAC_CHECK_ENFORCE
2508 /* 21167099 - only check if we allow write */
2509 if (!mac_vnode_enforce
) {
2513 cred
= vfs_context_ucred(ctx
);
2514 if (!mac_cred_check_enforce(cred
)) {
2517 VFS_KERNEL_DEBUG_START1(88, mp
);
2518 MAC_CHECK(mount_check_fsctl
, cred
, mp
, mp
->mnt_mntlabel
, cmd
);
2519 VFS_KERNEL_DEBUG_END1(88, mp
);
2525 mac_devfs_label_associate_device(dev_t dev
, struct devnode
*de
,
2526 const char *fullpath
)
2528 #if SECURITY_MAC_CHECK_ENFORCE
2529 /* 21167099 - only check if we allow write */
2530 if (!mac_device_enforce
) {
2535 VFS_KERNEL_DEBUG_START1(89, de
);
2536 MAC_PERFORM(devfs_label_associate_device
, dev
, de
, de
->dn_label
,
2538 VFS_KERNEL_DEBUG_END1(89, de
);
2542 mac_devfs_label_associate_directory(const char *dirname
, int dirnamelen
,
2543 struct devnode
*de
, const char *fullpath
)
2545 #if SECURITY_MAC_CHECK_ENFORCE
2546 /* 21167099 - only check if we allow write */
2547 if (!mac_device_enforce
) {
2552 VFS_KERNEL_DEBUG_START1(90, de
);
2553 MAC_PERFORM(devfs_label_associate_directory
, dirname
, dirnamelen
, de
,
2554 de
->dn_label
, fullpath
);
2555 VFS_KERNEL_DEBUG_END1(90, de
);
2559 vn_setlabel(struct vnode
*vp
, struct label
*intlabel
, vfs_context_t context
)
2563 #if SECURITY_MAC_CHECK_ENFORCE
2564 /* 21167099 - only check if we allow write */
2565 if (!mac_vnode_enforce
) {
2569 if (!mac_label_vnodes
) {
2573 if (vp
->v_mount
== NULL
) {
2574 printf("vn_setlabel: null v_mount\n");
2575 if (vp
->v_type
!= VNON
) {
2576 printf("vn_setlabel: null v_mount with non-VNON\n");
2581 if ((vp
->v_mount
->mnt_flag
& MNT_MULTILABEL
) == 0) {
2586 * Multi-phase commit. First check the policies to confirm the
2587 * change is OK. Then commit via the filesystem. Finally,
2588 * update the actual vnode label. Question: maybe the filesystem
2589 * should update the vnode at the end as part of VNOP_SETLABEL()?
2591 error
= mac_vnode_check_label_update(context
, vp
, intlabel
);
2596 error
= VNOP_SETLABEL(vp
, intlabel
, context
);
2597 if (error
== ENOTSUP
) {
2598 error
= mac_vnode_label_store(context
, vp
,
2601 printf("%s: mac_vnode_label_store failed %d\n",
2605 mac_vnode_label_update(context
, vp
, intlabel
);
2607 printf("vn_setlabel: vop setlabel failed %d\n", error
);
2615 mac_vnode_label_associate_fdesc(struct mount
*mp
, struct fdescnode
*fnp
,
2616 struct vnode
*vp
, vfs_context_t ctx
)
2618 struct fileproc
*fp
;
2619 #if CONFIG_MACF_SOCKET_SUBSET
2629 VFS_KERNEL_DEBUG_START1(91, vp
);
2631 * If no backing file, let the policy choose which label to use.
2633 if (fnp
->fd_fd
== -1) {
2634 MAC_PERFORM(vnode_label_associate_file
, vfs_context_ucred(ctx
),
2635 mp
, mp
->mnt_mntlabel
, NULL
, NULL
, vp
, vp
->v_label
);
2636 VFS_KERNEL_DEBUG_END1(91, vp
);
2640 p
= vfs_context_proc(ctx
);
2641 error
= fp_lookup(p
, fnp
->fd_fd
, &fp
, 0);
2643 VFS_KERNEL_DEBUG_END1(91, vp
);
2647 if (fp
->f_fglob
== NULL
) {
2652 switch (FILEGLOB_DTYPE(fp
->f_fglob
)) {
2654 fvp
= (struct vnode
*)fp
->f_fglob
->fg_data
;
2655 if ((error
= vnode_getwithref(fvp
))) {
2658 if (fvp
->v_label
!= NULL
) {
2659 if (mac_label_vnodes
!= 0 && vp
->v_label
== NULL
) {
2660 mac_vnode_label_init(vp
); /* init dst label */
2662 MAC_PERFORM(vnode_label_copy
, fvp
->v_label
, vp
->v_label
);
2664 (void)vnode_put(fvp
);
2666 #if CONFIG_MACF_SOCKET_SUBSET
2668 so
= (struct socket
*)fp
->f_fglob
->fg_data
;
2670 MAC_PERFORM(vnode_label_associate_socket
,
2671 vfs_context_ucred(ctx
), (socket_t
)so
, so
->so_label
,
2673 socket_unlock(so
, 1);
2677 pshm_label_associate(fp
, vp
, ctx
);
2680 psem_label_associate(fp
, vp
, ctx
);
2683 cpipe
= (struct pipe
*)fp
->f_fglob
->fg_data
;
2684 /* kern/sys_pipe.c:pipe_select() suggests this test. */
2685 if (cpipe
== (struct pipe
*)-1) {
2690 MAC_PERFORM(vnode_label_associate_pipe
, vfs_context_ucred(ctx
),
2691 cpipe
, cpipe
->pipe_label
, vp
, vp
->v_label
);
2695 case DTYPE_FSEVENTS
:
2697 case DTYPE_NETPOLICY
:
2699 MAC_PERFORM(vnode_label_associate_file
, vfs_context_ucred(ctx
),
2700 mp
, mp
->mnt_mntlabel
, fp
->f_fglob
, fp
->f_fglob
->fg_label
,
2705 VFS_KERNEL_DEBUG_END1(91, vp
);
2706 fp_drop(p
, fnp
->fd_fd
, fp
, 0);
2711 mac_vnode_label_get(struct vnode
*vp
, int slot
, intptr_t sentinel
)
2715 KASSERT(vp
!= NULL
, ("mac_vnode_label_get: NULL vnode"));
2718 return mac_label_get(l
, slot
);
2725 mac_vnode_label_set(struct vnode
*vp
, int slot
, intptr_t v
)
2728 KASSERT(vp
!= NULL
, ("mac_vnode_label_set: NULL vnode"));
2731 mac_vnode_label_init(vp
);
2734 mac_label_set(l
, slot
, v
);