1*1b191cb5SApple OSS Distributions /*
2*1b191cb5SApple OSS Distributions * Copyright (c) 2007-2016 Apple Inc. All rights reserved.
3*1b191cb5SApple OSS Distributions *
4*1b191cb5SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*1b191cb5SApple OSS Distributions *
6*1b191cb5SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*1b191cb5SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*1b191cb5SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*1b191cb5SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*1b191cb5SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*1b191cb5SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*1b191cb5SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*1b191cb5SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*1b191cb5SApple OSS Distributions *
15*1b191cb5SApple OSS Distributions * Please obtain a copy of the License at
16*1b191cb5SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*1b191cb5SApple OSS Distributions *
18*1b191cb5SApple OSS Distributions * The Original Code and all software distributed under the License are
19*1b191cb5SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*1b191cb5SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*1b191cb5SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*1b191cb5SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*1b191cb5SApple OSS Distributions * Please see the License for the specific language governing rights and
24*1b191cb5SApple OSS Distributions * limitations under the License.
25*1b191cb5SApple OSS Distributions *
26*1b191cb5SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*1b191cb5SApple OSS Distributions */
28*1b191cb5SApple OSS Distributions /*-
29*1b191cb5SApple OSS Distributions * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
30*1b191cb5SApple OSS Distributions * Copyright (c) 2001 Ilmar S. Habibulin
31*1b191cb5SApple OSS Distributions * Copyright (c) 2001, 2002, 2003, 2004 Networks Associates Technology, Inc.
32*1b191cb5SApple OSS Distributions * Copyright (c) 2005 SPARTA, Inc.
33*1b191cb5SApple OSS Distributions *
34*1b191cb5SApple OSS Distributions * This software was developed by Robert Watson and Ilmar Habibulin for the
35*1b191cb5SApple OSS Distributions * TrustedBSD Project.
36*1b191cb5SApple OSS Distributions *
37*1b191cb5SApple OSS Distributions * This software was developed for the FreeBSD Project in part by Network
38*1b191cb5SApple OSS Distributions * Associates Laboratories, the Security Research Division of Network
39*1b191cb5SApple OSS Distributions * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
40*1b191cb5SApple OSS Distributions * as part of the DARPA CHATS research program.
41*1b191cb5SApple OSS Distributions *
42*1b191cb5SApple OSS Distributions * Redistribution and use in source and binary forms, with or without
43*1b191cb5SApple OSS Distributions * modification, are permitted provided that the following conditions
44*1b191cb5SApple OSS Distributions * are met:
45*1b191cb5SApple OSS Distributions * 1. Redistributions of source code must retain the above copyright
46*1b191cb5SApple OSS Distributions * notice, this list of conditions and the following disclaimer.
47*1b191cb5SApple OSS Distributions * 2. Redistributions in binary form must reproduce the above copyright
48*1b191cb5SApple OSS Distributions * notice, this list of conditions and the following disclaimer in the
49*1b191cb5SApple OSS Distributions * documentation and/or other materials provided with the distribution.
50*1b191cb5SApple OSS Distributions *
51*1b191cb5SApple OSS Distributions * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
52*1b191cb5SApple OSS Distributions * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53*1b191cb5SApple OSS Distributions * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54*1b191cb5SApple OSS Distributions * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
55*1b191cb5SApple OSS Distributions * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56*1b191cb5SApple OSS Distributions * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57*1b191cb5SApple OSS Distributions * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58*1b191cb5SApple OSS Distributions * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59*1b191cb5SApple OSS Distributions * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60*1b191cb5SApple OSS Distributions * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61*1b191cb5SApple OSS Distributions * SUCH DAMAGE.
62*1b191cb5SApple OSS Distributions *
63*1b191cb5SApple OSS Distributions */
64*1b191cb5SApple OSS Distributions
65*1b191cb5SApple OSS Distributions #include <kern/kalloc.h>
66*1b191cb5SApple OSS Distributions #include <libkern/OSAtomic.h>
67*1b191cb5SApple OSS Distributions
68*1b191cb5SApple OSS Distributions #include <sys/param.h>
69*1b191cb5SApple OSS Distributions #include <sys/systm.h>
70*1b191cb5SApple OSS Distributions #include <sys/kernel.h>
71*1b191cb5SApple OSS Distributions #include <sys/proc.h>
72*1b191cb5SApple OSS Distributions #include <sys/kauth.h>
73*1b191cb5SApple OSS Distributions
74*1b191cb5SApple OSS Distributions #include <sys/file_internal.h>
75*1b191cb5SApple OSS Distributions #include <sys/imgact.h>
76*1b191cb5SApple OSS Distributions #include <sys/namei.h>
77*1b191cb5SApple OSS Distributions #include <sys/mount_internal.h>
78*1b191cb5SApple OSS Distributions #include <sys/pipe.h>
79*1b191cb5SApple OSS Distributions #include <sys/posix_sem.h>
80*1b191cb5SApple OSS Distributions #include <sys/posix_shm.h>
81*1b191cb5SApple OSS Distributions #include <sys/reason.h>
82*1b191cb5SApple OSS Distributions #include <sys/uio_internal.h>
83*1b191cb5SApple OSS Distributions #include <sys/vnode_internal.h>
84*1b191cb5SApple OSS Distributions #include <sys/kdebug.h>
85*1b191cb5SApple OSS Distributions
86*1b191cb5SApple OSS Distributions
87*1b191cb5SApple OSS Distributions #include <miscfs/devfs/devfsdefs.h>
88*1b191cb5SApple OSS Distributions #include <miscfs/devfs/fdesc.h>
89*1b191cb5SApple OSS Distributions
90*1b191cb5SApple OSS Distributions #include <security/mac_internal.h>
91*1b191cb5SApple OSS Distributions
92*1b191cb5SApple OSS Distributions /* convert {R,W,X}_OK values to V{READ,WRITE,EXEC} */
93*1b191cb5SApple OSS Distributions #define ACCESS_MODE_TO_VNODE_MASK(m) (m << 6)
94*1b191cb5SApple OSS Distributions
95*1b191cb5SApple OSS Distributions
96*1b191cb5SApple OSS Distributions /*
97*1b191cb5SApple OSS Distributions * Optional tracing of policy operations. Define VFS_TRACE_POLICY_OPS to trace the operations.
98*1b191cb5SApple OSS Distributions *
99*1b191cb5SApple OSS Distributions * Along with DBG_FSYSTEM and DBG_VFS, dcode in the macros below is used to construct
100*1b191cb5SApple OSS Distributions * KDBG_EVENTID(DBG_FSYSTEM, DBG_VFS, dcode) global event id, see bsd/sys/kdebug.h.
101*1b191cb5SApple OSS Distributions * Note that dcode is multiplied by 4 and ORed as part of the construction. See bsd/kern/trace_codes
102*1b191cb5SApple OSS Distributions * for list of system-wide {global event id, name} pairs. Currently DBG_VFS event ids are in range
103*1b191cb5SApple OSS Distributions * [0x3130000, 0x3130188].
104*1b191cb5SApple OSS Distributions */
105*1b191cb5SApple OSS Distributions
106*1b191cb5SApple OSS Distributions //#define VFS_TRACE_POLICY_OPS
107*1b191cb5SApple OSS Distributions
108*1b191cb5SApple OSS Distributions #ifdef VFS_TRACE_POLICY_OPS
109*1b191cb5SApple OSS Distributions #define DBG_VFS_CODE(dcode) FSDBG_CODE(DBG_VFS, dcode)
110*1b191cb5SApple OSS Distributions #define VFS_KERNEL_DEBUG_START0(dcode) KERNEL_DEBUG_CONSTANT(DBG_VFS_CODE(dcode) | DBG_FUNC_START, 0, 0, 0, 0, 0)
111*1b191cb5SApple OSS Distributions #define VFS_KERNEL_DEBUG_END0(dcode) KERNEL_DEBUG_CONSTANT(DBG_VFS_CODE(dcode) | DBG_FUNC_END, 0, 0, 0, 0, 0)
112*1b191cb5SApple OSS Distributions #define VFS_KERNEL_DEBUG_START1(dcode, darg) KERNEL_DEBUG_CONSTANT(DBG_VFS_CODE(dcode) | DBG_FUNC_START, darg, 0, 0, 0, 0)
113*1b191cb5SApple OSS Distributions #define VFS_KERNEL_DEBUG_END1(dcode, darg) KERNEL_DEBUG_CONSTANT(DBG_VFS_CODE(dcode) | DBG_FUNC_END, darg, 0, 0, 0, 0)
114*1b191cb5SApple OSS Distributions #else
115*1b191cb5SApple OSS Distributions #define VFS_KERNEL_DEBUG_START0(dcode) do {} while (0)
116*1b191cb5SApple OSS Distributions #define VFS_KERNEL_DEBUG_END0(dcode) do {} while (0)
117*1b191cb5SApple OSS Distributions #define VFS_KERNEL_DEBUG_START1(dcode, darg) do {} while (0)
118*1b191cb5SApple OSS Distributions #define VFS_KERNEL_DEBUG_END1(dcode, darg) do {} while (0)
119*1b191cb5SApple OSS Distributions #endif
120*1b191cb5SApple OSS Distributions
121*1b191cb5SApple OSS Distributions void
mac_devfs_label_init(struct devnode * de)122*1b191cb5SApple OSS Distributions mac_devfs_label_init(struct devnode *de)
123*1b191cb5SApple OSS Distributions {
124*1b191cb5SApple OSS Distributions mac_labelzone_alloc_owned(&de->dn_label, MAC_WAITOK, ^(struct label *label) {
125*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START0(0);
126*1b191cb5SApple OSS Distributions MAC_PERFORM(devfs_label_init, label);
127*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END0(0);
128*1b191cb5SApple OSS Distributions });
129*1b191cb5SApple OSS Distributions }
130*1b191cb5SApple OSS Distributions
131*1b191cb5SApple OSS Distributions struct label *
mac_devfs_label(struct devnode * de)132*1b191cb5SApple OSS Distributions mac_devfs_label(struct devnode *de)
133*1b191cb5SApple OSS Distributions {
134*1b191cb5SApple OSS Distributions return mac_label_verify(&de->dn_label);
135*1b191cb5SApple OSS Distributions }
136*1b191cb5SApple OSS Distributions
137*1b191cb5SApple OSS Distributions void
mac_devfs_label_destroy(struct devnode * de)138*1b191cb5SApple OSS Distributions mac_devfs_label_destroy(struct devnode *de)
139*1b191cb5SApple OSS Distributions {
140*1b191cb5SApple OSS Distributions mac_labelzone_free_owned(&de->dn_label, ^(struct label *label) {
141*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(3, label);
142*1b191cb5SApple OSS Distributions MAC_PERFORM(devfs_label_destroy, label);
143*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(3, label);
144*1b191cb5SApple OSS Distributions });
145*1b191cb5SApple OSS Distributions }
146*1b191cb5SApple OSS Distributions
147*1b191cb5SApple OSS Distributions void
mac_mount_label_init(struct mount * mp)148*1b191cb5SApple OSS Distributions mac_mount_label_init(struct mount *mp)
149*1b191cb5SApple OSS Distributions {
150*1b191cb5SApple OSS Distributions mac_labelzone_alloc_owned(&mp->mnt_mntlabel, MAC_WAITOK, ^(struct label *label) {
151*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START0(1);
152*1b191cb5SApple OSS Distributions MAC_PERFORM(mount_label_init, label);
153*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END0(1);
154*1b191cb5SApple OSS Distributions });
155*1b191cb5SApple OSS Distributions }
156*1b191cb5SApple OSS Distributions
157*1b191cb5SApple OSS Distributions struct label *
mac_mount_label(struct mount * mp)158*1b191cb5SApple OSS Distributions mac_mount_label(struct mount *mp)
159*1b191cb5SApple OSS Distributions {
160*1b191cb5SApple OSS Distributions return mac_label_verify(&mp->mnt_mntlabel);
161*1b191cb5SApple OSS Distributions }
162*1b191cb5SApple OSS Distributions
163*1b191cb5SApple OSS Distributions void
mac_mount_label_destroy(struct mount * mp)164*1b191cb5SApple OSS Distributions mac_mount_label_destroy(struct mount *mp)
165*1b191cb5SApple OSS Distributions {
166*1b191cb5SApple OSS Distributions mac_labelzone_free_owned(&mp->mnt_mntlabel, ^(struct label *label) {
167*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(4, label);
168*1b191cb5SApple OSS Distributions MAC_PERFORM(mount_label_destroy, label);
169*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(4, label);
170*1b191cb5SApple OSS Distributions });
171*1b191cb5SApple OSS Distributions }
172*1b191cb5SApple OSS Distributions
173*1b191cb5SApple OSS Distributions struct label *
mac_vnode_label_alloc(vnode_t vp)174*1b191cb5SApple OSS Distributions mac_vnode_label_alloc(vnode_t vp)
175*1b191cb5SApple OSS Distributions {
176*1b191cb5SApple OSS Distributions return mac_labelzone_alloc_for_owner(vp ? &vp->v_label : NULL, MAC_WAITOK, ^(struct label *label) {
177*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START0(2);
178*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_init, label);
179*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END0(2);
180*1b191cb5SApple OSS Distributions OSIncrementAtomic(&mac_vnode_label_count);
181*1b191cb5SApple OSS Distributions });
182*1b191cb5SApple OSS Distributions }
183*1b191cb5SApple OSS Distributions
184*1b191cb5SApple OSS Distributions void
mac_vnode_label_init(vnode_t vp)185*1b191cb5SApple OSS Distributions mac_vnode_label_init(vnode_t vp)
186*1b191cb5SApple OSS Distributions {
187*1b191cb5SApple OSS Distributions struct label *label;
188*1b191cb5SApple OSS Distributions
189*1b191cb5SApple OSS Distributions label = mac_vnode_label_alloc(vp);
190*1b191cb5SApple OSS Distributions vp->v_label = label;
191*1b191cb5SApple OSS Distributions }
192*1b191cb5SApple OSS Distributions
193*1b191cb5SApple OSS Distributions struct label *
mac_vnode_label(vnode_t vp)194*1b191cb5SApple OSS Distributions mac_vnode_label(vnode_t vp)
195*1b191cb5SApple OSS Distributions {
196*1b191cb5SApple OSS Distributions return mac_label_verify(&vp->v_label);
197*1b191cb5SApple OSS Distributions }
198*1b191cb5SApple OSS Distributions
199*1b191cb5SApple OSS Distributions static void
mac_vnode_label_cleanup(struct label * label)200*1b191cb5SApple OSS Distributions mac_vnode_label_cleanup(struct label *label)
201*1b191cb5SApple OSS Distributions {
202*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(5, label);
203*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_destroy, label);
204*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(5, label);
205*1b191cb5SApple OSS Distributions OSDecrementAtomic(&mac_vnode_label_count);
206*1b191cb5SApple OSS Distributions }
207*1b191cb5SApple OSS Distributions
208*1b191cb5SApple OSS Distributions void
mac_vnode_label_free(struct label * label)209*1b191cb5SApple OSS Distributions mac_vnode_label_free(struct label *label)
210*1b191cb5SApple OSS Distributions {
211*1b191cb5SApple OSS Distributions if (label != NULL) {
212*1b191cb5SApple OSS Distributions mac_vnode_label_cleanup(label);
213*1b191cb5SApple OSS Distributions mac_labelzone_free(label);
214*1b191cb5SApple OSS Distributions }
215*1b191cb5SApple OSS Distributions }
216*1b191cb5SApple OSS Distributions
217*1b191cb5SApple OSS Distributions void
mac_vnode_label_destroy(struct vnode * vp)218*1b191cb5SApple OSS Distributions mac_vnode_label_destroy(struct vnode *vp)
219*1b191cb5SApple OSS Distributions {
220*1b191cb5SApple OSS Distributions mac_labelzone_free_owned(&vp->v_label, ^(struct label *label) {
221*1b191cb5SApple OSS Distributions mac_vnode_label_cleanup(label);
222*1b191cb5SApple OSS Distributions });
223*1b191cb5SApple OSS Distributions }
224*1b191cb5SApple OSS Distributions
225*1b191cb5SApple OSS Distributions int
mac_vnode_label_init_needed(vnode_t vp)226*1b191cb5SApple OSS Distributions mac_vnode_label_init_needed(vnode_t vp)
227*1b191cb5SApple OSS Distributions {
228*1b191cb5SApple OSS Distributions #if CONFIG_MACF_LAZY_VNODE_LABELS
229*1b191cb5SApple OSS Distributions (void)vp;
230*1b191cb5SApple OSS Distributions return false;
231*1b191cb5SApple OSS Distributions #else
232*1b191cb5SApple OSS Distributions return mac_label_vnodes != 0 && mac_vnode_label(vp) == NULL;
233*1b191cb5SApple OSS Distributions #endif
234*1b191cb5SApple OSS Distributions }
235*1b191cb5SApple OSS Distributions
236*1b191cb5SApple OSS Distributions struct label *
mac_vnode_label_allocate(vnode_t vp)237*1b191cb5SApple OSS Distributions mac_vnode_label_allocate(vnode_t vp)
238*1b191cb5SApple OSS Distributions {
239*1b191cb5SApple OSS Distributions if (mac_vnode_label_init_needed(vp)) {
240*1b191cb5SApple OSS Distributions mac_vnode_label_init(vp);
241*1b191cb5SApple OSS Distributions }
242*1b191cb5SApple OSS Distributions return mac_vnode_label(vp);
243*1b191cb5SApple OSS Distributions }
244*1b191cb5SApple OSS Distributions
245*1b191cb5SApple OSS Distributions /*
246*1b191cb5SApple OSS Distributions * vnode labels are allocated at the same time as vnodes, but vnodes are never
247*1b191cb5SApple OSS Distributions * freed. Instead, we want to remove any sensitive information before putting
248*1b191cb5SApple OSS Distributions * them on the free list for reuse.
249*1b191cb5SApple OSS Distributions */
250*1b191cb5SApple OSS Distributions void
mac_vnode_label_recycle(vnode_t vp)251*1b191cb5SApple OSS Distributions mac_vnode_label_recycle(vnode_t vp)
252*1b191cb5SApple OSS Distributions {
253*1b191cb5SApple OSS Distributions struct label *v_label = mac_vnode_label(vp);
254*1b191cb5SApple OSS Distributions
255*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_recycle, v_label);
256*1b191cb5SApple OSS Distributions #if CONFIG_MACF_LAZY_VNODE_LABELS
257*1b191cb5SApple OSS Distributions if (v_label) {
258*1b191cb5SApple OSS Distributions mac_vnode_label_destroy(vp);
259*1b191cb5SApple OSS Distributions vp->v_lflag &= ~VL_LABELED;
260*1b191cb5SApple OSS Distributions }
261*1b191cb5SApple OSS Distributions #endif
262*1b191cb5SApple OSS Distributions }
263*1b191cb5SApple OSS Distributions
264*1b191cb5SApple OSS Distributions void
mac_vnode_label_copy(struct label * src,struct label * dest)265*1b191cb5SApple OSS Distributions mac_vnode_label_copy(struct label *src, struct label *dest)
266*1b191cb5SApple OSS Distributions {
267*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(6, src);
268*1b191cb5SApple OSS Distributions if (src == NULL) {
269*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_init, dest);
270*1b191cb5SApple OSS Distributions } else {
271*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_copy, src, dest);
272*1b191cb5SApple OSS Distributions }
273*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(6, src);
274*1b191cb5SApple OSS Distributions }
275*1b191cb5SApple OSS Distributions
276*1b191cb5SApple OSS Distributions int
mac_vnode_label_externalize_audit(struct vnode * vp,struct mac * mac)277*1b191cb5SApple OSS Distributions mac_vnode_label_externalize_audit(struct vnode *vp, struct mac *mac)
278*1b191cb5SApple OSS Distributions {
279*1b191cb5SApple OSS Distributions int error;
280*1b191cb5SApple OSS Distributions
281*1b191cb5SApple OSS Distributions /* It is assumed that any necessary vnode locking is done on entry */
282*1b191cb5SApple OSS Distributions error = MAC_EXTERNALIZE_AUDIT(vnode, mac_vnode_label(vp),
283*1b191cb5SApple OSS Distributions mac->m_string, mac->m_buflen);
284*1b191cb5SApple OSS Distributions
285*1b191cb5SApple OSS Distributions return error;
286*1b191cb5SApple OSS Distributions }
287*1b191cb5SApple OSS Distributions
288*1b191cb5SApple OSS Distributions int
mac_vnode_label_externalize(struct label * label,char * elements,char * outbuf,size_t outbuflen,int flags __unused)289*1b191cb5SApple OSS Distributions mac_vnode_label_externalize(struct label *label, char *elements,
290*1b191cb5SApple OSS Distributions char *outbuf, size_t outbuflen, int flags __unused)
291*1b191cb5SApple OSS Distributions {
292*1b191cb5SApple OSS Distributions int error;
293*1b191cb5SApple OSS Distributions
294*1b191cb5SApple OSS Distributions error = MAC_EXTERNALIZE(vnode, label, elements, outbuf, outbuflen);
295*1b191cb5SApple OSS Distributions
296*1b191cb5SApple OSS Distributions return error;
297*1b191cb5SApple OSS Distributions }
298*1b191cb5SApple OSS Distributions
299*1b191cb5SApple OSS Distributions int
mac_vnode_label_internalize(struct label * label,char * string)300*1b191cb5SApple OSS Distributions mac_vnode_label_internalize(struct label *label, char *string)
301*1b191cb5SApple OSS Distributions {
302*1b191cb5SApple OSS Distributions int error;
303*1b191cb5SApple OSS Distributions
304*1b191cb5SApple OSS Distributions error = MAC_INTERNALIZE(vnode, label, string);
305*1b191cb5SApple OSS Distributions
306*1b191cb5SApple OSS Distributions return error;
307*1b191cb5SApple OSS Distributions }
308*1b191cb5SApple OSS Distributions
309*1b191cb5SApple OSS Distributions int
mac_mount_label_internalize(struct label * label,char * string)310*1b191cb5SApple OSS Distributions mac_mount_label_internalize(struct label *label, char *string)
311*1b191cb5SApple OSS Distributions {
312*1b191cb5SApple OSS Distributions int error;
313*1b191cb5SApple OSS Distributions
314*1b191cb5SApple OSS Distributions error = MAC_INTERNALIZE(mount, label, string);
315*1b191cb5SApple OSS Distributions
316*1b191cb5SApple OSS Distributions return error;
317*1b191cb5SApple OSS Distributions }
318*1b191cb5SApple OSS Distributions
319*1b191cb5SApple OSS Distributions int
mac_mount_label_externalize(struct label * label,char * elements,char * outbuf,size_t outbuflen)320*1b191cb5SApple OSS Distributions mac_mount_label_externalize(struct label *label, char *elements,
321*1b191cb5SApple OSS Distributions char *outbuf, size_t outbuflen)
322*1b191cb5SApple OSS Distributions {
323*1b191cb5SApple OSS Distributions int error;
324*1b191cb5SApple OSS Distributions
325*1b191cb5SApple OSS Distributions error = MAC_EXTERNALIZE(mount, label, elements, outbuf, outbuflen);
326*1b191cb5SApple OSS Distributions
327*1b191cb5SApple OSS Distributions return error;
328*1b191cb5SApple OSS Distributions }
329*1b191cb5SApple OSS Distributions
330*1b191cb5SApple OSS Distributions void
mac_devfs_label_copy(struct label * src,struct label * dest)331*1b191cb5SApple OSS Distributions mac_devfs_label_copy(struct label *src, struct label *dest)
332*1b191cb5SApple OSS Distributions {
333*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
334*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
335*1b191cb5SApple OSS Distributions if (!mac_device_enforce) {
336*1b191cb5SApple OSS Distributions return;
337*1b191cb5SApple OSS Distributions }
338*1b191cb5SApple OSS Distributions #endif
339*1b191cb5SApple OSS Distributions
340*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(7, src);
341*1b191cb5SApple OSS Distributions MAC_PERFORM(devfs_label_copy, src, dest);
342*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(7, src);
343*1b191cb5SApple OSS Distributions }
344*1b191cb5SApple OSS Distributions
345*1b191cb5SApple OSS Distributions void
mac_devfs_label_update(struct mount * mp,struct devnode * de,struct vnode * vp)346*1b191cb5SApple OSS Distributions mac_devfs_label_update(struct mount *mp, struct devnode *de,
347*1b191cb5SApple OSS Distributions struct vnode *vp)
348*1b191cb5SApple OSS Distributions {
349*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
350*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
351*1b191cb5SApple OSS Distributions if (!mac_device_enforce) {
352*1b191cb5SApple OSS Distributions return;
353*1b191cb5SApple OSS Distributions }
354*1b191cb5SApple OSS Distributions #endif
355*1b191cb5SApple OSS Distributions
356*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(8, vp);
357*1b191cb5SApple OSS Distributions MAC_PERFORM(devfs_label_update, mp, de, mac_devfs_label(de), vp,
358*1b191cb5SApple OSS Distributions mac_vnode_label(vp));
359*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(8, vp);
360*1b191cb5SApple OSS Distributions }
361*1b191cb5SApple OSS Distributions
362*1b191cb5SApple OSS Distributions int
mac_vnode_label_associate(struct mount * mp,struct vnode * vp,vfs_context_t ctx)363*1b191cb5SApple OSS Distributions mac_vnode_label_associate(struct mount *mp, struct vnode *vp, vfs_context_t ctx)
364*1b191cb5SApple OSS Distributions {
365*1b191cb5SApple OSS Distributions struct devnode *dnp;
366*1b191cb5SApple OSS Distributions struct fdescnode *fnp;
367*1b191cb5SApple OSS Distributions int error = 0;
368*1b191cb5SApple OSS Distributions
369*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
370*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
371*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
372*1b191cb5SApple OSS Distributions return error;
373*1b191cb5SApple OSS Distributions }
374*1b191cb5SApple OSS Distributions #endif
375*1b191cb5SApple OSS Distributions
376*1b191cb5SApple OSS Distributions /* XXX: should not inspect v_tag in kernel! */
377*1b191cb5SApple OSS Distributions switch (vp->v_tag) {
378*1b191cb5SApple OSS Distributions case VT_DEVFS:
379*1b191cb5SApple OSS Distributions dnp = VTODN(vp);
380*1b191cb5SApple OSS Distributions mac_vnode_label_associate_devfs(mp, dnp, vp);
381*1b191cb5SApple OSS Distributions break;
382*1b191cb5SApple OSS Distributions case VT_FDESC:
383*1b191cb5SApple OSS Distributions fnp = VTOFDESC(vp);
384*1b191cb5SApple OSS Distributions error = mac_vnode_label_associate_fdesc(mp, fnp, vp, ctx);
385*1b191cb5SApple OSS Distributions break;
386*1b191cb5SApple OSS Distributions default:
387*1b191cb5SApple OSS Distributions error = mac_vnode_label_associate_extattr(mp, vp);
388*1b191cb5SApple OSS Distributions break;
389*1b191cb5SApple OSS Distributions }
390*1b191cb5SApple OSS Distributions
391*1b191cb5SApple OSS Distributions return error;
392*1b191cb5SApple OSS Distributions }
393*1b191cb5SApple OSS Distributions
394*1b191cb5SApple OSS Distributions void
mac_vnode_label_associate_devfs(struct mount * mp,struct devnode * de,struct vnode * vp)395*1b191cb5SApple OSS Distributions mac_vnode_label_associate_devfs(struct mount *mp, struct devnode *de,
396*1b191cb5SApple OSS Distributions struct vnode *vp)
397*1b191cb5SApple OSS Distributions {
398*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
399*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
400*1b191cb5SApple OSS Distributions if (!mac_device_enforce) {
401*1b191cb5SApple OSS Distributions return;
402*1b191cb5SApple OSS Distributions }
403*1b191cb5SApple OSS Distributions #endif
404*1b191cb5SApple OSS Distributions
405*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(9, vp);
406*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_associate_devfs,
407*1b191cb5SApple OSS Distributions mp, mp ? mac_mount_label(mp) : NULL,
408*1b191cb5SApple OSS Distributions de, mac_devfs_label(de),
409*1b191cb5SApple OSS Distributions vp, mac_vnode_label(vp));
410*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(9, vp);
411*1b191cb5SApple OSS Distributions }
412*1b191cb5SApple OSS Distributions
413*1b191cb5SApple OSS Distributions int
mac_vnode_label_associate_extattr(struct mount * mp,struct vnode * vp)414*1b191cb5SApple OSS Distributions mac_vnode_label_associate_extattr(struct mount *mp, struct vnode *vp)
415*1b191cb5SApple OSS Distributions {
416*1b191cb5SApple OSS Distributions int error;
417*1b191cb5SApple OSS Distributions
418*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(10, vp);
419*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_label_associate_extattr, mp, mac_mount_label(mp), vp,
420*1b191cb5SApple OSS Distributions mac_vnode_label(vp));
421*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(10, vp);
422*1b191cb5SApple OSS Distributions
423*1b191cb5SApple OSS Distributions return error;
424*1b191cb5SApple OSS Distributions }
425*1b191cb5SApple OSS Distributions
426*1b191cb5SApple OSS Distributions void
mac_vnode_label_associate_singlelabel(struct mount * mp,struct vnode * vp)427*1b191cb5SApple OSS Distributions mac_vnode_label_associate_singlelabel(struct mount *mp, struct vnode *vp)
428*1b191cb5SApple OSS Distributions {
429*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
430*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
431*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
432*1b191cb5SApple OSS Distributions return;
433*1b191cb5SApple OSS Distributions }
434*1b191cb5SApple OSS Distributions #endif
435*1b191cb5SApple OSS Distributions if (!mac_label_vnodes) {
436*1b191cb5SApple OSS Distributions return;
437*1b191cb5SApple OSS Distributions }
438*1b191cb5SApple OSS Distributions
439*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(11, vp);
440*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_associate_singlelabel, mp,
441*1b191cb5SApple OSS Distributions mp ? mac_mount_label(mp) : NULL, vp, mac_vnode_label(vp));
442*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(11, vp);
443*1b191cb5SApple OSS Distributions }
444*1b191cb5SApple OSS Distributions
445*1b191cb5SApple OSS Distributions int
mac_vnode_notify_create(vfs_context_t ctx,struct mount * mp,struct vnode * dvp,struct vnode * vp,struct componentname * cnp)446*1b191cb5SApple OSS Distributions mac_vnode_notify_create(vfs_context_t ctx, struct mount *mp,
447*1b191cb5SApple OSS Distributions struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
448*1b191cb5SApple OSS Distributions {
449*1b191cb5SApple OSS Distributions kauth_cred_t cred;
450*1b191cb5SApple OSS Distributions int error;
451*1b191cb5SApple OSS Distributions
452*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
453*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
454*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
455*1b191cb5SApple OSS Distributions return 0;
456*1b191cb5SApple OSS Distributions }
457*1b191cb5SApple OSS Distributions #endif
458*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
459*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
460*1b191cb5SApple OSS Distributions return 0;
461*1b191cb5SApple OSS Distributions }
462*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(12, vp);
463*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_notify_create, cred, mp, mac_mount_label(mp),
464*1b191cb5SApple OSS Distributions dvp, mac_vnode_label(dvp), vp, mac_vnode_label(vp), cnp);
465*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(12, vp);
466*1b191cb5SApple OSS Distributions
467*1b191cb5SApple OSS Distributions return error;
468*1b191cb5SApple OSS Distributions }
469*1b191cb5SApple OSS Distributions
470*1b191cb5SApple OSS Distributions void
mac_vnode_notify_rename(vfs_context_t ctx,struct vnode * fvp,struct vnode * fdvp,struct componentname * fcnp,struct vnode * tvp,struct vnode * tdvp,struct componentname * tcnp,bool swap)471*1b191cb5SApple OSS Distributions mac_vnode_notify_rename(vfs_context_t ctx, struct vnode *fvp,
472*1b191cb5SApple OSS Distributions struct vnode *fdvp, struct componentname *fcnp, struct vnode *tvp,
473*1b191cb5SApple OSS Distributions struct vnode *tdvp, struct componentname *tcnp, bool swap)
474*1b191cb5SApple OSS Distributions {
475*1b191cb5SApple OSS Distributions kauth_cred_t cred;
476*1b191cb5SApple OSS Distributions
477*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
478*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
479*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
480*1b191cb5SApple OSS Distributions return;
481*1b191cb5SApple OSS Distributions }
482*1b191cb5SApple OSS Distributions #endif
483*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
484*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
485*1b191cb5SApple OSS Distributions return;
486*1b191cb5SApple OSS Distributions }
487*1b191cb5SApple OSS Distributions
488*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(13, fvp);
489*1b191cb5SApple OSS Distributions MAC_POLICY_ITERATE({
490*1b191cb5SApple OSS Distributions /* BEGIN IGNORE CODESTYLE */
491*1b191cb5SApple OSS Distributions if (swap) {
492*1b191cb5SApple OSS Distributions if (mpc->mpc_ops->mpo_vnode_notify_swap != NULL) {
493*1b191cb5SApple OSS Distributions MAC_PERFORM_CALL(vnode_notify_swap, mpc);
494*1b191cb5SApple OSS Distributions mpc->mpc_ops->mpo_vnode_notify_swap(cred, fvp, mac_vnode_label(fvp),
495*1b191cb5SApple OSS Distributions tvp, mac_vnode_label(tvp));
496*1b191cb5SApple OSS Distributions MAC_PERFORM_RSLT(vnode_notify_swap, mpc);
497*1b191cb5SApple OSS Distributions } else if (mpc->mpc_ops->mpo_vnode_notify_rename != NULL) {
498*1b191cb5SApple OSS Distributions MAC_PERFORM_CALL(vnode_notify_swap_rename, mpc);
499*1b191cb5SApple OSS Distributions /* Call notify_rename twice, one for each member of the swap. */
500*1b191cb5SApple OSS Distributions mpc->mpc_ops->mpo_vnode_notify_rename(cred, fvp, mac_vnode_label(fvp),
501*1b191cb5SApple OSS Distributions tdvp, mac_vnode_label(tdvp), tcnp);
502*1b191cb5SApple OSS Distributions mpc->mpc_ops->mpo_vnode_notify_rename(cred, tvp, mac_vnode_label(tvp),
503*1b191cb5SApple OSS Distributions fdvp, mac_vnode_label(fdvp), fcnp);
504*1b191cb5SApple OSS Distributions MAC_PERFORM_RSLT(vnode_notify_swap_rename, mpc);
505*1b191cb5SApple OSS Distributions }
506*1b191cb5SApple OSS Distributions } else if (mpc->mpc_ops->mpo_vnode_notify_rename != NULL) {
507*1b191cb5SApple OSS Distributions MAC_PERFORM_CALL(vnode_notify_rename, mpc);
508*1b191cb5SApple OSS Distributions mpc->mpc_ops->mpo_vnode_notify_rename(cred, fvp, mac_vnode_label(fvp),
509*1b191cb5SApple OSS Distributions tdvp, mac_vnode_label(tdvp), tcnp);
510*1b191cb5SApple OSS Distributions MAC_PERFORM_RSLT(vnode_notify_rename, mpc);
511*1b191cb5SApple OSS Distributions }
512*1b191cb5SApple OSS Distributions /* END IGNORE CODESTYLE */
513*1b191cb5SApple OSS Distributions });
514*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(13, fvp);
515*1b191cb5SApple OSS Distributions }
516*1b191cb5SApple OSS Distributions
517*1b191cb5SApple OSS Distributions void
mac_vnode_notify_open(vfs_context_t ctx,struct vnode * vp,int acc_flags)518*1b191cb5SApple OSS Distributions mac_vnode_notify_open(vfs_context_t ctx, struct vnode *vp, int acc_flags)
519*1b191cb5SApple OSS Distributions {
520*1b191cb5SApple OSS Distributions kauth_cred_t cred;
521*1b191cb5SApple OSS Distributions
522*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
523*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
524*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
525*1b191cb5SApple OSS Distributions return;
526*1b191cb5SApple OSS Distributions }
527*1b191cb5SApple OSS Distributions #endif
528*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
529*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
530*1b191cb5SApple OSS Distributions return;
531*1b191cb5SApple OSS Distributions }
532*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(14, vp);
533*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_notify_open, cred, vp, mac_vnode_label(vp), acc_flags);
534*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(14, vp);
535*1b191cb5SApple OSS Distributions }
536*1b191cb5SApple OSS Distributions
537*1b191cb5SApple OSS Distributions void
mac_vnode_notify_link(vfs_context_t ctx,struct vnode * vp,struct vnode * dvp,struct componentname * cnp)538*1b191cb5SApple OSS Distributions mac_vnode_notify_link(vfs_context_t ctx, struct vnode *vp,
539*1b191cb5SApple OSS Distributions struct vnode *dvp, struct componentname *cnp)
540*1b191cb5SApple OSS Distributions {
541*1b191cb5SApple OSS Distributions kauth_cred_t cred;
542*1b191cb5SApple OSS Distributions
543*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
544*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
545*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
546*1b191cb5SApple OSS Distributions return;
547*1b191cb5SApple OSS Distributions }
548*1b191cb5SApple OSS Distributions #endif
549*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
550*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
551*1b191cb5SApple OSS Distributions return;
552*1b191cb5SApple OSS Distributions }
553*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(15, vp);
554*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_notify_link, cred, dvp, mac_vnode_label(dvp), vp, mac_vnode_label(vp), cnp);
555*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(15, vp);
556*1b191cb5SApple OSS Distributions }
557*1b191cb5SApple OSS Distributions
558*1b191cb5SApple OSS Distributions void
mac_vnode_notify_deleteextattr(vfs_context_t ctx,struct vnode * vp,const char * name)559*1b191cb5SApple OSS Distributions mac_vnode_notify_deleteextattr(vfs_context_t ctx, struct vnode *vp, const char *name)
560*1b191cb5SApple OSS Distributions {
561*1b191cb5SApple OSS Distributions kauth_cred_t cred;
562*1b191cb5SApple OSS Distributions
563*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
564*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
565*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
566*1b191cb5SApple OSS Distributions return;
567*1b191cb5SApple OSS Distributions }
568*1b191cb5SApple OSS Distributions #endif
569*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
570*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
571*1b191cb5SApple OSS Distributions return;
572*1b191cb5SApple OSS Distributions }
573*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(16, vp);
574*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_notify_deleteextattr, cred, vp, mac_vnode_label(vp), name);
575*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(16, vp);
576*1b191cb5SApple OSS Distributions }
577*1b191cb5SApple OSS Distributions
578*1b191cb5SApple OSS Distributions void
mac_vnode_notify_setacl(vfs_context_t ctx,struct vnode * vp,struct kauth_acl * acl)579*1b191cb5SApple OSS Distributions mac_vnode_notify_setacl(vfs_context_t ctx, struct vnode *vp, struct kauth_acl *acl)
580*1b191cb5SApple OSS Distributions {
581*1b191cb5SApple OSS Distributions kauth_cred_t cred;
582*1b191cb5SApple OSS Distributions
583*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
584*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
585*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
586*1b191cb5SApple OSS Distributions return;
587*1b191cb5SApple OSS Distributions }
588*1b191cb5SApple OSS Distributions #endif
589*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
590*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
591*1b191cb5SApple OSS Distributions return;
592*1b191cb5SApple OSS Distributions }
593*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(17, vp);
594*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_notify_setacl, cred, vp, mac_vnode_label(vp), acl);
595*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(17, vp);
596*1b191cb5SApple OSS Distributions }
597*1b191cb5SApple OSS Distributions
598*1b191cb5SApple OSS Distributions void
mac_vnode_notify_setattrlist(vfs_context_t ctx,struct vnode * vp,struct attrlist * alist)599*1b191cb5SApple OSS Distributions mac_vnode_notify_setattrlist(vfs_context_t ctx, struct vnode *vp, struct attrlist *alist)
600*1b191cb5SApple OSS Distributions {
601*1b191cb5SApple OSS Distributions kauth_cred_t cred;
602*1b191cb5SApple OSS Distributions
603*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
604*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
605*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
606*1b191cb5SApple OSS Distributions return;
607*1b191cb5SApple OSS Distributions }
608*1b191cb5SApple OSS Distributions #endif
609*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
610*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
611*1b191cb5SApple OSS Distributions return;
612*1b191cb5SApple OSS Distributions }
613*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(18, vp);
614*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_notify_setattrlist, cred, vp, mac_vnode_label(vp), alist);
615*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(18, vp);
616*1b191cb5SApple OSS Distributions }
617*1b191cb5SApple OSS Distributions
618*1b191cb5SApple OSS Distributions void
mac_vnode_notify_setextattr(vfs_context_t ctx,struct vnode * vp,const char * name,struct uio * uio)619*1b191cb5SApple OSS Distributions mac_vnode_notify_setextattr(vfs_context_t ctx, struct vnode *vp, const char *name, struct uio *uio)
620*1b191cb5SApple OSS Distributions {
621*1b191cb5SApple OSS Distributions kauth_cred_t cred;
622*1b191cb5SApple OSS Distributions
623*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
624*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
625*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
626*1b191cb5SApple OSS Distributions return;
627*1b191cb5SApple OSS Distributions }
628*1b191cb5SApple OSS Distributions #endif
629*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
630*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
631*1b191cb5SApple OSS Distributions return;
632*1b191cb5SApple OSS Distributions }
633*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(19, vp);
634*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_notify_setextattr, cred, vp, mac_vnode_label(vp), name, uio);
635*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(19, vp);
636*1b191cb5SApple OSS Distributions }
637*1b191cb5SApple OSS Distributions
638*1b191cb5SApple OSS Distributions void
mac_vnode_notify_setflags(vfs_context_t ctx,struct vnode * vp,u_long flags)639*1b191cb5SApple OSS Distributions mac_vnode_notify_setflags(vfs_context_t ctx, struct vnode *vp, u_long flags)
640*1b191cb5SApple OSS Distributions {
641*1b191cb5SApple OSS Distributions kauth_cred_t cred;
642*1b191cb5SApple OSS Distributions
643*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
644*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
645*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
646*1b191cb5SApple OSS Distributions return;
647*1b191cb5SApple OSS Distributions }
648*1b191cb5SApple OSS Distributions #endif
649*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
650*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
651*1b191cb5SApple OSS Distributions return;
652*1b191cb5SApple OSS Distributions }
653*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(20, vp);
654*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_notify_setflags, cred, vp, mac_vnode_label(vp), flags);
655*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(20, vp);
656*1b191cb5SApple OSS Distributions }
657*1b191cb5SApple OSS Distributions
658*1b191cb5SApple OSS Distributions void
mac_vnode_notify_setmode(vfs_context_t ctx,struct vnode * vp,mode_t mode)659*1b191cb5SApple OSS Distributions mac_vnode_notify_setmode(vfs_context_t ctx, struct vnode *vp, mode_t mode)
660*1b191cb5SApple OSS Distributions {
661*1b191cb5SApple OSS Distributions kauth_cred_t cred;
662*1b191cb5SApple OSS Distributions
663*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
664*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
665*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
666*1b191cb5SApple OSS Distributions return;
667*1b191cb5SApple OSS Distributions }
668*1b191cb5SApple OSS Distributions #endif
669*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
670*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
671*1b191cb5SApple OSS Distributions return;
672*1b191cb5SApple OSS Distributions }
673*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(21, vp);
674*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_notify_setmode, cred, vp, mac_vnode_label(vp), mode);
675*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(21, vp);
676*1b191cb5SApple OSS Distributions }
677*1b191cb5SApple OSS Distributions
678*1b191cb5SApple OSS Distributions void
mac_vnode_notify_setowner(vfs_context_t ctx,struct vnode * vp,uid_t uid,gid_t gid)679*1b191cb5SApple OSS Distributions mac_vnode_notify_setowner(vfs_context_t ctx, struct vnode *vp, uid_t uid, gid_t gid)
680*1b191cb5SApple OSS Distributions {
681*1b191cb5SApple OSS Distributions kauth_cred_t cred;
682*1b191cb5SApple OSS Distributions
683*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
684*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
685*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
686*1b191cb5SApple OSS Distributions return;
687*1b191cb5SApple OSS Distributions }
688*1b191cb5SApple OSS Distributions #endif
689*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
690*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
691*1b191cb5SApple OSS Distributions return;
692*1b191cb5SApple OSS Distributions }
693*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(22, vp);
694*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_notify_setowner, cred, vp, mac_vnode_label(vp), uid, gid);
695*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(22, vp);
696*1b191cb5SApple OSS Distributions }
697*1b191cb5SApple OSS Distributions
698*1b191cb5SApple OSS Distributions void
mac_vnode_notify_setutimes(vfs_context_t ctx,struct vnode * vp,struct timespec atime,struct timespec mtime)699*1b191cb5SApple OSS Distributions mac_vnode_notify_setutimes(vfs_context_t ctx, struct vnode *vp, struct timespec atime, struct timespec mtime)
700*1b191cb5SApple OSS Distributions {
701*1b191cb5SApple OSS Distributions kauth_cred_t cred;
702*1b191cb5SApple OSS Distributions
703*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
704*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
705*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
706*1b191cb5SApple OSS Distributions return;
707*1b191cb5SApple OSS Distributions }
708*1b191cb5SApple OSS Distributions #endif
709*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
710*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
711*1b191cb5SApple OSS Distributions return;
712*1b191cb5SApple OSS Distributions }
713*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(23, vp);
714*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_notify_setutimes, cred, vp, mac_vnode_label(vp), atime, mtime);
715*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(23, vp);
716*1b191cb5SApple OSS Distributions }
717*1b191cb5SApple OSS Distributions
718*1b191cb5SApple OSS Distributions void
mac_vnode_notify_truncate(vfs_context_t ctx,kauth_cred_t file_cred,struct vnode * vp)719*1b191cb5SApple OSS Distributions mac_vnode_notify_truncate(vfs_context_t ctx, kauth_cred_t file_cred, struct vnode *vp)
720*1b191cb5SApple OSS Distributions {
721*1b191cb5SApple OSS Distributions kauth_cred_t cred;
722*1b191cb5SApple OSS Distributions
723*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
724*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
725*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
726*1b191cb5SApple OSS Distributions return;
727*1b191cb5SApple OSS Distributions }
728*1b191cb5SApple OSS Distributions #endif
729*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
730*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
731*1b191cb5SApple OSS Distributions return;
732*1b191cb5SApple OSS Distributions }
733*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(24, vp);
734*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_notify_truncate, cred, file_cred, vp, mac_vnode_label(vp));
735*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(24, vp);
736*1b191cb5SApple OSS Distributions }
737*1b191cb5SApple OSS Distributions
738*1b191cb5SApple OSS Distributions /*
739*1b191cb5SApple OSS Distributions * Extended attribute 'name' was updated via
740*1b191cb5SApple OSS Distributions * vn_setxattr() or vn_removexattr(). Allow the
741*1b191cb5SApple OSS Distributions * policy to update the vnode label.
742*1b191cb5SApple OSS Distributions */
743*1b191cb5SApple OSS Distributions void
mac_vnode_label_update_extattr(struct mount * mp,struct vnode * vp,const char * name)744*1b191cb5SApple OSS Distributions mac_vnode_label_update_extattr(struct mount *mp, struct vnode *vp,
745*1b191cb5SApple OSS Distributions const char *name)
746*1b191cb5SApple OSS Distributions {
747*1b191cb5SApple OSS Distributions int error = 0;
748*1b191cb5SApple OSS Distributions
749*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
750*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
751*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
752*1b191cb5SApple OSS Distributions return;
753*1b191cb5SApple OSS Distributions }
754*1b191cb5SApple OSS Distributions #endif
755*1b191cb5SApple OSS Distributions if (!mac_label_vnodes) {
756*1b191cb5SApple OSS Distributions return;
757*1b191cb5SApple OSS Distributions }
758*1b191cb5SApple OSS Distributions
759*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(25, vp);
760*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_update_extattr, mp, mac_mount_label(mp), vp,
761*1b191cb5SApple OSS Distributions mac_vnode_label(vp), name);
762*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(25, vp);
763*1b191cb5SApple OSS Distributions if (error == 0) {
764*1b191cb5SApple OSS Distributions return;
765*1b191cb5SApple OSS Distributions }
766*1b191cb5SApple OSS Distributions
767*1b191cb5SApple OSS Distributions vnode_lock(vp);
768*1b191cb5SApple OSS Distributions vnode_relabel(vp);
769*1b191cb5SApple OSS Distributions vnode_unlock(vp);
770*1b191cb5SApple OSS Distributions return;
771*1b191cb5SApple OSS Distributions }
772*1b191cb5SApple OSS Distributions
773*1b191cb5SApple OSS Distributions static int
mac_vnode_label_store(vfs_context_t ctx,struct vnode * vp,struct label * intlabel)774*1b191cb5SApple OSS Distributions mac_vnode_label_store(vfs_context_t ctx, struct vnode *vp,
775*1b191cb5SApple OSS Distributions struct label *intlabel)
776*1b191cb5SApple OSS Distributions {
777*1b191cb5SApple OSS Distributions kauth_cred_t cred;
778*1b191cb5SApple OSS Distributions int error;
779*1b191cb5SApple OSS Distributions
780*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
781*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
782*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
783*1b191cb5SApple OSS Distributions return 0;
784*1b191cb5SApple OSS Distributions }
785*1b191cb5SApple OSS Distributions #endif
786*1b191cb5SApple OSS Distributions if (!mac_label_vnodes) {
787*1b191cb5SApple OSS Distributions return 0;
788*1b191cb5SApple OSS Distributions }
789*1b191cb5SApple OSS Distributions
790*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
791*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
792*1b191cb5SApple OSS Distributions return 0;
793*1b191cb5SApple OSS Distributions }
794*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(26, vp);
795*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_label_store, cred, vp, mac_vnode_label(vp), intlabel);
796*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(26, vp);
797*1b191cb5SApple OSS Distributions
798*1b191cb5SApple OSS Distributions return error;
799*1b191cb5SApple OSS Distributions }
800*1b191cb5SApple OSS Distributions
801*1b191cb5SApple OSS Distributions void
mac_cred_label_update_execve(vfs_context_t ctx,kauth_cred_t new,struct vnode * vp,off_t offset,struct vnode * scriptvp,struct label * scriptvnodelabel,struct label * execl,u_int * csflags,void * macextensions,int * disjoint,int * labelupdateerror)802*1b191cb5SApple OSS Distributions mac_cred_label_update_execve(vfs_context_t ctx, kauth_cred_t new, struct vnode *vp, off_t offset,
803*1b191cb5SApple OSS Distributions struct vnode *scriptvp, struct label *scriptvnodelabel, struct label *execl, u_int *csflags,
804*1b191cb5SApple OSS Distributions void *macextensions, int *disjoint, int *labelupdateerror)
805*1b191cb5SApple OSS Distributions {
806*1b191cb5SApple OSS Distributions kauth_cred_t cred;
807*1b191cb5SApple OSS Distributions *disjoint = 0;
808*1b191cb5SApple OSS Distributions int error;
809*1b191cb5SApple OSS Distributions posix_cred_t pcred = posix_cred_get(new);
810*1b191cb5SApple OSS Distributions
811*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
812*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
813*1b191cb5SApple OSS Distributions if (!mac_proc_enforce || !mac_vnode_enforce) {
814*1b191cb5SApple OSS Distributions return;
815*1b191cb5SApple OSS Distributions }
816*1b191cb5SApple OSS Distributions #endif
817*1b191cb5SApple OSS Distributions
818*1b191cb5SApple OSS Distributions /* mark the new cred to indicate "matching" includes the label */
819*1b191cb5SApple OSS Distributions pcred->cr_flags |= CRF_MAC_ENFORCE;
820*1b191cb5SApple OSS Distributions
821*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
822*1b191cb5SApple OSS Distributions
823*1b191cb5SApple OSS Distributions /*
824*1b191cb5SApple OSS Distributions * NB: Cannot use MAC_CHECK macro because we need a sequence point after
825*1b191cb5SApple OSS Distributions * calling exec_spawnattr_getmacpolicyinfo() and before passing the
826*1b191cb5SApple OSS Distributions * spawnattrlen as an argument to the hook.
827*1b191cb5SApple OSS Distributions */
828*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(27, vp);
829*1b191cb5SApple OSS Distributions {
830*1b191cb5SApple OSS Distributions struct mac_policy_conf *mpc;
831*1b191cb5SApple OSS Distributions u_int i;
832*1b191cb5SApple OSS Distributions
833*1b191cb5SApple OSS Distributions error = 0;
834*1b191cb5SApple OSS Distributions for (i = 0; i < mac_policy_list.staticmax; i++) {
835*1b191cb5SApple OSS Distributions mpc = mac_policy_list.entries[i].mpc;
836*1b191cb5SApple OSS Distributions if (mpc == NULL) {
837*1b191cb5SApple OSS Distributions continue;
838*1b191cb5SApple OSS Distributions }
839*1b191cb5SApple OSS Distributions
840*1b191cb5SApple OSS Distributions mpo_cred_label_update_execve_t *hook = mpc->mpc_ops->mpo_cred_label_update_execve;
841*1b191cb5SApple OSS Distributions if (hook == NULL) {
842*1b191cb5SApple OSS Distributions continue;
843*1b191cb5SApple OSS Distributions }
844*1b191cb5SApple OSS Distributions
845*1b191cb5SApple OSS Distributions size_t spawnattrlen = 0;
846*1b191cb5SApple OSS Distributions void *spawnattr = exec_spawnattr_getmacpolicyinfo(macextensions, mpc->mpc_name, &spawnattrlen);
847*1b191cb5SApple OSS Distributions
848*1b191cb5SApple OSS Distributions error = mac_error_select(hook(cred, new, vfs_context_proc(ctx), vp, offset, scriptvp,
849*1b191cb5SApple OSS Distributions mac_vnode_label(vp), scriptvnodelabel, execl, csflags, spawnattr, spawnattrlen, disjoint),
850*1b191cb5SApple OSS Distributions error);
851*1b191cb5SApple OSS Distributions }
852*1b191cb5SApple OSS Distributions if (mac_policy_list_conditional_busy() != 0) {
853*1b191cb5SApple OSS Distributions for (; i <= mac_policy_list.maxindex; i++) {
854*1b191cb5SApple OSS Distributions mpc = mac_policy_list.entries[i].mpc;
855*1b191cb5SApple OSS Distributions if (mpc == NULL) {
856*1b191cb5SApple OSS Distributions continue;
857*1b191cb5SApple OSS Distributions }
858*1b191cb5SApple OSS Distributions
859*1b191cb5SApple OSS Distributions mpo_cred_label_update_execve_t *hook = mpc->mpc_ops->mpo_cred_label_update_execve;
860*1b191cb5SApple OSS Distributions if (hook == NULL) {
861*1b191cb5SApple OSS Distributions continue;
862*1b191cb5SApple OSS Distributions }
863*1b191cb5SApple OSS Distributions
864*1b191cb5SApple OSS Distributions size_t spawnattrlen = 0;
865*1b191cb5SApple OSS Distributions void *spawnattr = exec_spawnattr_getmacpolicyinfo(macextensions, mpc->mpc_name, &spawnattrlen);
866*1b191cb5SApple OSS Distributions
867*1b191cb5SApple OSS Distributions error = mac_error_select(hook(cred, new, vfs_context_proc(ctx), vp, offset, scriptvp,
868*1b191cb5SApple OSS Distributions mac_vnode_label(vp), scriptvnodelabel, execl, csflags, spawnattr, spawnattrlen, disjoint),
869*1b191cb5SApple OSS Distributions error);
870*1b191cb5SApple OSS Distributions }
871*1b191cb5SApple OSS Distributions mac_policy_list_unbusy();
872*1b191cb5SApple OSS Distributions }
873*1b191cb5SApple OSS Distributions }
874*1b191cb5SApple OSS Distributions *labelupdateerror = error;
875*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(27, vp);
876*1b191cb5SApple OSS Distributions }
877*1b191cb5SApple OSS Distributions
878*1b191cb5SApple OSS Distributions int
mac_cred_check_label_update_execve(vfs_context_t ctx,struct vnode * vp,off_t offset,struct vnode * scriptvp,struct label * scriptvnodelabel,struct label * execlabel,struct proc * p,void * macextensions)879*1b191cb5SApple OSS Distributions mac_cred_check_label_update_execve(vfs_context_t ctx, struct vnode *vp, off_t offset,
880*1b191cb5SApple OSS Distributions struct vnode *scriptvp, struct label *scriptvnodelabel, struct label *execlabel,
881*1b191cb5SApple OSS Distributions struct proc *p, void *macextensions)
882*1b191cb5SApple OSS Distributions {
883*1b191cb5SApple OSS Distributions kauth_cred_t cred;
884*1b191cb5SApple OSS Distributions int result = 0;
885*1b191cb5SApple OSS Distributions
886*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
887*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
888*1b191cb5SApple OSS Distributions if (!mac_proc_enforce || !mac_vnode_enforce) {
889*1b191cb5SApple OSS Distributions return result;
890*1b191cb5SApple OSS Distributions }
891*1b191cb5SApple OSS Distributions #endif
892*1b191cb5SApple OSS Distributions
893*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
894*1b191cb5SApple OSS Distributions
895*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(28, vp);
896*1b191cb5SApple OSS Distributions /*
897*1b191cb5SApple OSS Distributions * NB: Cannot use MAC_BOOLEAN macro because we need a sequence point after
898*1b191cb5SApple OSS Distributions * calling exec_spawnattr_getmacpolicyinfo() and before passing the
899*1b191cb5SApple OSS Distributions * spawnattrlen as an argument to the hook.
900*1b191cb5SApple OSS Distributions */
901*1b191cb5SApple OSS Distributions {
902*1b191cb5SApple OSS Distributions struct mac_policy_conf *mpc;
903*1b191cb5SApple OSS Distributions u_int i;
904*1b191cb5SApple OSS Distributions
905*1b191cb5SApple OSS Distributions for (i = 0; i < mac_policy_list.staticmax; i++) {
906*1b191cb5SApple OSS Distributions mpc = mac_policy_list.entries[i].mpc;
907*1b191cb5SApple OSS Distributions if (mpc == NULL) {
908*1b191cb5SApple OSS Distributions continue;
909*1b191cb5SApple OSS Distributions }
910*1b191cb5SApple OSS Distributions
911*1b191cb5SApple OSS Distributions mpo_cred_check_label_update_execve_t *hook = mpc->mpc_ops->mpo_cred_check_label_update_execve;
912*1b191cb5SApple OSS Distributions if (hook == NULL) {
913*1b191cb5SApple OSS Distributions continue;
914*1b191cb5SApple OSS Distributions }
915*1b191cb5SApple OSS Distributions
916*1b191cb5SApple OSS Distributions size_t spawnattrlen = 0;
917*1b191cb5SApple OSS Distributions void *spawnattr = exec_spawnattr_getmacpolicyinfo(macextensions, mpc->mpc_name, &spawnattrlen);
918*1b191cb5SApple OSS Distributions
919*1b191cb5SApple OSS Distributions result = result || hook(cred, vp, offset, scriptvp, mac_vnode_label(vp), scriptvnodelabel, execlabel, p, spawnattr, spawnattrlen);
920*1b191cb5SApple OSS Distributions }
921*1b191cb5SApple OSS Distributions if (mac_policy_list_conditional_busy() != 0) {
922*1b191cb5SApple OSS Distributions for (; i <= mac_policy_list.maxindex; i++) {
923*1b191cb5SApple OSS Distributions mpc = mac_policy_list.entries[i].mpc;
924*1b191cb5SApple OSS Distributions if (mpc == NULL) {
925*1b191cb5SApple OSS Distributions continue;
926*1b191cb5SApple OSS Distributions }
927*1b191cb5SApple OSS Distributions
928*1b191cb5SApple OSS Distributions mpo_cred_check_label_update_execve_t *hook = mpc->mpc_ops->mpo_cred_check_label_update_execve;
929*1b191cb5SApple OSS Distributions if (hook == NULL) {
930*1b191cb5SApple OSS Distributions continue;
931*1b191cb5SApple OSS Distributions }
932*1b191cb5SApple OSS Distributions
933*1b191cb5SApple OSS Distributions size_t spawnattrlen = 0;
934*1b191cb5SApple OSS Distributions void *spawnattr = exec_spawnattr_getmacpolicyinfo(macextensions, mpc->mpc_name, &spawnattrlen);
935*1b191cb5SApple OSS Distributions
936*1b191cb5SApple OSS Distributions result = result || hook(cred, vp, offset, scriptvp, mac_vnode_label(vp), scriptvnodelabel, execlabel, p, spawnattr, spawnattrlen);
937*1b191cb5SApple OSS Distributions }
938*1b191cb5SApple OSS Distributions mac_policy_list_unbusy();
939*1b191cb5SApple OSS Distributions }
940*1b191cb5SApple OSS Distributions }
941*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(28, vp);
942*1b191cb5SApple OSS Distributions
943*1b191cb5SApple OSS Distributions return result;
944*1b191cb5SApple OSS Distributions }
945*1b191cb5SApple OSS Distributions
946*1b191cb5SApple OSS Distributions int
mac_vnode_check_access(vfs_context_t ctx,struct vnode * vp,int acc_mode)947*1b191cb5SApple OSS Distributions mac_vnode_check_access(vfs_context_t ctx, struct vnode *vp,
948*1b191cb5SApple OSS Distributions int acc_mode)
949*1b191cb5SApple OSS Distributions {
950*1b191cb5SApple OSS Distributions kauth_cred_t cred;
951*1b191cb5SApple OSS Distributions int error;
952*1b191cb5SApple OSS Distributions int mask;
953*1b191cb5SApple OSS Distributions
954*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
955*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
956*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
957*1b191cb5SApple OSS Distributions return 0;
958*1b191cb5SApple OSS Distributions }
959*1b191cb5SApple OSS Distributions #endif
960*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
961*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
962*1b191cb5SApple OSS Distributions return 0;
963*1b191cb5SApple OSS Distributions }
964*1b191cb5SApple OSS Distributions /* Convert {R,W,X}_OK values to V{READ,WRITE,EXEC} for entry points */
965*1b191cb5SApple OSS Distributions mask = ACCESS_MODE_TO_VNODE_MASK(acc_mode);
966*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(29, vp);
967*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_access, cred, vp, mac_vnode_label(vp), mask);
968*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(29, vp);
969*1b191cb5SApple OSS Distributions return error;
970*1b191cb5SApple OSS Distributions }
971*1b191cb5SApple OSS Distributions
972*1b191cb5SApple OSS Distributions int
mac_vnode_check_chdir(vfs_context_t ctx,struct vnode * dvp)973*1b191cb5SApple OSS Distributions mac_vnode_check_chdir(vfs_context_t ctx, struct vnode *dvp)
974*1b191cb5SApple OSS Distributions {
975*1b191cb5SApple OSS Distributions kauth_cred_t cred;
976*1b191cb5SApple OSS Distributions int error;
977*1b191cb5SApple OSS Distributions
978*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
979*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
980*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
981*1b191cb5SApple OSS Distributions return 0;
982*1b191cb5SApple OSS Distributions }
983*1b191cb5SApple OSS Distributions #endif
984*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
985*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
986*1b191cb5SApple OSS Distributions return 0;
987*1b191cb5SApple OSS Distributions }
988*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(30, dvp);
989*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_chdir, cred, dvp, mac_vnode_label(dvp));
990*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(30, dvp);
991*1b191cb5SApple OSS Distributions return error;
992*1b191cb5SApple OSS Distributions }
993*1b191cb5SApple OSS Distributions
994*1b191cb5SApple OSS Distributions int
mac_vnode_check_chroot(vfs_context_t ctx,struct vnode * dvp,struct componentname * cnp)995*1b191cb5SApple OSS Distributions mac_vnode_check_chroot(vfs_context_t ctx, struct vnode *dvp,
996*1b191cb5SApple OSS Distributions struct componentname *cnp)
997*1b191cb5SApple OSS Distributions {
998*1b191cb5SApple OSS Distributions kauth_cred_t cred;
999*1b191cb5SApple OSS Distributions int error;
1000*1b191cb5SApple OSS Distributions
1001*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1002*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1003*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1004*1b191cb5SApple OSS Distributions return 0;
1005*1b191cb5SApple OSS Distributions }
1006*1b191cb5SApple OSS Distributions #endif
1007*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1008*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1009*1b191cb5SApple OSS Distributions return 0;
1010*1b191cb5SApple OSS Distributions }
1011*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(31, dvp);
1012*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_chroot, cred, dvp, mac_vnode_label(dvp), cnp);
1013*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(31, dvp);
1014*1b191cb5SApple OSS Distributions return error;
1015*1b191cb5SApple OSS Distributions }
1016*1b191cb5SApple OSS Distributions
1017*1b191cb5SApple OSS Distributions int
mac_vnode_check_clone(vfs_context_t ctx,struct vnode * dvp,struct vnode * vp,struct componentname * cnp)1018*1b191cb5SApple OSS Distributions mac_vnode_check_clone(vfs_context_t ctx, struct vnode *dvp,
1019*1b191cb5SApple OSS Distributions struct vnode *vp, struct componentname *cnp)
1020*1b191cb5SApple OSS Distributions {
1021*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1022*1b191cb5SApple OSS Distributions int error;
1023*1b191cb5SApple OSS Distributions
1024*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1025*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1026*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1027*1b191cb5SApple OSS Distributions return 0;
1028*1b191cb5SApple OSS Distributions }
1029*1b191cb5SApple OSS Distributions #endif
1030*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1031*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1032*1b191cb5SApple OSS Distributions return 0;
1033*1b191cb5SApple OSS Distributions }
1034*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(32, dvp);
1035*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_clone, cred, dvp, mac_vnode_label(dvp), vp,
1036*1b191cb5SApple OSS Distributions mac_vnode_label(vp), cnp);
1037*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(32, dvp);
1038*1b191cb5SApple OSS Distributions return error;
1039*1b191cb5SApple OSS Distributions }
1040*1b191cb5SApple OSS Distributions int
mac_vnode_check_create(vfs_context_t ctx,struct vnode * dvp,struct componentname * cnp,struct vnode_attr * vap)1041*1b191cb5SApple OSS Distributions mac_vnode_check_create(vfs_context_t ctx, struct vnode *dvp,
1042*1b191cb5SApple OSS Distributions struct componentname *cnp, struct vnode_attr *vap)
1043*1b191cb5SApple OSS Distributions {
1044*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1045*1b191cb5SApple OSS Distributions int error;
1046*1b191cb5SApple OSS Distributions
1047*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1048*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1049*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1050*1b191cb5SApple OSS Distributions return 0;
1051*1b191cb5SApple OSS Distributions }
1052*1b191cb5SApple OSS Distributions #endif
1053*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1054*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1055*1b191cb5SApple OSS Distributions return 0;
1056*1b191cb5SApple OSS Distributions }
1057*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(33, dvp);
1058*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_create, cred, dvp, mac_vnode_label(dvp), cnp, vap);
1059*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(33, dvp);
1060*1b191cb5SApple OSS Distributions return error;
1061*1b191cb5SApple OSS Distributions }
1062*1b191cb5SApple OSS Distributions
1063*1b191cb5SApple OSS Distributions int
mac_vnode_check_unlink(vfs_context_t ctx,struct vnode * dvp,struct vnode * vp,struct componentname * cnp)1064*1b191cb5SApple OSS Distributions mac_vnode_check_unlink(vfs_context_t ctx, struct vnode *dvp, struct vnode *vp,
1065*1b191cb5SApple OSS Distributions struct componentname *cnp)
1066*1b191cb5SApple OSS Distributions {
1067*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1068*1b191cb5SApple OSS Distributions int error;
1069*1b191cb5SApple OSS Distributions
1070*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1071*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1072*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1073*1b191cb5SApple OSS Distributions return 0;
1074*1b191cb5SApple OSS Distributions }
1075*1b191cb5SApple OSS Distributions #endif
1076*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1077*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1078*1b191cb5SApple OSS Distributions return 0;
1079*1b191cb5SApple OSS Distributions }
1080*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(34, dvp);
1081*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_unlink, cred, dvp, mac_vnode_label(dvp), vp,
1082*1b191cb5SApple OSS Distributions mac_vnode_label(vp), cnp);
1083*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(34, dvp);
1084*1b191cb5SApple OSS Distributions return error;
1085*1b191cb5SApple OSS Distributions }
1086*1b191cb5SApple OSS Distributions #if 0
1087*1b191cb5SApple OSS Distributions int
1088*1b191cb5SApple OSS Distributions mac_vnode_check_deleteacl(vfs_context_t ctx, struct vnode *vp,
1089*1b191cb5SApple OSS Distributions acl_type_t type)
1090*1b191cb5SApple OSS Distributions {
1091*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1092*1b191cb5SApple OSS Distributions int error;
1093*1b191cb5SApple OSS Distributions
1094*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1095*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1096*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1097*1b191cb5SApple OSS Distributions return 0;
1098*1b191cb5SApple OSS Distributions }
1099*1b191cb5SApple OSS Distributions #endif
1100*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1101*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1102*1b191cb5SApple OSS Distributions return 0;
1103*1b191cb5SApple OSS Distributions }
1104*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(35, dvp);
1105*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_deleteacl, cred, vp, mac_vnode_label(vp), type);
1106*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(35, dvp);
1107*1b191cb5SApple OSS Distributions return error;
1108*1b191cb5SApple OSS Distributions }
1109*1b191cb5SApple OSS Distributions #endif
1110*1b191cb5SApple OSS Distributions
1111*1b191cb5SApple OSS Distributions int
mac_vnode_check_deleteextattr(vfs_context_t ctx,struct vnode * vp,const char * name)1112*1b191cb5SApple OSS Distributions mac_vnode_check_deleteextattr(vfs_context_t ctx, struct vnode *vp,
1113*1b191cb5SApple OSS Distributions const char *name)
1114*1b191cb5SApple OSS Distributions {
1115*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1116*1b191cb5SApple OSS Distributions int error;
1117*1b191cb5SApple OSS Distributions
1118*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1119*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1120*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1121*1b191cb5SApple OSS Distributions return 0;
1122*1b191cb5SApple OSS Distributions }
1123*1b191cb5SApple OSS Distributions #endif
1124*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1125*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1126*1b191cb5SApple OSS Distributions return 0;
1127*1b191cb5SApple OSS Distributions }
1128*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(36, vp);
1129*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_deleteextattr, cred, vp, mac_vnode_label(vp), name);
1130*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(36, vp);
1131*1b191cb5SApple OSS Distributions return error;
1132*1b191cb5SApple OSS Distributions }
1133*1b191cb5SApple OSS Distributions int
mac_vnode_check_exchangedata(vfs_context_t ctx,struct vnode * v1,struct vnode * v2)1134*1b191cb5SApple OSS Distributions mac_vnode_check_exchangedata(vfs_context_t ctx,
1135*1b191cb5SApple OSS Distributions struct vnode *v1, struct vnode *v2)
1136*1b191cb5SApple OSS Distributions {
1137*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1138*1b191cb5SApple OSS Distributions int error;
1139*1b191cb5SApple OSS Distributions
1140*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1141*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1142*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1143*1b191cb5SApple OSS Distributions return 0;
1144*1b191cb5SApple OSS Distributions }
1145*1b191cb5SApple OSS Distributions #endif
1146*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1147*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1148*1b191cb5SApple OSS Distributions return 0;
1149*1b191cb5SApple OSS Distributions }
1150*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(37, v1);
1151*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_exchangedata, cred, v1, mac_vnode_label(v1),
1152*1b191cb5SApple OSS Distributions v2, mac_vnode_label(v2));
1153*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(37, v1);
1154*1b191cb5SApple OSS Distributions
1155*1b191cb5SApple OSS Distributions return error;
1156*1b191cb5SApple OSS Distributions }
1157*1b191cb5SApple OSS Distributions
1158*1b191cb5SApple OSS Distributions #if 0
1159*1b191cb5SApple OSS Distributions int
1160*1b191cb5SApple OSS Distributions mac_vnode_check_getacl(vfs_context_t ctx, struct vnode *vp, acl_type_t type)
1161*1b191cb5SApple OSS Distributions {
1162*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1163*1b191cb5SApple OSS Distributions int error;
1164*1b191cb5SApple OSS Distributions
1165*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1166*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1167*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1168*1b191cb5SApple OSS Distributions return 0;
1169*1b191cb5SApple OSS Distributions }
1170*1b191cb5SApple OSS Distributions #endif
1171*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1172*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1173*1b191cb5SApple OSS Distributions return 0;
1174*1b191cb5SApple OSS Distributions }
1175*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(38, vp);
1176*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_getacl, cred, vp, mac_vnode_label(vp), type);
1177*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(38, vp);
1178*1b191cb5SApple OSS Distributions return error;
1179*1b191cb5SApple OSS Distributions }
1180*1b191cb5SApple OSS Distributions #endif
1181*1b191cb5SApple OSS Distributions
1182*1b191cb5SApple OSS Distributions int
mac_vnode_check_getattr(vfs_context_t ctx,struct ucred * file_cred,struct vnode * vp,struct vnode_attr * va)1183*1b191cb5SApple OSS Distributions mac_vnode_check_getattr(vfs_context_t ctx, struct ucred *file_cred,
1184*1b191cb5SApple OSS Distributions struct vnode *vp, struct vnode_attr *va)
1185*1b191cb5SApple OSS Distributions {
1186*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1187*1b191cb5SApple OSS Distributions int error;
1188*1b191cb5SApple OSS Distributions
1189*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1190*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1191*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1192*1b191cb5SApple OSS Distributions return 0;
1193*1b191cb5SApple OSS Distributions }
1194*1b191cb5SApple OSS Distributions #endif
1195*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1196*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1197*1b191cb5SApple OSS Distributions return 0;
1198*1b191cb5SApple OSS Distributions }
1199*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(39, vp);
1200*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_getattr, cred, file_cred, vp, mac_vnode_label(vp), va);
1201*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(39, vp);
1202*1b191cb5SApple OSS Distributions return error;
1203*1b191cb5SApple OSS Distributions }
1204*1b191cb5SApple OSS Distributions
1205*1b191cb5SApple OSS Distributions int
mac_vnode_check_getattrlist(vfs_context_t ctx,struct vnode * vp,struct attrlist * alist,uint64_t options)1206*1b191cb5SApple OSS Distributions mac_vnode_check_getattrlist(vfs_context_t ctx, struct vnode *vp,
1207*1b191cb5SApple OSS Distributions struct attrlist *alist, uint64_t options)
1208*1b191cb5SApple OSS Distributions {
1209*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1210*1b191cb5SApple OSS Distributions int error;
1211*1b191cb5SApple OSS Distributions
1212*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1213*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1214*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1215*1b191cb5SApple OSS Distributions return 0;
1216*1b191cb5SApple OSS Distributions }
1217*1b191cb5SApple OSS Distributions #endif
1218*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1219*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1220*1b191cb5SApple OSS Distributions return 0;
1221*1b191cb5SApple OSS Distributions }
1222*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(40, vp);
1223*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_getattrlist, cred, vp, mac_vnode_label(vp), alist, options);
1224*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(40, vp);
1225*1b191cb5SApple OSS Distributions
1226*1b191cb5SApple OSS Distributions /* Falsify results instead of returning error? */
1227*1b191cb5SApple OSS Distributions return error;
1228*1b191cb5SApple OSS Distributions }
1229*1b191cb5SApple OSS Distributions
1230*1b191cb5SApple OSS Distributions int
mac_vnode_check_exec(vfs_context_t ctx,struct vnode * vp,struct image_params * imgp)1231*1b191cb5SApple OSS Distributions mac_vnode_check_exec(vfs_context_t ctx, struct vnode *vp,
1232*1b191cb5SApple OSS Distributions struct image_params *imgp)
1233*1b191cb5SApple OSS Distributions {
1234*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1235*1b191cb5SApple OSS Distributions int error = 0;
1236*1b191cb5SApple OSS Distributions
1237*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1238*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1239*1b191cb5SApple OSS Distributions if (!mac_proc_enforce || !mac_vnode_enforce) {
1240*1b191cb5SApple OSS Distributions return 0;
1241*1b191cb5SApple OSS Distributions }
1242*1b191cb5SApple OSS Distributions #endif
1243*1b191cb5SApple OSS Distributions
1244*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1245*1b191cb5SApple OSS Distributions
1246*1b191cb5SApple OSS Distributions /*
1247*1b191cb5SApple OSS Distributions * NB: Cannot use MAC_CHECK macro because we need a sequence point after
1248*1b191cb5SApple OSS Distributions * calling exec_spawnattr_getmacpolicyinfo() and before passing the
1249*1b191cb5SApple OSS Distributions * spawnattrlen as an argument to the hook.
1250*1b191cb5SApple OSS Distributions */
1251*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(41, vp);
1252*1b191cb5SApple OSS Distributions {
1253*1b191cb5SApple OSS Distributions struct mac_policy_conf *mpc;
1254*1b191cb5SApple OSS Distributions u_int i;
1255*1b191cb5SApple OSS Distributions
1256*1b191cb5SApple OSS Distributions for (i = 0; i < mac_policy_list.staticmax; i++) {
1257*1b191cb5SApple OSS Distributions mpc = mac_policy_list.entries[i].mpc;
1258*1b191cb5SApple OSS Distributions if (mpc == NULL) {
1259*1b191cb5SApple OSS Distributions continue;
1260*1b191cb5SApple OSS Distributions }
1261*1b191cb5SApple OSS Distributions
1262*1b191cb5SApple OSS Distributions mpo_vnode_check_exec_t *hook = mpc->mpc_ops->mpo_vnode_check_exec;
1263*1b191cb5SApple OSS Distributions if (hook == NULL) {
1264*1b191cb5SApple OSS Distributions continue;
1265*1b191cb5SApple OSS Distributions }
1266*1b191cb5SApple OSS Distributions
1267*1b191cb5SApple OSS Distributions size_t spawnattrlen = 0;
1268*1b191cb5SApple OSS Distributions void *spawnattr = exec_spawnattr_getmacpolicyinfo(&imgp->ip_px_smpx, mpc->mpc_name, &spawnattrlen);
1269*1b191cb5SApple OSS Distributions
1270*1b191cb5SApple OSS Distributions error = mac_error_select(
1271*1b191cb5SApple OSS Distributions hook(cred,
1272*1b191cb5SApple OSS Distributions vp, imgp->ip_scriptvp, mac_vnode_label(vp), imgp->ip_scriptlabelp,
1273*1b191cb5SApple OSS Distributions imgp->ip_execlabelp, &imgp->ip_ndp->ni_cnd, &imgp->ip_csflags,
1274*1b191cb5SApple OSS Distributions spawnattr, spawnattrlen), error);
1275*1b191cb5SApple OSS Distributions }
1276*1b191cb5SApple OSS Distributions if (mac_policy_list_conditional_busy() != 0) {
1277*1b191cb5SApple OSS Distributions for (; i <= mac_policy_list.maxindex; i++) {
1278*1b191cb5SApple OSS Distributions mpc = mac_policy_list.entries[i].mpc;
1279*1b191cb5SApple OSS Distributions if (mpc == NULL) {
1280*1b191cb5SApple OSS Distributions continue;
1281*1b191cb5SApple OSS Distributions }
1282*1b191cb5SApple OSS Distributions
1283*1b191cb5SApple OSS Distributions mpo_vnode_check_exec_t *hook = mpc->mpc_ops->mpo_vnode_check_exec;
1284*1b191cb5SApple OSS Distributions if (hook == NULL) {
1285*1b191cb5SApple OSS Distributions continue;
1286*1b191cb5SApple OSS Distributions }
1287*1b191cb5SApple OSS Distributions
1288*1b191cb5SApple OSS Distributions size_t spawnattrlen = 0;
1289*1b191cb5SApple OSS Distributions void *spawnattr = exec_spawnattr_getmacpolicyinfo(&imgp->ip_px_smpx, mpc->mpc_name, &spawnattrlen);
1290*1b191cb5SApple OSS Distributions
1291*1b191cb5SApple OSS Distributions error = mac_error_select(
1292*1b191cb5SApple OSS Distributions hook(cred,
1293*1b191cb5SApple OSS Distributions vp, imgp->ip_scriptvp, mac_vnode_label(vp), imgp->ip_scriptlabelp,
1294*1b191cb5SApple OSS Distributions imgp->ip_execlabelp, &imgp->ip_ndp->ni_cnd, &imgp->ip_csflags,
1295*1b191cb5SApple OSS Distributions spawnattr, spawnattrlen), error);
1296*1b191cb5SApple OSS Distributions }
1297*1b191cb5SApple OSS Distributions mac_policy_list_unbusy();
1298*1b191cb5SApple OSS Distributions }
1299*1b191cb5SApple OSS Distributions }
1300*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(41, vp);
1301*1b191cb5SApple OSS Distributions
1302*1b191cb5SApple OSS Distributions return error;
1303*1b191cb5SApple OSS Distributions }
1304*1b191cb5SApple OSS Distributions
1305*1b191cb5SApple OSS Distributions int
mac_vnode_check_fsgetpath(vfs_context_t ctx,struct vnode * vp)1306*1b191cb5SApple OSS Distributions mac_vnode_check_fsgetpath(vfs_context_t ctx, struct vnode *vp)
1307*1b191cb5SApple OSS Distributions {
1308*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1309*1b191cb5SApple OSS Distributions int error;
1310*1b191cb5SApple OSS Distributions
1311*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1312*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1313*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1314*1b191cb5SApple OSS Distributions return 0;
1315*1b191cb5SApple OSS Distributions }
1316*1b191cb5SApple OSS Distributions #endif
1317*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1318*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1319*1b191cb5SApple OSS Distributions return 0;
1320*1b191cb5SApple OSS Distributions }
1321*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(42, vp);
1322*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_fsgetpath, cred, vp, mac_vnode_label(vp));
1323*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(42, vp);
1324*1b191cb5SApple OSS Distributions return error;
1325*1b191cb5SApple OSS Distributions }
1326*1b191cb5SApple OSS Distributions
1327*1b191cb5SApple OSS Distributions int
mac_vnode_check_signature(struct vnode * vp,struct cs_blob * cs_blob,struct image_params * imgp,unsigned int * cs_flags,unsigned int * signer_type,int flags,unsigned int platform)1328*1b191cb5SApple OSS Distributions mac_vnode_check_signature(struct vnode *vp, struct cs_blob *cs_blob,
1329*1b191cb5SApple OSS Distributions struct image_params *imgp,
1330*1b191cb5SApple OSS Distributions unsigned int *cs_flags, unsigned int *signer_type,
1331*1b191cb5SApple OSS Distributions int flags, unsigned int platform)
1332*1b191cb5SApple OSS Distributions {
1333*1b191cb5SApple OSS Distributions int error;
1334*1b191cb5SApple OSS Distributions char *fatal_failure_desc = NULL;
1335*1b191cb5SApple OSS Distributions size_t fatal_failure_desc_len = 0;
1336*1b191cb5SApple OSS Distributions
1337*1b191cb5SApple OSS Distributions char *vn_path = NULL;
1338*1b191cb5SApple OSS Distributions vm_size_t vn_pathlen = MAXPATHLEN;
1339*1b191cb5SApple OSS Distributions cpu_type_t cpu_type = (imgp == NULL) ? CPU_TYPE_ANY : imgp->ip_origcputype;
1340*1b191cb5SApple OSS Distributions
1341*1b191cb5SApple OSS Distributions
1342*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1343*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1344*1b191cb5SApple OSS Distributions if (!mac_proc_enforce || !mac_vnode_enforce) {
1345*1b191cb5SApple OSS Distributions return 0;
1346*1b191cb5SApple OSS Distributions }
1347*1b191cb5SApple OSS Distributions #endif
1348*1b191cb5SApple OSS Distributions
1349*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(43, vp);
1350*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_signature, vp, mac_vnode_label(vp), cpu_type, cs_blob,
1351*1b191cb5SApple OSS Distributions cs_flags, signer_type, flags, platform, &fatal_failure_desc, &fatal_failure_desc_len);
1352*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(43, vp);
1353*1b191cb5SApple OSS Distributions
1354*1b191cb5SApple OSS Distributions if (fatal_failure_desc_len) {
1355*1b191cb5SApple OSS Distributions // A fatal code signature validation failure occured, formulate a crash
1356*1b191cb5SApple OSS Distributions // reason.
1357*1b191cb5SApple OSS Distributions
1358*1b191cb5SApple OSS Distributions char const *path = NULL;
1359*1b191cb5SApple OSS Distributions
1360*1b191cb5SApple OSS Distributions vn_path = zalloc(ZV_NAMEI);
1361*1b191cb5SApple OSS Distributions if (vn_getpath(vp, vn_path, (int*)&vn_pathlen) == 0) {
1362*1b191cb5SApple OSS Distributions path = vn_path;
1363*1b191cb5SApple OSS Distributions } else {
1364*1b191cb5SApple OSS Distributions path = "(get vnode path failed)";
1365*1b191cb5SApple OSS Distributions }
1366*1b191cb5SApple OSS Distributions
1367*1b191cb5SApple OSS Distributions if (error == 0) {
1368*1b191cb5SApple OSS Distributions panic("mac_vnode_check_signature: MAC hook returned no error, "
1369*1b191cb5SApple OSS Distributions "but status is claimed to be fatal? "
1370*1b191cb5SApple OSS Distributions "path: '%s', fatal_failure_desc_len: %ld, fatal_failure_desc:\n%s\n",
1371*1b191cb5SApple OSS Distributions path, fatal_failure_desc_len, fatal_failure_desc);
1372*1b191cb5SApple OSS Distributions }
1373*1b191cb5SApple OSS Distributions
1374*1b191cb5SApple OSS Distributions printf("mac_vnode_check_signature: %s: code signature validation failed fatally: %s",
1375*1b191cb5SApple OSS Distributions path, fatal_failure_desc);
1376*1b191cb5SApple OSS Distributions
1377*1b191cb5SApple OSS Distributions if (imgp == NULL) {
1378*1b191cb5SApple OSS Distributions goto out;
1379*1b191cb5SApple OSS Distributions }
1380*1b191cb5SApple OSS Distributions
1381*1b191cb5SApple OSS Distributions os_reason_t reason = os_reason_create(OS_REASON_CODESIGNING,
1382*1b191cb5SApple OSS Distributions CODESIGNING_EXIT_REASON_TASKGATED_INVALID_SIG);
1383*1b191cb5SApple OSS Distributions
1384*1b191cb5SApple OSS Distributions if (reason == OS_REASON_NULL) {
1385*1b191cb5SApple OSS Distributions printf("mac_vnode_check_signature: %s: failure to allocate exit reason for validation failure: %s\n",
1386*1b191cb5SApple OSS Distributions path, fatal_failure_desc);
1387*1b191cb5SApple OSS Distributions goto out;
1388*1b191cb5SApple OSS Distributions }
1389*1b191cb5SApple OSS Distributions
1390*1b191cb5SApple OSS Distributions imgp->ip_cs_error = reason;
1391*1b191cb5SApple OSS Distributions reason->osr_flags = (OS_REASON_FLAG_GENERATE_CRASH_REPORT |
1392*1b191cb5SApple OSS Distributions OS_REASON_FLAG_CONSISTENT_FAILURE);
1393*1b191cb5SApple OSS Distributions
1394*1b191cb5SApple OSS Distributions if (fatal_failure_desc == NULL) {
1395*1b191cb5SApple OSS Distributions // This may happen if allocation for the buffer failed.
1396*1b191cb5SApple OSS Distributions printf("mac_vnode_check_signature: %s: fatal failure is missing its description.\n", path);
1397*1b191cb5SApple OSS Distributions } else {
1398*1b191cb5SApple OSS Distributions mach_vm_address_t data_addr = 0;
1399*1b191cb5SApple OSS Distributions
1400*1b191cb5SApple OSS Distributions int reason_error = 0;
1401*1b191cb5SApple OSS Distributions int kcdata_error = 0;
1402*1b191cb5SApple OSS Distributions
1403*1b191cb5SApple OSS Distributions if ((reason_error = os_reason_alloc_buffer_noblock(reason, kcdata_estimate_required_buffer_size
1404*1b191cb5SApple OSS Distributions (1, (uint32_t)fatal_failure_desc_len))) == 0 &&
1405*1b191cb5SApple OSS Distributions (kcdata_error = kcdata_get_memory_addr(&reason->osr_kcd_descriptor,
1406*1b191cb5SApple OSS Distributions EXIT_REASON_USER_DESC, (uint32_t)fatal_failure_desc_len,
1407*1b191cb5SApple OSS Distributions &data_addr)) == KERN_SUCCESS) {
1408*1b191cb5SApple OSS Distributions kern_return_t mc_error = kcdata_memcpy(&reason->osr_kcd_descriptor, (mach_vm_address_t)data_addr,
1409*1b191cb5SApple OSS Distributions fatal_failure_desc, (uint32_t)fatal_failure_desc_len);
1410*1b191cb5SApple OSS Distributions
1411*1b191cb5SApple OSS Distributions if (mc_error != KERN_SUCCESS) {
1412*1b191cb5SApple OSS Distributions printf("mac_vnode_check_signature: %s: failed to copy reason string "
1413*1b191cb5SApple OSS Distributions "(kcdata_memcpy error: %d, length: %ld)\n",
1414*1b191cb5SApple OSS Distributions path, mc_error, fatal_failure_desc_len);
1415*1b191cb5SApple OSS Distributions }
1416*1b191cb5SApple OSS Distributions } else {
1417*1b191cb5SApple OSS Distributions printf("mac_vnode_check_signature: %s: failed to allocate space for reason string "
1418*1b191cb5SApple OSS Distributions "(os_reason_alloc_buffer error: %d, kcdata error: %d, length: %ld)\n",
1419*1b191cb5SApple OSS Distributions path, reason_error, kcdata_error, fatal_failure_desc_len);
1420*1b191cb5SApple OSS Distributions }
1421*1b191cb5SApple OSS Distributions }
1422*1b191cb5SApple OSS Distributions }
1423*1b191cb5SApple OSS Distributions
1424*1b191cb5SApple OSS Distributions out:
1425*1b191cb5SApple OSS Distributions if (vn_path) {
1426*1b191cb5SApple OSS Distributions zfree(ZV_NAMEI, vn_path);
1427*1b191cb5SApple OSS Distributions }
1428*1b191cb5SApple OSS Distributions
1429*1b191cb5SApple OSS Distributions if (fatal_failure_desc_len > 0 && fatal_failure_desc != NULL) {
1430*1b191cb5SApple OSS Distributions /* KERN_AMFI_SUPPORTS_DATA_ALLOC >= 2 */
1431*1b191cb5SApple OSS Distributions kfree_data(fatal_failure_desc, fatal_failure_desc_len);
1432*1b191cb5SApple OSS Distributions }
1433*1b191cb5SApple OSS Distributions
1434*1b191cb5SApple OSS Distributions return error;
1435*1b191cb5SApple OSS Distributions }
1436*1b191cb5SApple OSS Distributions
1437*1b191cb5SApple OSS Distributions int
mac_vnode_check_supplemental_signature(struct vnode * vp,struct cs_blob * cs_blob,struct vnode * linked_vp,struct cs_blob * linked_cs_blob,unsigned int * signer_type)1438*1b191cb5SApple OSS Distributions mac_vnode_check_supplemental_signature(struct vnode *vp,
1439*1b191cb5SApple OSS Distributions struct cs_blob *cs_blob, struct vnode *linked_vp,
1440*1b191cb5SApple OSS Distributions struct cs_blob *linked_cs_blob, unsigned int *signer_type)
1441*1b191cb5SApple OSS Distributions {
1442*1b191cb5SApple OSS Distributions int error;
1443*1b191cb5SApple OSS Distributions
1444*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1445*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1446*1b191cb5SApple OSS Distributions if (!mac_proc_enforce || !mac_vnode_enforce) {
1447*1b191cb5SApple OSS Distributions return 0;
1448*1b191cb5SApple OSS Distributions }
1449*1b191cb5SApple OSS Distributions #endif
1450*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(93, vp);
1451*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_supplemental_signature, vp, mac_vnode_label(vp), cs_blob, linked_vp, linked_cs_blob,
1452*1b191cb5SApple OSS Distributions signer_type);
1453*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(93, vp);
1454*1b191cb5SApple OSS Distributions
1455*1b191cb5SApple OSS Distributions return error;
1456*1b191cb5SApple OSS Distributions }
1457*1b191cb5SApple OSS Distributions
1458*1b191cb5SApple OSS Distributions #if 0
1459*1b191cb5SApple OSS Distributions int
1460*1b191cb5SApple OSS Distributions mac_vnode_check_getacl(vfs_context_t ctx, struct vnode *vp, acl_type_t type)
1461*1b191cb5SApple OSS Distributions {
1462*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1463*1b191cb5SApple OSS Distributions int error;
1464*1b191cb5SApple OSS Distributions
1465*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1466*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1467*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1468*1b191cb5SApple OSS Distributions return 0;
1469*1b191cb5SApple OSS Distributions }
1470*1b191cb5SApple OSS Distributions #endif
1471*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1472*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1473*1b191cb5SApple OSS Distributions return 0;
1474*1b191cb5SApple OSS Distributions }
1475*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(44, vp);
1476*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_getacl, cred, vp, mac_vnode_label(vp), type);
1477*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(44, vp);
1478*1b191cb5SApple OSS Distributions return error;
1479*1b191cb5SApple OSS Distributions }
1480*1b191cb5SApple OSS Distributions #endif
1481*1b191cb5SApple OSS Distributions
1482*1b191cb5SApple OSS Distributions int
mac_vnode_check_getextattr(vfs_context_t ctx,struct vnode * vp,const char * name,struct uio * uio)1483*1b191cb5SApple OSS Distributions mac_vnode_check_getextattr(vfs_context_t ctx, struct vnode *vp,
1484*1b191cb5SApple OSS Distributions const char *name, struct uio *uio)
1485*1b191cb5SApple OSS Distributions {
1486*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1487*1b191cb5SApple OSS Distributions int error;
1488*1b191cb5SApple OSS Distributions
1489*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1490*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1491*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1492*1b191cb5SApple OSS Distributions return 0;
1493*1b191cb5SApple OSS Distributions }
1494*1b191cb5SApple OSS Distributions #endif
1495*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1496*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1497*1b191cb5SApple OSS Distributions return 0;
1498*1b191cb5SApple OSS Distributions }
1499*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(45, vp);
1500*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_getextattr, cred, vp, mac_vnode_label(vp),
1501*1b191cb5SApple OSS Distributions name, uio);
1502*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(45, vp);
1503*1b191cb5SApple OSS Distributions return error;
1504*1b191cb5SApple OSS Distributions }
1505*1b191cb5SApple OSS Distributions
1506*1b191cb5SApple OSS Distributions int
mac_vnode_check_ioctl(vfs_context_t ctx,struct vnode * vp,u_long cmd)1507*1b191cb5SApple OSS Distributions mac_vnode_check_ioctl(vfs_context_t ctx, struct vnode *vp, u_long cmd)
1508*1b191cb5SApple OSS Distributions {
1509*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1510*1b191cb5SApple OSS Distributions int error;
1511*1b191cb5SApple OSS Distributions
1512*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1513*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1514*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1515*1b191cb5SApple OSS Distributions return 0;
1516*1b191cb5SApple OSS Distributions }
1517*1b191cb5SApple OSS Distributions #endif
1518*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1519*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1520*1b191cb5SApple OSS Distributions return 0;
1521*1b191cb5SApple OSS Distributions }
1522*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(46, vp);
1523*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_ioctl, cred, vp, mac_vnode_label(vp), cmd);
1524*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(46, vp);
1525*1b191cb5SApple OSS Distributions return error;
1526*1b191cb5SApple OSS Distributions }
1527*1b191cb5SApple OSS Distributions
1528*1b191cb5SApple OSS Distributions int
mac_vnode_check_kqfilter(vfs_context_t ctx,kauth_cred_t file_cred,struct knote * kn,struct vnode * vp)1529*1b191cb5SApple OSS Distributions mac_vnode_check_kqfilter(vfs_context_t ctx, kauth_cred_t file_cred,
1530*1b191cb5SApple OSS Distributions struct knote *kn, struct vnode *vp)
1531*1b191cb5SApple OSS Distributions {
1532*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1533*1b191cb5SApple OSS Distributions int error;
1534*1b191cb5SApple OSS Distributions
1535*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1536*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1537*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1538*1b191cb5SApple OSS Distributions return 0;
1539*1b191cb5SApple OSS Distributions }
1540*1b191cb5SApple OSS Distributions #endif
1541*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1542*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1543*1b191cb5SApple OSS Distributions return 0;
1544*1b191cb5SApple OSS Distributions }
1545*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(47, vp);
1546*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_kqfilter, cred, file_cred, kn, vp,
1547*1b191cb5SApple OSS Distributions mac_vnode_label(vp));
1548*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(47, vp);
1549*1b191cb5SApple OSS Distributions
1550*1b191cb5SApple OSS Distributions return error;
1551*1b191cb5SApple OSS Distributions }
1552*1b191cb5SApple OSS Distributions
1553*1b191cb5SApple OSS Distributions int
mac_vnode_check_link(vfs_context_t ctx,struct vnode * dvp,struct vnode * vp,struct componentname * cnp)1554*1b191cb5SApple OSS Distributions mac_vnode_check_link(vfs_context_t ctx, struct vnode *dvp,
1555*1b191cb5SApple OSS Distributions struct vnode *vp, struct componentname *cnp)
1556*1b191cb5SApple OSS Distributions {
1557*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1558*1b191cb5SApple OSS Distributions int error;
1559*1b191cb5SApple OSS Distributions
1560*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1561*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1562*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1563*1b191cb5SApple OSS Distributions return 0;
1564*1b191cb5SApple OSS Distributions }
1565*1b191cb5SApple OSS Distributions #endif
1566*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1567*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1568*1b191cb5SApple OSS Distributions return 0;
1569*1b191cb5SApple OSS Distributions }
1570*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(48, vp);
1571*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_link, cred, dvp, mac_vnode_label(dvp), vp,
1572*1b191cb5SApple OSS Distributions mac_vnode_label(vp), cnp);
1573*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(48, vp);
1574*1b191cb5SApple OSS Distributions return error;
1575*1b191cb5SApple OSS Distributions }
1576*1b191cb5SApple OSS Distributions
1577*1b191cb5SApple OSS Distributions int
mac_vnode_check_listextattr(vfs_context_t ctx,struct vnode * vp)1578*1b191cb5SApple OSS Distributions mac_vnode_check_listextattr(vfs_context_t ctx, struct vnode *vp)
1579*1b191cb5SApple OSS Distributions {
1580*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1581*1b191cb5SApple OSS Distributions int error;
1582*1b191cb5SApple OSS Distributions
1583*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1584*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1585*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1586*1b191cb5SApple OSS Distributions return 0;
1587*1b191cb5SApple OSS Distributions }
1588*1b191cb5SApple OSS Distributions #endif
1589*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1590*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1591*1b191cb5SApple OSS Distributions return 0;
1592*1b191cb5SApple OSS Distributions }
1593*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(49, vp);
1594*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_listextattr, cred, vp, mac_vnode_label(vp));
1595*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(49, vp);
1596*1b191cb5SApple OSS Distributions return error;
1597*1b191cb5SApple OSS Distributions }
1598*1b191cb5SApple OSS Distributions
1599*1b191cb5SApple OSS Distributions int
mac_vnode_check_lookup_preflight(vfs_context_t ctx,struct vnode * dvp,const char * path,size_t pathlen)1600*1b191cb5SApple OSS Distributions mac_vnode_check_lookup_preflight(vfs_context_t ctx, struct vnode *dvp,
1601*1b191cb5SApple OSS Distributions const char *path, size_t pathlen)
1602*1b191cb5SApple OSS Distributions {
1603*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1604*1b191cb5SApple OSS Distributions int error;
1605*1b191cb5SApple OSS Distributions
1606*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1607*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1608*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1609*1b191cb5SApple OSS Distributions return 0;
1610*1b191cb5SApple OSS Distributions }
1611*1b191cb5SApple OSS Distributions #endif
1612*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1613*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1614*1b191cb5SApple OSS Distributions return 0;
1615*1b191cb5SApple OSS Distributions }
1616*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(50, dvp);
1617*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_lookup_preflight, cred, dvp, mac_vnode_label(dvp), path, pathlen);
1618*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(50, dvp);
1619*1b191cb5SApple OSS Distributions return error;
1620*1b191cb5SApple OSS Distributions }
1621*1b191cb5SApple OSS Distributions
1622*1b191cb5SApple OSS Distributions int
mac_vnode_check_lookup(vfs_context_t ctx,struct vnode * dvp,struct componentname * cnp)1623*1b191cb5SApple OSS Distributions mac_vnode_check_lookup(vfs_context_t ctx, struct vnode *dvp,
1624*1b191cb5SApple OSS Distributions struct componentname *cnp)
1625*1b191cb5SApple OSS Distributions {
1626*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1627*1b191cb5SApple OSS Distributions int error;
1628*1b191cb5SApple OSS Distributions
1629*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1630*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1631*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1632*1b191cb5SApple OSS Distributions return 0;
1633*1b191cb5SApple OSS Distributions }
1634*1b191cb5SApple OSS Distributions #endif
1635*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1636*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1637*1b191cb5SApple OSS Distributions return 0;
1638*1b191cb5SApple OSS Distributions }
1639*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(51, dvp);
1640*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_lookup, cred, dvp, mac_vnode_label(dvp), cnp);
1641*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(51, dvp);
1642*1b191cb5SApple OSS Distributions return error;
1643*1b191cb5SApple OSS Distributions }
1644*1b191cb5SApple OSS Distributions
1645*1b191cb5SApple OSS Distributions int
mac_vnode_check_open(vfs_context_t ctx,struct vnode * vp,int acc_mode)1646*1b191cb5SApple OSS Distributions mac_vnode_check_open(vfs_context_t ctx, struct vnode *vp, int acc_mode)
1647*1b191cb5SApple OSS Distributions {
1648*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1649*1b191cb5SApple OSS Distributions int error;
1650*1b191cb5SApple OSS Distributions
1651*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1652*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1653*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1654*1b191cb5SApple OSS Distributions return 0;
1655*1b191cb5SApple OSS Distributions }
1656*1b191cb5SApple OSS Distributions #endif
1657*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1658*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1659*1b191cb5SApple OSS Distributions return 0;
1660*1b191cb5SApple OSS Distributions }
1661*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(52, vp);
1662*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_open, cred, vp, mac_vnode_label(vp), acc_mode);
1663*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(52, vp);
1664*1b191cb5SApple OSS Distributions return error;
1665*1b191cb5SApple OSS Distributions }
1666*1b191cb5SApple OSS Distributions
1667*1b191cb5SApple OSS Distributions int
mac_vnode_check_read(vfs_context_t ctx,struct ucred * file_cred,struct vnode * vp)1668*1b191cb5SApple OSS Distributions mac_vnode_check_read(vfs_context_t ctx, struct ucred *file_cred,
1669*1b191cb5SApple OSS Distributions struct vnode *vp)
1670*1b191cb5SApple OSS Distributions {
1671*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1672*1b191cb5SApple OSS Distributions int error;
1673*1b191cb5SApple OSS Distributions
1674*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1675*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1676*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1677*1b191cb5SApple OSS Distributions return 0;
1678*1b191cb5SApple OSS Distributions }
1679*1b191cb5SApple OSS Distributions #endif
1680*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1681*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1682*1b191cb5SApple OSS Distributions return 0;
1683*1b191cb5SApple OSS Distributions }
1684*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(53, vp);
1685*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_read, cred, file_cred, vp,
1686*1b191cb5SApple OSS Distributions mac_vnode_label(vp));
1687*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(53, vp);
1688*1b191cb5SApple OSS Distributions
1689*1b191cb5SApple OSS Distributions return error;
1690*1b191cb5SApple OSS Distributions }
1691*1b191cb5SApple OSS Distributions
1692*1b191cb5SApple OSS Distributions int
mac_vnode_check_readdir(vfs_context_t ctx,struct vnode * dvp)1693*1b191cb5SApple OSS Distributions mac_vnode_check_readdir(vfs_context_t ctx, struct vnode *dvp)
1694*1b191cb5SApple OSS Distributions {
1695*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1696*1b191cb5SApple OSS Distributions int error;
1697*1b191cb5SApple OSS Distributions
1698*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1699*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1700*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1701*1b191cb5SApple OSS Distributions return 0;
1702*1b191cb5SApple OSS Distributions }
1703*1b191cb5SApple OSS Distributions #endif
1704*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1705*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1706*1b191cb5SApple OSS Distributions return 0;
1707*1b191cb5SApple OSS Distributions }
1708*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(54, dvp);
1709*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_readdir, cred, dvp, mac_vnode_label(dvp));
1710*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(54, dvp);
1711*1b191cb5SApple OSS Distributions return error;
1712*1b191cb5SApple OSS Distributions }
1713*1b191cb5SApple OSS Distributions
1714*1b191cb5SApple OSS Distributions int
mac_vnode_check_readlink(vfs_context_t ctx,struct vnode * vp)1715*1b191cb5SApple OSS Distributions mac_vnode_check_readlink(vfs_context_t ctx, struct vnode *vp)
1716*1b191cb5SApple OSS Distributions {
1717*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1718*1b191cb5SApple OSS Distributions int error;
1719*1b191cb5SApple OSS Distributions
1720*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1721*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1722*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1723*1b191cb5SApple OSS Distributions return 0;
1724*1b191cb5SApple OSS Distributions }
1725*1b191cb5SApple OSS Distributions #endif
1726*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1727*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1728*1b191cb5SApple OSS Distributions return 0;
1729*1b191cb5SApple OSS Distributions }
1730*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(55, vp);
1731*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_readlink, cred, vp, mac_vnode_label(vp));
1732*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(55, vp);
1733*1b191cb5SApple OSS Distributions return error;
1734*1b191cb5SApple OSS Distributions }
1735*1b191cb5SApple OSS Distributions
1736*1b191cb5SApple OSS Distributions int
mac_vnode_check_label_update(vfs_context_t ctx,struct vnode * vp,struct label * newlabel)1737*1b191cb5SApple OSS Distributions mac_vnode_check_label_update(vfs_context_t ctx, struct vnode *vp,
1738*1b191cb5SApple OSS Distributions struct label *newlabel)
1739*1b191cb5SApple OSS Distributions {
1740*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1741*1b191cb5SApple OSS Distributions int error;
1742*1b191cb5SApple OSS Distributions
1743*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1744*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1745*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1746*1b191cb5SApple OSS Distributions return 0;
1747*1b191cb5SApple OSS Distributions }
1748*1b191cb5SApple OSS Distributions #endif
1749*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1750*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1751*1b191cb5SApple OSS Distributions return 0;
1752*1b191cb5SApple OSS Distributions }
1753*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(56, vp);
1754*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_label_update, cred, vp, mac_vnode_label(vp), newlabel);
1755*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(56, vp);
1756*1b191cb5SApple OSS Distributions
1757*1b191cb5SApple OSS Distributions return error;
1758*1b191cb5SApple OSS Distributions }
1759*1b191cb5SApple OSS Distributions
1760*1b191cb5SApple OSS Distributions int
mac_vnode_check_rename(vfs_context_t ctx,struct vnode * dvp,struct vnode * vp,struct componentname * cnp,struct vnode * tdvp,struct vnode * tvp,struct componentname * tcnp)1761*1b191cb5SApple OSS Distributions mac_vnode_check_rename(vfs_context_t ctx, struct vnode *dvp,
1762*1b191cb5SApple OSS Distributions struct vnode *vp, struct componentname *cnp, struct vnode *tdvp,
1763*1b191cb5SApple OSS Distributions struct vnode *tvp, struct componentname *tcnp)
1764*1b191cb5SApple OSS Distributions {
1765*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1766*1b191cb5SApple OSS Distributions int error;
1767*1b191cb5SApple OSS Distributions
1768*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1769*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1770*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1771*1b191cb5SApple OSS Distributions return 0;
1772*1b191cb5SApple OSS Distributions }
1773*1b191cb5SApple OSS Distributions #endif
1774*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1775*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1776*1b191cb5SApple OSS Distributions return 0;
1777*1b191cb5SApple OSS Distributions }
1778*1b191cb5SApple OSS Distributions
1779*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(57, vp);
1780*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_rename_from, cred, dvp, mac_vnode_label(dvp), vp,
1781*1b191cb5SApple OSS Distributions mac_vnode_label(vp), cnp);
1782*1b191cb5SApple OSS Distributions if (error) {
1783*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(57, vp);
1784*1b191cb5SApple OSS Distributions return error;
1785*1b191cb5SApple OSS Distributions }
1786*1b191cb5SApple OSS Distributions
1787*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_rename_to, cred, tdvp, mac_vnode_label(tdvp), tvp,
1788*1b191cb5SApple OSS Distributions tvp != NULL ? mac_vnode_label(tvp) : NULL, dvp == tdvp, tcnp);
1789*1b191cb5SApple OSS Distributions if (error) {
1790*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(57, vp);
1791*1b191cb5SApple OSS Distributions return error;
1792*1b191cb5SApple OSS Distributions }
1793*1b191cb5SApple OSS Distributions
1794*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_rename, cred, dvp, mac_vnode_label(dvp), vp,
1795*1b191cb5SApple OSS Distributions mac_vnode_label(vp), cnp, tdvp, mac_vnode_label(tdvp), tvp,
1796*1b191cb5SApple OSS Distributions tvp != NULL ? mac_vnode_label(tvp) : NULL, tcnp);
1797*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(57, vp);
1798*1b191cb5SApple OSS Distributions return error;
1799*1b191cb5SApple OSS Distributions }
1800*1b191cb5SApple OSS Distributions
1801*1b191cb5SApple OSS Distributions int
mac_vnode_check_revoke(vfs_context_t ctx,struct vnode * vp)1802*1b191cb5SApple OSS Distributions mac_vnode_check_revoke(vfs_context_t ctx, struct vnode *vp)
1803*1b191cb5SApple OSS Distributions {
1804*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1805*1b191cb5SApple OSS Distributions int error;
1806*1b191cb5SApple OSS Distributions
1807*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1808*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1809*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1810*1b191cb5SApple OSS Distributions return 0;
1811*1b191cb5SApple OSS Distributions }
1812*1b191cb5SApple OSS Distributions #endif
1813*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1814*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1815*1b191cb5SApple OSS Distributions return 0;
1816*1b191cb5SApple OSS Distributions }
1817*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(58, vp);
1818*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_revoke, cred, vp, mac_vnode_label(vp));
1819*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(58, vp);
1820*1b191cb5SApple OSS Distributions return error;
1821*1b191cb5SApple OSS Distributions }
1822*1b191cb5SApple OSS Distributions
1823*1b191cb5SApple OSS Distributions int
mac_vnode_check_searchfs(vfs_context_t ctx,struct vnode * vp,struct attrlist * returnattrs,struct attrlist * searchattrs)1824*1b191cb5SApple OSS Distributions mac_vnode_check_searchfs(vfs_context_t ctx, struct vnode *vp, struct attrlist *returnattrs,
1825*1b191cb5SApple OSS Distributions struct attrlist *searchattrs)
1826*1b191cb5SApple OSS Distributions {
1827*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1828*1b191cb5SApple OSS Distributions int error;
1829*1b191cb5SApple OSS Distributions
1830*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1831*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1832*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1833*1b191cb5SApple OSS Distributions return 0;
1834*1b191cb5SApple OSS Distributions }
1835*1b191cb5SApple OSS Distributions #endif
1836*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1837*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1838*1b191cb5SApple OSS Distributions return 0;
1839*1b191cb5SApple OSS Distributions }
1840*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(59, vp);
1841*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_searchfs, cred, vp, mac_vnode_label(vp), returnattrs, searchattrs);
1842*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(59, vp);
1843*1b191cb5SApple OSS Distributions return error;
1844*1b191cb5SApple OSS Distributions }
1845*1b191cb5SApple OSS Distributions
1846*1b191cb5SApple OSS Distributions int
mac_vnode_check_select(vfs_context_t ctx,struct vnode * vp,int which)1847*1b191cb5SApple OSS Distributions mac_vnode_check_select(vfs_context_t ctx, struct vnode *vp, int which)
1848*1b191cb5SApple OSS Distributions {
1849*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1850*1b191cb5SApple OSS Distributions int error;
1851*1b191cb5SApple OSS Distributions
1852*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1853*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1854*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1855*1b191cb5SApple OSS Distributions return 0;
1856*1b191cb5SApple OSS Distributions }
1857*1b191cb5SApple OSS Distributions #endif
1858*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1859*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1860*1b191cb5SApple OSS Distributions return 0;
1861*1b191cb5SApple OSS Distributions }
1862*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(60, vp);
1863*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_select, cred, vp, mac_vnode_label(vp), which);
1864*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(60, vp);
1865*1b191cb5SApple OSS Distributions return error;
1866*1b191cb5SApple OSS Distributions }
1867*1b191cb5SApple OSS Distributions
1868*1b191cb5SApple OSS Distributions int
mac_vnode_check_setacl(vfs_context_t ctx,struct vnode * vp,struct kauth_acl * acl)1869*1b191cb5SApple OSS Distributions mac_vnode_check_setacl(vfs_context_t ctx, struct vnode *vp,
1870*1b191cb5SApple OSS Distributions struct kauth_acl *acl)
1871*1b191cb5SApple OSS Distributions {
1872*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1873*1b191cb5SApple OSS Distributions int error;
1874*1b191cb5SApple OSS Distributions
1875*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1876*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1877*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1878*1b191cb5SApple OSS Distributions return 0;
1879*1b191cb5SApple OSS Distributions }
1880*1b191cb5SApple OSS Distributions #endif
1881*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1882*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1883*1b191cb5SApple OSS Distributions return 0;
1884*1b191cb5SApple OSS Distributions }
1885*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(61, vp);
1886*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_setacl, cred, vp, mac_vnode_label(vp), acl);
1887*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(61, vp);
1888*1b191cb5SApple OSS Distributions return error;
1889*1b191cb5SApple OSS Distributions }
1890*1b191cb5SApple OSS Distributions
1891*1b191cb5SApple OSS Distributions int
mac_vnode_check_setattrlist(vfs_context_t ctx,struct vnode * vp,struct attrlist * alist)1892*1b191cb5SApple OSS Distributions mac_vnode_check_setattrlist(vfs_context_t ctx, struct vnode *vp,
1893*1b191cb5SApple OSS Distributions struct attrlist *alist)
1894*1b191cb5SApple OSS Distributions {
1895*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1896*1b191cb5SApple OSS Distributions int error;
1897*1b191cb5SApple OSS Distributions
1898*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1899*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1900*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1901*1b191cb5SApple OSS Distributions return 0;
1902*1b191cb5SApple OSS Distributions }
1903*1b191cb5SApple OSS Distributions #endif
1904*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1905*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1906*1b191cb5SApple OSS Distributions return 0;
1907*1b191cb5SApple OSS Distributions }
1908*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(62, vp);
1909*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_setattrlist, cred, vp, mac_vnode_label(vp), alist);
1910*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(62, vp);
1911*1b191cb5SApple OSS Distributions return error;
1912*1b191cb5SApple OSS Distributions }
1913*1b191cb5SApple OSS Distributions
1914*1b191cb5SApple OSS Distributions int
mac_vnode_check_setextattr(vfs_context_t ctx,struct vnode * vp,const char * name,struct uio * uio)1915*1b191cb5SApple OSS Distributions mac_vnode_check_setextattr(vfs_context_t ctx, struct vnode *vp,
1916*1b191cb5SApple OSS Distributions const char *name, struct uio *uio)
1917*1b191cb5SApple OSS Distributions {
1918*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1919*1b191cb5SApple OSS Distributions int error;
1920*1b191cb5SApple OSS Distributions
1921*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1922*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1923*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1924*1b191cb5SApple OSS Distributions return 0;
1925*1b191cb5SApple OSS Distributions }
1926*1b191cb5SApple OSS Distributions #endif
1927*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1928*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1929*1b191cb5SApple OSS Distributions return 0;
1930*1b191cb5SApple OSS Distributions }
1931*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(63, vp);
1932*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_setextattr, cred, vp, mac_vnode_label(vp),
1933*1b191cb5SApple OSS Distributions name, uio);
1934*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(63, vp);
1935*1b191cb5SApple OSS Distributions return error;
1936*1b191cb5SApple OSS Distributions }
1937*1b191cb5SApple OSS Distributions
1938*1b191cb5SApple OSS Distributions int
mac_vnode_check_setflags(vfs_context_t ctx,struct vnode * vp,u_long flags)1939*1b191cb5SApple OSS Distributions mac_vnode_check_setflags(vfs_context_t ctx, struct vnode *vp, u_long flags)
1940*1b191cb5SApple OSS Distributions {
1941*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1942*1b191cb5SApple OSS Distributions int error;
1943*1b191cb5SApple OSS Distributions
1944*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1945*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1946*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1947*1b191cb5SApple OSS Distributions return 0;
1948*1b191cb5SApple OSS Distributions }
1949*1b191cb5SApple OSS Distributions #endif
1950*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1951*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1952*1b191cb5SApple OSS Distributions return 0;
1953*1b191cb5SApple OSS Distributions }
1954*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(64, vp);
1955*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_setflags, cred, vp, mac_vnode_label(vp), flags);
1956*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(64, vp);
1957*1b191cb5SApple OSS Distributions return error;
1958*1b191cb5SApple OSS Distributions }
1959*1b191cb5SApple OSS Distributions
1960*1b191cb5SApple OSS Distributions int
mac_vnode_check_setmode(vfs_context_t ctx,struct vnode * vp,mode_t mode)1961*1b191cb5SApple OSS Distributions mac_vnode_check_setmode(vfs_context_t ctx, struct vnode *vp, mode_t mode)
1962*1b191cb5SApple OSS Distributions {
1963*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1964*1b191cb5SApple OSS Distributions int error;
1965*1b191cb5SApple OSS Distributions
1966*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1967*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1968*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1969*1b191cb5SApple OSS Distributions return 0;
1970*1b191cb5SApple OSS Distributions }
1971*1b191cb5SApple OSS Distributions #endif
1972*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1973*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1974*1b191cb5SApple OSS Distributions return 0;
1975*1b191cb5SApple OSS Distributions }
1976*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(65, vp);
1977*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_setmode, cred, vp, mac_vnode_label(vp), mode);
1978*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(65, vp);
1979*1b191cb5SApple OSS Distributions return error;
1980*1b191cb5SApple OSS Distributions }
1981*1b191cb5SApple OSS Distributions
1982*1b191cb5SApple OSS Distributions int
mac_vnode_check_setowner(vfs_context_t ctx,struct vnode * vp,uid_t uid,gid_t gid)1983*1b191cb5SApple OSS Distributions mac_vnode_check_setowner(vfs_context_t ctx, struct vnode *vp, uid_t uid,
1984*1b191cb5SApple OSS Distributions gid_t gid)
1985*1b191cb5SApple OSS Distributions {
1986*1b191cb5SApple OSS Distributions kauth_cred_t cred;
1987*1b191cb5SApple OSS Distributions int error;
1988*1b191cb5SApple OSS Distributions
1989*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
1990*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
1991*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
1992*1b191cb5SApple OSS Distributions return 0;
1993*1b191cb5SApple OSS Distributions }
1994*1b191cb5SApple OSS Distributions #endif
1995*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
1996*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
1997*1b191cb5SApple OSS Distributions return 0;
1998*1b191cb5SApple OSS Distributions }
1999*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(66, vp);
2000*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_setowner, cred, vp, mac_vnode_label(vp), uid, gid);
2001*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(66, vp);
2002*1b191cb5SApple OSS Distributions return error;
2003*1b191cb5SApple OSS Distributions }
2004*1b191cb5SApple OSS Distributions
2005*1b191cb5SApple OSS Distributions int
mac_vnode_check_setutimes(vfs_context_t ctx,struct vnode * vp,struct timespec atime,struct timespec mtime)2006*1b191cb5SApple OSS Distributions mac_vnode_check_setutimes(vfs_context_t ctx, struct vnode *vp,
2007*1b191cb5SApple OSS Distributions struct timespec atime, struct timespec mtime)
2008*1b191cb5SApple OSS Distributions {
2009*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2010*1b191cb5SApple OSS Distributions int error;
2011*1b191cb5SApple OSS Distributions
2012*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2013*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2014*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2015*1b191cb5SApple OSS Distributions return 0;
2016*1b191cb5SApple OSS Distributions }
2017*1b191cb5SApple OSS Distributions #endif
2018*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2019*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2020*1b191cb5SApple OSS Distributions return 0;
2021*1b191cb5SApple OSS Distributions }
2022*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(67, vp);
2023*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_setutimes, cred, vp, mac_vnode_label(vp), atime,
2024*1b191cb5SApple OSS Distributions mtime);
2025*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(67, vp);
2026*1b191cb5SApple OSS Distributions return error;
2027*1b191cb5SApple OSS Distributions }
2028*1b191cb5SApple OSS Distributions
2029*1b191cb5SApple OSS Distributions int
mac_vnode_check_stat(vfs_context_t ctx,struct ucred * file_cred,struct vnode * vp)2030*1b191cb5SApple OSS Distributions mac_vnode_check_stat(vfs_context_t ctx, struct ucred *file_cred,
2031*1b191cb5SApple OSS Distributions struct vnode *vp)
2032*1b191cb5SApple OSS Distributions {
2033*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2034*1b191cb5SApple OSS Distributions int error;
2035*1b191cb5SApple OSS Distributions
2036*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2037*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2038*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2039*1b191cb5SApple OSS Distributions return 0;
2040*1b191cb5SApple OSS Distributions }
2041*1b191cb5SApple OSS Distributions #endif
2042*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2043*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2044*1b191cb5SApple OSS Distributions return 0;
2045*1b191cb5SApple OSS Distributions }
2046*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(68, vp);
2047*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_stat, cred, file_cred, vp,
2048*1b191cb5SApple OSS Distributions mac_vnode_label(vp));
2049*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(68, vp);
2050*1b191cb5SApple OSS Distributions return error;
2051*1b191cb5SApple OSS Distributions }
2052*1b191cb5SApple OSS Distributions
2053*1b191cb5SApple OSS Distributions int
mac_vnode_check_trigger_resolve(vfs_context_t ctx,struct vnode * dvp,struct componentname * cnp)2054*1b191cb5SApple OSS Distributions mac_vnode_check_trigger_resolve(vfs_context_t ctx, struct vnode *dvp,
2055*1b191cb5SApple OSS Distributions struct componentname *cnp)
2056*1b191cb5SApple OSS Distributions {
2057*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2058*1b191cb5SApple OSS Distributions int error;
2059*1b191cb5SApple OSS Distributions
2060*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2061*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2062*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2063*1b191cb5SApple OSS Distributions return 0;
2064*1b191cb5SApple OSS Distributions }
2065*1b191cb5SApple OSS Distributions #endif
2066*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2067*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2068*1b191cb5SApple OSS Distributions return 0;
2069*1b191cb5SApple OSS Distributions }
2070*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(69, dvp);
2071*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_trigger_resolve, cred, dvp, mac_vnode_label(dvp), cnp);
2072*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(69, dvp);
2073*1b191cb5SApple OSS Distributions return error;
2074*1b191cb5SApple OSS Distributions }
2075*1b191cb5SApple OSS Distributions
2076*1b191cb5SApple OSS Distributions int
mac_vnode_check_truncate(vfs_context_t ctx,struct ucred * file_cred,struct vnode * vp)2077*1b191cb5SApple OSS Distributions mac_vnode_check_truncate(vfs_context_t ctx, struct ucred *file_cred,
2078*1b191cb5SApple OSS Distributions struct vnode *vp)
2079*1b191cb5SApple OSS Distributions {
2080*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2081*1b191cb5SApple OSS Distributions int error;
2082*1b191cb5SApple OSS Distributions
2083*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2084*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2085*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2086*1b191cb5SApple OSS Distributions return 0;
2087*1b191cb5SApple OSS Distributions }
2088*1b191cb5SApple OSS Distributions #endif
2089*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2090*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2091*1b191cb5SApple OSS Distributions return 0;
2092*1b191cb5SApple OSS Distributions }
2093*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(70, vp);
2094*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_truncate, cred, file_cred, vp,
2095*1b191cb5SApple OSS Distributions mac_vnode_label(vp));
2096*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(70, vp);
2097*1b191cb5SApple OSS Distributions
2098*1b191cb5SApple OSS Distributions return error;
2099*1b191cb5SApple OSS Distributions }
2100*1b191cb5SApple OSS Distributions
2101*1b191cb5SApple OSS Distributions int
mac_vnode_check_write(vfs_context_t ctx,struct ucred * file_cred,struct vnode * vp)2102*1b191cb5SApple OSS Distributions mac_vnode_check_write(vfs_context_t ctx, struct ucred *file_cred,
2103*1b191cb5SApple OSS Distributions struct vnode *vp)
2104*1b191cb5SApple OSS Distributions {
2105*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2106*1b191cb5SApple OSS Distributions int error;
2107*1b191cb5SApple OSS Distributions
2108*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2109*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2110*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2111*1b191cb5SApple OSS Distributions return 0;
2112*1b191cb5SApple OSS Distributions }
2113*1b191cb5SApple OSS Distributions #endif
2114*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2115*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2116*1b191cb5SApple OSS Distributions return 0;
2117*1b191cb5SApple OSS Distributions }
2118*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(71, vp);
2119*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_write, cred, file_cred, vp, mac_vnode_label(vp));
2120*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(71, vp);
2121*1b191cb5SApple OSS Distributions
2122*1b191cb5SApple OSS Distributions return error;
2123*1b191cb5SApple OSS Distributions }
2124*1b191cb5SApple OSS Distributions
2125*1b191cb5SApple OSS Distributions int
mac_vnode_check_uipc_bind(vfs_context_t ctx,struct vnode * dvp,struct componentname * cnp,struct vnode_attr * vap)2126*1b191cb5SApple OSS Distributions mac_vnode_check_uipc_bind(vfs_context_t ctx, struct vnode *dvp,
2127*1b191cb5SApple OSS Distributions struct componentname *cnp, struct vnode_attr *vap)
2128*1b191cb5SApple OSS Distributions {
2129*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2130*1b191cb5SApple OSS Distributions int error;
2131*1b191cb5SApple OSS Distributions
2132*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2133*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2134*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2135*1b191cb5SApple OSS Distributions return 0;
2136*1b191cb5SApple OSS Distributions }
2137*1b191cb5SApple OSS Distributions #endif
2138*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2139*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2140*1b191cb5SApple OSS Distributions return 0;
2141*1b191cb5SApple OSS Distributions }
2142*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(72, dvp);
2143*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_uipc_bind, cred, dvp, mac_vnode_label(dvp), cnp, vap);
2144*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(72, dvp);
2145*1b191cb5SApple OSS Distributions return error;
2146*1b191cb5SApple OSS Distributions }
2147*1b191cb5SApple OSS Distributions
2148*1b191cb5SApple OSS Distributions int
mac_vnode_check_uipc_connect(vfs_context_t ctx,struct vnode * vp,struct socket * so)2149*1b191cb5SApple OSS Distributions mac_vnode_check_uipc_connect(vfs_context_t ctx, struct vnode *vp, struct socket *so)
2150*1b191cb5SApple OSS Distributions {
2151*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2152*1b191cb5SApple OSS Distributions int error;
2153*1b191cb5SApple OSS Distributions
2154*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2155*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2156*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2157*1b191cb5SApple OSS Distributions return 0;
2158*1b191cb5SApple OSS Distributions }
2159*1b191cb5SApple OSS Distributions #endif
2160*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2161*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2162*1b191cb5SApple OSS Distributions return 0;
2163*1b191cb5SApple OSS Distributions }
2164*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(73, vp);
2165*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_uipc_connect, cred, vp, mac_vnode_label(vp), (socket_t) so);
2166*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(73, vp);
2167*1b191cb5SApple OSS Distributions return error;
2168*1b191cb5SApple OSS Distributions }
2169*1b191cb5SApple OSS Distributions
2170*1b191cb5SApple OSS Distributions void
mac_vnode_label_update(vfs_context_t ctx,struct vnode * vp,struct label * newlabel)2171*1b191cb5SApple OSS Distributions mac_vnode_label_update(vfs_context_t ctx, struct vnode *vp, struct label *newlabel)
2172*1b191cb5SApple OSS Distributions {
2173*1b191cb5SApple OSS Distributions kauth_cred_t cred = vfs_context_ucred(ctx);
2174*1b191cb5SApple OSS Distributions struct label *tmpl = NULL;
2175*1b191cb5SApple OSS Distributions
2176*1b191cb5SApple OSS Distributions if (mac_vnode_label(vp) == NULL) {
2177*1b191cb5SApple OSS Distributions tmpl = mac_vnode_label_alloc(vp);
2178*1b191cb5SApple OSS Distributions }
2179*1b191cb5SApple OSS Distributions
2180*1b191cb5SApple OSS Distributions vnode_lock(vp);
2181*1b191cb5SApple OSS Distributions
2182*1b191cb5SApple OSS Distributions /*
2183*1b191cb5SApple OSS Distributions * Recheck under lock. We allocate labels for vnodes lazily, so
2184*1b191cb5SApple OSS Distributions * somebody else might have already got here first.
2185*1b191cb5SApple OSS Distributions */
2186*1b191cb5SApple OSS Distributions if (mac_vnode_label(vp) == NULL) {
2187*1b191cb5SApple OSS Distributions vp->v_label = tmpl;
2188*1b191cb5SApple OSS Distributions tmpl = NULL;
2189*1b191cb5SApple OSS Distributions }
2190*1b191cb5SApple OSS Distributions
2191*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(74, vp);
2192*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_update, cred, vp, mac_vnode_label(vp), newlabel);
2193*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(74, vp);
2194*1b191cb5SApple OSS Distributions vnode_unlock(vp);
2195*1b191cb5SApple OSS Distributions
2196*1b191cb5SApple OSS Distributions if (tmpl != NULL) {
2197*1b191cb5SApple OSS Distributions mac_vnode_label_free(tmpl);
2198*1b191cb5SApple OSS Distributions }
2199*1b191cb5SApple OSS Distributions }
2200*1b191cb5SApple OSS Distributions
2201*1b191cb5SApple OSS Distributions int
mac_vnode_find_sigs(struct proc * p,struct vnode * vp,off_t offset)2202*1b191cb5SApple OSS Distributions mac_vnode_find_sigs(struct proc *p, struct vnode *vp, off_t offset)
2203*1b191cb5SApple OSS Distributions {
2204*1b191cb5SApple OSS Distributions int error;
2205*1b191cb5SApple OSS Distributions
2206*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2207*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2208*1b191cb5SApple OSS Distributions if (!mac_proc_enforce || !mac_vnode_enforce) {
2209*1b191cb5SApple OSS Distributions return 0;
2210*1b191cb5SApple OSS Distributions }
2211*1b191cb5SApple OSS Distributions #endif
2212*1b191cb5SApple OSS Distributions
2213*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(75, vp);
2214*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_find_sigs, p, vp, offset, mac_vnode_label(vp));
2215*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(75, vp);
2216*1b191cb5SApple OSS Distributions
2217*1b191cb5SApple OSS Distributions return error;
2218*1b191cb5SApple OSS Distributions }
2219*1b191cb5SApple OSS Distributions
2220*1b191cb5SApple OSS Distributions void
mac_mount_label_associate(vfs_context_t ctx,struct mount * mp)2221*1b191cb5SApple OSS Distributions mac_mount_label_associate(vfs_context_t ctx, struct mount *mp)
2222*1b191cb5SApple OSS Distributions {
2223*1b191cb5SApple OSS Distributions kauth_cred_t cred = vfs_context_ucred(ctx);
2224*1b191cb5SApple OSS Distributions
2225*1b191cb5SApple OSS Distributions /* XXX: eventually this logic may be handled by the policy? */
2226*1b191cb5SApple OSS Distributions
2227*1b191cb5SApple OSS Distributions /* We desire MULTILABEL for the root filesystem. */
2228*1b191cb5SApple OSS Distributions if ((mp->mnt_flag & MNT_ROOTFS) &&
2229*1b191cb5SApple OSS Distributions (strcmp(mp->mnt_vfsstat.f_fstypename, "hfs") == 0)) {
2230*1b191cb5SApple OSS Distributions mp->mnt_flag |= MNT_MULTILABEL;
2231*1b191cb5SApple OSS Distributions }
2232*1b191cb5SApple OSS Distributions
2233*1b191cb5SApple OSS Distributions /* MULTILABEL on DEVFS. */
2234*1b191cb5SApple OSS Distributions if (strcmp(mp->mnt_vfsstat.f_fstypename, "devfs") == 0) {
2235*1b191cb5SApple OSS Distributions mp->mnt_flag |= MNT_MULTILABEL;
2236*1b191cb5SApple OSS Distributions }
2237*1b191cb5SApple OSS Distributions
2238*1b191cb5SApple OSS Distributions /* MULTILABEL on FDESC pseudo-filesystem. */
2239*1b191cb5SApple OSS Distributions if (strcmp(mp->mnt_vfsstat.f_fstypename, "fdesc") == 0) {
2240*1b191cb5SApple OSS Distributions mp->mnt_flag |= MNT_MULTILABEL;
2241*1b191cb5SApple OSS Distributions }
2242*1b191cb5SApple OSS Distributions
2243*1b191cb5SApple OSS Distributions /* MULTILABEL on all NFS filesystems. */
2244*1b191cb5SApple OSS Distributions if (strcmp(mp->mnt_vfsstat.f_fstypename, "nfs") == 0) {
2245*1b191cb5SApple OSS Distributions mp->mnt_flag |= MNT_MULTILABEL;
2246*1b191cb5SApple OSS Distributions }
2247*1b191cb5SApple OSS Distributions
2248*1b191cb5SApple OSS Distributions /* MULTILABEL on all AFP filesystems. */
2249*1b191cb5SApple OSS Distributions if (strcmp(mp->mnt_vfsstat.f_fstypename, "afpfs") == 0) {
2250*1b191cb5SApple OSS Distributions mp->mnt_flag |= MNT_MULTILABEL;
2251*1b191cb5SApple OSS Distributions }
2252*1b191cb5SApple OSS Distributions
2253*1b191cb5SApple OSS Distributions if (mp->mnt_vtable != NULL) {
2254*1b191cb5SApple OSS Distributions /* Any filesystem that supports native XATTRs. */
2255*1b191cb5SApple OSS Distributions if ((mp->mnt_vtable->vfc_vfsflags & VFC_VFSNATIVEXATTR)) {
2256*1b191cb5SApple OSS Distributions mp->mnt_flag |= MNT_MULTILABEL;
2257*1b191cb5SApple OSS Distributions }
2258*1b191cb5SApple OSS Distributions
2259*1b191cb5SApple OSS Distributions /* Filesystem does not support multilabel. */
2260*1b191cb5SApple OSS Distributions if ((mp->mnt_vtable->vfc_vfsflags & VFC_VFSNOMACLABEL) &&
2261*1b191cb5SApple OSS Distributions (mp->mnt_flag & MNT_MULTILABEL)) {
2262*1b191cb5SApple OSS Distributions mp->mnt_flag &= ~MNT_MULTILABEL;
2263*1b191cb5SApple OSS Distributions }
2264*1b191cb5SApple OSS Distributions }
2265*1b191cb5SApple OSS Distributions
2266*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(76, mp);
2267*1b191cb5SApple OSS Distributions MAC_PERFORM(mount_label_associate, cred, mp, mac_mount_label(mp));
2268*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(76, mp);
2269*1b191cb5SApple OSS Distributions #if DEBUG
2270*1b191cb5SApple OSS Distributions printf("MAC Framework enabling %s support: %s -> %s (%s)\n",
2271*1b191cb5SApple OSS Distributions mp->mnt_flag & MNT_MULTILABEL ? "multilabel" : "singlelabel",
2272*1b191cb5SApple OSS Distributions mp->mnt_vfsstat.f_mntfromname,
2273*1b191cb5SApple OSS Distributions mp->mnt_vfsstat.f_mntonname,
2274*1b191cb5SApple OSS Distributions mp->mnt_vfsstat.f_fstypename);
2275*1b191cb5SApple OSS Distributions #endif
2276*1b191cb5SApple OSS Distributions }
2277*1b191cb5SApple OSS Distributions
2278*1b191cb5SApple OSS Distributions int
mac_mount_check_mount(vfs_context_t ctx,struct vnode * vp,struct componentname * cnp,const char * vfc_name)2279*1b191cb5SApple OSS Distributions mac_mount_check_mount(vfs_context_t ctx, struct vnode *vp,
2280*1b191cb5SApple OSS Distributions struct componentname *cnp, const char *vfc_name)
2281*1b191cb5SApple OSS Distributions {
2282*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2283*1b191cb5SApple OSS Distributions int error;
2284*1b191cb5SApple OSS Distributions
2285*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2286*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2287*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2288*1b191cb5SApple OSS Distributions return 0;
2289*1b191cb5SApple OSS Distributions }
2290*1b191cb5SApple OSS Distributions #endif
2291*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2292*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2293*1b191cb5SApple OSS Distributions return 0;
2294*1b191cb5SApple OSS Distributions }
2295*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(77, vp);
2296*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_mount, cred, vp, mac_vnode_label(vp), cnp, vfc_name);
2297*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(77, vp);
2298*1b191cb5SApple OSS Distributions
2299*1b191cb5SApple OSS Distributions return error;
2300*1b191cb5SApple OSS Distributions }
2301*1b191cb5SApple OSS Distributions
2302*1b191cb5SApple OSS Distributions int
mac_mount_check_mount_late(vfs_context_t ctx,struct mount * mp)2303*1b191cb5SApple OSS Distributions mac_mount_check_mount_late(vfs_context_t ctx, struct mount *mp)
2304*1b191cb5SApple OSS Distributions {
2305*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2306*1b191cb5SApple OSS Distributions int error;
2307*1b191cb5SApple OSS Distributions
2308*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2309*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2310*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2311*1b191cb5SApple OSS Distributions return 0;
2312*1b191cb5SApple OSS Distributions }
2313*1b191cb5SApple OSS Distributions #endif
2314*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2315*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2316*1b191cb5SApple OSS Distributions return 0;
2317*1b191cb5SApple OSS Distributions }
2318*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(78, mp);
2319*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_mount_late, cred, mp);
2320*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(78, mp);
2321*1b191cb5SApple OSS Distributions
2322*1b191cb5SApple OSS Distributions return error;
2323*1b191cb5SApple OSS Distributions }
2324*1b191cb5SApple OSS Distributions
2325*1b191cb5SApple OSS Distributions int
mac_mount_check_snapshot_create(vfs_context_t ctx,struct mount * mp,const char * name)2326*1b191cb5SApple OSS Distributions mac_mount_check_snapshot_create(vfs_context_t ctx, struct mount *mp,
2327*1b191cb5SApple OSS Distributions const char *name)
2328*1b191cb5SApple OSS Distributions {
2329*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2330*1b191cb5SApple OSS Distributions int error;
2331*1b191cb5SApple OSS Distributions
2332*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2333*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2334*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2335*1b191cb5SApple OSS Distributions return 0;
2336*1b191cb5SApple OSS Distributions }
2337*1b191cb5SApple OSS Distributions #endif
2338*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2339*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2340*1b191cb5SApple OSS Distributions return 0;
2341*1b191cb5SApple OSS Distributions }
2342*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(79, mp);
2343*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_snapshot_create, cred, mp, name);
2344*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(79, mp);
2345*1b191cb5SApple OSS Distributions return error;
2346*1b191cb5SApple OSS Distributions }
2347*1b191cb5SApple OSS Distributions
2348*1b191cb5SApple OSS Distributions int
mac_mount_check_snapshot_delete(vfs_context_t ctx,struct mount * mp,const char * name)2349*1b191cb5SApple OSS Distributions mac_mount_check_snapshot_delete(vfs_context_t ctx, struct mount *mp,
2350*1b191cb5SApple OSS Distributions const char *name)
2351*1b191cb5SApple OSS Distributions {
2352*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2353*1b191cb5SApple OSS Distributions int error;
2354*1b191cb5SApple OSS Distributions
2355*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2356*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2357*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2358*1b191cb5SApple OSS Distributions return 0;
2359*1b191cb5SApple OSS Distributions }
2360*1b191cb5SApple OSS Distributions #endif
2361*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2362*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2363*1b191cb5SApple OSS Distributions return 0;
2364*1b191cb5SApple OSS Distributions }
2365*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(80, mp);
2366*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_snapshot_delete, cred, mp, name);
2367*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(80, mp);
2368*1b191cb5SApple OSS Distributions return error;
2369*1b191cb5SApple OSS Distributions }
2370*1b191cb5SApple OSS Distributions
2371*1b191cb5SApple OSS Distributions int
mac_mount_check_snapshot_mount(vfs_context_t ctx,struct vnode * rvp,struct vnode * vp,struct componentname * cnp,const char * name,const char * vfc_name)2372*1b191cb5SApple OSS Distributions mac_mount_check_snapshot_mount(vfs_context_t ctx, struct vnode *rvp, struct vnode *vp, struct componentname *cnp,
2373*1b191cb5SApple OSS Distributions const char *name, const char *vfc_name)
2374*1b191cb5SApple OSS Distributions {
2375*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2376*1b191cb5SApple OSS Distributions int error;
2377*1b191cb5SApple OSS Distributions
2378*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2379*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2380*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2381*1b191cb5SApple OSS Distributions return 0;
2382*1b191cb5SApple OSS Distributions }
2383*1b191cb5SApple OSS Distributions #endif
2384*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2385*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2386*1b191cb5SApple OSS Distributions return 0;
2387*1b191cb5SApple OSS Distributions }
2388*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(92, vp);
2389*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_snapshot_mount, cred, rvp, vp, cnp, name, vfc_name);
2390*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(92, vp);
2391*1b191cb5SApple OSS Distributions return error;
2392*1b191cb5SApple OSS Distributions }
2393*1b191cb5SApple OSS Distributions
2394*1b191cb5SApple OSS Distributions int
mac_mount_check_snapshot_revert(vfs_context_t ctx,struct mount * mp,const char * name)2395*1b191cb5SApple OSS Distributions mac_mount_check_snapshot_revert(vfs_context_t ctx, struct mount *mp,
2396*1b191cb5SApple OSS Distributions const char *name)
2397*1b191cb5SApple OSS Distributions {
2398*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2399*1b191cb5SApple OSS Distributions int error;
2400*1b191cb5SApple OSS Distributions
2401*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2402*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2403*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2404*1b191cb5SApple OSS Distributions return 0;
2405*1b191cb5SApple OSS Distributions }
2406*1b191cb5SApple OSS Distributions #endif
2407*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2408*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2409*1b191cb5SApple OSS Distributions return 0;
2410*1b191cb5SApple OSS Distributions }
2411*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(81, mp);
2412*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_snapshot_revert, cred, mp, name);
2413*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(81, mp);
2414*1b191cb5SApple OSS Distributions return error;
2415*1b191cb5SApple OSS Distributions }
2416*1b191cb5SApple OSS Distributions
2417*1b191cb5SApple OSS Distributions int
mac_mount_check_remount(vfs_context_t ctx,struct mount * mp)2418*1b191cb5SApple OSS Distributions mac_mount_check_remount(vfs_context_t ctx, struct mount *mp)
2419*1b191cb5SApple OSS Distributions {
2420*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2421*1b191cb5SApple OSS Distributions int error;
2422*1b191cb5SApple OSS Distributions
2423*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2424*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2425*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2426*1b191cb5SApple OSS Distributions return 0;
2427*1b191cb5SApple OSS Distributions }
2428*1b191cb5SApple OSS Distributions #endif
2429*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2430*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2431*1b191cb5SApple OSS Distributions return 0;
2432*1b191cb5SApple OSS Distributions }
2433*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(82, mp);
2434*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_remount, cred, mp, mac_mount_label(mp));
2435*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(82, mp);
2436*1b191cb5SApple OSS Distributions
2437*1b191cb5SApple OSS Distributions return error;
2438*1b191cb5SApple OSS Distributions }
2439*1b191cb5SApple OSS Distributions
2440*1b191cb5SApple OSS Distributions int
mac_mount_check_umount(vfs_context_t ctx,struct mount * mp)2441*1b191cb5SApple OSS Distributions mac_mount_check_umount(vfs_context_t ctx, struct mount *mp)
2442*1b191cb5SApple OSS Distributions {
2443*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2444*1b191cb5SApple OSS Distributions int error;
2445*1b191cb5SApple OSS Distributions
2446*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2447*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2448*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2449*1b191cb5SApple OSS Distributions return 0;
2450*1b191cb5SApple OSS Distributions }
2451*1b191cb5SApple OSS Distributions #endif
2452*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2453*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2454*1b191cb5SApple OSS Distributions return 0;
2455*1b191cb5SApple OSS Distributions }
2456*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(83, mp);
2457*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_umount, cred, mp, mac_mount_label(mp));
2458*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(83, mp);
2459*1b191cb5SApple OSS Distributions
2460*1b191cb5SApple OSS Distributions return error;
2461*1b191cb5SApple OSS Distributions }
2462*1b191cb5SApple OSS Distributions
2463*1b191cb5SApple OSS Distributions int
mac_mount_check_getattr(vfs_context_t ctx,struct mount * mp,struct vfs_attr * vfa)2464*1b191cb5SApple OSS Distributions mac_mount_check_getattr(vfs_context_t ctx, struct mount *mp,
2465*1b191cb5SApple OSS Distributions struct vfs_attr *vfa)
2466*1b191cb5SApple OSS Distributions {
2467*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2468*1b191cb5SApple OSS Distributions int error;
2469*1b191cb5SApple OSS Distributions
2470*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2471*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2472*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2473*1b191cb5SApple OSS Distributions return 0;
2474*1b191cb5SApple OSS Distributions }
2475*1b191cb5SApple OSS Distributions #endif
2476*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2477*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2478*1b191cb5SApple OSS Distributions return 0;
2479*1b191cb5SApple OSS Distributions }
2480*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(84, mp);
2481*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_getattr, cred, mp, mac_mount_label(mp), vfa);
2482*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(84, mp);
2483*1b191cb5SApple OSS Distributions return error;
2484*1b191cb5SApple OSS Distributions }
2485*1b191cb5SApple OSS Distributions
2486*1b191cb5SApple OSS Distributions int
mac_mount_check_setattr(vfs_context_t ctx,struct mount * mp,struct vfs_attr * vfa)2487*1b191cb5SApple OSS Distributions mac_mount_check_setattr(vfs_context_t ctx, struct mount *mp,
2488*1b191cb5SApple OSS Distributions struct vfs_attr *vfa)
2489*1b191cb5SApple OSS Distributions {
2490*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2491*1b191cb5SApple OSS Distributions int error;
2492*1b191cb5SApple OSS Distributions
2493*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2494*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2495*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2496*1b191cb5SApple OSS Distributions return 0;
2497*1b191cb5SApple OSS Distributions }
2498*1b191cb5SApple OSS Distributions #endif
2499*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2500*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2501*1b191cb5SApple OSS Distributions return 0;
2502*1b191cb5SApple OSS Distributions }
2503*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(85, mp);
2504*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_setattr, cred, mp, mac_mount_label(mp), vfa);
2505*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(85, mp);
2506*1b191cb5SApple OSS Distributions return error;
2507*1b191cb5SApple OSS Distributions }
2508*1b191cb5SApple OSS Distributions
2509*1b191cb5SApple OSS Distributions int
mac_mount_check_stat(vfs_context_t ctx,struct mount * mount)2510*1b191cb5SApple OSS Distributions mac_mount_check_stat(vfs_context_t ctx, struct mount *mount)
2511*1b191cb5SApple OSS Distributions {
2512*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2513*1b191cb5SApple OSS Distributions int error;
2514*1b191cb5SApple OSS Distributions
2515*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2516*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2517*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2518*1b191cb5SApple OSS Distributions return 0;
2519*1b191cb5SApple OSS Distributions }
2520*1b191cb5SApple OSS Distributions #endif
2521*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2522*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2523*1b191cb5SApple OSS Distributions return 0;
2524*1b191cb5SApple OSS Distributions }
2525*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(86, mount);
2526*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_stat, cred, mount, mac_mount_label(mount));
2527*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(86, mount);
2528*1b191cb5SApple OSS Distributions
2529*1b191cb5SApple OSS Distributions return error;
2530*1b191cb5SApple OSS Distributions }
2531*1b191cb5SApple OSS Distributions
2532*1b191cb5SApple OSS Distributions int
mac_mount_check_label_update(vfs_context_t ctx,struct mount * mount)2533*1b191cb5SApple OSS Distributions mac_mount_check_label_update(vfs_context_t ctx, struct mount *mount)
2534*1b191cb5SApple OSS Distributions {
2535*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2536*1b191cb5SApple OSS Distributions int error;
2537*1b191cb5SApple OSS Distributions
2538*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2539*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2540*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2541*1b191cb5SApple OSS Distributions return 0;
2542*1b191cb5SApple OSS Distributions }
2543*1b191cb5SApple OSS Distributions #endif
2544*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2545*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2546*1b191cb5SApple OSS Distributions return 0;
2547*1b191cb5SApple OSS Distributions }
2548*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(87, mount);
2549*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_label_update, cred, mount, mac_mount_label(mount));
2550*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(87, mount);
2551*1b191cb5SApple OSS Distributions
2552*1b191cb5SApple OSS Distributions return error;
2553*1b191cb5SApple OSS Distributions }
2554*1b191cb5SApple OSS Distributions
2555*1b191cb5SApple OSS Distributions int
mac_mount_check_fsctl(vfs_context_t ctx,struct mount * mp,u_long cmd)2556*1b191cb5SApple OSS Distributions mac_mount_check_fsctl(vfs_context_t ctx, struct mount *mp, u_long cmd)
2557*1b191cb5SApple OSS Distributions {
2558*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2559*1b191cb5SApple OSS Distributions int error;
2560*1b191cb5SApple OSS Distributions
2561*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2562*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2563*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2564*1b191cb5SApple OSS Distributions return 0;
2565*1b191cb5SApple OSS Distributions }
2566*1b191cb5SApple OSS Distributions #endif
2567*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2568*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2569*1b191cb5SApple OSS Distributions return 0;
2570*1b191cb5SApple OSS Distributions }
2571*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(88, mp);
2572*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_fsctl, cred, mp, mac_mount_label(mp), cmd);
2573*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(88, mp);
2574*1b191cb5SApple OSS Distributions
2575*1b191cb5SApple OSS Distributions return error;
2576*1b191cb5SApple OSS Distributions }
2577*1b191cb5SApple OSS Distributions
2578*1b191cb5SApple OSS Distributions void
mac_devfs_label_associate_device(dev_t dev,struct devnode * de,const char * fullpath)2579*1b191cb5SApple OSS Distributions mac_devfs_label_associate_device(dev_t dev, struct devnode *de,
2580*1b191cb5SApple OSS Distributions const char *fullpath)
2581*1b191cb5SApple OSS Distributions {
2582*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2583*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2584*1b191cb5SApple OSS Distributions if (!mac_device_enforce) {
2585*1b191cb5SApple OSS Distributions return;
2586*1b191cb5SApple OSS Distributions }
2587*1b191cb5SApple OSS Distributions #endif
2588*1b191cb5SApple OSS Distributions
2589*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(89, de);
2590*1b191cb5SApple OSS Distributions MAC_PERFORM(devfs_label_associate_device, dev, de, mac_devfs_label(de),
2591*1b191cb5SApple OSS Distributions fullpath);
2592*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(89, de);
2593*1b191cb5SApple OSS Distributions }
2594*1b191cb5SApple OSS Distributions
2595*1b191cb5SApple OSS Distributions void
mac_devfs_label_associate_directory(const char * dirname,int dirnamelen,struct devnode * de,const char * fullpath)2596*1b191cb5SApple OSS Distributions mac_devfs_label_associate_directory(const char *dirname, int dirnamelen,
2597*1b191cb5SApple OSS Distributions struct devnode *de, const char *fullpath)
2598*1b191cb5SApple OSS Distributions {
2599*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2600*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2601*1b191cb5SApple OSS Distributions if (!mac_device_enforce) {
2602*1b191cb5SApple OSS Distributions return;
2603*1b191cb5SApple OSS Distributions }
2604*1b191cb5SApple OSS Distributions #endif
2605*1b191cb5SApple OSS Distributions
2606*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(90, de);
2607*1b191cb5SApple OSS Distributions MAC_PERFORM(devfs_label_associate_directory, dirname, dirnamelen, de,
2608*1b191cb5SApple OSS Distributions mac_devfs_label(de), fullpath);
2609*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(90, de);
2610*1b191cb5SApple OSS Distributions }
2611*1b191cb5SApple OSS Distributions
2612*1b191cb5SApple OSS Distributions int
vn_setlabel(struct vnode * vp,struct label * intlabel,vfs_context_t context)2613*1b191cb5SApple OSS Distributions vn_setlabel(struct vnode *vp, struct label *intlabel, vfs_context_t context)
2614*1b191cb5SApple OSS Distributions {
2615*1b191cb5SApple OSS Distributions int error;
2616*1b191cb5SApple OSS Distributions
2617*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2618*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2619*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2620*1b191cb5SApple OSS Distributions return 0;
2621*1b191cb5SApple OSS Distributions }
2622*1b191cb5SApple OSS Distributions #endif
2623*1b191cb5SApple OSS Distributions if (!mac_label_vnodes) {
2624*1b191cb5SApple OSS Distributions return 0;
2625*1b191cb5SApple OSS Distributions }
2626*1b191cb5SApple OSS Distributions
2627*1b191cb5SApple OSS Distributions if (vp->v_mount == NULL) {
2628*1b191cb5SApple OSS Distributions printf("vn_setlabel: null v_mount\n");
2629*1b191cb5SApple OSS Distributions if (vp->v_type != VNON) {
2630*1b191cb5SApple OSS Distributions printf("vn_setlabel: null v_mount with non-VNON\n");
2631*1b191cb5SApple OSS Distributions }
2632*1b191cb5SApple OSS Distributions return EBADF;
2633*1b191cb5SApple OSS Distributions }
2634*1b191cb5SApple OSS Distributions
2635*1b191cb5SApple OSS Distributions if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0) {
2636*1b191cb5SApple OSS Distributions return ENOTSUP;
2637*1b191cb5SApple OSS Distributions }
2638*1b191cb5SApple OSS Distributions
2639*1b191cb5SApple OSS Distributions /*
2640*1b191cb5SApple OSS Distributions * Multi-phase commit. First check the policies to confirm the
2641*1b191cb5SApple OSS Distributions * change is OK. Then commit via the filesystem. Finally,
2642*1b191cb5SApple OSS Distributions * update the actual vnode label. Question: maybe the filesystem
2643*1b191cb5SApple OSS Distributions * should update the vnode at the end as part of VNOP_SETLABEL()?
2644*1b191cb5SApple OSS Distributions */
2645*1b191cb5SApple OSS Distributions error = mac_vnode_check_label_update(context, vp, intlabel);
2646*1b191cb5SApple OSS Distributions if (error) {
2647*1b191cb5SApple OSS Distributions return error;
2648*1b191cb5SApple OSS Distributions }
2649*1b191cb5SApple OSS Distributions
2650*1b191cb5SApple OSS Distributions error = VNOP_SETLABEL(vp, intlabel, context);
2651*1b191cb5SApple OSS Distributions if (error == ENOTSUP) {
2652*1b191cb5SApple OSS Distributions error = mac_vnode_label_store(context, vp,
2653*1b191cb5SApple OSS Distributions intlabel);
2654*1b191cb5SApple OSS Distributions if (error) {
2655*1b191cb5SApple OSS Distributions printf("%s: mac_vnode_label_store failed %d\n",
2656*1b191cb5SApple OSS Distributions __func__, error);
2657*1b191cb5SApple OSS Distributions return error;
2658*1b191cb5SApple OSS Distributions }
2659*1b191cb5SApple OSS Distributions mac_vnode_label_update(context, vp, intlabel);
2660*1b191cb5SApple OSS Distributions } else if (error) {
2661*1b191cb5SApple OSS Distributions printf("vn_setlabel: vop setlabel failed %d\n", error);
2662*1b191cb5SApple OSS Distributions return error;
2663*1b191cb5SApple OSS Distributions }
2664*1b191cb5SApple OSS Distributions
2665*1b191cb5SApple OSS Distributions return 0;
2666*1b191cb5SApple OSS Distributions }
2667*1b191cb5SApple OSS Distributions
2668*1b191cb5SApple OSS Distributions int
mac_vnode_label_associate_fdesc(struct mount * mp,struct fdescnode * fnp,struct vnode * vp,vfs_context_t ctx)2669*1b191cb5SApple OSS Distributions mac_vnode_label_associate_fdesc(struct mount *mp, struct fdescnode *fnp,
2670*1b191cb5SApple OSS Distributions struct vnode *vp, vfs_context_t ctx)
2671*1b191cb5SApple OSS Distributions {
2672*1b191cb5SApple OSS Distributions struct fileproc *fp;
2673*1b191cb5SApple OSS Distributions #if CONFIG_MACF_SOCKET_SUBSET
2674*1b191cb5SApple OSS Distributions struct socket *so;
2675*1b191cb5SApple OSS Distributions #endif
2676*1b191cb5SApple OSS Distributions struct pipe *cpipe;
2677*1b191cb5SApple OSS Distributions struct vnode *fvp;
2678*1b191cb5SApple OSS Distributions struct proc *p;
2679*1b191cb5SApple OSS Distributions int error;
2680*1b191cb5SApple OSS Distributions
2681*1b191cb5SApple OSS Distributions error = 0;
2682*1b191cb5SApple OSS Distributions
2683*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(91, vp);
2684*1b191cb5SApple OSS Distributions /*
2685*1b191cb5SApple OSS Distributions * If no backing file, let the policy choose which label to use.
2686*1b191cb5SApple OSS Distributions */
2687*1b191cb5SApple OSS Distributions if (fnp->fd_fd == -1) {
2688*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_associate_file, vfs_context_ucred(ctx),
2689*1b191cb5SApple OSS Distributions mp, mac_mount_label(mp), NULL, NULL, vp, mac_vnode_label(vp));
2690*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(91, vp);
2691*1b191cb5SApple OSS Distributions return 0;
2692*1b191cb5SApple OSS Distributions }
2693*1b191cb5SApple OSS Distributions
2694*1b191cb5SApple OSS Distributions p = vfs_context_proc(ctx);
2695*1b191cb5SApple OSS Distributions error = fp_lookup(p, fnp->fd_fd, &fp, 0);
2696*1b191cb5SApple OSS Distributions if (error) {
2697*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(91, vp);
2698*1b191cb5SApple OSS Distributions return error;
2699*1b191cb5SApple OSS Distributions }
2700*1b191cb5SApple OSS Distributions
2701*1b191cb5SApple OSS Distributions if (fp->fp_glob == NULL) {
2702*1b191cb5SApple OSS Distributions error = EBADF;
2703*1b191cb5SApple OSS Distributions goto out;
2704*1b191cb5SApple OSS Distributions }
2705*1b191cb5SApple OSS Distributions
2706*1b191cb5SApple OSS Distributions switch (FILEGLOB_DTYPE(fp->fp_glob)) {
2707*1b191cb5SApple OSS Distributions case DTYPE_VNODE:
2708*1b191cb5SApple OSS Distributions fvp = (struct vnode *)fp_get_data(fp);
2709*1b191cb5SApple OSS Distributions if ((error = vnode_getwithref(fvp))) {
2710*1b191cb5SApple OSS Distributions goto out;
2711*1b191cb5SApple OSS Distributions }
2712*1b191cb5SApple OSS Distributions if (mac_vnode_label(fvp) != NULL) {
2713*1b191cb5SApple OSS Distributions if (mac_label_vnodes != 0 && mac_vnode_label(vp) == NULL) {
2714*1b191cb5SApple OSS Distributions mac_vnode_label_init(vp); /* init dst label */
2715*1b191cb5SApple OSS Distributions }
2716*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_copy, mac_vnode_label(fvp), mac_vnode_label(vp));
2717*1b191cb5SApple OSS Distributions }
2718*1b191cb5SApple OSS Distributions (void)vnode_put(fvp);
2719*1b191cb5SApple OSS Distributions break;
2720*1b191cb5SApple OSS Distributions #if CONFIG_MACF_SOCKET_SUBSET
2721*1b191cb5SApple OSS Distributions case DTYPE_SOCKET:
2722*1b191cb5SApple OSS Distributions so = (struct socket *)fp_get_data(fp);
2723*1b191cb5SApple OSS Distributions socket_lock(so, 1);
2724*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_associate_socket,
2725*1b191cb5SApple OSS Distributions vfs_context_ucred(ctx), (socket_t)so, NULL,
2726*1b191cb5SApple OSS Distributions vp, mac_vnode_label(vp));
2727*1b191cb5SApple OSS Distributions socket_unlock(so, 1);
2728*1b191cb5SApple OSS Distributions break;
2729*1b191cb5SApple OSS Distributions #endif
2730*1b191cb5SApple OSS Distributions case DTYPE_PSXSHM:
2731*1b191cb5SApple OSS Distributions pshm_label_associate(fp, vp, ctx);
2732*1b191cb5SApple OSS Distributions break;
2733*1b191cb5SApple OSS Distributions case DTYPE_PSXSEM:
2734*1b191cb5SApple OSS Distributions psem_label_associate(fp, vp, ctx);
2735*1b191cb5SApple OSS Distributions break;
2736*1b191cb5SApple OSS Distributions case DTYPE_PIPE:
2737*1b191cb5SApple OSS Distributions cpipe = (struct pipe *)fp_get_data(fp);
2738*1b191cb5SApple OSS Distributions /* kern/sys_pipe.c:pipe_select() suggests this test. */
2739*1b191cb5SApple OSS Distributions if (cpipe == (struct pipe *)-1) {
2740*1b191cb5SApple OSS Distributions error = EINVAL;
2741*1b191cb5SApple OSS Distributions goto out;
2742*1b191cb5SApple OSS Distributions }
2743*1b191cb5SApple OSS Distributions PIPE_LOCK(cpipe);
2744*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_associate_pipe, vfs_context_ucred(ctx),
2745*1b191cb5SApple OSS Distributions cpipe, mac_pipe_label(cpipe), vp, mac_vnode_label(vp));
2746*1b191cb5SApple OSS Distributions PIPE_UNLOCK(cpipe);
2747*1b191cb5SApple OSS Distributions break;
2748*1b191cb5SApple OSS Distributions case DTYPE_KQUEUE:
2749*1b191cb5SApple OSS Distributions case DTYPE_FSEVENTS:
2750*1b191cb5SApple OSS Distributions case DTYPE_ATALK:
2751*1b191cb5SApple OSS Distributions case DTYPE_NETPOLICY:
2752*1b191cb5SApple OSS Distributions case DTYPE_CHANNEL:
2753*1b191cb5SApple OSS Distributions case DTYPE_NEXUS:
2754*1b191cb5SApple OSS Distributions default:
2755*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_label_associate_file, vfs_context_ucred(ctx),
2756*1b191cb5SApple OSS Distributions mp, mac_mount_label(mp), fp->fp_glob, NULL,
2757*1b191cb5SApple OSS Distributions vp, mac_vnode_label(vp));
2758*1b191cb5SApple OSS Distributions break;
2759*1b191cb5SApple OSS Distributions }
2760*1b191cb5SApple OSS Distributions out:
2761*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(91, vp);
2762*1b191cb5SApple OSS Distributions fp_drop(p, fnp->fd_fd, fp, 0);
2763*1b191cb5SApple OSS Distributions return error;
2764*1b191cb5SApple OSS Distributions }
2765*1b191cb5SApple OSS Distributions
2766*1b191cb5SApple OSS Distributions intptr_t
mac_vnode_label_get(struct vnode * vp,int slot,intptr_t sentinel)2767*1b191cb5SApple OSS Distributions mac_vnode_label_get(struct vnode *vp, int slot, intptr_t sentinel)
2768*1b191cb5SApple OSS Distributions {
2769*1b191cb5SApple OSS Distributions struct label *l;
2770*1b191cb5SApple OSS Distributions
2771*1b191cb5SApple OSS Distributions KASSERT(vp != NULL, ("mac_vnode_label_get: NULL vnode"));
2772*1b191cb5SApple OSS Distributions l = mac_vnode_label(vp);
2773*1b191cb5SApple OSS Distributions if (l != NULL) {
2774*1b191cb5SApple OSS Distributions return mac_label_get(l, slot);
2775*1b191cb5SApple OSS Distributions } else {
2776*1b191cb5SApple OSS Distributions return sentinel;
2777*1b191cb5SApple OSS Distributions }
2778*1b191cb5SApple OSS Distributions }
2779*1b191cb5SApple OSS Distributions
2780*1b191cb5SApple OSS Distributions void
mac_vnode_label_set(struct vnode * vp,int slot,intptr_t v)2781*1b191cb5SApple OSS Distributions mac_vnode_label_set(struct vnode *vp, int slot, intptr_t v)
2782*1b191cb5SApple OSS Distributions {
2783*1b191cb5SApple OSS Distributions struct label *l;
2784*1b191cb5SApple OSS Distributions KASSERT(vp != NULL, ("mac_vnode_label_set: NULL vnode"));
2785*1b191cb5SApple OSS Distributions l = mac_vnode_label(vp);
2786*1b191cb5SApple OSS Distributions if (l == NULL) {
2787*1b191cb5SApple OSS Distributions mac_vnode_label_init(vp);
2788*1b191cb5SApple OSS Distributions l = mac_vnode_label(vp);
2789*1b191cb5SApple OSS Distributions }
2790*1b191cb5SApple OSS Distributions mac_label_set(l, slot, v);
2791*1b191cb5SApple OSS Distributions }
2792*1b191cb5SApple OSS Distributions
2793*1b191cb5SApple OSS Distributions void
mac_vnode_notify_reclaim(struct vnode * vp)2794*1b191cb5SApple OSS Distributions mac_vnode_notify_reclaim(struct vnode *vp)
2795*1b191cb5SApple OSS Distributions {
2796*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(94, vp);
2797*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_notify_reclaim, vp);
2798*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(94, vp);
2799*1b191cb5SApple OSS Distributions }
2800*1b191cb5SApple OSS Distributions
2801*1b191cb5SApple OSS Distributions int
mac_mount_check_quotactl(vfs_context_t ctx,struct mount * mp,int cmd,int id)2802*1b191cb5SApple OSS Distributions mac_mount_check_quotactl(vfs_context_t ctx, struct mount *mp, int cmd, int id)
2803*1b191cb5SApple OSS Distributions {
2804*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2805*1b191cb5SApple OSS Distributions int error;
2806*1b191cb5SApple OSS Distributions
2807*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2808*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2809*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2810*1b191cb5SApple OSS Distributions return 0;
2811*1b191cb5SApple OSS Distributions }
2812*1b191cb5SApple OSS Distributions #endif
2813*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2814*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2815*1b191cb5SApple OSS Distributions return 0;
2816*1b191cb5SApple OSS Distributions }
2817*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(95, mp);
2818*1b191cb5SApple OSS Distributions MAC_CHECK(mount_check_quotactl, cred, mp, cmd, id);
2819*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(95, mp);
2820*1b191cb5SApple OSS Distributions
2821*1b191cb5SApple OSS Distributions return error;
2822*1b191cb5SApple OSS Distributions }
2823*1b191cb5SApple OSS Distributions
2824*1b191cb5SApple OSS Distributions int
mac_vnode_check_getattrlistbulk(vfs_context_t ctx,struct vnode * vp,struct attrlist * alist,uint64_t options)2825*1b191cb5SApple OSS Distributions mac_vnode_check_getattrlistbulk(vfs_context_t ctx, struct vnode *vp, struct attrlist *alist, uint64_t options)
2826*1b191cb5SApple OSS Distributions {
2827*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2828*1b191cb5SApple OSS Distributions int error;
2829*1b191cb5SApple OSS Distributions
2830*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2831*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2832*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2833*1b191cb5SApple OSS Distributions return 0;
2834*1b191cb5SApple OSS Distributions }
2835*1b191cb5SApple OSS Distributions #endif
2836*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2837*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2838*1b191cb5SApple OSS Distributions return 0;
2839*1b191cb5SApple OSS Distributions }
2840*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(96, mp);
2841*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_getattrlistbulk, cred, vp, alist, options);
2842*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(96, mp);
2843*1b191cb5SApple OSS Distributions
2844*1b191cb5SApple OSS Distributions return error;
2845*1b191cb5SApple OSS Distributions }
2846*1b191cb5SApple OSS Distributions
2847*1b191cb5SApple OSS Distributions int
mac_vnode_check_copyfile(vfs_context_t ctx,struct vnode * dvp,struct vnode * tvp,struct vnode * fvp,struct componentname * cnp,mode_t mode,int flags)2848*1b191cb5SApple OSS Distributions mac_vnode_check_copyfile(vfs_context_t ctx, struct vnode *dvp,
2849*1b191cb5SApple OSS Distributions struct vnode *tvp, struct vnode *fvp, struct componentname *cnp,
2850*1b191cb5SApple OSS Distributions mode_t mode, int flags)
2851*1b191cb5SApple OSS Distributions {
2852*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2853*1b191cb5SApple OSS Distributions int error;
2854*1b191cb5SApple OSS Distributions
2855*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2856*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2857*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2858*1b191cb5SApple OSS Distributions return 0;
2859*1b191cb5SApple OSS Distributions }
2860*1b191cb5SApple OSS Distributions #endif
2861*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2862*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2863*1b191cb5SApple OSS Distributions return 0;
2864*1b191cb5SApple OSS Distributions }
2865*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(97, dvp);
2866*1b191cb5SApple OSS Distributions MAC_CHECK(vnode_check_copyfile, cred, dvp, mac_vnode_label(dvp),
2867*1b191cb5SApple OSS Distributions tvp, tvp ? mac_vnode_label(tvp) : NULL, fvp, mac_vnode_label(fvp), cnp, mode, flags);
2868*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(97, dvp);
2869*1b191cb5SApple OSS Distributions return error;
2870*1b191cb5SApple OSS Distributions }
2871*1b191cb5SApple OSS Distributions
2872*1b191cb5SApple OSS Distributions void
mac_vnode_notify_unlink(vfs_context_t ctx,struct vnode * dvp,struct vnode * vp,struct componentname * cnp)2873*1b191cb5SApple OSS Distributions mac_vnode_notify_unlink(vfs_context_t ctx, struct vnode *dvp, struct vnode *vp,
2874*1b191cb5SApple OSS Distributions struct componentname *cnp)
2875*1b191cb5SApple OSS Distributions {
2876*1b191cb5SApple OSS Distributions kauth_cred_t cred;
2877*1b191cb5SApple OSS Distributions
2878*1b191cb5SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
2879*1b191cb5SApple OSS Distributions /* 21167099 - only check if we allow write */
2880*1b191cb5SApple OSS Distributions if (!mac_vnode_enforce) {
2881*1b191cb5SApple OSS Distributions return;
2882*1b191cb5SApple OSS Distributions }
2883*1b191cb5SApple OSS Distributions #endif
2884*1b191cb5SApple OSS Distributions cred = vfs_context_ucred(ctx);
2885*1b191cb5SApple OSS Distributions if (!mac_cred_check_enforce(cred)) {
2886*1b191cb5SApple OSS Distributions return;
2887*1b191cb5SApple OSS Distributions }
2888*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_START1(98, vp);
2889*1b191cb5SApple OSS Distributions MAC_PERFORM(vnode_notify_unlink, cred, dvp, mac_vnode_label(dvp), vp,
2890*1b191cb5SApple OSS Distributions mac_vnode_label(vp), cnp);
2891*1b191cb5SApple OSS Distributions VFS_KERNEL_DEBUG_END1(98, vp);
2892*1b191cb5SApple OSS Distributions }
2893