]> git.saurik.com Git - apple/xnu.git/blob - security/mac_base.c
xnu-7195.60.75.tar.gz
[apple/xnu.git] / security / mac_base.c
1 /*
2 * Copyright (c) 2007-2020 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*-
29 * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
30 * Copyright (c) 2001 Ilmar S. Habibulin
31 * Copyright (c) 2001, 2002, 2003, 2004 Networks Associates Technology, Inc.
32 * Copyright (c) 2005-2006 SPARTA, Inc.
33 *
34 * This software was developed by Robert Watson and Ilmar Habibulin for the
35 * TrustedBSD Project.
36 *
37 * This software was developed for the FreeBSD Project in part by Network
38 * Associates Laboratories, the Security Research Division of Network
39 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
40 * as part of the DARPA CHATS research program.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 *
63 */
64
65 /*-
66 * Framework for extensible kernel access control. This file contains
67 * Kernel and userland interface to the framework, policy registration
68 * and composition. Per-object interfaces, controls, and labeling may be
69 * found in src/sys/mac/. Sample policies may be found in src/sys/mac*.
70 */
71
72 #include <stdarg.h>
73 #include <string.h>
74 #include <security/mac_internal.h>
75 #include <security/mac_mach_internal.h>
76 #include <sys/param.h>
77 #include <sys/vnode.h>
78 #include <sys/vnode_internal.h>
79 #include <sys/vfs_context.h>
80 #include <sys/namei.h>
81 #include <bsd/bsm/audit.h>
82 #include <bsd/security/audit/audit.h>
83 #include <bsd/security/audit/audit_private.h>
84 #include <sys/file.h>
85 #include <sys/file_internal.h>
86 #include <sys/filedesc.h>
87 #include <sys/proc.h>
88 #include <sys/proc_internal.h>
89 #include <sys/kauth.h>
90 #include <sys/sysproto.h>
91
92 #include <mach/exception_types.h>
93 #include <mach/vm_types.h>
94 #include <mach/vm_prot.h>
95
96 #include <kern/kalloc.h>
97 #include <kern/sched_prim.h>
98 #include <kern/task.h>
99
100 #if CONFIG_MACF
101 #include <security/mac.h>
102 #include <security/mac_policy.h>
103 #include <security/mac_framework.h>
104 #include <security/mac_internal.h>
105 #include <security/mac_mach_internal.h>
106 #endif
107
108 #include <libkern/section_keywords.h>
109
110 /*
111 * define MB_DEBUG to display run-time debugging information
112 * #define MB_DEBUG 1
113 */
114
115 #ifdef MB_DEBUG
116 #define DPRINTF(x) printf x
117 #else
118 #define MB_DEBUG
119 #define DPRINTF(x)
120 #endif
121
122 #if CONFIG_MACF
123 SYSCTL_NODE(, OID_AUTO, security, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
124 "Security Controls");
125 SYSCTL_NODE(_security, OID_AUTO, mac, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
126 "TrustedBSD MAC policy controls");
127
128 /*
129 * Declare that the kernel provides MAC support, version 1. This permits
130 * modules to refuse to be loaded if the necessary support isn't present,
131 * even if it's pre-boot.
132 */
133 #if 0
134 MODULE_VERSION(kernel_mac_support, 1);
135 #endif
136
137 #if MAC_MAX_SLOTS > 32
138 #error "MAC_MAX_SLOTS too large"
139 #endif
140
141 static unsigned int mac_max_slots = MAC_MAX_SLOTS;
142 static unsigned int mac_slot_offsets_free = (1 << MAC_MAX_SLOTS) - 1;
143 SYSCTL_UINT(_security_mac, OID_AUTO, max_slots, CTLFLAG_RD | CTLFLAG_LOCKED,
144 &mac_max_slots, 0, "");
145
146 /*
147 * Has the kernel started generating labeled objects yet? All read/write
148 * access to this variable is serialized during the boot process. Following
149 * the end of serialization, we don't update this flag; no locking.
150 */
151 int mac_late = 0;
152
153 /*
154 * Flag to indicate whether or not we should allocate label storage for
155 * new vnodes. Since most dynamic policies we currently work with don't
156 * rely on vnode labeling, try to avoid paying the cost of mtag allocation
157 * unless specifically notified of interest. One result of this is
158 * that if a dynamically loaded policy requests vnode labels, it must
159 * be able to deal with a NULL label being returned on any vnodes that
160 * were already in flight when the policy was loaded. Since the policy
161 * already has to deal with uninitialized labels, this probably won't
162 * be a problem.
163 */
164 #if CONFIG_MACF_LAZY_VNODE_LABELS
165 unsigned int mac_label_vnodes = 1;
166 #else
167 unsigned int mac_label_vnodes = 0;
168 #endif /* CONFIG_MACF_LAZY_VNODE_LABELS */
169 SYSCTL_UINT(_security_mac, OID_AUTO, labelvnodes, SECURITY_MAC_CTLFLAGS
170 #if CONFIG_MACF_LAZY_VNODE_LABELS
171 | CTLFLAG_RD
172 #endif
173 , &mac_label_vnodes, 0, "Label all vnodes");
174
175 unsigned int mac_vnode_label_count = 0;
176 SYSCTL_UINT(_security_mac, OID_AUTO, vnode_label_count, SECURITY_MAC_CTLFLAGS | CTLFLAG_RD,
177 &mac_vnode_label_count, 0, "Count of vnode labels");
178
179 unsigned int mac_device_enforce = 1;
180 SYSCTL_UINT(_security_mac, OID_AUTO, device_enforce, SECURITY_MAC_CTLFLAGS,
181 &mac_device_enforce, 0, "Enforce MAC policy on device operations");
182
183 unsigned int mac_pipe_enforce = 1;
184 SYSCTL_UINT(_security_mac, OID_AUTO, pipe_enforce, SECURITY_MAC_CTLFLAGS,
185 &mac_pipe_enforce, 0, "Enforce MAC policy on pipe operations");
186
187 unsigned int mac_posixsem_enforce = 1;
188 SYSCTL_UINT(_security_mac, OID_AUTO, posixsem_enforce, SECURITY_MAC_CTLFLAGS,
189 &mac_posixsem_enforce, 0, "Enforce MAC policy on POSIX semaphores");
190
191 unsigned int mac_posixshm_enforce = 1;
192 SYSCTL_UINT(_security_mac, OID_AUTO, posixshm_enforce, SECURITY_MAC_CTLFLAGS,
193 &mac_posixshm_enforce, 0, "Enforce MAC policy on Posix Shared Memory");
194
195 unsigned int mac_proc_enforce = 1;
196 SYSCTL_UINT(_security_mac, OID_AUTO, proc_enforce, SECURITY_MAC_CTLFLAGS,
197 &mac_proc_enforce, 0, "Enforce MAC policy on process operations");
198
199 unsigned int mac_socket_enforce = 1;
200 SYSCTL_UINT(_security_mac, OID_AUTO, socket_enforce, SECURITY_MAC_CTLFLAGS,
201 &mac_socket_enforce, 0, "Enforce MAC policy on socket operations");
202
203 unsigned int mac_system_enforce = 1;
204 SYSCTL_UINT(_security_mac, OID_AUTO, system_enforce, SECURITY_MAC_CTLFLAGS,
205 &mac_system_enforce, 0, "Enforce MAC policy on system-wide interfaces");
206
207 unsigned int mac_sysvmsg_enforce = 1;
208 SYSCTL_UINT(_security_mac, OID_AUTO, sysvmsg_enforce, SECURITY_MAC_CTLFLAGS,
209 &mac_sysvmsg_enforce, 0, "Enforce MAC policy on System V IPC message queues");
210
211 unsigned int mac_sysvsem_enforce = 1;
212 SYSCTL_UINT(_security_mac, OID_AUTO, sysvsem_enforce, SECURITY_MAC_CTLFLAGS,
213 &mac_sysvsem_enforce, 0, "Enforce MAC policy on System V IPC semaphores");
214
215 unsigned int mac_sysvshm_enforce = 1;
216 SYSCTL_INT(_security_mac, OID_AUTO, sysvshm_enforce, SECURITY_MAC_CTLFLAGS,
217 &mac_sysvshm_enforce, 0, "Enforce MAC policy on System V Shared Memory");
218
219 unsigned int mac_vm_enforce = 1;
220 SYSCTL_INT(_security_mac, OID_AUTO, vm_enforce, SECURITY_MAC_CTLFLAGS,
221 &mac_vm_enforce, 0, "Enforce MAC policy on VM operations");
222
223 unsigned int mac_vnode_enforce = 1;
224 SYSCTL_UINT(_security_mac, OID_AUTO, vnode_enforce, SECURITY_MAC_CTLFLAGS,
225 &mac_vnode_enforce, 0, "Enforce MAC policy on vnode operations");
226
227 /*
228 * mac_policy_list holds the list of policy modules. Modules with a
229 * handle lower than staticmax are considered "static" and cannot be
230 * unloaded. Such policies can be invoked without holding the busy count.
231 *
232 * Modules with a handle at or above the staticmax high water mark
233 * are considered to be "dynamic" policies. A busy count is maintained
234 * for the list, stored in mac_policy_busy. The busy count is protected
235 * by mac_policy_mtx; the list may be modified only while the busy
236 * count is 0, requiring that the lock be held to prevent new references
237 * to the list from being acquired. For almost all operations,
238 * incrementing the busy count is sufficient to guarantee consistency,
239 * as the list cannot be modified while the busy count is elevated.
240 * For a few special operations involving a change to the list of
241 * active policies, the mtx itself must be held.
242 */
243 static lck_mtx_t *mac_policy_mtx;
244
245 /*
246 * Policy list array allocation chunk size. Each entry holds a pointer.
247 */
248 #define MAC_POLICY_LIST_CHUNKSIZE 8
249
250 static int mac_policy_busy;
251
252 #if !XNU_TARGET_OS_OSX
253 SECURITY_READ_ONLY_LATE(mac_policy_list_t) mac_policy_list;
254 SECURITY_READ_ONLY_LATE(static struct mac_policy_list_element) mac_policy_static_entries[MAC_POLICY_LIST_CHUNKSIZE];
255 #else
256 mac_policy_list_t mac_policy_list;
257 #endif
258
259 /*
260 * mac_label_element_list holds the master list of label namespaces for
261 * all the policies. When a policy is loaded, each of it's label namespace
262 * elements is added to the master list if not already present. When a
263 * policy is unloaded, the namespace elements are removed if no other
264 * policy is interested in that namespace element.
265 */
266 struct mac_label_element_list_t mac_label_element_list;
267 struct mac_label_element_list_t mac_static_label_element_list;
268
269 static __inline void
270 mac_policy_grab_exclusive(void)
271 {
272 lck_mtx_lock(mac_policy_mtx);
273 while (mac_policy_busy != 0) {
274 lck_mtx_sleep(mac_policy_mtx, LCK_SLEEP_UNLOCK,
275 (event_t)&mac_policy_busy, THREAD_UNINT);
276 lck_mtx_lock(mac_policy_mtx);
277 }
278 }
279
280 static __inline void
281 mac_policy_release_exclusive(void)
282 {
283 KASSERT(mac_policy_busy == 0,
284 ("mac_policy_release_exclusive(): not exclusive"));
285 lck_mtx_unlock(mac_policy_mtx);
286 thread_wakeup((event_t) &mac_policy_busy);
287 }
288
289 void
290 mac_policy_list_busy(void)
291 {
292 lck_mtx_lock(mac_policy_mtx);
293 mac_policy_busy++;
294 lck_mtx_unlock(mac_policy_mtx);
295 }
296
297 int
298 mac_policy_list_conditional_busy(void)
299 {
300 int ret;
301
302 if (mac_policy_list.numloaded <= mac_policy_list.staticmax) {
303 return 0;
304 }
305
306 lck_mtx_lock(mac_policy_mtx);
307 if (mac_policy_list.numloaded > mac_policy_list.staticmax) {
308 mac_policy_busy++;
309 ret = 1;
310 } else {
311 ret = 0;
312 }
313 lck_mtx_unlock(mac_policy_mtx);
314 return ret;
315 }
316
317 void
318 mac_policy_list_unbusy(void)
319 {
320 lck_mtx_lock(mac_policy_mtx);
321 mac_policy_busy--;
322 KASSERT(mac_policy_busy >= 0, ("MAC_POLICY_LIST_LOCK"));
323 if (mac_policy_busy == 0) {
324 thread_wakeup(&mac_policy_busy);
325 }
326 lck_mtx_unlock(mac_policy_mtx);
327 }
328
329 /*
330 * Early pre-malloc MAC initialization, including appropriate SMP locks.
331 */
332 void
333 mac_policy_init(void)
334 {
335 lck_grp_attr_t *mac_lck_grp_attr;
336 lck_attr_t *mac_lck_attr;
337 lck_grp_t *mac_lck_grp;
338
339 mac_policy_list.numloaded = 0;
340 mac_policy_list.max = MAC_POLICY_LIST_CHUNKSIZE;
341 mac_policy_list.maxindex = 0;
342 mac_policy_list.staticmax = 0;
343 mac_policy_list.freehint = 0;
344 mac_policy_list.chunks = 1;
345
346 #if !XNU_TARGET_OS_OSX
347 mac_policy_list.entries = mac_policy_static_entries;
348 #else
349 mac_policy_list.entries = kalloc_flags(
350 sizeof(struct mac_policy_list_element) * MAC_POLICY_LIST_CHUNKSIZE,
351 Z_WAITOK | Z_ZERO);
352 #endif
353
354 LIST_INIT(&mac_label_element_list);
355 LIST_INIT(&mac_static_label_element_list);
356
357 mac_lck_grp_attr = lck_grp_attr_alloc_init();
358 mac_lck_grp = lck_grp_alloc_init("MAC lock", mac_lck_grp_attr);
359 mac_lck_attr = lck_attr_alloc_init();
360 lck_attr_setdefault(mac_lck_attr);
361 mac_policy_mtx = lck_mtx_alloc_init(mac_lck_grp, mac_lck_attr);
362 lck_attr_free(mac_lck_attr);
363 lck_grp_attr_free(mac_lck_grp_attr);
364 lck_grp_free(mac_lck_grp);
365 }
366
367 /* Function pointer set up for loading security extensions.
368 * It is set to an actual function after OSlibkernInit()
369 * has been called, and is set back to 0 by OSKextRemoveKextBootstrap()
370 * after bsd_init().
371 */
372 void (*load_security_extensions_function)(void) = 0;
373
374 /*
375 * Init after early Mach startup, but before BSD
376 */
377 void
378 mac_policy_initmach(void)
379 {
380 /*
381 * For the purposes of modules that want to know if they were
382 * loaded "early", set the mac_late flag once we've processed
383 * modules either linked into the kernel, or loaded before the
384 * kernel startup.
385 */
386
387 if (load_security_extensions_function) {
388 load_security_extensions_function();
389 }
390 mac_late = 1;
391 }
392
393 /*
394 * BSD startup.
395 */
396 void
397 mac_policy_initbsd(void)
398 {
399 struct mac_policy_conf *mpc;
400 u_int i;
401
402 printf("MAC Framework successfully initialized\n");
403
404 /* Call bsd init functions of already loaded policies */
405
406 /*
407 * Using the exclusive lock means no other framework entry
408 * points can proceed while initializations are running.
409 * This may not be necessary.
410 */
411 mac_policy_grab_exclusive();
412
413 for (i = 0; i <= mac_policy_list.maxindex; i++) {
414 mpc = mac_get_mpc(i);
415 if ((mpc != NULL) && (mpc->mpc_ops->mpo_policy_initbsd != NULL)) {
416 (*(mpc->mpc_ops->mpo_policy_initbsd))(mpc);
417 }
418 }
419
420 mac_policy_release_exclusive();
421 }
422
423 /*
424 * After a policy has been loaded, add the label namespaces managed by the
425 * policy to either the static or non-static label namespace list.
426 * A namespace is added to the the list only if it is not already on one of
427 * the lists.
428 */
429 void
430 mac_policy_addto_labellist(mac_policy_handle_t handle, int static_entry)
431 {
432 struct mac_label_listener **new_mlls;
433 struct mac_label_element *mle, **new_mles;
434 struct mac_label_element_list_t *list;
435 struct mac_policy_conf *mpc;
436 const char *name, *name2;
437 u_int idx, mle_free, mll_free;
438
439 mpc = mac_get_mpc(handle);
440
441 if (mpc->mpc_labelnames == NULL) {
442 return;
443 }
444
445 if (mpc->mpc_labelname_count == 0) {
446 return;
447 }
448
449 if (static_entry) {
450 list = &mac_static_label_element_list;
451 } else {
452 list = &mac_label_element_list;
453 }
454
455 /*
456 * Before we grab the policy list lock, allocate enough memory
457 * to contain the potential new elements so we don't have to
458 * give up the lock, or allocate with the lock held.
459 */
460 MALLOC(new_mles, struct mac_label_element **,
461 sizeof(struct mac_label_element *) *
462 mpc->mpc_labelname_count, M_MACTEMP, M_WAITOK | M_ZERO);
463 for (idx = 0; idx < mpc->mpc_labelname_count; idx++) {
464 MALLOC(new_mles[idx], struct mac_label_element *,
465 sizeof(struct mac_label_element),
466 M_MACTEMP, M_WAITOK);
467 }
468 mle_free = 0;
469 MALLOC(new_mlls, struct mac_label_listener **,
470 sizeof(struct mac_label_listener *) *
471 mpc->mpc_labelname_count, M_MACTEMP, M_WAITOK);
472 for (idx = 0; idx < mpc->mpc_labelname_count; idx++) {
473 MALLOC(new_mlls[idx], struct mac_label_listener *,
474 sizeof(struct mac_label_listener), M_MACTEMP, M_WAITOK);
475 }
476 mll_free = 0;
477
478 if (mac_late) {
479 mac_policy_grab_exclusive();
480 }
481 for (idx = 0; idx < mpc->mpc_labelname_count; idx++) {
482 if (*(name = mpc->mpc_labelnames[idx]) == '?') {
483 name++;
484 }
485 /*
486 * Check both label element lists and add to the
487 * appropriate list only if not already on a list.
488 */
489 LIST_FOREACH(mle, &mac_static_label_element_list, mle_list) {
490 if (*(name2 = mle->mle_name) == '?') {
491 name2++;
492 }
493 if (strcmp(name, name2) == 0) {
494 break;
495 }
496 }
497 if (mle == NULL) {
498 LIST_FOREACH(mle, &mac_label_element_list, mle_list) {
499 if (*(name2 = mle->mle_name) == '?') {
500 name2++;
501 }
502 if (strcmp(name, name2) == 0) {
503 break;
504 }
505 }
506 }
507 if (mle == NULL) {
508 mle = new_mles[mle_free];
509 strlcpy(mle->mle_name, mpc->mpc_labelnames[idx],
510 MAC_MAX_LABEL_ELEMENT_NAME);
511 LIST_INIT(&mle->mle_listeners);
512 LIST_INSERT_HEAD(list, mle, mle_list);
513 mle_free++;
514 }
515 /* Add policy handler as a listener. */
516 new_mlls[mll_free]->mll_handle = handle;
517 LIST_INSERT_HEAD(&mle->mle_listeners, new_mlls[mll_free],
518 mll_list);
519 mll_free++;
520 }
521 if (mac_late) {
522 mac_policy_release_exclusive();
523 }
524
525 /* Free up any unused label elements and listeners */
526 for (idx = mle_free; idx < mpc->mpc_labelname_count; idx++) {
527 FREE(new_mles[idx], M_MACTEMP);
528 }
529 FREE(new_mles, M_MACTEMP);
530 for (idx = mll_free; idx < mpc->mpc_labelname_count; idx++) {
531 FREE(new_mlls[idx], M_MACTEMP);
532 }
533 FREE(new_mlls, M_MACTEMP);
534 }
535
536 /*
537 * After a policy has been unloaded, remove the label namespaces that the
538 * the policy manages from the non-static list of namespaces.
539 * The removal only takes place when no other policy is interested in the
540 * namespace.
541 *
542 * Must be called with the policy exclusive lock held.
543 */
544 void
545 mac_policy_removefrom_labellist(mac_policy_handle_t handle)
546 {
547 struct mac_label_listener *mll;
548 struct mac_label_element *mle;
549 struct mac_policy_conf *mpc;
550
551 mpc = mac_get_mpc(handle);
552
553 if (mpc->mpc_labelnames == NULL) {
554 return;
555 }
556
557 if (mpc->mpc_labelname_count == 0) {
558 return;
559 }
560
561 /*
562 * Unregister policy as being interested in any label
563 * namespaces. If no other policy is listening, remove
564 * that label element from the list. Note that we only
565 * have to worry about the non-static list.
566 */
567 LIST_FOREACH(mle, &mac_label_element_list, mle_list) {
568 LIST_FOREACH(mll, &mle->mle_listeners, mll_list) {
569 if (mll->mll_handle == handle) {
570 LIST_REMOVE(mll, mll_list);
571 FREE(mll, M_MACTEMP);
572 if (LIST_EMPTY(&mle->mle_listeners)) {
573 LIST_REMOVE(mle, mle_list);
574 FREE(mle, M_MACTEMP);
575 }
576 return;
577 }
578 }
579 }
580 }
581
582 /*
583 * After the policy list has changed, walk the list to update any global
584 * flags.
585 */
586 static void
587 mac_policy_updateflags(void)
588 {
589 }
590
591 static __inline void
592 mac_policy_fixup_mmd_list(struct mac_module_data *new)
593 {
594 struct mac_module_data *old;
595 struct mac_module_data_element *ele, *aele;
596 struct mac_module_data_list *arr, *dict;
597 unsigned int i, j, k;
598
599 old = new->base_addr;
600 DPRINTF(("fixup_mmd: old %p new %p\n", old, new));
601 for (i = 0; i < new->count; i++) {
602 ele = &(new->data[i]);
603 DPRINTF(("fixup_mmd: ele %p\n", ele));
604 DPRINTF((" key %p value %p\n", ele->key, ele->value));
605 mmd_fixup_ele(old, new, ele); /* Fix up key/value ptrs. */
606 DPRINTF((" key %p value %p\n", ele->key, ele->value));
607 if (ele->value_type == MAC_DATA_TYPE_ARRAY) {
608 arr = (struct mac_module_data_list *)ele->value;
609 DPRINTF(("fixup_mmd: array @%p\n", arr));
610 for (j = 0; j < arr->count; j++) {
611 aele = &(arr->list[j]);
612 DPRINTF(("fixup_mmd: aele %p\n", aele));
613 DPRINTF((" key %p value %p\n", aele->key, aele->value));
614 mmd_fixup_ele(old, new, aele);
615 DPRINTF((" key %p value %p\n", aele->key, aele->value));
616 if (arr->type == MAC_DATA_TYPE_DICT) {
617 dict = (struct mac_module_data_list *)aele->value;
618 DPRINTF(("fixup_mmd: dict @%p\n", dict));
619 for (k = 0; k < dict->count; k++) {
620 mmd_fixup_ele(old, new,
621 &(dict->list[k]));
622 }
623 }
624 }
625 }
626 }
627 new->base_addr = new;
628 }
629
630 int
631 mac_policy_register(struct mac_policy_conf *mpc, mac_policy_handle_t *handlep,
632 void *xd)
633 {
634 #if XNU_TARGET_OS_OSX
635 struct mac_policy_list_element *tmac_policy_list_element;
636 #endif
637 int error, slot, static_entry = 0;
638 u_int i;
639
640 /*
641 * Some preliminary checks to make sure the policy's conf structure
642 * contains the required fields.
643 */
644 if (mpc->mpc_name == NULL) {
645 panic("policy's name is not set\n");
646 }
647
648 if (mpc->mpc_fullname == NULL) {
649 panic("policy's full name is not set\n");
650 }
651
652 if (mpc->mpc_labelname_count > MAC_MAX_MANAGED_NAMESPACES) {
653 panic("policy's managed label namespaces exceeds maximum\n");
654 }
655
656 if (mpc->mpc_ops == NULL) {
657 panic("policy's OPs field is NULL\n");
658 }
659
660 error = 0;
661
662 if (mac_late) {
663 if (mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_NOTLATE) {
664 printf("Module %s does not support late loading.\n",
665 mpc->mpc_name);
666 return EPERM;
667 }
668 mac_policy_grab_exclusive();
669 }
670
671 if (mac_policy_list.numloaded >= mac_policy_list.max) {
672 #if XNU_TARGET_OS_OSX
673 /* allocate new policy list array, zero new chunk */
674 tmac_policy_list_element =
675 kalloc((sizeof(struct mac_policy_list_element) *
676 MAC_POLICY_LIST_CHUNKSIZE) * (mac_policy_list.chunks + 1));
677 bzero(&tmac_policy_list_element[mac_policy_list.max],
678 sizeof(struct mac_policy_list_element) *
679 MAC_POLICY_LIST_CHUNKSIZE);
680
681 /* copy old entries into new list */
682 memcpy(tmac_policy_list_element, mac_policy_list.entries,
683 sizeof(struct mac_policy_list_element) *
684 MAC_POLICY_LIST_CHUNKSIZE * mac_policy_list.chunks);
685
686 /* free old array */
687 kfree(mac_policy_list.entries,
688 sizeof(struct mac_policy_list_element) *
689 MAC_POLICY_LIST_CHUNKSIZE * mac_policy_list.chunks);
690
691 mac_policy_list.entries = tmac_policy_list_element;
692
693 /* Update maximums, etc */
694 mac_policy_list.max += MAC_POLICY_LIST_CHUNKSIZE;
695 mac_policy_list.chunks++;
696 #else
697 printf("out of space in mac_policy_list.\n");
698 return ENOMEM;
699 #endif /* XNU_TARGET_OS_OSX */
700 }
701
702 /* Check for policy with same name already loaded */
703 for (i = 0; i <= mac_policy_list.maxindex; i++) {
704 if (mac_policy_list.entries[i].mpc == NULL) {
705 continue;
706 }
707
708 if (strcmp(mac_policy_list.entries[i].mpc->mpc_name,
709 mpc->mpc_name) == 0) {
710 error = EEXIST;
711 goto out;
712 }
713 }
714
715 if (mpc->mpc_field_off != NULL) {
716 slot = ffs(mac_slot_offsets_free);
717 if (slot == 0) {
718 error = ENOMEM;
719 goto out;
720 }
721 slot--;
722 mac_slot_offsets_free &= ~(1 << slot);
723 *mpc->mpc_field_off = slot;
724 }
725 mpc->mpc_runtime_flags |= MPC_RUNTIME_FLAG_REGISTERED;
726
727 if (xd) {
728 struct mac_module_data *mmd = xd; /* module data from plist */
729
730 /* Make a copy of the data. */
731 mpc->mpc_data = (void *)kalloc(mmd->size);
732 if (mpc->mpc_data != NULL) {
733 memcpy(mpc->mpc_data, mmd, mmd->size);
734
735 /* Fix up pointers after copy. */
736 mac_policy_fixup_mmd_list(mpc->mpc_data);
737 }
738 }
739
740 /* Find the first free handle in the list (using our hint). */
741 for (i = mac_policy_list.freehint; i < mac_policy_list.max; i++) {
742 if (mac_policy_list.entries[i].mpc == NULL) {
743 *handlep = i;
744 mac_policy_list.freehint = ++i;
745 break;
746 }
747 }
748
749 /*
750 * If we are loading a MAC module before the framework has
751 * finished initializing or the module is not unloadable and
752 * we can place its handle adjacent to the last static entry,
753 * bump the static policy high water mark.
754 * Static policies can get by with weaker locking requirements.
755 */
756 if (!mac_late ||
757 ((mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK) == 0 &&
758 *handlep == mac_policy_list.staticmax)) {
759 static_entry = 1;
760 mac_policy_list.staticmax++;
761 }
762
763 mac_policy_list.entries[*handlep].mpc = mpc;
764
765 /* Update counters, etc */
766 if (*handlep > mac_policy_list.maxindex) {
767 mac_policy_list.maxindex = *handlep;
768 }
769 mac_policy_list.numloaded++;
770
771 /* Per-policy initialization. */
772 printf("calling mpo_policy_init for %s\n", mpc->mpc_name);
773 if (mpc->mpc_ops->mpo_policy_init != NULL) {
774 (*(mpc->mpc_ops->mpo_policy_init))(mpc);
775 }
776
777 if (mac_late && mpc->mpc_ops->mpo_policy_initbsd != NULL) {
778 printf("calling mpo_policy_initbsd for %s\n", mpc->mpc_name);
779 (*(mpc->mpc_ops->mpo_policy_initbsd))(mpc);
780 }
781
782 mac_policy_updateflags();
783
784 if (mac_late) {
785 mac_policy_release_exclusive();
786 }
787
788 mac_policy_addto_labellist(*handlep, static_entry);
789
790 printf("Security policy loaded: %s (%s)\n", mpc->mpc_fullname,
791 mpc->mpc_name);
792
793 return 0;
794
795 out:
796 if (mac_late) {
797 mac_policy_release_exclusive();
798 }
799
800 return error;
801 }
802
803 int
804 mac_policy_unregister(mac_policy_handle_t handle)
805 {
806 struct mac_policy_conf *mpc;
807
808 /*
809 * If we fail the load, we may get a request to unload. Check
810 * to see if we did the run-time registration, and if not,
811 * silently succeed.
812 */
813 mac_policy_grab_exclusive();
814 mpc = mac_get_mpc(handle);
815 if ((mpc->mpc_runtime_flags & MPC_RUNTIME_FLAG_REGISTERED) == 0) {
816 mac_policy_release_exclusive();
817 return 0;
818 }
819
820 #if 0
821 /*
822 * Don't allow unloading modules with private data.
823 */
824 if (mpc->mpc_field_off != NULL) {
825 MAC_POLICY_LIST_UNLOCK();
826 return EBUSY;
827 }
828 #endif
829 /*
830 * Only allow the unload to proceed if the module is unloadable
831 * by its own definition.
832 */
833 if ((mpc->mpc_loadtime_flags & MPC_LOADTIME_FLAG_UNLOADOK) == 0) {
834 mac_policy_release_exclusive();
835 return EBUSY;
836 }
837
838 mac_policy_removefrom_labellist(handle);
839
840 mac_get_mpc(handle) = NULL;
841 if (handle < mac_policy_list.freehint &&
842 handle >= mac_policy_list.staticmax) {
843 mac_policy_list.freehint = handle;
844 }
845
846 if (handle == mac_policy_list.maxindex) {
847 mac_policy_list.maxindex--;
848 }
849
850 mac_policy_list.numloaded--;
851 if (mpc->mpc_field_off != NULL) {
852 mac_slot_offsets_free |= (1 << *mpc->mpc_field_off);
853 }
854
855 if (mpc->mpc_ops->mpo_policy_destroy != NULL) {
856 (*(mpc->mpc_ops->mpo_policy_destroy))(mpc);
857 }
858
859 mpc->mpc_runtime_flags &= ~MPC_RUNTIME_FLAG_REGISTERED;
860 mac_policy_updateflags();
861
862 mac_policy_release_exclusive();
863
864 if (mpc->mpc_data) {
865 struct mac_module_data *mmd = mpc->mpc_data;
866 kfree(mmd, mmd->size);
867 mpc->mpc_data = NULL;
868 }
869
870 printf("Security policy unload: %s (%s)\n", mpc->mpc_fullname,
871 mpc->mpc_name);
872
873 return 0;
874 }
875
876 /*
877 * Define an error value precedence, and given two arguments, selects the
878 * value with the higher precedence.
879 */
880 int
881 mac_error_select(int error1, int error2)
882 {
883 /* Certain decision-making errors take top priority. */
884 if (error1 == EDEADLK || error2 == EDEADLK) {
885 return EDEADLK;
886 }
887
888 /* Invalid arguments should be reported where possible. */
889 if (error1 == EINVAL || error2 == EINVAL) {
890 return EINVAL;
891 }
892
893 /* Precedence goes to "visibility", with both process and file. */
894 if (error1 == ESRCH || error2 == ESRCH) {
895 return ESRCH;
896 }
897
898 if (error1 == ENOENT || error2 == ENOENT) {
899 return ENOENT;
900 }
901
902 /* Precedence goes to DAC/MAC protections. */
903 if (error1 == EACCES || error2 == EACCES) {
904 return EACCES;
905 }
906
907 /* Precedence goes to privilege. */
908 if (error1 == EPERM || error2 == EPERM) {
909 return EPERM;
910 }
911
912 /* Precedence goes to error over success; otherwise, arbitrary. */
913 if (error1 != 0) {
914 return error1;
915 }
916 return error2;
917 }
918
919 void
920 mac_label_init(struct label *label)
921 {
922 bzero(label, sizeof(*label));
923 label->l_flags = MAC_FLAG_INITIALIZED;
924 }
925
926 void
927 mac_label_destroy(struct label *label)
928 {
929 KASSERT(label->l_flags & MAC_FLAG_INITIALIZED,
930 ("destroying uninitialized label"));
931
932 bzero(label, sizeof(*label));
933 /* implicit: label->l_flags &= ~MAC_FLAG_INITIALIZED; */
934 }
935
936 int
937 mac_check_structmac_consistent(struct user_mac *mac)
938 {
939 if (mac->m_buflen > MAC_MAX_LABEL_BUF_LEN || mac->m_buflen == 0) {
940 return EINVAL;
941 }
942
943 return 0;
944 }
945
946 /*
947 * Get the external forms of labels from all policies, for a single
948 * label namespace or "*" for all namespaces. Returns ENOENT if no policy
949 * is registered for the namespace, unless the namespace begins with a '?'.
950 */
951 static int
952 mac_label_externalize(size_t mpo_externalize_off, struct label *label,
953 const char *element, struct sbuf *sb)
954 {
955 struct mac_policy_conf *mpc;
956 struct mac_label_listener *mll;
957 struct mac_label_element *mle;
958 struct mac_label_element_list_t *element_list;
959 const char *name;
960 int (*mpo_externalize)(struct label *, char *, struct sbuf *);
961 int all_labels = 0, ignorenotfound = 0, error = 0, busy = FALSE;
962 int sb_pos;
963 unsigned int count = 0;
964
965 if (element[0] == '?') {
966 element++;
967 ignorenotfound = 1;
968 } else if (element[0] == '*' && element[1] == '\0') {
969 all_labels = 1;
970 }
971
972 element_list = &mac_static_label_element_list;
973 element_loop:
974 LIST_FOREACH(mle, element_list, mle_list) {
975 name = mle->mle_name;
976 if (all_labels) {
977 if (*name == '?') {
978 continue;
979 }
980 } else {
981 if (*name == '?') {
982 name++;
983 }
984 if (strcmp(name, element) != 0) {
985 continue;
986 }
987 }
988 LIST_FOREACH(mll, &mle->mle_listeners, mll_list) {
989 mpc = mac_policy_list.entries[mll->mll_handle].mpc;
990 if (mpc == NULL) {
991 continue;
992 }
993 mpo_externalize = *(const typeof(mpo_externalize) *)
994 ((const char *)mpc->mpc_ops + mpo_externalize_off);
995 if (mpo_externalize == NULL) {
996 continue;
997 }
998 sb_pos = sbuf_len(sb);
999 error = sbuf_printf(sb, "%s/", name);
1000 if (error) {
1001 goto done;
1002 }
1003 error = mpo_externalize(label, mle->mle_name, sb);
1004 if (error) {
1005 if (error != ENOENT) {
1006 goto done;
1007 }
1008 /*
1009 * If a policy doesn't have a label to
1010 * externalize it returns ENOENT. This
1011 * may occur for policies that support
1012 * multiple label elements for some
1013 * (but not all) object types.
1014 */
1015 sbuf_setpos(sb, sb_pos);
1016 error = 0;
1017 continue;
1018 }
1019 error = sbuf_putc(sb, ',');
1020 if (error) {
1021 goto done;
1022 }
1023 count++;
1024 }
1025 }
1026 /* If there are dynamic policies present, check their elements too. */
1027 if (!busy && mac_policy_list_conditional_busy() == 1) {
1028 element_list = &mac_label_element_list;
1029 busy = TRUE;
1030 goto element_loop;
1031 }
1032 done:
1033 if (busy) {
1034 mac_policy_list_unbusy();
1035 }
1036 if (!error && count == 0) {
1037 if (!all_labels && !ignorenotfound) {
1038 error = ENOENT; /* XXX: ENOLABEL? */
1039 }
1040 }
1041 return error;
1042 }
1043
1044 /*
1045 * Get the external forms of labels from all policies, for all label
1046 * namespaces contained in a list.
1047 *
1048 * XXX This may be leaking an sbuf.
1049 */
1050 int
1051 mac_externalize(size_t mpo_externalize_off, struct label *label,
1052 const char *elementlist, char *outbuf, size_t outbuflen)
1053 {
1054 char *element;
1055 char *scratch_base;
1056 char *scratch;
1057 struct sbuf sb;
1058 int error = 0, len;
1059
1060 /* allocate a scratch buffer the size of the string */
1061 MALLOC(scratch_base, char *, strlen(elementlist) + 1, M_MACTEMP, M_WAITOK);
1062 if (scratch_base == NULL) {
1063 error = ENOMEM;
1064 goto out;
1065 }
1066
1067 /* copy the elementlist to the scratch buffer */
1068 strlcpy(scratch_base, elementlist, strlen(elementlist) + 1);
1069
1070 /*
1071 * set up a temporary pointer that can be used to iterate the
1072 * scratch buffer without losing the allocation address
1073 */
1074 scratch = scratch_base;
1075
1076 /*
1077 * initialize an sbuf mapping over the output buffer (or newly-allocated internal buffer, if
1078 * outbuf is NULL), up to sbuf's limit of INT_MAX.
1079 */
1080 if (outbuflen > INT_MAX) {
1081 outbuflen = INT_MAX;
1082 }
1083 if (sbuf_new(&sb, outbuf, (int)outbuflen, SBUF_FIXEDLEN) == NULL) {
1084 /* could not allocate interior buffer */
1085 error = ENOMEM;
1086 goto out;
1087 }
1088 /* iterate the scratch buffer; NOTE: buffer contents modified! */
1089 while ((element = strsep(&scratch, ",")) != NULL) {
1090 error = mac_label_externalize(mpo_externalize_off, label,
1091 element, &sb);
1092 if (error) {
1093 break;
1094 }
1095 }
1096 if ((len = sbuf_len(&sb)) > 0) {
1097 sbuf_setpos(&sb, len - 1); /* trim trailing comma */
1098 }
1099 sbuf_finish(&sb);
1100
1101 out:
1102 if (scratch_base != NULL) {
1103 FREE(scratch_base, M_MACTEMP);
1104 }
1105
1106 return error;
1107 }
1108
1109 /*
1110 * Have all policies set the internal form of a label, for a single
1111 * label namespace.
1112 */
1113 static int
1114 mac_label_internalize(size_t mpo_internalize_off, struct label *label,
1115 char *element_name, char *element_data)
1116 {
1117 struct mac_policy_conf *mpc;
1118 struct mac_label_listener *mll;
1119 struct mac_label_element *mle;
1120 struct mac_label_element_list_t *element_list;
1121 int (*mpo_internalize)(struct label *, char *, char *);
1122 int error = 0, busy = FALSE;
1123 unsigned int count = 0;
1124 const char *name;
1125
1126 element_list = &mac_static_label_element_list;
1127 element_loop:
1128 LIST_FOREACH(mle, element_list, mle_list) {
1129 if (*(name = mle->mle_name) == '?') {
1130 name++;
1131 }
1132 if (strcmp(element_name, name) != 0) {
1133 continue;
1134 }
1135 LIST_FOREACH(mll, &mle->mle_listeners, mll_list) {
1136 mpc = mac_policy_list.entries[mll->mll_handle].mpc;
1137 if (mpc == NULL) {
1138 continue;
1139 }
1140 mpo_internalize = *(const typeof(mpo_internalize) *)
1141 ((const char *)mpc->mpc_ops + mpo_internalize_off);
1142 if (mpo_internalize == NULL) {
1143 continue;
1144 }
1145 error = mpo_internalize(label, element_name,
1146 element_data);
1147 if (error) {
1148 goto done;
1149 }
1150 count++;
1151 }
1152 }
1153 /* If there are dynamic policies present, check their elements too. */
1154 if (!busy && mac_policy_list_conditional_busy() == 1) {
1155 element_list = &mac_label_element_list;
1156 busy = TRUE;
1157 goto element_loop;
1158 }
1159 done:
1160 if (busy) {
1161 mac_policy_list_unbusy();
1162 }
1163 if (!error && count == 0) {
1164 error = ENOPOLICY;
1165 }
1166 return error;
1167 }
1168
1169 int
1170 mac_internalize(size_t mpo_internalize_off, struct label *label,
1171 char *textlabels)
1172 {
1173 char *element_name, *element_data;
1174 int error = 0;
1175
1176 while (!error && (element_name = strsep(&textlabels, ",")) != NULL) {
1177 element_data = strchr(element_name, '/');
1178 if (element_data == NULL) {
1179 error = EINVAL;
1180 break;
1181 }
1182 *element_data++ = '\0';
1183 error = mac_label_internalize(mpo_internalize_off, label,
1184 element_name, element_data);
1185 }
1186 return error;
1187 }
1188
1189 /* system calls */
1190
1191 int
1192 __mac_get_pid(struct proc *p, struct __mac_get_pid_args *uap, int *ret __unused)
1193 {
1194 char *elements, *buffer;
1195 struct user_mac mac;
1196 struct proc *tproc;
1197 struct ucred *tcred;
1198 int error;
1199 size_t ulen;
1200
1201 AUDIT_ARG(pid, uap->pid);
1202 if (IS_64BIT_PROCESS(p)) {
1203 struct user64_mac mac64;
1204 error = copyin(uap->mac_p, &mac64, sizeof(mac64));
1205 mac.m_buflen = mac64.m_buflen;
1206 mac.m_string = mac64.m_string;
1207 } else {
1208 struct user32_mac mac32;
1209 error = copyin(uap->mac_p, &mac32, sizeof(mac32));
1210 mac.m_buflen = mac32.m_buflen;
1211 mac.m_string = mac32.m_string;
1212 }
1213 if (error) {
1214 return error;
1215 }
1216
1217 error = mac_check_structmac_consistent(&mac);
1218 if (error) {
1219 return error;
1220 }
1221
1222 tproc = proc_find(uap->pid);
1223 if (tproc == NULL) {
1224 return ESRCH;
1225 }
1226 tcred = kauth_cred_proc_ref(tproc);
1227 proc_rele(tproc);
1228
1229 MALLOC(elements, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
1230 error = copyinstr(mac.m_string, elements, mac.m_buflen, &ulen);
1231 if (error) {
1232 FREE(elements, M_MACTEMP);
1233 kauth_cred_unref(&tcred);
1234 return error;
1235 }
1236 AUDIT_ARG(mac_string, elements);
1237
1238 MALLOC(buffer, char *, mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
1239 error = mac_cred_label_externalize(tcred->cr_label, elements,
1240 buffer, mac.m_buflen, M_WAITOK);
1241 if (error == 0) {
1242 error = copyout(buffer, mac.m_string, strlen(buffer) + 1);
1243 }
1244
1245 FREE(buffer, M_MACTEMP);
1246 FREE(elements, M_MACTEMP);
1247 kauth_cred_unref(&tcred);
1248 return error;
1249 }
1250
1251 int
1252 __mac_get_proc(proc_t p, struct __mac_get_proc_args *uap, int *ret __unused)
1253 {
1254 char *elements, *buffer;
1255 struct user_mac mac;
1256 kauth_cred_t cr;
1257 int error;
1258 size_t ulen;
1259
1260 if (IS_64BIT_PROCESS(p)) {
1261 struct user64_mac mac64;
1262 error = copyin(uap->mac_p, &mac64, sizeof(mac64));
1263 mac.m_buflen = mac64.m_buflen;
1264 mac.m_string = mac64.m_string;
1265 } else {
1266 struct user32_mac mac32;
1267 error = copyin(uap->mac_p, &mac32, sizeof(mac32));
1268 mac.m_buflen = mac32.m_buflen;
1269 mac.m_string = mac32.m_string;
1270 }
1271 if (error) {
1272 return error;
1273 }
1274
1275 error = mac_check_structmac_consistent(&mac);
1276 if (error) {
1277 return error;
1278 }
1279
1280 MALLOC(elements, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
1281 error = copyinstr(mac.m_string, elements, mac.m_buflen, &ulen);
1282 if (error) {
1283 FREE(elements, M_MACTEMP);
1284 return error;
1285 }
1286 AUDIT_ARG(mac_string, elements);
1287
1288 cr = kauth_cred_proc_ref(p);
1289
1290 MALLOC(buffer, char *, mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
1291 error = mac_cred_label_externalize(cr->cr_label,
1292 elements, buffer, mac.m_buflen, M_WAITOK);
1293 if (error == 0) {
1294 error = copyout(buffer, mac.m_string, strlen(buffer) + 1);
1295 }
1296
1297 FREE(buffer, M_MACTEMP);
1298 FREE(elements, M_MACTEMP);
1299 kauth_cred_unref(&cr);
1300 return error;
1301 }
1302
1303 int
1304 __mac_set_proc(proc_t p, struct __mac_set_proc_args *uap, int *ret __unused)
1305 {
1306 struct label *intlabel;
1307 struct user_mac mac;
1308 char *buffer;
1309 int error;
1310 size_t ulen;
1311
1312 if (IS_64BIT_PROCESS(p)) {
1313 struct user64_mac mac64;
1314 error = copyin(uap->mac_p, &mac64, sizeof(mac64));
1315 mac.m_buflen = mac64.m_buflen;
1316 mac.m_string = mac64.m_string;
1317 } else {
1318 struct user32_mac mac32;
1319 error = copyin(uap->mac_p, &mac32, sizeof(mac32));
1320 mac.m_buflen = mac32.m_buflen;
1321 mac.m_string = mac32.m_string;
1322 }
1323 if (error) {
1324 return error;
1325 }
1326
1327 error = mac_check_structmac_consistent(&mac);
1328 if (error) {
1329 return error;
1330 }
1331
1332 MALLOC(buffer, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
1333 error = copyinstr(mac.m_string, buffer, mac.m_buflen, &ulen);
1334 if (error) {
1335 FREE(buffer, M_MACTEMP);
1336 return error;
1337 }
1338 AUDIT_ARG(mac_string, buffer);
1339
1340 intlabel = mac_cred_label_alloc();
1341 error = mac_cred_label_internalize(intlabel, buffer);
1342 FREE(buffer, M_MACTEMP);
1343 if (error) {
1344 goto out;
1345 }
1346
1347 error = mac_cred_check_label_update(kauth_cred_get(), intlabel);
1348 if (error) {
1349 goto out;
1350 }
1351
1352 error = kauth_proc_label_update(p, intlabel);
1353 if (error) {
1354 goto out;
1355 }
1356
1357 out:
1358 mac_cred_label_free(intlabel);
1359 return error;
1360 }
1361
1362 int
1363 __mac_get_fd(proc_t p, struct __mac_get_fd_args *uap, int *ret __unused)
1364 {
1365 struct fileproc *fp;
1366 struct vnode *vp;
1367 struct user_mac mac;
1368 char *elements, *buffer;
1369 int error;
1370 size_t ulen;
1371 kauth_cred_t my_cred;
1372 struct label *intlabel;
1373
1374 AUDIT_ARG(fd, uap->fd);
1375
1376 if (IS_64BIT_PROCESS(p)) {
1377 struct user64_mac mac64;
1378 error = copyin(uap->mac_p, &mac64, sizeof(mac64));
1379 mac.m_buflen = mac64.m_buflen;
1380 mac.m_string = mac64.m_string;
1381 } else {
1382 struct user32_mac mac32;
1383 error = copyin(uap->mac_p, &mac32, sizeof(mac32));
1384 mac.m_buflen = mac32.m_buflen;
1385 mac.m_string = mac32.m_string;
1386 }
1387
1388 if (error) {
1389 return error;
1390 }
1391
1392 error = mac_check_structmac_consistent(&mac);
1393 if (error) {
1394 return error;
1395 }
1396
1397 MALLOC(elements, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
1398 error = copyinstr(mac.m_string, elements, mac.m_buflen, &ulen);
1399 if (error) {
1400 FREE(elements, M_MACTEMP);
1401 return error;
1402 }
1403 AUDIT_ARG(mac_string, elements);
1404
1405 MALLOC(buffer, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
1406 error = fp_lookup(p, uap->fd, &fp, 0);
1407 if (error) {
1408 FREE(buffer, M_MACTEMP);
1409 FREE(elements, M_MACTEMP);
1410 return error;
1411 }
1412
1413 my_cred = kauth_cred_proc_ref(p);
1414 error = mac_file_check_get(my_cred, fp->fp_glob, elements, mac.m_buflen);
1415 kauth_cred_unref(&my_cred);
1416 if (error) {
1417 fp_drop(p, uap->fd, fp, 0);
1418 FREE(buffer, M_MACTEMP);
1419 FREE(elements, M_MACTEMP);
1420 return error;
1421 }
1422
1423 switch (FILEGLOB_DTYPE(fp->fp_glob)) {
1424 case DTYPE_VNODE:
1425 intlabel = mac_vnode_label_alloc();
1426 if (intlabel == NULL) {
1427 error = ENOMEM;
1428 break;
1429 }
1430 vp = (struct vnode *)fp->fp_glob->fg_data;
1431 error = vnode_getwithref(vp);
1432 if (error == 0) {
1433 mac_vnode_label_copy(vp->v_label, intlabel);
1434 error = mac_vnode_label_externalize(intlabel,
1435 elements, buffer,
1436 mac.m_buflen, M_WAITOK);
1437 vnode_put(vp);
1438 }
1439 mac_vnode_label_free(intlabel);
1440 break;
1441 case DTYPE_SOCKET:
1442 case DTYPE_PSXSHM:
1443 case DTYPE_PSXSEM:
1444 case DTYPE_PIPE:
1445 case DTYPE_KQUEUE:
1446 case DTYPE_FSEVENTS:
1447 case DTYPE_ATALK:
1448 case DTYPE_NETPOLICY:
1449 default:
1450 error = ENOSYS; // only sockets/vnodes so far
1451 break;
1452 }
1453 fp_drop(p, uap->fd, fp, 0);
1454
1455 if (error == 0) {
1456 error = copyout(buffer, mac.m_string, strlen(buffer) + 1);
1457 }
1458
1459 FREE(buffer, M_MACTEMP);
1460 FREE(elements, M_MACTEMP);
1461 return error;
1462 }
1463
1464 static int
1465 mac_get_filelink(proc_t p, user_addr_t mac_p, user_addr_t path_p, int follow)
1466 {
1467 struct vnode *vp;
1468 vfs_context_t ctx;
1469 char *elements, *buffer;
1470 struct nameidata nd;
1471 struct label *intlabel;
1472 struct user_mac mac;
1473 int error;
1474 size_t ulen;
1475
1476 if (IS_64BIT_PROCESS(p)) {
1477 struct user64_mac mac64;
1478 error = copyin(mac_p, &mac64, sizeof(mac64));
1479 mac.m_buflen = mac64.m_buflen;
1480 mac.m_string = mac64.m_string;
1481 } else {
1482 struct user32_mac mac32;
1483 error = copyin(mac_p, &mac32, sizeof(mac32));
1484 mac.m_buflen = mac32.m_buflen;
1485 mac.m_string = mac32.m_string;
1486 }
1487
1488 if (error) {
1489 return error;
1490 }
1491
1492 error = mac_check_structmac_consistent(&mac);
1493 if (error) {
1494 return error;
1495 }
1496
1497 MALLOC(elements, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
1498 MALLOC(buffer, char *, mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
1499
1500 error = copyinstr(mac.m_string, elements, mac.m_buflen, &ulen);
1501 if (error) {
1502 FREE(buffer, M_MACTEMP);
1503 FREE(elements, M_MACTEMP);
1504 return error;
1505 }
1506 AUDIT_ARG(mac_string, elements);
1507
1508 ctx = vfs_context_current();
1509
1510 NDINIT(&nd, LOOKUP, OP_LOOKUP,
1511 LOCKLEAF | (follow ? FOLLOW : NOFOLLOW) | AUDITVNPATH1,
1512 UIO_USERSPACE, path_p, ctx);
1513 error = namei(&nd);
1514 if (error) {
1515 FREE(buffer, M_MACTEMP);
1516 FREE(elements, M_MACTEMP);
1517 return error;
1518 }
1519 vp = nd.ni_vp;
1520
1521 nameidone(&nd);
1522
1523 intlabel = mac_vnode_label_alloc();
1524 mac_vnode_label_copy(vp->v_label, intlabel);
1525 error = mac_vnode_label_externalize(intlabel, elements, buffer,
1526 mac.m_buflen, M_WAITOK);
1527 mac_vnode_label_free(intlabel);
1528 if (error == 0) {
1529 error = copyout(buffer, mac.m_string, strlen(buffer) + 1);
1530 }
1531
1532 vnode_put(vp);
1533
1534 FREE(buffer, M_MACTEMP);
1535 FREE(elements, M_MACTEMP);
1536
1537 return error;
1538 }
1539
1540 int
1541 __mac_get_file(proc_t p, struct __mac_get_file_args *uap,
1542 int *ret __unused)
1543 {
1544 return mac_get_filelink(p, uap->mac_p, uap->path_p, 1);
1545 }
1546
1547 int
1548 __mac_get_link(proc_t p, struct __mac_get_link_args *uap,
1549 int *ret __unused)
1550 {
1551 return mac_get_filelink(p, uap->mac_p, uap->path_p, 0);
1552 }
1553
1554 int
1555 __mac_set_fd(proc_t p, struct __mac_set_fd_args *uap, int *ret __unused)
1556 {
1557 struct fileproc *fp;
1558 struct user_mac mac;
1559 struct vfs_context *ctx = vfs_context_current();
1560 int error;
1561 size_t ulen;
1562 char *buffer;
1563 struct label *intlabel;
1564 struct vnode *vp;
1565
1566 AUDIT_ARG(fd, uap->fd);
1567
1568 if (IS_64BIT_PROCESS(p)) {
1569 struct user64_mac mac64;
1570 error = copyin(uap->mac_p, &mac64, sizeof(mac64));
1571 mac.m_buflen = mac64.m_buflen;
1572 mac.m_string = mac64.m_string;
1573 } else {
1574 struct user32_mac mac32;
1575 error = copyin(uap->mac_p, &mac32, sizeof(mac32));
1576 mac.m_buflen = mac32.m_buflen;
1577 mac.m_string = mac32.m_string;
1578 }
1579 if (error) {
1580 return error;
1581 }
1582
1583 error = mac_check_structmac_consistent(&mac);
1584 if (error) {
1585 return error;
1586 }
1587
1588 MALLOC(buffer, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
1589 error = copyinstr(mac.m_string, buffer, mac.m_buflen, &ulen);
1590 if (error) {
1591 FREE(buffer, M_MACTEMP);
1592 return error;
1593 }
1594 AUDIT_ARG(mac_string, buffer);
1595
1596 error = fp_lookup(p, uap->fd, &fp, 0);
1597 if (error) {
1598 FREE(buffer, M_MACTEMP);
1599 return error;
1600 }
1601
1602
1603 error = mac_file_check_set(vfs_context_ucred(ctx), fp->fp_glob, buffer, mac.m_buflen);
1604 if (error) {
1605 fp_drop(p, uap->fd, fp, 0);
1606 FREE(buffer, M_MACTEMP);
1607 return error;
1608 }
1609
1610 switch (FILEGLOB_DTYPE(fp->fp_glob)) {
1611 case DTYPE_VNODE:
1612 if (mac_label_vnodes == 0) {
1613 error = ENOSYS;
1614 break;
1615 }
1616
1617 intlabel = mac_vnode_label_alloc();
1618
1619 error = mac_vnode_label_internalize(intlabel, buffer);
1620 if (error) {
1621 mac_vnode_label_free(intlabel);
1622 break;
1623 }
1624
1625
1626 vp = (struct vnode *)fp->fp_glob->fg_data;
1627
1628 error = vnode_getwithref(vp);
1629 if (error == 0) {
1630 error = vn_setlabel(vp, intlabel, ctx);
1631 vnode_put(vp);
1632 }
1633 mac_vnode_label_free(intlabel);
1634 break;
1635
1636 case DTYPE_SOCKET:
1637 case DTYPE_PSXSHM:
1638 case DTYPE_PSXSEM:
1639 case DTYPE_PIPE:
1640 case DTYPE_KQUEUE:
1641 case DTYPE_FSEVENTS:
1642 case DTYPE_ATALK:
1643 case DTYPE_NETPOLICY:
1644 default:
1645 error = ENOSYS; // only sockets/vnodes so far
1646 break;
1647 }
1648
1649 fp_drop(p, uap->fd, fp, 0);
1650 FREE(buffer, M_MACTEMP);
1651 return error;
1652 }
1653
1654 static int
1655 mac_set_filelink(proc_t p, user_addr_t mac_p, user_addr_t path_p,
1656 int follow)
1657 {
1658 struct vnode *vp;
1659 struct vfs_context *ctx = vfs_context_current();
1660 struct label *intlabel;
1661 struct nameidata nd;
1662 struct user_mac mac;
1663 char *buffer;
1664 int error;
1665 size_t ulen;
1666
1667 if (mac_label_vnodes == 0) {
1668 return ENOSYS;
1669 }
1670
1671 if (IS_64BIT_PROCESS(p)) {
1672 struct user64_mac mac64;
1673 error = copyin(mac_p, &mac64, sizeof(mac64));
1674 mac.m_buflen = mac64.m_buflen;
1675 mac.m_string = mac64.m_string;
1676 } else {
1677 struct user32_mac mac32;
1678 error = copyin(mac_p, &mac32, sizeof(mac32));
1679 mac.m_buflen = mac32.m_buflen;
1680 mac.m_string = mac32.m_string;
1681 }
1682 if (error) {
1683 return error;
1684 }
1685
1686 error = mac_check_structmac_consistent(&mac);
1687 if (error) {
1688 printf("mac_set_file: failed structure consistency check\n");
1689 return error;
1690 }
1691
1692 MALLOC(buffer, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
1693 error = copyinstr(mac.m_string, buffer, mac.m_buflen, &ulen);
1694 if (error) {
1695 FREE(buffer, M_MACTEMP);
1696 return error;
1697 }
1698 AUDIT_ARG(mac_string, buffer);
1699
1700 intlabel = mac_vnode_label_alloc();
1701 error = mac_vnode_label_internalize(intlabel, buffer);
1702 FREE(buffer, M_MACTEMP);
1703 if (error) {
1704 mac_vnode_label_free(intlabel);
1705 return error;
1706 }
1707
1708 NDINIT(&nd, LOOKUP, OP_LOOKUP,
1709 LOCKLEAF | (follow ? FOLLOW : NOFOLLOW) | AUDITVNPATH1,
1710 UIO_USERSPACE, path_p, ctx);
1711 error = namei(&nd);
1712 if (error) {
1713 mac_vnode_label_free(intlabel);
1714 return error;
1715 }
1716 vp = nd.ni_vp;
1717
1718 nameidone(&nd);
1719
1720 error = vn_setlabel(vp, intlabel, ctx);
1721 vnode_put(vp);
1722 mac_vnode_label_free(intlabel);
1723
1724 return error;
1725 }
1726
1727 int
1728 __mac_set_file(proc_t p, struct __mac_set_file_args *uap,
1729 int *ret __unused)
1730 {
1731 return mac_set_filelink(p, uap->mac_p, uap->path_p, 1);
1732 }
1733
1734 int
1735 __mac_set_link(proc_t p, struct __mac_set_link_args *uap,
1736 int *ret __unused)
1737 {
1738 return mac_set_filelink(p, uap->mac_p, uap->path_p, 0);
1739 }
1740
1741 /*
1742 * __mac_syscall: Perform a MAC policy system call
1743 *
1744 * Parameters: p Process calling this routine
1745 * uap User argument descriptor (see below)
1746 * retv (Unused)
1747 *
1748 * Indirect: uap->policy Name of target MAC policy
1749 * uap->call MAC policy-specific system call to perform
1750 * uap->arg MAC policy-specific system call arguments
1751 *
1752 * Returns: 0 Success
1753 * !0 Not success
1754 *
1755 */
1756 int
1757 __mac_syscall(proc_t p, struct __mac_syscall_args *uap, int *retv __unused)
1758 {
1759 struct mac_policy_conf *mpc;
1760 char target[MAC_MAX_POLICY_NAME];
1761 int error;
1762 u_int i;
1763 size_t ulen;
1764
1765 error = copyinstr(uap->policy, target, sizeof(target), &ulen);
1766 if (error) {
1767 return error;
1768 }
1769 AUDIT_ARG(value32, uap->call);
1770 AUDIT_ARG(mac_string, target);
1771
1772 error = ENOPOLICY;
1773
1774 for (i = 0; i < mac_policy_list.staticmax; i++) {
1775 mpc = mac_policy_list.entries[i].mpc;
1776 if (mpc == NULL) {
1777 continue;
1778 }
1779
1780 if (strcmp(mpc->mpc_name, target) == 0 &&
1781 mpc->mpc_ops->mpo_policy_syscall != NULL) {
1782 error = mpc->mpc_ops->mpo_policy_syscall(p,
1783 uap->call, uap->arg);
1784 goto done;
1785 }
1786 }
1787 if (mac_policy_list_conditional_busy() != 0) {
1788 for (; i <= mac_policy_list.maxindex; i++) {
1789 mpc = mac_policy_list.entries[i].mpc;
1790 if (mpc == NULL) {
1791 continue;
1792 }
1793
1794 if (strcmp(mpc->mpc_name, target) == 0 &&
1795 mpc->mpc_ops->mpo_policy_syscall != NULL) {
1796 error = mpc->mpc_ops->mpo_policy_syscall(p,
1797 uap->call, uap->arg);
1798 break;
1799 }
1800 }
1801 mac_policy_list_unbusy();
1802 }
1803
1804 done:
1805 return error;
1806 }
1807
1808 int
1809 mac_mount_label_get(struct mount *mp, user_addr_t mac_p)
1810 {
1811 char *elements, *buffer;
1812 struct label *label;
1813 struct user_mac mac;
1814 int error;
1815 size_t ulen;
1816
1817 if (IS_64BIT_PROCESS(current_proc())) {
1818 struct user64_mac mac64;
1819 error = copyin(mac_p, &mac64, sizeof(mac64));
1820 mac.m_buflen = mac64.m_buflen;
1821 mac.m_string = mac64.m_string;
1822 } else {
1823 struct user32_mac mac32;
1824 error = copyin(mac_p, &mac32, sizeof(mac32));
1825 mac.m_buflen = mac32.m_buflen;
1826 mac.m_string = mac32.m_string;
1827 }
1828 if (error) {
1829 return error;
1830 }
1831
1832 error = mac_check_structmac_consistent(&mac);
1833 if (error) {
1834 return error;
1835 }
1836
1837 MALLOC(elements, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
1838 error = copyinstr(mac.m_string, elements, mac.m_buflen, &ulen);
1839 if (error) {
1840 FREE(elements, M_MACTEMP);
1841 return error;
1842 }
1843 AUDIT_ARG(mac_string, elements);
1844
1845 label = mp->mnt_mntlabel;
1846 MALLOC(buffer, char *, mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
1847 error = mac_mount_label_externalize(label, elements, buffer,
1848 mac.m_buflen);
1849 FREE(elements, M_MACTEMP);
1850
1851 if (error == 0) {
1852 error = copyout(buffer, mac.m_string, strlen(buffer) + 1);
1853 }
1854 FREE(buffer, M_MACTEMP);
1855
1856 return error;
1857 }
1858
1859 /*
1860 * __mac_get_mount: Get mount point label information for a given pathname
1861 *
1862 * Parameters: p (ignored)
1863 * uap User argument descriptor (see below)
1864 * ret (ignored)
1865 *
1866 * Indirect: uap->path Pathname
1867 * uap->mac_p MAC info
1868 *
1869 * Returns: 0 Success
1870 * !0 Not success
1871 */
1872 int
1873 __mac_get_mount(proc_t p __unused, struct __mac_get_mount_args *uap,
1874 int *ret __unused)
1875 {
1876 struct nameidata nd;
1877 struct vfs_context *ctx = vfs_context_current();
1878 struct mount *mp;
1879 int error;
1880
1881 NDINIT(&nd, LOOKUP, OP_LOOKUP, FOLLOW | AUDITVNPATH1,
1882 UIO_USERSPACE, uap->path, ctx);
1883 error = namei(&nd);
1884 if (error) {
1885 return error;
1886 }
1887 mp = nd.ni_vp->v_mount;
1888 mount_ref(mp, 0);
1889 vnode_put(nd.ni_vp);
1890 nameidone(&nd);
1891
1892 error = mac_mount_label_get(mp, uap->mac_p);
1893 mount_drop(mp, 0);
1894 return error;
1895 }
1896
1897 /*
1898 * mac_schedule_userret()
1899 *
1900 * Schedule a callback to the mpo_thread_userret hook. The mpo_thread_userret
1901 * hook is called just before the thread exit from the kernel in ast_taken().
1902 *
1903 * Returns: 0 Success
1904 * !0 Not successful
1905 */
1906 int
1907 mac_schedule_userret(void)
1908 {
1909 act_set_astmacf(current_thread());
1910 return 0;
1911 }
1912
1913 /*
1914 * mac_do_machexc()
1915 *
1916 * Do a Mach exception. This should only be done in the mpo_thread_userret
1917 * callback.
1918 *
1919 * params: code exception code
1920 * subcode exception subcode
1921 * flags flags:
1922 * MAC_DOEXCF_TRACED Only do exception if being
1923 * ptrace()'ed.
1924 *
1925 *
1926 * Returns: 0 Success
1927 * !0 Not successful
1928 */
1929 int
1930 mac_do_machexc(int64_t code, int64_t subcode, uint32_t flags)
1931 {
1932 mach_exception_data_type_t codes[EXCEPTION_CODE_MAX];
1933 proc_t p = current_proc();
1934
1935 /* Only allow execption codes in MACF's reserved range. */
1936 if ((code < EXC_MACF_MIN) || (code > EXC_MACF_MAX)) {
1937 return 1;
1938 }
1939
1940 if (flags & MAC_DOEXCF_TRACED &&
1941 !(p->p_lflag & P_LTRACED && (p->p_lflag & P_LPPWAIT) == 0)) {
1942 return 0;
1943 }
1944
1945
1946 /* Send the Mach exception */
1947 codes[0] = (mach_exception_data_type_t)code;
1948 codes[1] = (mach_exception_data_type_t)subcode;
1949
1950 return bsd_exception(EXC_SOFTWARE, codes, 2) != KERN_SUCCESS;
1951 }
1952
1953 #else /* MAC */
1954
1955 void (*load_security_extensions_function)(void) = 0;
1956
1957 struct sysctl_oid_list sysctl__security_mac_children;
1958
1959 int
1960 mac_policy_register(struct mac_policy_conf *mpc __unused,
1961 mac_policy_handle_t *handlep __unused, void *xd __unused)
1962 {
1963 return 0;
1964 }
1965
1966 int
1967 mac_policy_unregister(mac_policy_handle_t handle __unused)
1968 {
1969 return 0;
1970 }
1971
1972 int
1973 mac_audit_text(char *text __unused, mac_policy_handle_t handle __unused)
1974 {
1975 return 0;
1976 }
1977
1978 int
1979 mac_vnop_setxattr(struct vnode *vp __unused, const char *name __unused, char *buf __unused, size_t len __unused)
1980 {
1981 return ENOENT;
1982 }
1983
1984 int
1985 mac_vnop_getxattr(struct vnode *vp __unused, const char *name __unused,
1986 char *buf __unused, size_t len __unused, size_t *attrlen __unused)
1987 {
1988 return ENOENT;
1989 }
1990
1991 int
1992 mac_vnop_removexattr(struct vnode *vp __unused, const char *name __unused)
1993 {
1994 return ENOENT;
1995 }
1996
1997 int
1998 mac_file_setxattr(struct fileglob *fg __unused, const char *name __unused, char *buf __unused, size_t len __unused)
1999 {
2000 return ENOENT;
2001 }
2002
2003 int
2004 mac_file_getxattr(struct fileglob *fg __unused, const char *name __unused,
2005 char *buf __unused, size_t len __unused, size_t *attrlen __unused)
2006 {
2007 return ENOENT;
2008 }
2009
2010 int
2011 mac_file_removexattr(struct fileglob *fg __unused, const char *name __unused)
2012 {
2013 return ENOENT;
2014 }
2015
2016 intptr_t
2017 mac_label_get(struct label *l __unused, int slot __unused)
2018 {
2019 return 0;
2020 }
2021
2022 void
2023 mac_label_set(struct label *l __unused, int slot __unused, intptr_t v __unused)
2024 {
2025 return;
2026 }
2027
2028 int mac_iokit_check_hid_control(kauth_cred_t cred __unused);
2029 int
2030 mac_iokit_check_hid_control(kauth_cred_t cred __unused)
2031 {
2032 return 0;
2033 }
2034
2035 int mac_mount_check_snapshot_mount(vfs_context_t ctx, struct vnode *rvp, struct vnode *vp, struct componentname *cnp,
2036 const char *name, const char *vfc_name);
2037 int
2038 mac_mount_check_snapshot_mount(vfs_context_t ctx __unused, struct vnode *rvp __unused, struct vnode *vp __unused,
2039 struct componentname *cnp __unused, const char *name __unused, const char *vfc_name __unused)
2040 {
2041 return 0;
2042 }
2043
2044 int mac_vnode_check_trigger_resolve(vfs_context_t ctx __unused, struct vnode *dvp __unused, struct componentname *cnp __unused);
2045 int
2046 mac_vnode_check_trigger_resolve(vfs_context_t ctx __unused, struct vnode *dvp __unused, struct componentname *cnp __unused)
2047 {
2048 return 0;
2049 }
2050
2051 #endif /* !MAC */