]> git.saurik.com Git - apple/xnu.git/blob - security/mac_policy.h
2d5f1b348b1310e820795ccad92a38e13fad50b9
[apple/xnu.git] / security / mac_policy.h
1 /*
2 * Copyright (c) 2007-2016 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-2002 Robert N. M. Watson
30 * Copyright (c) 2001-2005 Networks Associates Technology, Inc.
31 * Copyright (c) 2005-2007 SPARTA, Inc.
32 * All rights reserved.
33 *
34 * This software was developed by Robert Watson for the TrustedBSD Project.
35 *
36 * This software was developed for the FreeBSD Project in part by Network
37 * Associates Laboratories, the Security Research Division of Network
38 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
39 * as part of the DARPA CHATS research program.
40 *
41 * This software was enhanced by SPARTA ISSO under SPAWAR contract
42 * N66001-04-C-6019 ("SEFOS").
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 *
65 * $FreeBSD: src/sys/sys/mac_policy.h,v 1.39 2003/04/18 19:57:37 rwatson Exp $
66 */
67
68 /**
69 @file mac_policy.h
70 @brief Kernel Interfaces for MAC policy modules
71
72 This header defines the list of operations that are defined by the
73 TrustedBSD MAC Framwork on Darwin. MAC Policy modules register
74 with the framework to declare interest in a specific set of
75 operations. If interest in an entry point is not declared, then
76 the policy will be ignored when the Framework evaluates that entry
77 point.
78 */
79
80 #ifndef _SECURITY_MAC_POLICY_H_
81 #define _SECURITY_MAC_POLICY_H_
82
83 #ifndef PRIVATE
84 #warning "MAC policy is not KPI, see Technical Q&A QA1574, this header will be removed in next version"
85 #endif
86
87 #include <security/_label.h>
88
89 struct attrlist;
90 struct auditinfo;
91 struct bpf_d;
92 struct cs_blob;
93 struct devnode;
94 struct exception_action;
95 struct fileglob;
96 struct ifnet;
97 struct inpcb;
98 struct ipq;
99 struct label;
100 struct mac_module_data;
101 struct mac_policy_conf;
102 struct mbuf;
103 struct mount;
104 struct msg;
105 struct msqid_kernel;
106 struct pipe;
107 struct pseminfo;
108 struct pshminfo;
109 struct sbuf;
110 struct semid_kernel;
111 struct shmid_kernel;
112 struct socket;
113 struct sockopt;
114 struct task;
115 struct thread;
116 struct tty;
117 struct ucred;
118 struct vfs_attr;
119 struct vnode;
120 /** @struct dummy */
121
122
123
124 #ifndef _KAUTH_CRED_T
125 #define _KAUTH_CRED_T
126 typedef struct ucred *kauth_cred_t;
127 #endif /* !_KAUTH_CRED_T */
128
129 #ifndef __IOKIT_PORTS_DEFINED__
130 #define __IOKIT_PORTS_DEFINED__
131 #ifdef __cplusplus
132 class OSObject;
133 typedef OSObject *io_object_t;
134 #else
135 struct OSObject;
136 typedef struct OSObject *io_object_t;
137 #endif
138 #endif /* __IOKIT_PORTS_DEFINED__ */
139
140 /*-
141 * MAC entry points are generally named using the following template:
142 *
143 * mpo_<object>_<operation>()
144 *
145 * or:
146 *
147 * mpo_<object>_check_<operation>()
148 *
149 * Entry points are sorted by object type.
150 *
151 * It may be desirable also to consider some subsystems as "objects", such
152 * as system, iokit, etc.
153 */
154
155 /**
156 @name Entry Points for Label Management
157
158 These are the entry points corresponding to the life cycle events for
159 kernel objects, such as initialization, creation, and destruction.
160
161 Most policies (that use labels) will initialize labels by allocating
162 space for policy-specific data. In most cases, it is permitted to
163 sleep during label initialization operations; it will be noted when
164 it is not permitted.
165
166 Initialization usually will not require doing more than allocating a
167 generic label for the given object. What follows initialization is
168 creation, where a label is made specific to the object it is associated
169 with. Destruction occurs when the label is no longer needed, such as
170 when the corresponding object is destroyed. All necessary cleanup should
171 be performed in label destroy operations.
172
173 Where possible, the label entry points have identical parameters. If
174 the policy module does not require structure-specific label
175 information, the same function may be registered in the policy
176 operation vector. Many policies will implement two such generic
177 allocation calls: one to handle sleepable requests, and one to handle
178 potentially non-sleepable requests.
179 */
180
181
182 /**
183 @brief Audit event postselection
184 @param cred Subject credential
185 @param syscode Syscall number
186 @param args Syscall arguments
187 @param error Syscall errno
188 @param retval Syscall return value
189
190 This is the MAC Framework audit postselect, which is called before
191 exiting a syscall to determine if an audit event should be committed.
192 A return value of MAC_AUDIT_NO forces the audit record to be suppressed.
193 Any other return value results in the audit record being committed.
194
195 @warning The suppression behavior will probably go away in Apple's
196 future version of the audit implementation.
197
198 @return Return MAC_AUDIT_NO to force suppression of the audit record.
199 Any other value results in the audit record being committed.
200
201 */
202 typedef int mpo_audit_check_postselect_t(
203 kauth_cred_t cred,
204 unsigned short syscode,
205 void *args,
206 int error,
207 int retval
208 );
209 /**
210 @brief Audit event preselection
211 @param cred Subject credential
212 @param syscode Syscall number
213 @param args Syscall arguments
214
215 This is the MAC Framework audit preselect, which is called before a
216 syscall is entered to determine if an audit event should be created.
217 If the MAC policy forces the syscall to be audited, MAC_AUDIT_YES should be
218 returned. A return value of MAC_AUDIT_NO causes the audit record to
219 be suppressed. Returning MAC_POLICY_DEFAULT indicates that the policy wants
220 to defer to the system's existing preselection mechanism.
221
222 When policies return different preferences, the Framework decides what action
223 to take based on the following policy. If any policy returns MAC_AUDIT_YES,
224 then create an audit record, else if any policy returns MAC_AUDIT_NO, then
225 suppress the creations of an audit record, else defer to the system's
226 existing preselection mechanism.
227
228 @warning The audit implementation in Apple's current version is
229 incomplete, so the MAC policies have priority over the system's existing
230 mechanisms. This will probably change in the future version where
231 the audit implementation is more complete.
232
233 @return Return MAC_AUDIT_YES to force auditing of the syscall,
234 MAC_AUDIT_NO to force no auditing of the syscall, MAC_AUDIT_DEFAULT
235 to allow auditing mechanisms to determine if the syscall is audited.
236
237 */
238 typedef int mpo_audit_check_preselect_t(
239 kauth_cred_t cred,
240 unsigned short syscode,
241 void *args
242 );
243 /**
244 @brief Initialize BPF descriptor label
245 @param label New label to initialize
246
247 Initialize the label for a newly instantiated BPF descriptor.
248 Sleeping is permitted.
249 */
250 typedef void mpo_bpfdesc_label_init_t(
251 struct label *label
252 );
253 /**
254 @brief Destroy BPF descriptor label
255 @param label The label to be destroyed
256
257 Destroy a BPF descriptor label. Since the BPF descriptor
258 is going out of scope, policy modules should free any internal
259 storage associated with the label so that it may be destroyed.
260 */
261 typedef void mpo_bpfdesc_label_destroy_t(
262 struct label *label
263 );
264 /**
265 @brief Associate a BPF descriptor with a label
266 @param cred User credential creating the BPF descriptor
267 @param bpf_d The BPF descriptor
268 @param bpflabel The new label
269
270 Set the label on a newly created BPF descriptor from the passed
271 subject credential. This call will be made when a BPF device node
272 is opened by a process with the passed subject credential.
273 */
274 typedef void mpo_bpfdesc_label_associate_t(
275 kauth_cred_t cred,
276 struct bpf_d *bpf_d,
277 struct label *bpflabel
278 );
279 /**
280 @brief Check whether BPF can read from a network interface
281 @param bpf_d Subject; the BPF descriptor
282 @param bpflabel Policy label for bpf_d
283 @param ifp Object; the network interface
284 @param ifnetlabel Policy label for ifp
285
286 Determine whether the MAC framework should permit datagrams from
287 the passed network interface to be delivered to the buffers of
288 the passed BPF descriptor. Return (0) for success, or an errno
289 value for failure. Suggested failure: EACCES for label mismatches,
290 EPERM for lack of privilege.
291 */
292 typedef int mpo_bpfdesc_check_receive_t(
293 struct bpf_d *bpf_d,
294 struct label *bpflabel,
295 struct ifnet *ifp,
296 struct label *ifnetlabel
297 );
298 /**
299 @brief Indicate desire to change the process label at exec time
300 @param old Existing subject credential
301 @param vp File being executed
302 @param offset Offset of binary within file being executed
303 @param scriptvp Script being executed by interpreter, if any.
304 @param vnodelabel Label corresponding to vp
305 @param scriptvnodelabel Script vnode label
306 @param execlabel Userspace provided execution label
307 @param p Object process
308 @param macpolicyattr MAC policy-specific spawn attribute data
309 @param macpolicyattrlen Length of policy-specific spawn attribute data
310 @see mac_execve
311 @see mpo_cred_label_update_execve_t
312 @see mpo_vnode_check_exec_t
313
314 Indicate whether this policy intends to update the label of a newly
315 created credential from the existing subject credential (old). This
316 call occurs when a process executes the passed vnode. If a policy
317 returns success from this entry point, the mpo_cred_label_update_execve
318 entry point will later be called with the same parameters. Access
319 has already been checked via the mpo_vnode_check_exec entry point,
320 this entry point is necessary to preserve kernel locking constraints
321 during program execution.
322
323 The supplied vnode and vnodelabel correspond with the file actually
324 being executed; in the case that the file is interpreted (for
325 example, a script), the label of the original exec-time vnode has
326 been preserved in scriptvnodelabel.
327
328 The final label, execlabel, corresponds to a label supplied by a
329 user space application through the use of the mac_execve system call.
330
331 The vnode lock is held during this operation. No changes should be
332 made to the old credential structure.
333
334 @warning Even if a policy returns 0, it should behave correctly in
335 the presence of an invocation of mpo_cred_label_update_execve, as that
336 call may happen as a result of another policy requesting a transition.
337
338 @return Non-zero if a transition is required, 0 otherwise.
339 */
340 typedef int mpo_cred_check_label_update_execve_t(
341 kauth_cred_t old,
342 struct vnode *vp,
343 off_t offset,
344 struct vnode *scriptvp,
345 struct label *vnodelabel,
346 struct label *scriptvnodelabel,
347 struct label *execlabel,
348 struct proc *p,
349 void *macpolicyattr,
350 size_t macpolicyattrlen
351 );
352 /**
353 @brief Access control check for relabelling processes
354 @param cred Subject credential
355 @param newlabel New label to apply to the user credential
356 @see mpo_cred_label_update_t
357 @see mac_set_proc
358
359 Determine whether the subject identified by the credential can relabel
360 itself to the supplied new label (newlabel). This access control check
361 is called when the mac_set_proc system call is invoked. A user space
362 application will supply a new value, the value will be internalized
363 and provided in newlabel.
364
365 @return Return 0 if access is granted, otherwise an appropriate value for
366 errno should be returned.
367 */
368 typedef int mpo_cred_check_label_update_t(
369 kauth_cred_t cred,
370 struct label *newlabel
371 );
372 /**
373 @brief Access control check for visibility of other subjects
374 @param u1 Subject credential
375 @param u2 Object credential
376
377 Determine whether the subject identified by the credential u1 can
378 "see" other subjects with the passed subject credential u2. This call
379 may be made in a number of situations, including inter-process status
380 sysctls used by ps, and in procfs lookups.
381
382 @return Return 0 if access is granted, otherwise an appropriate value for
383 errno should be returned. Suggested failure: EACCES for label mismatch,
384 EPERM for lack of privilege, or ESRCH to hide visibility.
385 */
386 typedef int mpo_cred_check_visible_t(
387 kauth_cred_t u1,
388 kauth_cred_t u2
389 );
390 /**
391 @brief Associate a credential with a new process at fork
392 @param cred credential to inherited by new process
393 @param proc the new process
394
395 Allow a process to associate the credential with a new
396 process for reference countng purposes.
397 NOTE: the credential can be dis-associated in ways other
398 than exit - so this strategy is flawed - should just
399 catch label destroy callback.
400 */
401 typedef void mpo_cred_label_associate_fork_t(
402 kauth_cred_t cred,
403 proc_t proc
404 );
405 /**
406 @brief Create the first process
407 @param cred Subject credential to be labeled
408
409 Create the subject credential of process 0, the parent of all BSD
410 kernel processes. Policies should update the label in the
411 previously initialized credential structure.
412 */
413 typedef void mpo_cred_label_associate_kernel_t(
414 kauth_cred_t cred
415 );
416 /**
417 @brief Create a credential label
418 @param parent_cred Parent credential
419 @param child_cred Child credential
420
421 Set the label of a newly created credential, most likely using the
422 information in the supplied parent credential.
423
424 @warning This call is made when crcopy or crdup is invoked on a
425 newly created struct ucred, and should not be confused with a
426 process fork or creation event.
427 */
428 typedef void mpo_cred_label_associate_t(
429 kauth_cred_t parent_cred,
430 kauth_cred_t child_cred
431 );
432 /**
433 @brief Create the first process
434 @param cred Subject credential to be labeled
435
436 Create the subject credential of process 1, the parent of all BSD
437 user processes. Policies should update the label in the previously
438 initialized credential structure. This is the 'init' process.
439 */
440 typedef void mpo_cred_label_associate_user_t(
441 kauth_cred_t cred
442 );
443 /**
444 @brief Destroy credential label
445 @param label The label to be destroyed
446
447 Destroy a user credential label. Since the user credential
448 is going out of scope, policy modules should free any internal
449 storage associated with the label so that it may be destroyed.
450 */
451 typedef void mpo_cred_label_destroy_t(
452 struct label *label
453 );
454 /**
455 @brief Externalize a user credential label for auditing
456 @param label Label to be externalized
457 @param element_name Name of the label namespace for which labels should be
458 externalized
459 @param sb String buffer to be filled with a text representation of the label
460
461 Produce an external representation of the label on a user credential for
462 inclusion in an audit record. An externalized label consists of a text
463 representation of the label contents that will be added to the audit record
464 as part of a text token. Policy-agnostic user space tools will display
465 this externalized version.
466
467 @return 0 on success, return non-zero if an error occurs while
468 externalizing the label data.
469
470 */
471 typedef int mpo_cred_label_externalize_audit_t(
472 struct label *label,
473 char *element_name,
474 struct sbuf *sb
475 );
476 /**
477 @brief Externalize a user credential label
478 @param label Label to be externalized
479 @param element_name Name of the label namespace for which labels should be
480 externalized
481 @param sb String buffer to be filled with a text representation of the label
482
483 Produce an external representation of the label on a user
484 credential. An externalized label consists of a text representation
485 of the label contents that can be used with user applications.
486 Policy-agnostic user space tools will display this externalized
487 version.
488
489 @return 0 on success, return non-zero if an error occurs while
490 externalizing the label data.
491
492 */
493 typedef int mpo_cred_label_externalize_t(
494 struct label *label,
495 char *element_name,
496 struct sbuf *sb
497 );
498 /**
499 @brief Initialize user credential label
500 @param label New label to initialize
501
502 Initialize the label for a newly instantiated user credential.
503 Sleeping is permitted.
504 */
505 typedef void mpo_cred_label_init_t(
506 struct label *label
507 );
508 /**
509 @brief Internalize a user credential label
510 @param label Label to be internalized
511 @param element_name Name of the label namespace for which the label should
512 be internalized
513 @param element_data Text data to be internalized
514
515 Produce a user credential label from an external representation. An
516 externalized label consists of a text representation of the label
517 contents that can be used with user applications. Policy-agnostic
518 user space tools will forward text version to the kernel for
519 processing by individual policy modules.
520
521 The policy's internalize entry points will be called only if the
522 policy has registered interest in the label namespace.
523
524 @return 0 on success, Otherwise, return non-zero if an error occurs
525 while internalizing the label data.
526
527 */
528 typedef int mpo_cred_label_internalize_t(
529 struct label *label,
530 char *element_name,
531 char *element_data
532 );
533 /**
534 @brief Update credential at exec time
535 @param old_cred Existing subject credential
536 @param new_cred New subject credential to be labeled
537 @param p Object process.
538 @param vp File being executed
539 @param offset Offset of binary within file being executed
540 @param scriptvp Script being executed by interpreter, if any.
541 @param vnodelabel Label corresponding to vp
542 @param scriptvnodelabel Script vnode label
543 @param execlabel Userspace provided execution label
544 @param csflags Code signing flags to be set after exec
545 @param macpolicyattr MAC policy-specific spawn attribute data.
546 @param macpolicyattrlen Length of policy-specific spawn attribute data.
547 @see mac_execve
548 @see mpo_cred_check_label_update_execve_t
549 @see mpo_vnode_check_exec_t
550
551 Update the label of a newly created credential (new) from the
552 existing subject credential (old). This call occurs when a process
553 executes the passed vnode and one of the loaded policy modules has
554 returned success from the mpo_cred_check_label_update_execve entry point.
555 Access has already been checked via the mpo_vnode_check_exec entry
556 point, this entry point is only used to update any policy state.
557
558 The supplied vnode and vnodelabel correspond with the file actually
559 being executed; in the case that the file is interpreted (for
560 example, a script), the label of the original exec-time vnode has
561 been preserved in scriptvnodelabel.
562
563 The final label, execlabel, corresponds to a label supplied by a
564 user space application through the use of the mac_execve system call.
565
566 If non-NULL, the value pointed to by disjointp will be set to 0 to
567 indicate that the old and new credentials are not disjoint, or 1 to
568 indicate that they are.
569
570 The vnode lock is held during this operation. No changes should be
571 made to the old credential structure.
572 @return 0 on success, Otherwise, return non-zero if update results in
573 termination of child.
574 */
575 typedef int mpo_cred_label_update_execve_t(
576 kauth_cred_t old_cred,
577 kauth_cred_t new_cred,
578 struct proc *p,
579 struct vnode *vp,
580 off_t offset,
581 struct vnode *scriptvp,
582 struct label *vnodelabel,
583 struct label *scriptvnodelabel,
584 struct label *execlabel,
585 u_int *csflags,
586 void *macpolicyattr,
587 size_t macpolicyattrlen,
588 int *disjointp
589 );
590 /**
591 @brief Update a credential label
592 @param cred The existing credential
593 @param newlabel A new label to apply to the credential
594 @see mpo_cred_check_label_update_t
595 @see mac_set_proc
596
597 Update the label on a user credential, using the supplied new label.
598 This is called as a result of a process relabel operation. Access
599 control was already confirmed by mpo_cred_check_label_update.
600 */
601 typedef void mpo_cred_label_update_t(
602 kauth_cred_t cred,
603 struct label *newlabel
604 );
605 /**
606 @brief Create a new devfs device
607 @param dev Major and minor numbers of special file
608 @param de "inode" of new device file
609 @param label Destination label
610 @param fullpath Path relative to mount (e.g. /dev) of new device file
611
612 This entry point labels a new devfs device. The label will likely be based
613 on the path to the device, or the major and minor numbers.
614 The policy should store an appropriate label into 'label'.
615 */
616 typedef void mpo_devfs_label_associate_device_t(
617 dev_t dev,
618 struct devnode *de,
619 struct label *label,
620 const char *fullpath
621 );
622 /**
623 @brief Create a new devfs directory
624 @param dirname Name of new directory
625 @param dirnamelen Length of 'dirname'
626 @param de "inode" of new directory
627 @param label Destination label
628 @param fullpath Path relative to mount (e.g. /dev) of new directory
629
630 This entry point labels a new devfs directory. The label will likely be
631 based on the path of the new directory. The policy should store an appropriate
632 label into 'label'. The devfs root directory is labelled in this way.
633 */
634 typedef void mpo_devfs_label_associate_directory_t(
635 const char *dirname,
636 int dirnamelen,
637 struct devnode *de,
638 struct label *label,
639 const char *fullpath
640 );
641 /**
642 @brief Copy a devfs label
643 @param src Source devfs label
644 @param dest Destination devfs label
645
646 Copy the label information from src to dest. The devfs file system
647 often duplicates (splits) existing device nodes rather than creating
648 new ones.
649 */
650 typedef void mpo_devfs_label_copy_t(
651 struct label *src,
652 struct label *dest
653 );
654 /**
655 @brief Destroy devfs label
656 @param label The label to be destroyed
657
658 Destroy a devfs entry label. Since the object is going out
659 of scope, policy modules should free any internal storage associated
660 with the label so that it may be destroyed.
661 */
662 typedef void mpo_devfs_label_destroy_t(
663 struct label *label
664 );
665 /**
666 @brief Initialize devfs label
667 @param label New label to initialize
668
669 Initialize the label for a newly instantiated devfs entry. Sleeping
670 is permitted.
671 */
672 typedef void mpo_devfs_label_init_t(
673 struct label *label
674 );
675 /**
676 @brief Update a devfs label after relabelling its vnode
677 @param mp Devfs mount point
678 @param de Affected devfs directory entry
679 @param delabel Label of devfs directory entry
680 @param vp Vnode associated with de
681 @param vnodelabel New label of vnode
682
683 Update a devfs label when its vnode is manually relabelled,
684 for example with setfmac(1). Typically, this will simply copy
685 the vnode label into the devfs label.
686 */
687 typedef void mpo_devfs_label_update_t(
688 struct mount *mp,
689 struct devnode *de,
690 struct label *delabel,
691 struct vnode *vp,
692 struct label *vnodelabel
693 );
694 /**
695 @brief Access control for sending an exception to an exception action
696 @param crashlabel The crashing process's label
697 @param action Exception action
698 @param exclabel Policy label for exception action
699
700 Determine whether the the exception message caused by the victim
701 process can be sent to the exception action.
702
703 @return Return 0 if the message can be sent, otherwise an
704 appropriate value for errno should be returned.
705 */
706 typedef int mpo_exc_action_check_exception_send_t(
707 struct label *crashlabel,
708 struct exception_action *action,
709 struct label *exclabel
710 );
711 /**
712 @brief Create an exception action label
713 @param action Exception action to label
714 @param exclabel Policy label to be filled in for exception action
715
716 Set the label on an exception action.
717 */
718 typedef void mpo_exc_action_label_associate_t(
719 struct exception_action *action,
720 struct label *exclabel
721 );
722 /**
723 @brief Copy an exception action label
724 @param src Source exception action label
725 @param dest Destination exception action label
726
727 Copy the label information from src to dest.
728 Exception actions are often inherited, e.g. from parent to child.
729 In that case, the labels are copied instead of created fresh.
730 */
731 typedef void mpo_exc_action_label_copy_t(
732 struct label *src,
733 struct label *dest
734 );
735 /**
736 @brief Destroy exception action label
737 @param label The label to be destroyed
738
739 Destroy the label on an exception action. In this entry point, a
740 policy module should free any internal storage associated with
741 label so that it may be destroyed.
742 */
743 typedef void mpo_exc_action_label_destroy_t(
744 struct label *label
745 );
746 /**
747 @brief Initialize exception action label
748 @param label New label to initialize
749
750 Initialize a label for an exception action.
751 */
752 typedef int mpo_exc_action_label_init_t(
753 struct label *label
754 );
755 /**
756 @brief Update the label on an exception action
757 @param p Process to update the label from
758 @param exclabel Policy label to be updated for exception action
759
760 Update the credentials of an exception action with the given task.
761 */
762 typedef void mpo_exc_action_label_update_t(
763 struct proc *p,
764 struct label *exclabel
765 );
766 /**
767 @brief Access control for changing the offset of a file descriptor
768 @param cred Subject credential
769 @param fg Fileglob structure
770 @param label Policy label for fg
771
772 Determine whether the subject identified by the credential can
773 change the offset of the file represented by fg.
774
775 @return Return 0 if access if granted, otherwise an appropriate
776 value for errno should be returned.
777 */
778 typedef int mpo_file_check_change_offset_t(
779 kauth_cred_t cred,
780 struct fileglob *fg,
781 struct label *label
782 );
783 /**
784 @brief Access control for creating a file descriptor
785 @param cred Subject credential
786
787 Determine whether the subject identified by the credential can
788 allocate a new file descriptor.
789
790 @return Return 0 if access if granted, otherwise an appropriate
791 value for errno should be returned.
792 */
793 typedef int mpo_file_check_create_t(
794 kauth_cred_t cred
795 );
796 /**
797 @brief Access control for duplicating a file descriptor
798 @param cred Subject credential
799 @param fg Fileglob structure
800 @param label Policy label for fg
801 @param newfd New file descriptor number
802
803 Determine whether the subject identified by the credential can
804 duplicate the fileglob structure represented by fg and as file
805 descriptor number newfd.
806
807 @return Return 0 if access if granted, otherwise an appropriate
808 value for errno should be returned.
809 */
810 typedef int mpo_file_check_dup_t(
811 kauth_cred_t cred,
812 struct fileglob *fg,
813 struct label *label,
814 int newfd
815 );
816 /**
817 @brief Access control check for fcntl
818 @param cred Subject credential
819 @param fg Fileglob structure
820 @param label Policy label for fg
821 @param cmd Control operation to be performed; see fcntl(2)
822 @param arg fcnt arguments; see fcntl(2)
823
824 Determine whether the subject identified by the credential can perform
825 the file control operation indicated by cmd.
826
827 @return Return 0 if access is granted, otherwise an appropriate value for
828 errno should be returned.
829 */
830 typedef int mpo_file_check_fcntl_t(
831 kauth_cred_t cred,
832 struct fileglob *fg,
833 struct label *label,
834 int cmd,
835 user_long_t arg
836 );
837 /**
838 @brief Access control check for mac_get_fd
839 @param cred Subject credential
840 @param fg Fileglob structure
841 @param elements Element buffer
842 @param len Length of buffer
843
844 Determine whether the subject identified by the credential should be allowed
845 to get an externalized version of the label on the object indicated by fd.
846
847 @return Return 0 if access is granted, otherwise an appropriate value for
848 errno should be returned.
849 */
850 typedef int mpo_file_check_get_t(
851 kauth_cred_t cred,
852 struct fileglob *fg,
853 char *elements,
854 int len
855 );
856 /**
857 @brief Access control for getting the offset of a file descriptor
858 @param cred Subject credential
859 @param fg Fileglob structure
860 @param label Policy label for fg
861
862 Determine whether the subject identified by the credential can
863 get the offset of the file represented by fg.
864
865 @return Return 0 if access if granted, otherwise an appropriate
866 value for errno should be returned.
867 */
868 typedef int mpo_file_check_get_offset_t(
869 kauth_cred_t cred,
870 struct fileglob *fg,
871 struct label *label
872 );
873 /**
874 @brief Access control for inheriting a file descriptor
875 @param cred Subject credential
876 @param fg Fileglob structure
877 @param label Policy label for fg
878
879 Determine whether the subject identified by the credential can
880 inherit the fileglob structure represented by fg.
881
882 @return Return 0 if access if granted, otherwise an appropriate
883 value for errno should be returned.
884 */
885 typedef int mpo_file_check_inherit_t(
886 kauth_cred_t cred,
887 struct fileglob *fg,
888 struct label *label
889 );
890 /**
891 @brief Access control check for file ioctl
892 @param cred Subject credential
893 @param fg Fileglob structure
894 @param label Policy label for fg
895 @param cmd The ioctl command; see ioctl(2)
896
897 Determine whether the subject identified by the credential can perform
898 the ioctl operation indicated by cmd.
899
900 @warning Since ioctl data is opaque from the standpoint of the MAC
901 framework, policies must exercise extreme care when implementing
902 access control checks.
903
904 @return Return 0 if access is granted, otherwise an appropriate value for
905 errno should be returned.
906
907 */
908 typedef int mpo_file_check_ioctl_t(
909 kauth_cred_t cred,
910 struct fileglob *fg,
911 struct label *label,
912 unsigned int cmd
913 );
914 /**
915 @brief Access control check for file locking
916 @param cred Subject credential
917 @param fg Fileglob structure
918 @param label Policy label for fg
919 @param op The lock operation (F_GETLK, F_SETLK, F_UNLK)
920 @param fl The flock structure
921
922 Determine whether the subject identified by the credential can perform
923 the lock operation indicated by op and fl on the file represented by fg.
924
925 @return Return 0 if access is granted, otherwise an appropriate value for
926 errno should be returned.
927
928 */
929 typedef int mpo_file_check_lock_t(
930 kauth_cred_t cred,
931 struct fileglob *fg,
932 struct label *label,
933 int op,
934 struct flock *fl
935 );
936 /**
937 @brief Check with library validation if a macho slice is allowed to be combined into a proc.
938 @param p Subject process
939 @param fg Fileglob structure
940 @param slice_offset offset of the code slice
941 @param error_message error message returned to user-space in case of error (userspace pointer)
942 @param error_message_size error message size
943
944 Its a little odd that the MAC/kext writes into userspace since this
945 implies there is only one MAC module that implements this, however
946 the alterantive is to allocate memory in xnu, on the hope that
947 the MAC module will use it, or allocated in the MAC module and then
948 free it in xnu. Either of these are very appeling, so lets go with
949 the slightly more hacky way.
950
951 @return Return 0 if access is granted, otherwise an appropriate value for
952 errno should be returned.
953 */
954 typedef int mpo_file_check_library_validation_t(
955 struct proc *p,
956 struct fileglob *fg,
957 off_t slice_offset,
958 user_long_t error_message,
959 size_t error_message_size
960 );
961 /**
962 @brief Access control check for mapping a file
963 @param cred Subject credential
964 @param fg fileglob representing file to map
965 @param label Policy label associated with vp
966 @param prot mmap protections; see mmap(2)
967 @param flags Type of mapped object; see mmap(2)
968 @param maxprot Maximum rights
969
970 Determine whether the subject identified by the credential should be
971 allowed to map the file represented by fg with the protections specified
972 in prot. The maxprot field holds the maximum permissions on the new
973 mapping, a combination of VM_PROT_READ, VM_PROT_WRITE, and VM_PROT_EXECUTE.
974 To avoid overriding prior access control checks, a policy should only
975 remove flags from maxprot.
976
977 @return Return 0 if access is granted, otherwise an appropriate value for
978 errno should be returned. Suggested failure: EACCES for label mismatch or
979 EPERM for lack of privilege.
980 */
981 typedef int mpo_file_check_mmap_t(
982 kauth_cred_t cred,
983 struct fileglob *fg,
984 struct label *label,
985 int prot,
986 int flags,
987 uint64_t file_pos,
988 int *maxprot
989 );
990 /**
991 @brief Downgrade the mmap protections
992 @param cred Subject credential
993 @param fg file to map
994 @param label Policy label associated with vp
995 @param prot mmap protections to be downgraded
996
997 Downgrade the mmap protections based on the subject and object labels.
998 */
999 typedef void mpo_file_check_mmap_downgrade_t(
1000 kauth_cred_t cred,
1001 struct fileglob *fg,
1002 struct label *label,
1003 int *prot
1004 );
1005 /**
1006 @brief Access control for receiving a file descriptor
1007 @param cred Subject credential
1008 @param fg Fileglob structure
1009 @param label Policy label for fg
1010
1011 Determine whether the subject identified by the credential can
1012 receive the fileglob structure represented by fg.
1013
1014 @return Return 0 if access if granted, otherwise an appropriate
1015 value for errno should be returned.
1016 */
1017 typedef int mpo_file_check_receive_t(
1018 kauth_cred_t cred,
1019 struct fileglob *fg,
1020 struct label *label
1021 );
1022 /**
1023 @brief Access control check for mac_set_fd
1024 @param cred Subject credential
1025 @param fg Fileglob structure
1026 @param elements Elements buffer
1027 @param len Length of elements buffer
1028
1029 Determine whether the subject identified by the credential can
1030 perform the mac_set_fd operation. The mac_set_fd operation is used
1031 to associate a MAC label with a file.
1032
1033 @return Return 0 if access is granted, otherwise an appropriate value for
1034 errno should be returned.
1035 */
1036 typedef int mpo_file_check_set_t(
1037 kauth_cred_t cred,
1038 struct fileglob *fg,
1039 char *elements,
1040 int len
1041 );
1042 /**
1043 @brief Create file label
1044 @param cred Subject credential
1045 @param fg Fileglob structure
1046 @param label Policy label for fg
1047 */
1048 typedef void mpo_file_label_associate_t(
1049 kauth_cred_t cred,
1050 struct fileglob *fg,
1051 struct label *label
1052 );
1053 /**
1054 @brief Destroy file label
1055 @param label The label to be destroyed
1056
1057 Destroy the label on a file descriptor. In this entry point, a
1058 policy module should free any internal storage associated with
1059 label so that it may be destroyed.
1060 */
1061 typedef void mpo_file_label_destroy_t(
1062 struct label *label
1063 );
1064 /**
1065 @brief Initialize file label
1066 @param label New label to initialize
1067 */
1068 typedef void mpo_file_label_init_t(
1069 struct label *label
1070 );
1071 /**
1072 @brief Access control check for relabeling network interfaces
1073 @param cred Subject credential
1074 @param ifp network interface being relabeled
1075 @param ifnetlabel Current label of the network interfaces
1076 @param newlabel New label to apply to the network interfaces
1077 @see mpo_ifnet_label_update_t
1078
1079 Determine whether the subject identified by the credential can
1080 relabel the network interface represented by ifp to the supplied
1081 new label (newlabel).
1082
1083 @return Return 0 if access is granted, otherwise an appropriate value for
1084 errno should be returned.
1085 */
1086 typedef int mpo_ifnet_check_label_update_t(
1087 kauth_cred_t cred,
1088 struct ifnet *ifp,
1089 struct label *ifnetlabel,
1090 struct label *newlabel
1091 );
1092 /**
1093 @brief Access control check for relabeling network interfaces
1094 @param ifp Network interface mbuf will be transmitted through
1095 @param ifnetlabel Label of the network interfaces
1096 @param m The mbuf to be transmitted
1097 @param mbuflabel Label of the mbuf to be transmitted
1098 @param family Address Family, AF_*
1099 @param type Type of socket, SOCK_{STREAM,DGRAM,RAW}
1100
1101 Determine whether the mbuf with label mbuflabel may be transmitted
1102 through the network interface represented by ifp that has the
1103 label ifnetlabel.
1104
1105 @return Return 0 if access is granted, otherwise an appropriate value for
1106 errno should be returned.
1107 */
1108 typedef int mpo_ifnet_check_transmit_t(
1109 struct ifnet *ifp,
1110 struct label *ifnetlabel,
1111 struct mbuf *m,
1112 struct label *mbuflabel,
1113 int family,
1114 int type
1115 );
1116 /**
1117 @brief Create a network interface label
1118 @param ifp Network interface labeled
1119 @param ifnetlabel Label for the network interface
1120
1121 Set the label of a newly created network interface, most likely
1122 using the information in the supplied network interface struct.
1123 */
1124 typedef void mpo_ifnet_label_associate_t(
1125 struct ifnet *ifp,
1126 struct label *ifnetlabel
1127 );
1128 /**
1129 @brief Copy an ifnet label
1130 @param src Source ifnet label
1131 @param dest Destination ifnet label
1132
1133 Copy the label information from src to dest.
1134 */
1135 typedef void mpo_ifnet_label_copy_t(
1136 struct label *src,
1137 struct label *dest
1138 );
1139 /**
1140 @brief Destroy ifnet label
1141 @param label The label to be destroyed
1142
1143 Destroy the label on an ifnet label. In this entry point, a
1144 policy module should free any internal storage associated with
1145 label so that it may be destroyed.
1146 */
1147 typedef void mpo_ifnet_label_destroy_t(
1148 struct label *label
1149 );
1150 /**
1151 @brief Externalize an ifnet label
1152 @param label Label to be externalized
1153 @param element_name Name of the label namespace for which labels should be
1154 externalized
1155 @param sb String buffer to be filled with a text representation of the label
1156
1157 Produce an external representation of the label on an interface.
1158 An externalized label consists of a text representation of the
1159 label contents that can be used with user applications.
1160 Policy-agnostic user space tools will display this externalized
1161 version.
1162
1163 @return 0 on success, return non-zero if an error occurs while
1164 externalizing the label data.
1165
1166 */
1167 typedef int mpo_ifnet_label_externalize_t(
1168 struct label *label,
1169 char *element_name,
1170 struct sbuf *sb
1171 );
1172 /**
1173 @brief Initialize ifnet label
1174 @param label New label to initialize
1175 */
1176 typedef void mpo_ifnet_label_init_t(
1177 struct label *label
1178 );
1179 /**
1180 @brief Internalize an interface label
1181 @param label Label to be internalized
1182 @param element_name Name of the label namespace for which the label should
1183 be internalized
1184 @param element_data Text data to be internalized
1185
1186 Produce an interface label from an external representation. An
1187 externalized label consists of a text representation of the label
1188 contents that can be used with user applications. Policy-agnostic
1189 user space tools will forward text version to the kernel for
1190 processing by individual policy modules.
1191
1192 The policy's internalize entry points will be called only if the
1193 policy has registered interest in the label namespace.
1194
1195 @return 0 on success, Otherwise, return non-zero if an error occurs
1196 while internalizing the label data.
1197
1198 */
1199 typedef int mpo_ifnet_label_internalize_t(
1200 struct label *label,
1201 char *element_name,
1202 char *element_data
1203 );
1204 /**
1205 @brief Recycle up a network interface label
1206 @param label The label to be recycled
1207
1208 Recycle a network interface label. Darwin caches the struct ifnet
1209 of detached ifnets in a "free pool". Before ifnets are returned
1210 to the "free pool", policies can cleanup or overwrite any information
1211 present in the label.
1212 */
1213 typedef void mpo_ifnet_label_recycle_t(
1214 struct label *label
1215 );
1216 /**
1217 @brief Update a network interface label
1218 @param cred Subject credential
1219 @param ifp The network interface to be relabeled
1220 @param ifnetlabel The current label of the network interface
1221 @param newlabel A new label to apply to the network interface
1222 @see mpo_ifnet_check_label_update_t
1223
1224 Update the label on a network interface, using the supplied new label.
1225 */
1226 typedef void mpo_ifnet_label_update_t(
1227 kauth_cred_t cred,
1228 struct ifnet *ifp,
1229 struct label *ifnetlabel,
1230 struct label *newlabel
1231 );
1232 /**
1233 @brief Access control check for delivering a packet to a socket
1234 @param inp inpcb the socket is associated with
1235 @param inplabel Label of the inpcb
1236 @param m The mbuf being received
1237 @param mbuflabel Label of the mbuf being received
1238 @param family Address family, AF_*
1239 @param type Type of socket, SOCK_{STREAM,DGRAM,RAW}
1240
1241 Determine whether the mbuf with label mbuflabel may be received
1242 by the socket associated with inpcb that has the label inplabel.
1243
1244 @return Return 0 if access is granted, otherwise an appropriate value for
1245 errno should be returned.
1246 */
1247 typedef int mpo_inpcb_check_deliver_t(
1248 struct inpcb *inp,
1249 struct label *inplabel,
1250 struct mbuf *m,
1251 struct label *mbuflabel,
1252 int family,
1253 int type
1254 );
1255 /**
1256 @brief Create an inpcb label
1257 @param so Socket containing the inpcb to be labeled
1258 @param solabel Label of the socket
1259 @param inp inpcb to be labeled
1260 @param inplabel Label for the inpcb
1261
1262 Set the label of a newly created inpcb, most likely
1263 using the information in the socket and/or socket label.
1264 */
1265 typedef void mpo_inpcb_label_associate_t(
1266 struct socket *so,
1267 struct label *solabel,
1268 struct inpcb *inp,
1269 struct label *inplabel
1270 );
1271 /**
1272 @brief Destroy inpcb label
1273 @param label The label to be destroyed
1274
1275 Destroy the label on an inpcb label. In this entry point, a
1276 policy module should free any internal storage associated with
1277 label so that it may be destroyed.
1278 */
1279 typedef void mpo_inpcb_label_destroy_t(
1280 struct label *label
1281 );
1282 /**
1283 @brief Initialize inpcb label
1284 @param label New label to initialize
1285 @param flag M_WAITOK or M_NOWAIT
1286 */
1287 typedef int mpo_inpcb_label_init_t(
1288 struct label *label,
1289 int flag
1290 );
1291 /**
1292 @brief Recycle up an inpcb label
1293 @param label The label to be recycled
1294
1295 Recycle an inpcb label. Darwin allocates the inpcb as part of
1296 the socket structure in some cases. For this case we must recycle
1297 rather than destroy the inpcb as it will be reused later.
1298 */
1299 typedef void mpo_inpcb_label_recycle_t(
1300 struct label *label
1301 );
1302 /**
1303 @brief Update an inpcb label from a socket label
1304 @param so Socket containing the inpcb to be relabeled
1305 @param solabel New label of the socket
1306 @param inp inpcb to be labeled
1307 @param inplabel Label for the inpcb
1308
1309 Set the label of a newly created inpcb due to a change in the
1310 underlying socket label.
1311 */
1312 typedef void mpo_inpcb_label_update_t(
1313 struct socket *so,
1314 struct label *solabel,
1315 struct inpcb *inp,
1316 struct label *inplabel
1317 );
1318 /**
1319 @brief Device hardware access control
1320 @param devtype Type of device connected
1321
1322 This is the MAC Framework device access control, which is called by the I/O
1323 Kit when a new device is connected to the system to determine whether that
1324 device should be trusted. A list of properties associated with the device
1325 is passed as an XML-formatted string. The routine should examine these
1326 properties to determine the trustworthiness of the device. A return value
1327 of EPERM forces the device to be claimed by a special device driver that
1328 will prevent its operation.
1329
1330 @warning This is an experimental interface and may change in the future.
1331
1332 @return Return EPERM to indicate that the device is untrusted and should
1333 not be allowed to operate. Return zero to indicate that the device is
1334 trusted and should be allowed to operate normally.
1335
1336 */
1337 typedef int mpo_iokit_check_device_t(
1338 char *devtype,
1339 struct mac_module_data *mdata
1340 );
1341 /**
1342 @brief Access control check for opening an I/O Kit device
1343 @param cred Subject credential
1344 @param user_client User client instance
1345 @param user_client_type User client type
1346
1347 Determine whether the subject identified by the credential can open an
1348 I/O Kit device at the passed path of the passed user client class and
1349 type.
1350
1351 @return Return 0 if access is granted, or an appropriate value for
1352 errno should be returned.
1353 */
1354 typedef int mpo_iokit_check_open_t(
1355 kauth_cred_t cred,
1356 io_object_t user_client,
1357 unsigned int user_client_type
1358 );
1359 /**
1360 @brief Access control check for setting I/O Kit device properties
1361 @param cred Subject credential
1362 @param entry Target device
1363 @param properties Property list
1364
1365 Determine whether the subject identified by the credential can set
1366 properties on an I/O Kit device.
1367
1368 @return Return 0 if access is granted, or an appropriate value for
1369 errno should be returned.
1370 */
1371 typedef int mpo_iokit_check_set_properties_t(
1372 kauth_cred_t cred,
1373 io_object_t entry,
1374 io_object_t properties
1375 );
1376 /**
1377 @brief Indicate desire to filter I/O Kit devices properties
1378 @param cred Subject credential
1379 @param entry Target device
1380 @see mpo_iokit_check_get_property_t
1381
1382 Indicate whether this policy may restrict the subject credential
1383 from reading properties of the target device.
1384 If a policy returns success from this entry point, the
1385 mpo_iokit_check_get_property entry point will later be called
1386 for each property that the subject credential tries to read from
1387 the target device.
1388
1389 This entry point is primarilly to optimize bulk property reads
1390 by skipping calls to the mpo_iokit_check_get_property entry point
1391 for credentials / devices no MAC policy is interested in.
1392
1393 @warning Even if a policy returns 0, it should behave correctly in
1394 the presence of an invocation of mpo_iokit_check_get_property, as that
1395 call may happen as a result of another policy requesting a transition.
1396
1397 @return Non-zero if a transition is required, 0 otherwise.
1398 */
1399 typedef int mpo_iokit_check_filter_properties_t(
1400 kauth_cred_t cred,
1401 io_object_t entry
1402 );
1403 /**
1404 @brief Access control check for getting I/O Kit device properties
1405 @param cred Subject credential
1406 @param entry Target device
1407 @param name Property name
1408
1409 Determine whether the subject identified by the credential can get
1410 properties on an I/O Kit device.
1411
1412 @return Return 0 if access is granted, or an appropriate value for
1413 errno.
1414 */
1415 typedef int mpo_iokit_check_get_property_t(
1416 kauth_cred_t cred,
1417 io_object_t entry,
1418 const char *name
1419 );
1420 /**
1421 @brief Access control check for software HID control
1422 @param cred Subject credential
1423
1424 Determine whether the subject identified by the credential can
1425 control the HID (Human Interface Device) subsystem, such as to
1426 post synthetic keypresses, pointer movement and clicks.
1427
1428 @return Return 0 if access is granted, or an appropriate value for
1429 errno.
1430 */
1431 typedef int mpo_iokit_check_hid_control_t(
1432 kauth_cred_t cred
1433 );
1434 /**
1435 @brief Create an IP reassembly queue label
1436 @param fragment First received IP fragment
1437 @param fragmentlabel Policy label for fragment
1438 @param ipq IP reassembly queue to be labeled
1439 @param ipqlabel Policy label to be filled in for ipq
1440
1441 Set the label on a newly created IP reassembly queue from
1442 the mbuf header of the first received fragment.
1443 */
1444 typedef void mpo_ipq_label_associate_t(
1445 struct mbuf *fragment,
1446 struct label *fragmentlabel,
1447 struct ipq *ipq,
1448 struct label *ipqlabel
1449 );
1450 /**
1451 @brief Compare an mbuf header label to an ipq label
1452 @param fragment IP datagram fragment
1453 @param fragmentlabel Policy label for fragment
1454 @param ipq IP fragment reassembly queue
1455 @param ipqlabel Policy label for ipq
1456
1457 Compare the label of the mbuf header containing an IP datagram
1458 (fragment) fragment with the label of the passed IP fragment
1459 reassembly queue (ipq). Return (1) for a successful match, or (0)
1460 for no match. This call is made when the IP stack attempts to
1461 find an existing fragment reassembly queue for a newly received
1462 fragment; if this fails, a new fragment reassembly queue may be
1463 instantiated for the fragment. Policies may use this entry point
1464 to prevent the reassembly of otherwise matching IP fragments if
1465 policy does not permit them to be reassembled based on the label
1466 or other information.
1467 */
1468 typedef int mpo_ipq_label_compare_t(
1469 struct mbuf *fragment,
1470 struct label *fragmentlabel,
1471 struct ipq *ipq,
1472 struct label *ipqlabel
1473 );
1474 /**
1475 @brief Destroy IP reassembly queue label
1476 @param label The label to be destroyed
1477
1478 Destroy the label on an IP fragment queue. In this entry point, a
1479 policy module should free any internal storage associated with
1480 label so that it may be destroyed.
1481 */
1482 typedef void mpo_ipq_label_destroy_t(
1483 struct label *label
1484 );
1485 /**
1486 @brief Initialize IP reassembly queue label
1487 @param label New label to initialize
1488 @param flag M_WAITOK or M_NOWAIT
1489
1490 Initialize the label on a newly instantiated IP fragment reassembly
1491 queue. The flag field may be one of M_WAITOK and M_NOWAIT, and
1492 should be employed to avoid performing a sleeping malloc(9) during
1493 this initialization call. IP fragment reassembly queue allocation
1494 frequently occurs in performance sensitive environments, and the
1495 implementation should be careful to avoid sleeping or long-lived
1496 operations. This entry point is permitted to fail resulting in
1497 the failure to allocate the IP fragment reassembly queue.
1498 */
1499 typedef int mpo_ipq_label_init_t(
1500 struct label *label,
1501 int flag
1502 );
1503 /**
1504 @brief Update the label on an IP fragment reassembly queue
1505 @param fragment IP fragment
1506 @param fragmentlabel Policy label for fragment
1507 @param ipq IP fragment reassembly queue
1508 @param ipqlabel Policy label to be updated for ipq
1509
1510 Update the label on an IP fragment reassembly queue (ipq) based
1511 on the acceptance of the passed IP fragment mbuf header (fragment).
1512 */
1513 typedef void mpo_ipq_label_update_t(
1514 struct mbuf *fragment,
1515 struct label *fragmentlabel,
1516 struct ipq *ipq,
1517 struct label *ipqlabel
1518 );
1519 /**
1520 @brief Assign a label to a new mbuf
1521 @param bpf_d BPF descriptor
1522 @param b_label Policy label for bpf_d
1523 @param m Object; mbuf
1524 @param m_label Policy label to fill in for m
1525
1526 Set the label on the mbuf header of a newly created datagram
1527 generated using the passed BPF descriptor. This call is made when
1528 a write is performed to the BPF device associated with the passed
1529 BPF descriptor.
1530 */
1531 typedef void mpo_mbuf_label_associate_bpfdesc_t(
1532 struct bpf_d *bpf_d,
1533 struct label *b_label,
1534 struct mbuf *m,
1535 struct label *m_label
1536 );
1537 /**
1538 @brief Assign a label to a new mbuf
1539 @param ifp Interface descriptor
1540 @param i_label Existing label of ifp
1541 @param m Object; mbuf
1542 @param m_label Policy label to fill in for m
1543
1544 Label an mbuf based on the interface from which it was received.
1545 */
1546 typedef void mpo_mbuf_label_associate_ifnet_t(
1547 struct ifnet *ifp,
1548 struct label *i_label,
1549 struct mbuf *m,
1550 struct label *m_label
1551 );
1552 /**
1553 @brief Assign a label to a new mbuf
1554 @param inp inpcb structure
1555 @param i_label Existing label of inp
1556 @param m Object; mbuf
1557 @param m_label Policy label to fill in for m
1558
1559 Label an mbuf based on the inpcb from which it was derived.
1560 */
1561 typedef void mpo_mbuf_label_associate_inpcb_t(
1562 struct inpcb *inp,
1563 struct label *i_label,
1564 struct mbuf *m,
1565 struct label *m_label
1566 );
1567 /**
1568 @brief Set the label on a newly reassembled IP datagram
1569 @param ipq IP fragment reassembly queue
1570 @param ipqlabel Policy label for ipq
1571 @param mbuf IP datagram to be labeled
1572 @param mbuflabel Policy label to be filled in for mbuf
1573
1574 Set the label on a newly reassembled IP datagram (mbuf) from the IP
1575 fragment reassembly queue (ipq) from which it was generated.
1576 */
1577 typedef void mpo_mbuf_label_associate_ipq_t(
1578 struct ipq *ipq,
1579 struct label *ipqlabel,
1580 struct mbuf *mbuf,
1581 struct label *mbuflabel
1582 );
1583 /**
1584 @brief Assign a label to a new mbuf
1585 @param ifp Subject; network interface
1586 @param i_label Existing label of ifp
1587 @param m Object; mbuf
1588 @param m_label Policy label to fill in for m
1589
1590 Set the label on the mbuf header of a newly created datagram
1591 generated for the purposes of a link layer response for the passed
1592 interface. This call may be made in a number of situations, including
1593 for ARP or ND6 responses in the IPv4 and IPv6 stacks.
1594 */
1595 typedef void mpo_mbuf_label_associate_linklayer_t(
1596 struct ifnet *ifp,
1597 struct label *i_label,
1598 struct mbuf *m,
1599 struct label *m_label
1600 );
1601 /**
1602 @brief Assign a label to a new mbuf
1603 @param oldmbuf mbuf headerder for existing datagram for existing datagram
1604 @param oldmbuflabel Policy label for oldmbuf
1605 @param ifp Network interface
1606 @param ifplabel Policy label for ifp
1607 @param newmbuf mbuf header to be labeled for new datagram
1608 @param newmbuflabel Policy label for newmbuf
1609
1610 Set the label on the mbuf header of a newly created datagram
1611 generated from the existing passed datagram when it is processed
1612 by the passed multicast encapsulation interface. This call is made
1613 when an mbuf is to be delivered using the virtual interface.
1614 */
1615 typedef void mpo_mbuf_label_associate_multicast_encap_t(
1616 struct mbuf *oldmbuf,
1617 struct label *oldmbuflabel,
1618 struct ifnet *ifp,
1619 struct label *ifplabel,
1620 struct mbuf *newmbuf,
1621 struct label *newmbuflabel
1622 );
1623 /**
1624 @brief Assign a label to a new mbuf
1625 @param oldmbuf Received datagram
1626 @param oldmbuflabel Policy label for oldmbuf
1627 @param newmbuf Newly created datagram
1628 @param newmbuflabel Policy label for newmbuf
1629
1630 Set the label on the mbuf header of a newly created datagram generated
1631 by the IP stack in response to an existing received datagram (oldmbuf).
1632 This call may be made in a number of situations, including when responding
1633 to ICMP request datagrams.
1634 */
1635 typedef void mpo_mbuf_label_associate_netlayer_t(
1636 struct mbuf *oldmbuf,
1637 struct label *oldmbuflabel,
1638 struct mbuf *newmbuf,
1639 struct label *newmbuflabel
1640 );
1641 /**
1642 @brief Assign a label to a new mbuf
1643 @param so Socket to label
1644 @param so_label Policy label for socket
1645 @param m Object; mbuf
1646 @param m_label Policy label to fill in for m
1647
1648 An mbuf structure is used to store network traffic in transit.
1649 When an application sends data to a socket or a pipe, it is wrapped
1650 in an mbuf first. This function sets the label on a newly created mbuf header
1651 based on the socket sending the data. The contents of the label should be
1652 suitable for performing an access check on the receiving side of the
1653 communication.
1654
1655 Only labeled MBUFs will be presented to the policy via this entrypoint.
1656 */
1657 typedef void mpo_mbuf_label_associate_socket_t(
1658 socket_t so,
1659 struct label *so_label,
1660 struct mbuf *m,
1661 struct label *m_label
1662 );
1663 /**
1664 @brief Copy a mbuf label
1665 @param src Source label
1666 @param dest Destination label
1667
1668 Copy the mbuf label information in src into dest.
1669
1670 Only called when both source and destination mbufs have labels.
1671 */
1672 typedef void mpo_mbuf_label_copy_t(
1673 struct label *src,
1674 struct label *dest
1675 );
1676 /**
1677 @brief Destroy mbuf label
1678 @param label The label to be destroyed
1679
1680 Destroy a mbuf label. Since the
1681 object is going out of scope, policy modules should free any
1682 internal storage associated with the label so that it may be
1683 destroyed.
1684 */
1685 typedef void mpo_mbuf_label_destroy_t(
1686 struct label *label
1687 );
1688 /**
1689 @brief Initialize mbuf label
1690 @param label New label to initialize
1691 @param flag Malloc flags
1692
1693 Initialize the label for a newly instantiated mbuf.
1694
1695 @warning Since it is possible for the flags to be set to
1696 M_NOWAIT, the malloc operation may fail.
1697
1698 @return On success, 0, otherwise, an appropriate errno return value.
1699 */
1700 typedef int mpo_mbuf_label_init_t(
1701 struct label *label,
1702 int flag
1703 );
1704 /**
1705 @brief Access control check for fsctl
1706 @param cred Subject credential
1707 @param mp The mount point
1708 @param label Label associated with the mount point
1709 @param cmd Filesystem-dependent request code; see fsctl(2)
1710
1711 Determine whether the subject identified by the credential can perform
1712 the volume operation indicated by com.
1713
1714 @warning The fsctl() system call is directly analogous to ioctl(); since
1715 the associated data is opaque from the standpoint of the MAC framework
1716 and since these operations can affect many aspects of system operation,
1717 policies must exercise extreme care when implementing access control checks.
1718
1719 @return Return 0 if access is granted, otherwise an appropriate value for
1720 errno should be returned.
1721 */
1722 typedef int mpo_mount_check_fsctl_t(
1723 kauth_cred_t cred,
1724 struct mount *mp,
1725 struct label *label,
1726 unsigned int cmd
1727 );
1728 /**
1729 @brief Access control check for the retrieval of file system attributes
1730 @param cred Subject credential
1731 @param mp The mount structure of the file system
1732 @param vfa The attributes requested
1733
1734 This entry point determines whether given subject can get information
1735 about the given file system. This check happens during statfs() syscalls,
1736 but is also used by other parts within the kernel such as the audit system.
1737
1738 @return Return 0 if access is granted, otherwise an appropriate value for
1739 errno should be returned.
1740
1741 @note Policies may change the contents of vfa to alter the list of
1742 file system attributes returned.
1743 */
1744
1745 typedef int mpo_mount_check_getattr_t(
1746 kauth_cred_t cred,
1747 struct mount *mp,
1748 struct label *mp_label,
1749 struct vfs_attr *vfa
1750 );
1751 /**
1752 @brief Access control check for mount point relabeling
1753 @param cred Subject credential
1754 @param mp Object file system mount point
1755 @param mntlabel Policy label for fle system mount point
1756
1757 Determine whether the subject identified by the credential can relabel
1758 the mount point. This call is made when a file system mount is updated.
1759
1760 @return Return 0 if access is granted, otherwise an appropriate value for
1761 errno should be returned. Suggested failure: EACCES for label mismatch
1762 or EPERM for lack of privilege.
1763 */
1764 typedef int mpo_mount_check_label_update_t(
1765 kauth_cred_t cred,
1766 struct mount *mp,
1767 struct label *mntlabel
1768 );
1769 /**
1770 @brief Access control check for mounting a file system
1771 @param cred Subject credential
1772 @param vp Vnode that is to be the mount point
1773 @param vlabel Label associated with the vnode
1774 @param cnp Component name for vp
1775 @param vfc_name Filesystem type name
1776
1777 Determine whether the subject identified by the credential can perform
1778 the mount operation on the target vnode.
1779
1780 @return Return 0 if access is granted, otherwise an appropriate value for
1781 errno should be returned.
1782 */
1783 typedef int mpo_mount_check_mount_t(
1784 kauth_cred_t cred,
1785 struct vnode *vp,
1786 struct label *vlabel,
1787 struct componentname *cnp,
1788 const char *vfc_name
1789 );
1790 /**
1791 @brief Access control check for fs_snapshot_create
1792 @param cred Subject credential
1793 @mp Filesystem mount point to create snapshot of
1794 @name Name of snapshot to create
1795
1796 Determine whether the subject identified by the credential can
1797 create a snapshot of the filesystem at the given mount point.
1798
1799 @return Return 0 if access is granted, otherwise an appropriate value
1800 for errno should be returned.
1801 */
1802 typedef int mpo_mount_check_snapshot_create_t(
1803 kauth_cred_t cred,
1804 struct mount *mp,
1805 const char *name
1806 );
1807 /**
1808 @brief Access control check for fs_snapshot_delete
1809 @param cred Subject credential
1810 @mp Filesystem mount point to delete snapshot of
1811 @name Name of snapshot to delete
1812
1813 Determine whether the subject identified by the credential can
1814 delete the named snapshot from the filesystem at the given
1815 mount point.
1816
1817 @return Return 0 if access is granted, otherwise an appropriate value
1818 for errno should be returned.
1819 */
1820 typedef int mpo_mount_check_snapshot_delete_t(
1821 kauth_cred_t cred,
1822 struct mount *mp,
1823 const char *name
1824 );
1825 /**
1826 @brief Access control check remounting a filesystem
1827 @param cred Subject credential
1828 @param mp The mount point
1829 @param mlabel Label currently associated with the mount point
1830
1831 Determine whether the subject identified by the credential can perform
1832 the remount operation on the target vnode.
1833
1834 @return Return 0 if access is granted, otherwise an appropriate value for
1835 errno should be returned.
1836 */
1837 typedef int mpo_mount_check_remount_t(
1838 kauth_cred_t cred,
1839 struct mount *mp,
1840 struct label *mlabel
1841 );
1842 /**
1843 @brief Access control check for the settting of file system attributes
1844 @param cred Subject credential
1845 @param mp The mount structure of the file system
1846 @param vfa The attributes requested
1847
1848 This entry point determines whether given subject can set information
1849 about the given file system, for example the volume name.
1850
1851 @return Return 0 if access is granted, otherwise an appropriate value for
1852 errno should be returned.
1853 */
1854
1855 typedef int mpo_mount_check_setattr_t(
1856 kauth_cred_t cred,
1857 struct mount *mp,
1858 struct label *mp_label,
1859 struct vfs_attr *vfa
1860 );
1861 /**
1862 @brief Access control check for file system statistics
1863 @param cred Subject credential
1864 @param mp Object file system mount
1865 @param mntlabel Policy label for mp
1866
1867 Determine whether the subject identified by the credential can see
1868 the results of a statfs performed on the file system. This call may
1869 be made in a number of situations, including during invocations of
1870 statfs(2) and related calls, as well as to determine what file systems
1871 to exclude from listings of file systems, such as when getfsstat(2)
1872 is invoked.
1873
1874 @return Return 0 if access is granted, otherwise an appropriate value for
1875 errno should be returned. Suggested failure: EACCES for label mismatch
1876 or EPERM for lack of privilege.
1877 */
1878 typedef int mpo_mount_check_stat_t(
1879 kauth_cred_t cred,
1880 struct mount *mp,
1881 struct label *mntlabel
1882 );
1883 /**
1884 @brief Access control check for unmounting a filesystem
1885 @param cred Subject credential
1886 @param mp The mount point
1887 @param mlabel Label associated with the mount point
1888
1889 Determine whether the subject identified by the credential can perform
1890 the unmount operation on the target vnode.
1891
1892 @return Return 0 if access is granted, otherwise an appropriate value for
1893 errno should be returned.
1894 */
1895 typedef int mpo_mount_check_umount_t(
1896 kauth_cred_t cred,
1897 struct mount *mp,
1898 struct label *mlabel
1899 );
1900 /**
1901 @brief Create mount labels
1902 @param cred Subject credential
1903 @param mp Mount point of file system being mounted
1904 @param mntlabel Label to associate with the new mount point
1905 @see mpo_mount_label_init_t
1906
1907 Fill out the labels on the mount point being created by the supplied
1908 user credential. This call is made when file systems are first mounted.
1909 */
1910 typedef void mpo_mount_label_associate_t(
1911 kauth_cred_t cred,
1912 struct mount *mp,
1913 struct label *mntlabel
1914 );
1915 /**
1916 @brief Destroy mount label
1917 @param label The label to be destroyed
1918
1919 Destroy a file system mount label. Since the
1920 object is going out of scope, policy modules should free any
1921 internal storage associated with the label so that it may be
1922 destroyed.
1923 */
1924 typedef void mpo_mount_label_destroy_t(
1925 struct label *label
1926 );
1927 /**
1928 @brief Externalize a mount point label
1929 @param label Label to be externalized
1930 @param element_name Name of the label namespace for which labels should be
1931 externalized
1932 @param sb String buffer to be filled with a text representation of the label
1933
1934 Produce an external representation of the mount point label. An
1935 externalized label consists of a text representation of the label
1936 contents that can be used with user applications. Policy-agnostic
1937 user space tools will display this externalized version.
1938
1939 The policy's externalize entry points will be called only if the
1940 policy has registered interest in the label namespace.
1941
1942 @return 0 on success, return non-zero if an error occurs while
1943 externalizing the label data.
1944
1945 */
1946 typedef int mpo_mount_label_externalize_t(
1947 struct label *label,
1948 char *element_name,
1949 struct sbuf *sb
1950 );
1951 /**
1952 @brief Initialize mount point label
1953 @param label New label to initialize
1954
1955 Initialize the label for a newly instantiated mount structure.
1956 This label is typically used to store a default label in the case
1957 that the file system has been mounted singlelabel. Since some
1958 file systems do not support persistent labels (extended attributes)
1959 or are read-only (such as CD-ROMs), it is often necessary to store
1960 a default label separately from the label of the mount point
1961 itself. Sleeping is permitted.
1962 */
1963 typedef void mpo_mount_label_init_t(
1964 struct label *label
1965 );
1966 /**
1967 @brief Internalize a mount point label
1968 @param label Label to be internalized
1969 @param element_name Name of the label namespace for which the label should
1970 be internalized
1971 @param element_data Text data to be internalized
1972
1973 Produce a mount point file system label from an external representation.
1974 An externalized label consists of a text representation of the label
1975 contents that can be used with user applications. Policy-agnostic
1976 user space tools will forward text version to the kernel for
1977 processing by individual policy modules.
1978
1979 The policy's internalize entry points will be called only if the
1980 policy has registered interest in the label namespace.
1981
1982 @return 0 on success, Otherwise, return non-zero if an error occurs
1983 while internalizing the label data.
1984
1985 */
1986 typedef int mpo_mount_label_internalize_t(
1987 struct label *label,
1988 char *element_name,
1989 char *element_data
1990 );
1991 /**
1992 @brief Set the label on an IPv4 datagram fragment
1993 @param datagram Datagram being fragmented
1994 @param datagramlabel Policy label for datagram
1995 @param fragment New fragment
1996 @param fragmentlabel Policy label for fragment
1997
1998 Called when an IPv4 datagram is fragmented into several smaller datagrams.
1999 Policies implementing mbuf labels will typically copy the label from the
2000 source datagram to the new fragment.
2001 */
2002 typedef void mpo_netinet_fragment_t(
2003 struct mbuf *datagram,
2004 struct label *datagramlabel,
2005 struct mbuf *fragment,
2006 struct label *fragmentlabel
2007 );
2008 /**
2009 @brief Set the label on an ICMP reply
2010 @param m mbuf containing the ICMP reply
2011 @param mlabel Policy label for m
2012
2013 A policy may wish to update the label of an mbuf that refers to
2014 an ICMP packet being sent in response to an IP packet. This may
2015 be called in response to a bad packet or an ICMP request.
2016 */
2017 typedef void mpo_netinet_icmp_reply_t(
2018 struct mbuf *m,
2019 struct label *mlabel
2020 );
2021 /**
2022 @brief Set the label on a TCP reply
2023 @param m mbuf containing the TCP reply
2024 @param mlabel Policy label for m
2025
2026 Called for outgoing TCP packets not associated with an actual socket.
2027 */
2028 typedef void mpo_netinet_tcp_reply_t(
2029 struct mbuf *m,
2030 struct label *mlabel
2031 );
2032 /**
2033 @brief Access control check for pipe ioctl
2034 @param cred Subject credential
2035 @param cpipe Object to be accessed
2036 @param pipelabel The label on the pipe
2037 @param cmd The ioctl command; see ioctl(2)
2038
2039 Determine whether the subject identified by the credential can perform
2040 the ioctl operation indicated by cmd.
2041
2042 @warning Since ioctl data is opaque from the standpoint of the MAC
2043 framework, policies must exercise extreme care when implementing
2044 access control checks.
2045
2046 @return Return 0 if access is granted, otherwise an appropriate value for
2047 errno should be returned.
2048
2049 */
2050 typedef int mpo_pipe_check_ioctl_t(
2051 kauth_cred_t cred,
2052 struct pipe *cpipe,
2053 struct label *pipelabel,
2054 unsigned int cmd
2055 );
2056 /**
2057 @brief Access control check for pipe kqfilter
2058 @param cred Subject credential
2059 @param kn Object knote
2060 @param cpipe Object to be accessed
2061 @param pipelabel Policy label for the pipe
2062
2063 Determine whether the subject identified by the credential can
2064 receive the knote on the passed pipe.
2065
2066 @return Return 0 if access if granted, otherwise an appropriate
2067 value for errno should be returned.
2068 */
2069 typedef int mpo_pipe_check_kqfilter_t(
2070 kauth_cred_t cred,
2071 struct knote *kn,
2072 struct pipe *cpipe,
2073 struct label *pipelabel
2074 );
2075 /**
2076 @brief Access control check for pipe relabel
2077 @param cred Subject credential
2078 @param cpipe Object to be accessed
2079 @param pipelabel The current label on the pipe
2080 @param newlabel The new label to be used
2081
2082 Determine whether the subject identified by the credential can
2083 perform a relabel operation on the passed pipe. The cred object holds
2084 the credentials of the subject performing the operation.
2085
2086 @return Return 0 if access is granted, otherwise an appropriate value for
2087 errno should be returned.
2088
2089 */
2090 typedef int mpo_pipe_check_label_update_t(
2091 kauth_cred_t cred,
2092 struct pipe *cpipe,
2093 struct label *pipelabel,
2094 struct label *newlabel
2095 );
2096 /**
2097 @brief Access control check for pipe read
2098 @param cred Subject credential
2099 @param cpipe Object to be accessed
2100 @param pipelabel The label on the pipe
2101
2102 Determine whether the subject identified by the credential can
2103 perform a read operation on the passed pipe. The cred object holds
2104 the credentials of the subject performing the operation.
2105
2106 @return Return 0 if access is granted, otherwise an appropriate value for
2107 errno should be returned.
2108
2109 */
2110 typedef int mpo_pipe_check_read_t(
2111 kauth_cred_t cred,
2112 struct pipe *cpipe,
2113 struct label *pipelabel
2114 );
2115 /**
2116 @brief Access control check for pipe select
2117 @param cred Subject credential
2118 @param cpipe Object to be accessed
2119 @param pipelabel The label on the pipe
2120 @param which The operation selected on: FREAD or FWRITE
2121
2122 Determine whether the subject identified by the credential can
2123 perform a select operation on the passed pipe. The cred object holds
2124 the credentials of the subject performing the operation.
2125
2126 @return Return 0 if access is granted, otherwise an appropriate value for
2127 errno should be returned.
2128
2129 */
2130 typedef int mpo_pipe_check_select_t(
2131 kauth_cred_t cred,
2132 struct pipe *cpipe,
2133 struct label *pipelabel,
2134 int which
2135 );
2136 /**
2137 @brief Access control check for pipe stat
2138 @param cred Subject credential
2139 @param cpipe Object to be accessed
2140 @param pipelabel The label on the pipe
2141
2142 Determine whether the subject identified by the credential can
2143 perform a stat operation on the passed pipe. The cred object holds
2144 the credentials of the subject performing the operation.
2145
2146 @return Return 0 if access is granted, otherwise an appropriate value for
2147 errno should be returned.
2148
2149 */
2150 typedef int mpo_pipe_check_stat_t(
2151 kauth_cred_t cred,
2152 struct pipe *cpipe,
2153 struct label *pipelabel
2154 );
2155 /**
2156 @brief Access control check for pipe write
2157 @param cred Subject credential
2158 @param cpipe Object to be accessed
2159 @param pipelabel The label on the pipe
2160
2161 Determine whether the subject identified by the credential can
2162 perform a write operation on the passed pipe. The cred object holds
2163 the credentials of the subject performing the operation.
2164
2165 @return Return 0 if access is granted, otherwise an appropriate value for
2166 errno should be returned.
2167
2168 */
2169 typedef int mpo_pipe_check_write_t(
2170 kauth_cred_t cred,
2171 struct pipe *cpipe,
2172 struct label *pipelabel
2173 );
2174 /**
2175 @brief Create a pipe label
2176 @param cred Subject credential
2177 @param cpipe object to be labeled
2178 @param pipelabel Label for the pipe object
2179
2180 Create a label for the pipe object being created by the supplied
2181 user credential. This call is made when the pipe is being created
2182 XXXPIPE(for one or both sides of the pipe?).
2183
2184 */
2185 typedef void mpo_pipe_label_associate_t(
2186 kauth_cred_t cred,
2187 struct pipe *cpipe,
2188 struct label *pipelabel
2189 );
2190 /**
2191 @brief Copy a pipe label
2192 @param src Source pipe label
2193 @param dest Destination pipe label
2194
2195 Copy the pipe label associated with src to dest.
2196 XXXPIPE Describe when this is used: most likely during pipe creation to
2197 copy from rpipe to wpipe.
2198 */
2199 typedef void mpo_pipe_label_copy_t(
2200 struct label *src,
2201 struct label *dest
2202 );
2203 /**
2204 @brief Destroy pipe label
2205 @param label The label to be destroyed
2206
2207 Destroy a pipe label. Since the object is going out of scope,
2208 policy modules should free any internal storage associated with the
2209 label so that it may be destroyed.
2210 */
2211 typedef void mpo_pipe_label_destroy_t(
2212 struct label *label
2213 );
2214 /**
2215 @brief Externalize a pipe label
2216 @param label Label to be externalized
2217 @param element_name Name of the label namespace for which labels should be
2218 externalized
2219 @param sb String buffer to be filled with a text representation of the label
2220
2221 Produce an external representation of the label on a pipe.
2222 An externalized label consists of a text representation
2223 of the label contents that can be used with user applications.
2224 Policy-agnostic user space tools will display this externalized
2225 version.
2226
2227 The policy's externalize entry points will be called only if the
2228 policy has registered interest in the label namespace.
2229
2230 @return 0 on success, return non-zero if an error occurs while
2231 externalizing the label data.
2232
2233 */
2234 typedef int mpo_pipe_label_externalize_t(
2235 struct label *label,
2236 char *element_name,
2237 struct sbuf *sb
2238 );
2239 /**
2240 @brief Initialize pipe label
2241 @param label New label to initialize
2242
2243 Initialize label storage for use with a newly instantiated pipe object.
2244 Sleeping is permitted.
2245 */
2246 typedef void mpo_pipe_label_init_t(
2247 struct label *label
2248 );
2249 /**
2250 @brief Internalize a pipe label
2251 @param label Label to be internalized
2252 @param element_name Name of the label namespace for which the label should
2253 be internalized
2254 @param element_data Text data to be internalized
2255
2256 Produce a pipe label from an external representation. An
2257 externalized label consists of a text representation of the label
2258 contents that can be used with user applications. Policy-agnostic
2259 user space tools will forward text version to the kernel for
2260 processing by individual policy modules.
2261
2262 The policy's internalize entry points will be called only if the
2263 policy has registered interest in the label namespace.
2264
2265 @return 0 on success, Otherwise, return non-zero if an error occurs
2266 while internalizing the label data.
2267
2268 */
2269 typedef int mpo_pipe_label_internalize_t(
2270 struct label *label,
2271 char *element_name,
2272 char *element_data
2273 );
2274 /**
2275 @brief Update a pipe label
2276 @param cred Subject credential
2277 @param cpipe Object to be labeled
2278 @param oldlabel Existing pipe label
2279 @param newlabel New label to replace existing label
2280 @see mpo_pipe_check_label_update_t
2281
2282 The subject identified by the credential has previously requested
2283 and was authorized to relabel the pipe; this entry point allows
2284 policies to perform the actual relabel operation. Policies should
2285 update oldlabel using the label stored in the newlabel parameter.
2286
2287 */
2288 typedef void mpo_pipe_label_update_t(
2289 kauth_cred_t cred,
2290 struct pipe *cpipe,
2291 struct label *oldlabel,
2292 struct label *newlabel
2293 );
2294 /**
2295 @brief Policy unload event
2296 @param mpc MAC policy configuration
2297
2298 This is the MAC Framework policy unload event. This entry point will
2299 only be called if the module's policy configuration allows unload (if
2300 the MPC_LOADTIME_FLAG_UNLOADOK is set). Most security policies won't
2301 want to be unloaded; they should set their flags to prevent this
2302 entry point from being called.
2303
2304 @warning During this call, the mac policy list mutex is held, so
2305 sleep operations cannot be performed, and calls out to other kernel
2306 subsystems must be made with caution.
2307
2308 @see MPC_LOADTIME_FLAG_UNLOADOK
2309 */
2310 typedef void mpo_policy_destroy_t(
2311 struct mac_policy_conf *mpc
2312 );
2313 /**
2314 @brief Policy initialization event
2315 @param mpc MAC policy configuration
2316 @see mac_policy_register
2317 @see mpo_policy_initbsd_t
2318
2319 This is the MAC Framework policy initialization event. This entry
2320 point is called during mac_policy_register, when the policy module
2321 is first registered with the MAC Framework. This is often done very
2322 early in the boot process, after the kernel Mach subsystem has been
2323 initialized, but prior to the BSD subsystem being initialized.
2324 Since the kernel BSD services are not yet available, it is possible
2325 that some initialization must occur later, possibly in the
2326 mpo_policy_initbsd_t policy entry point, such as registering BSD system
2327 controls (sysctls). Policy modules loaded at boot time will be
2328 registered and initialized before labeled Mach objects are created.
2329
2330 @warning During this call, the mac policy list mutex is held, so
2331 sleep operations cannot be performed, and calls out to other kernel
2332 subsystems must be made with caution.
2333 */
2334 typedef void mpo_policy_init_t(
2335 struct mac_policy_conf *mpc
2336 );
2337 /**
2338 @brief Policy BSD initialization event
2339 @param mpc MAC policy configuration
2340 @see mpo_policy_init_t
2341
2342 This entry point is called after the kernel BSD subsystem has been
2343 initialized. By this point, the module should already be loaded,
2344 registered, and initialized. Since policy modules are initialized
2345 before kernel BSD services are available, this second initialization
2346 phase is necessary. At this point, BSD services (memory management,
2347 synchronization primitives, vfs, etc.) are available, but the first
2348 process has not yet been created. Mach-related objects and tasks
2349 will already be fully initialized and may be in use--policies requiring
2350 ubiquitous labeling may also want to implement mpo_policy_init_t.
2351
2352 @warning During this call, the mac policy list mutex is held, so
2353 sleep operations cannot be performed, and calls out to other kernel
2354 subsystems must be made with caution.
2355 */
2356 typedef void mpo_policy_initbsd_t(
2357 struct mac_policy_conf *mpc
2358 );
2359 /**
2360 @brief Policy extension service
2361 @param p Calling process
2362 @param call Policy-specific syscall number
2363 @param arg Pointer to syscall arguments
2364
2365 This entry point provides a policy-multiplexed system call so that
2366 policies may provide additional services to user processes without
2367 registering specific system calls. The policy name provided during
2368 registration is used to demux calls from userland, and the arguments
2369 will be forwarded to this entry point. When implementing new
2370 services, security modules should be sure to invoke appropriate
2371 access control checks from the MAC framework as needed. For
2372 example, if a policy implements an augmented signal functionality,
2373 it should call the necessary signal access control checks to invoke
2374 the MAC framework and other registered policies.
2375
2376 @warning Since the format and contents of the policy-specific
2377 arguments are unknown to the MAC Framework, modules must perform the
2378 required copyin() of the syscall data on their own. No policy
2379 mediation is performed, so policies must perform any necessary
2380 access control checks themselves. If multiple policies are loaded,
2381 they will currently be unable to mediate calls to other policies.
2382
2383 @return In the event of an error, an appropriate value for errno
2384 should be returned, otherwise return 0 upon success.
2385 */
2386 typedef int mpo_policy_syscall_t(
2387 struct proc *p,
2388 int call,
2389 user_addr_t arg
2390 );
2391 /**
2392 @brief Access control check for POSIX semaphore create
2393 @param cred Subject credential
2394 @param name String name of the semaphore
2395
2396 Determine whether the subject identified by the credential can create
2397 a POSIX semaphore specified by name.
2398
2399 @return Return 0 if access is granted, otherwise an appropriate value for
2400 errno should be returned.
2401 */
2402 typedef int mpo_posixsem_check_create_t(
2403 kauth_cred_t cred,
2404 const char *name
2405 );
2406 /**
2407 @brief Access control check for POSIX semaphore open
2408 @param cred Subject credential
2409 @param ps Pointer to semaphore information structure
2410 @param semlabel Label associated with the semaphore
2411
2412 Determine whether the subject identified by the credential can open
2413 the named POSIX semaphore with label semlabel.
2414
2415 @return Return 0 if access is granted, otherwise an appropriate value for
2416 errno should be returned.
2417 */
2418 typedef int mpo_posixsem_check_open_t(
2419 kauth_cred_t cred,
2420 struct pseminfo *ps,
2421 struct label *semlabel
2422 );
2423 /**
2424 @brief Access control check for POSIX semaphore post
2425 @param cred Subject credential
2426 @param ps Pointer to semaphore information structure
2427 @param semlabel Label associated with the semaphore
2428
2429 Determine whether the subject identified by the credential can unlock
2430 the named POSIX semaphore with label semlabel.
2431
2432 @return Return 0 if access is granted, otherwise an appropriate value for
2433 errno should be returned.
2434 */
2435 typedef int mpo_posixsem_check_post_t(
2436 kauth_cred_t cred,
2437 struct pseminfo *ps,
2438 struct label *semlabel
2439 );
2440 /**
2441 @brief Access control check for POSIX semaphore unlink
2442 @param cred Subject credential
2443 @param ps Pointer to semaphore information structure
2444 @param semlabel Label associated with the semaphore
2445 @param name String name of the semaphore
2446
2447 Determine whether the subject identified by the credential can remove
2448 the named POSIX semaphore with label semlabel.
2449
2450 @return Return 0 if access is granted, otherwise an appropriate value for
2451 errno should be returned.
2452 */
2453 typedef int mpo_posixsem_check_unlink_t(
2454 kauth_cred_t cred,
2455 struct pseminfo *ps,
2456 struct label *semlabel,
2457 const char *name
2458 );
2459 /**
2460 @brief Access control check for POSIX semaphore wait
2461 @param cred Subject credential
2462 @param ps Pointer to semaphore information structure
2463 @param semlabel Label associated with the semaphore
2464
2465 Determine whether the subject identified by the credential can lock
2466 the named POSIX semaphore with label semlabel.
2467
2468 @return Return 0 if access is granted, otherwise an appropriate value for
2469 errno should be returned.
2470 */
2471 typedef int mpo_posixsem_check_wait_t(
2472 kauth_cred_t cred,
2473 struct pseminfo *ps,
2474 struct label *semlabel
2475 );
2476 /**
2477 @brief Create a POSIX semaphore label
2478 @param cred Subject credential
2479 @param ps Pointer to semaphore information structure
2480 @param semlabel Label to associate with the new semaphore
2481 @param name String name of the semaphore
2482
2483 Label a new POSIX semaphore. The label was previously
2484 initialized and associated with the semaphore. At this time, an
2485 appropriate initial label value should be assigned to the object and
2486 stored in semalabel.
2487 */
2488 typedef void mpo_posixsem_label_associate_t(
2489 kauth_cred_t cred,
2490 struct pseminfo *ps,
2491 struct label *semlabel,
2492 const char *name
2493 );
2494 /**
2495 @brief Destroy POSIX semaphore label
2496 @param label The label to be destroyed
2497
2498 Destroy a POSIX semaphore label. Since the object is
2499 going out of scope, policy modules should free any internal storage
2500 associated with the label so that it may be destroyed.
2501 */
2502 typedef void mpo_posixsem_label_destroy_t(
2503 struct label *label
2504 );
2505 /**
2506 @brief Initialize POSIX semaphore label
2507 @param label New label to initialize
2508
2509 Initialize the label for a newly instantiated POSIX semaphore. Sleeping
2510 is permitted.
2511 */
2512 typedef void mpo_posixsem_label_init_t(
2513 struct label *label
2514 );
2515 /**
2516 @brief Access control check for POSIX shared memory region create
2517 @param cred Subject credential
2518 @param name String name of the shared memory region
2519
2520 Determine whether the subject identified by the credential can create
2521 the POSIX shared memory region referenced by name.
2522
2523 @return Return 0 if access is granted, otherwise an appropriate value for
2524 errno should be returned.
2525 */
2526 typedef int mpo_posixshm_check_create_t(
2527 kauth_cred_t cred,
2528 const char *name
2529 );
2530 /**
2531 @brief Access control check for mapping POSIX shared memory
2532 @param cred Subject credential
2533 @param ps Pointer to shared memory information structure
2534 @param shmlabel Label associated with the shared memory region
2535 @param prot mmap protections; see mmap(2)
2536 @param flags shmat flags; see shmat(2)
2537
2538 Determine whether the subject identified by the credential can map
2539 the POSIX shared memory segment associated with shmlabel.
2540
2541 @return Return 0 if access is granted, otherwise an appropriate value for
2542 errno should be returned.
2543 */
2544 typedef int mpo_posixshm_check_mmap_t(
2545 kauth_cred_t cred,
2546 struct pshminfo *ps,
2547 struct label *shmlabel,
2548 int prot,
2549 int flags
2550 );
2551 /**
2552 @brief Access control check for POSIX shared memory region open
2553 @param cred Subject credential
2554 @param ps Pointer to shared memory information structure
2555 @param shmlabel Label associated with the shared memory region
2556 @param fflags shm_open(2) open flags ('fflags' encoded)
2557
2558 Determine whether the subject identified by the credential can open
2559 the POSIX shared memory region.
2560
2561 @return Return 0 if access is granted, otherwise an appropriate value for
2562 errno should be returned.
2563 */
2564 typedef int mpo_posixshm_check_open_t(
2565 kauth_cred_t cred,
2566 struct pshminfo *ps,
2567 struct label *shmlabel,
2568 int fflags
2569 );
2570 /**
2571 @brief Access control check for POSIX shared memory stat
2572 @param cred Subject credential
2573 @param ps Pointer to shared memory information structure
2574 @param shmlabel Label associated with the shared memory region
2575
2576 Determine whether the subject identified by the credential can obtain
2577 status for the POSIX shared memory segment associated with shmlabel.
2578
2579 @return Return 0 if access is granted, otherwise an appropriate value for
2580 errno should be returned.
2581 */
2582 typedef int mpo_posixshm_check_stat_t(
2583 kauth_cred_t cred,
2584 struct pshminfo *ps,
2585 struct label *shmlabel
2586 );
2587 /**
2588 @brief Access control check for POSIX shared memory truncate
2589 @param cred Subject credential
2590 @param ps Pointer to shared memory information structure
2591 @param shmlabel Label associated with the shared memory region
2592 @param len Length to truncate or extend shared memory segment
2593
2594 Determine whether the subject identified by the credential can truncate
2595 or extend (to len) the POSIX shared memory segment associated with shmlabel.
2596
2597 @return Return 0 if access is granted, otherwise an appropriate value for
2598 errno should be returned.
2599 */
2600 typedef int mpo_posixshm_check_truncate_t(
2601 kauth_cred_t cred,
2602 struct pshminfo *ps,
2603 struct label *shmlabel,
2604 off_t len
2605 );
2606 /**
2607 @brief Access control check for POSIX shared memory unlink
2608 @param cred Subject credential
2609 @param ps Pointer to shared memory information structure
2610 @param shmlabel Label associated with the shared memory region
2611 @param name String name of the shared memory region
2612
2613 Determine whether the subject identified by the credential can delete
2614 the POSIX shared memory segment associated with shmlabel.
2615
2616 @return Return 0 if access is granted, otherwise an appropriate value for
2617 errno should be returned.
2618 */
2619 typedef int mpo_posixshm_check_unlink_t(
2620 kauth_cred_t cred,
2621 struct pshminfo *ps,
2622 struct label *shmlabel,
2623 const char *name
2624 );
2625 /**
2626 @brief Create a POSIX shared memory region label
2627 @param cred Subject credential
2628 @param ps Pointer to shared memory information structure
2629 @param shmlabel Label to associate with the new shared memory region
2630 @param name String name of the shared memory region
2631
2632 Label a new POSIX shared memory region. The label was previously
2633 initialized and associated with the shared memory region. At this
2634 time, an appropriate initial label value should be assigned to the
2635 object and stored in shmlabel.
2636 */
2637 typedef void mpo_posixshm_label_associate_t(
2638 kauth_cred_t cred,
2639 struct pshminfo *ps,
2640 struct label *shmlabel,
2641 const char *name
2642 );
2643 /**
2644 @brief Destroy POSIX shared memory label
2645 @param label The label to be destroyed
2646
2647 Destroy a POSIX shared memory region label. Since the
2648 object is going out of scope, policy modules should free any
2649 internal storage associated with the label so that it may be
2650 destroyed.
2651 */
2652 typedef void mpo_posixshm_label_destroy_t(
2653 struct label *label
2654 );
2655 /**
2656 @brief Initialize POSIX Shared Memory region label
2657 @param label New label to initialize
2658
2659 Initialize the label for newly a instantiated POSIX Shared Memory
2660 region. Sleeping is permitted.
2661 */
2662 typedef void mpo_posixshm_label_init_t(
2663 struct label *label
2664 );
2665 /**
2666 @brief Access control check for privileged operations
2667 @param cred Subject credential
2668 @param priv Requested privilege (see sys/priv.h)
2669
2670 Determine whether the subject identified by the credential can perform
2671 a privileged operation. Privileged operations are allowed if the cred
2672 is the superuser or any policy returns zero for mpo_priv_grant, unless
2673 any policy returns nonzero for mpo_priv_check.
2674
2675 @return Return 0 if access is granted, otherwise EPERM should be returned.
2676 */
2677 typedef int mpo_priv_check_t(
2678 kauth_cred_t cred,
2679 int priv
2680 );
2681 /**
2682 @brief Grant regular users the ability to perform privileged operations
2683 @param cred Subject credential
2684 @param priv Requested privilege (see sys/priv.h)
2685
2686 Determine whether the subject identified by the credential should be
2687 allowed to perform a privileged operation that in the absense of any
2688 MAC policy it would not be able to perform. Privileged operations are
2689 allowed if the cred is the superuser or any policy returns zero for
2690 mpo_priv_grant, unless any policy returns nonzero for mpo_priv_check.
2691
2692 Unlike other MAC hooks which can only reduce the privilege of a
2693 credential, this hook raises the privilege of a credential when it
2694 returns 0. Extreme care must be taken when implementing this hook to
2695 avoid undermining the security of the system.
2696
2697 @return Return 0 if additional privilege is granted, otherwise EPERM
2698 should be returned.
2699 */
2700 typedef int mpo_priv_grant_t(
2701 kauth_cred_t cred,
2702 int priv
2703 );
2704 /**
2705 @brief Access control check for debugging process
2706 @param cred Subject credential
2707 @param proc Object process
2708
2709 Determine whether the subject identified by the credential can debug
2710 the passed process. This call may be made in a number of situations,
2711 including use of the ptrace(2) and ktrace(2) APIs, as well as for some
2712 types of procfs operations.
2713
2714 @return Return 0 if access is granted, otherwise an appropriate value for
2715 errno should be returned. Suggested failure: EACCES for label mismatch,
2716 EPERM for lack of privilege, or ESRCH to hide visibility of the target.
2717 */
2718 typedef int mpo_proc_check_debug_t(
2719 kauth_cred_t cred,
2720 struct proc *proc
2721 );
2722 /**
2723 @brief Access control over fork
2724 @param cred Subject credential
2725 @param proc Subject process trying to fork
2726
2727 Determine whether the subject identified is allowed to fork.
2728
2729 @return Return 0 if access is granted, otherwise an appropriate value for
2730 errno should be returned.
2731 */
2732 typedef int mpo_proc_check_fork_t(
2733 kauth_cred_t cred,
2734 struct proc *proc
2735 );
2736 /**
2737 @brief Access control check for setting host special ports.
2738 @param cred Subject credential
2739 @param id The host special port to set
2740 @param port The new value to set for the special port
2741
2742 @return Return 0 if access is granted, otherwise an appropriate value for
2743 errno should be returned.
2744 */
2745 typedef int mpo_proc_check_set_host_special_port_t(
2746 kauth_cred_t cred,
2747 int id,
2748 struct ipc_port *port
2749 );
2750 /**
2751 @brief Access control check for setting host exception ports.
2752 @param cred Subject credential
2753 @param exception Exception port to set
2754
2755 @return Return 0 if access is granted, otherwise an appropriate value for
2756 errno should be returned.
2757 */
2758 typedef int mpo_proc_check_set_host_exception_port_t(
2759 kauth_cred_t cred,
2760 unsigned int exception
2761 );
2762 /**
2763 @brief Access control over pid_suspend and pid_resume
2764 @param cred Subject credential
2765 @param proc Subject process trying to run pid_suspend or pid_resume
2766 @param sr Call is suspend (0) or resume (1)
2767
2768 Determine whether the subject identified is allowed to suspend or resume
2769 other processes.
2770
2771 @return Return 0 if access is granted, otherwise an appropriate value for
2772 errno should be returned.
2773 */
2774 typedef int mpo_proc_check_suspend_resume_t(
2775 kauth_cred_t cred,
2776 struct proc *proc,
2777 int sr
2778 );
2779 /**
2780 @brief Access control check for retrieving audit information
2781 @param cred Subject credential
2782
2783 Determine whether the subject identified by the credential can get
2784 audit information such as the audit user ID, the preselection mask,
2785 the terminal ID and the audit session ID, using the getaudit() system call.
2786
2787 @return Return 0 if access is granted, otherwise an appropriate value for
2788 errno should be returned.
2789 */
2790 typedef int mpo_proc_check_getaudit_t(
2791 kauth_cred_t cred
2792 );
2793 /**
2794 @brief Access control check for retrieving audit user ID
2795 @param cred Subject credential
2796
2797 Determine whether the subject identified by the credential can get
2798 the user identity being used by the auditing system, using the getauid()
2799 system call.
2800
2801 @return Return 0 if access is granted, otherwise an appropriate value for
2802 errno should be returned.
2803 */
2804 typedef int mpo_proc_check_getauid_t(
2805 kauth_cred_t cred
2806 );
2807 /**
2808 @brief Access control check for retrieving Login Context ID
2809 @param p0 Calling process
2810 @param p Effected process
2811 @param pid syscall PID argument
2812
2813 Determine if getlcid(2) system call is permitted.
2814
2815 Information returned by this system call is similar to that returned via
2816 process listings etc.
2817
2818 @return Return 0 if access is granted, otherwise an appropriate value for
2819 errno should be returned.
2820 */
2821 typedef int mpo_proc_check_getlcid_t(
2822 struct proc *p0,
2823 struct proc *p,
2824 pid_t pid
2825 );
2826 /**
2827 @brief Access control check for retrieving ledger information
2828 @param cred Subject credential
2829 @param target Object process
2830 @param op ledger operation
2831
2832 Determine if ledger(2) system call is permitted.
2833
2834 Information returned by this system call is similar to that returned via
2835 process listings etc.
2836
2837 @return Return 0 if access is granted, otherwise an appropriate value for
2838 errno should be returned.
2839 */
2840 typedef int mpo_proc_check_ledger_t(
2841 kauth_cred_t cred,
2842 struct proc *target,
2843 int op
2844 );
2845 /**
2846 @brief Access control check for escaping default CPU usage monitor parameters.
2847 @param cred Subject credential
2848
2849 Determine if a credential has permission to program CPU usage monitor parameters
2850 that are less restrictive than the global system-wide defaults.
2851
2852 @return Return 0 if access is granted, otherwise an appropriate value for
2853 errno should be returned.
2854 */
2855 typedef int mpo_proc_check_cpumon_t(
2856 kauth_cred_t cred
2857 );
2858 /**
2859 @brief Access control check for retrieving process information.
2860 @param cred Subject credential
2861 @param target Target process (may be null, may be zombie)
2862
2863 Determine if a credential has permission to access process information as defined
2864 by call number and flavor on target process
2865
2866 @return Return 0 if access is granted, otherwise an appropriate value for
2867 errno should be returned.
2868 */
2869 typedef int mpo_proc_check_proc_info_t(
2870 kauth_cred_t cred,
2871 struct proc *target,
2872 int callnum,
2873 int flavor
2874 );
2875 /**
2876 @brief Access control check for retrieving code signing information.
2877 @param cred Subject credential
2878 @param target Target process
2879 @param op Code signing operation being performed
2880
2881 Determine whether the subject identified by the credential should be
2882 allowed to get code signing information about the target process.
2883
2884 @return Return 0 if access is granted, otherwise an appropriate value for
2885 errno should be returned.
2886 */
2887 typedef int mpo_proc_check_get_cs_info_t(
2888 kauth_cred_t cred,
2889 struct proc *target,
2890 unsigned int op
2891 );
2892 /**
2893 @brief Access control check for setting code signing information.
2894 @param cred Subject credential
2895 @param target Target process
2896 @param op Code signing operation being performed.
2897
2898 Determine whether the subject identified by the credential should be
2899 allowed to set code signing information about the target process.
2900
2901 @return Return 0 if permission is granted, otherwise an appropriate
2902 value of errno should be returned.
2903 */
2904 typedef int mpo_proc_check_set_cs_info_t(
2905 kauth_cred_t cred,
2906 struct proc *target,
2907 unsigned int op
2908 );
2909 /**
2910 @brief Access control check for mmap MAP_ANON
2911 @param proc User process requesting the memory
2912 @param cred Subject credential
2913 @param u_addr Start address of the memory range
2914 @param u_size Length address of the memory range
2915 @param prot mmap protections; see mmap(2)
2916 @param flags Type of mapped object; see mmap(2)
2917 @param maxprot Maximum rights
2918
2919 Determine whether the subject identified by the credential should be
2920 allowed to obtain anonymous memory using the specified flags and
2921 protections on the new mapping. MAP_ANON will always be present in the
2922 flags. Certain combinations of flags with a non-NULL addr may
2923 cause a mapping to be rejected before this hook is called. The maxprot field
2924 holds the maximum permissions on the new mapping, a combination of
2925 VM_PROT_READ, VM_PROT_WRITE and VM_PROT_EXECUTE. To avoid overriding prior
2926 access control checks, a policy should only remove flags from maxprot.
2927
2928 @return Return 0 if access is granted, otherwise an appropriate value for
2929 errno should be returned. Suggested failure: EPERM for lack of privilege.
2930 */
2931 typedef int mpo_proc_check_map_anon_t(
2932 struct proc *proc,
2933 kauth_cred_t cred,
2934 user_addr_t u_addr,
2935 user_size_t u_size,
2936 int prot,
2937 int flags,
2938 int *maxprot
2939 );
2940 /**
2941 @brief Access control check for setting memory protections
2942 @param cred Subject credential
2943 @param proc User process requesting the change
2944 @param addr Start address of the memory range
2945 @param size Length address of the memory range
2946 @param prot Memory protections, see mmap(2)
2947
2948 Determine whether the subject identified by the credential should
2949 be allowed to set the specified memory protections on memory mapped
2950 in the process proc.
2951
2952 @return Return 0 if access is granted, otherwise an appropriate value for
2953 errno should be returned.
2954 */
2955 typedef int mpo_proc_check_mprotect_t(
2956 kauth_cred_t cred,
2957 struct proc *proc,
2958 user_addr_t addr,
2959 user_size_t size,
2960 int prot
2961 );
2962 /**
2963 @brief Access control check for changing scheduling parameters
2964 @param cred Subject credential
2965 @param proc Object process
2966
2967 Determine whether the subject identified by the credential can change
2968 the scheduling parameters of the passed process.
2969
2970 @return Return 0 if access is granted, otherwise an appropriate value for
2971 errno should be returned. Suggested failure: EACCES for label mismatch,
2972 EPERM for lack of privilege, or ESRCH to limit visibility.
2973 */
2974 typedef int mpo_proc_check_sched_t(
2975 kauth_cred_t cred,
2976 struct proc *proc
2977 );
2978 /**
2979 @brief Access control check for setting audit information
2980 @param cred Subject credential
2981 @param ai Audit information
2982
2983 Determine whether the subject identified by the credential can set
2984 audit information such as the the preselection mask, the terminal ID
2985 and the audit session ID, using the setaudit() system call.
2986
2987 @return Return 0 if access is granted, otherwise an appropriate value for
2988 errno should be returned.
2989 */
2990 typedef int mpo_proc_check_setaudit_t(
2991 kauth_cred_t cred,
2992 struct auditinfo_addr *ai
2993 );
2994 /**
2995 @brief Access control check for setting audit user ID
2996 @param cred Subject credential
2997 @param auid Audit user ID
2998
2999 Determine whether the subject identified by the credential can set
3000 the user identity used by the auditing system, using the setauid()
3001 system call.
3002
3003 @return Return 0 if access is granted, otherwise an appropriate value for
3004 errno should be returned.
3005 */
3006 typedef int mpo_proc_check_setauid_t(
3007 kauth_cred_t cred,
3008 uid_t auid
3009 );
3010 /**
3011 @brief Access control check for setting the Login Context
3012 @param p0 Calling process
3013 @param p Effected process
3014 @param pid syscall PID argument
3015 @param lcid syscall LCID argument
3016
3017 Determine if setlcid(2) system call is permitted.
3018
3019 See xnu/bsd/kern/kern_prot.c:setlcid() implementation for example of
3020 decoding syscall arguments to determine action desired by caller.
3021
3022 Five distinct actions are possible: CREATE JOIN LEAVE ADOPT ORPHAN
3023
3024 @return Return 0 if access is granted, otherwise an appropriate value for
3025 errno should be returned.
3026 */
3027 typedef int mpo_proc_check_setlcid_t(
3028 struct proc *p0,
3029 struct proc *p,
3030 pid_t pid,
3031 pid_t lcid
3032 );
3033 /**
3034 @brief Access control check for delivering signal
3035 @param cred Subject credential
3036 @param proc Object process
3037 @param signum Signal number; see kill(2)
3038
3039 Determine whether the subject identified by the credential can deliver
3040 the passed signal to the passed process.
3041
3042 @warning Programs typically expect to be able to send and receive
3043 signals as part or their normal process lifecycle; caution should be
3044 exercised when implementing access controls over signal events.
3045
3046 @return Return 0 if access is granted, otherwise an appropriate value for
3047 errno should be returned. Suggested failure: EACCES for label mismatch,
3048 EPERM for lack of privilege, or ESRCH to limit visibility.
3049 */
3050 typedef int mpo_proc_check_signal_t(
3051 kauth_cred_t cred,
3052 struct proc *proc,
3053 int signum
3054 );
3055 /**
3056 @brief Access control check for wait
3057 @param cred Subject credential
3058 @param proc Object process
3059
3060 Determine whether the subject identified by the credential can wait
3061 for process termination.
3062
3063 @warning Caution should be exercised when implementing access
3064 controls for wait, since programs often wait for child processes to
3065 exit. Failure to be notified of a child process terminating may
3066 cause the parent process to hang, or may produce zombie processes.
3067
3068 @return Return 0 if access is granted, otherwise an appropriate value for
3069 errno should be returned.
3070 */
3071 typedef int mpo_proc_check_wait_t(
3072 kauth_cred_t cred,
3073 struct proc *proc
3074 );
3075 /**
3076 @brief Destroy process label
3077 @param label The label to be destroyed
3078
3079 Destroy a process label. Since the object is going
3080 out of scope, policy modules should free any internal storage
3081 associated with the label so that it may be destroyed.
3082 */
3083 typedef void mpo_proc_label_destroy_t(
3084 struct label *label
3085 );
3086 /**
3087 @brief Initialize process label
3088 @param label New label to initialize
3089 @see mpo_cred_label_init_t
3090
3091 Initialize the label for a newly instantiated BSD process structure.
3092 Normally, security policies will store the process label in the user
3093 credential rather than here in the process structure. However,
3094 there are some floating label policies that may need to temporarily
3095 store a label in the process structure until it is safe to update
3096 the user credential label. Sleeping is permitted.
3097 */
3098 typedef void mpo_proc_label_init_t(
3099 struct label *label
3100 );
3101 /**
3102 @brief Access control check for socket accept
3103 @param cred Subject credential
3104 @param so Object socket
3105 @param socklabel Policy label for socket
3106
3107 Determine whether the subject identified by the credential can accept()
3108 a new connection on the socket from the host specified by addr.
3109
3110 @return Return 0 if access if granted, otherwise an appropriate
3111 value for errno should be returned.
3112 */
3113 typedef int mpo_socket_check_accept_t(
3114 kauth_cred_t cred,
3115 socket_t so,
3116 struct label *socklabel
3117 );
3118 /**
3119 @brief Access control check for a pending socket accept
3120 @param cred Subject credential
3121 @param so Object socket
3122 @param socklabel Policy label for socket
3123 @param addr Address of the listening socket (coming soon)
3124
3125 Determine whether the subject identified by the credential can accept()
3126 a pending connection on the socket from the host specified by addr.
3127
3128 @return Return 0 if access if granted, otherwise an appropriate
3129 value for errno should be returned.
3130 */
3131 typedef int mpo_socket_check_accepted_t(
3132 kauth_cred_t cred,
3133 socket_t so,
3134 struct label *socklabel,
3135 struct sockaddr *addr
3136 );
3137 /**
3138 @brief Access control check for socket bind
3139 @param cred Subject credential
3140 @param so Object socket
3141 @param socklabel Policy label for socket
3142 @param addr Name to assign to the socket
3143
3144 Determine whether the subject identified by the credential can bind()
3145 the name (addr) to the socket.
3146
3147 @return Return 0 if access if granted, otherwise an appropriate
3148 value for errno should be returned.
3149 */
3150 typedef int mpo_socket_check_bind_t(
3151 kauth_cred_t cred,
3152 socket_t so,
3153 struct label *socklabel,
3154 struct sockaddr *addr
3155 );
3156 /**
3157 @brief Access control check for socket connect
3158 @param cred Subject credential
3159 @param so Object socket
3160 @param socklabel Policy label for socket
3161 @param addr Name to assign to the socket
3162
3163 Determine whether the subject identified by the credential can
3164 connect() the passed socket to the remote host specified by addr.
3165
3166 @return Return 0 if access if granted, otherwise an appropriate
3167 value for errno should be returned.
3168 */
3169 typedef int mpo_socket_check_connect_t(
3170 kauth_cred_t cred,
3171 socket_t so,
3172 struct label *socklabel,
3173 struct sockaddr *addr
3174 );
3175 /**
3176 @brief Access control check for socket() system call.
3177 @param cred Subject credential
3178 @param domain communication domain
3179 @param type socket type
3180 @param protocol socket protocol
3181
3182 Determine whether the subject identified by the credential can
3183 make the socket() call.
3184
3185 @return Return 0 if access if granted, otherwise an appropriate
3186 value for errno should be returned.
3187 */
3188 typedef int mpo_socket_check_create_t(
3189 kauth_cred_t cred,
3190 int domain,
3191 int type,
3192 int protocol
3193 );
3194 /**
3195 @brief Access control check for delivering data to a user's receieve queue
3196 @param so The socket data is being delivered to
3197 @param so_label The label of so
3198 @param m The mbuf whose data will be deposited into the receive queue
3199 @param m_label The label of the sender of the data.
3200
3201 A socket has a queue for receiving incoming data. When a packet arrives
3202 on the wire, it eventually gets deposited into this queue, which the
3203 owner of the socket drains when they read from the socket's file descriptor.
3204
3205 This function determines whether the socket can receive data from
3206 the sender specified by m_label.
3207
3208 @warning There is an outstanding design issue surrounding the placement
3209 of this function. The check must be placed either before or after the
3210 TCP sequence and ACK counters are updated. Placing the check before
3211 the counters are updated causes the incoming packet to be resent by
3212 the remote if the check rejects it. Placing the check after the counters
3213 are updated results in a completely silent drop. As far as each TCP stack
3214 is concerned the packet was received, however, the data will not be in the
3215 socket's receive queue. Another consideration is that the current design
3216 requires using the "failed label" occasionally. In that case, on rejection,
3217 we want the remote TCP to resend the data. Because of this, we chose to
3218 place this check before the counters are updated, so rejected packets will be
3219 resent by the remote host.
3220
3221 If a policy keeps rejecting the same packet, eventually the connection will
3222 be dropped. Policies have several options if this design causes problems.
3223 For example, one options is to sanitize the mbuf such that it is acceptable,
3224 then accept it. That may require negotiation between policies as the
3225 Framework will not know to re-check the packet.
3226
3227 The policy must handle NULL MBUF labels. This will likely be the case
3228 for non-local TCP sockets for example.
3229
3230 @return Return 0 if access if granted, otherwise an appropriate
3231 value for errno should be returned.
3232 */
3233 typedef int mpo_socket_check_deliver_t(
3234 socket_t so,
3235 struct label *so_label,
3236 struct mbuf *m,
3237 struct label *m_label
3238 );
3239 /**
3240 @brief Access control check for socket kqfilter
3241 @param cred Subject credential
3242 @param kn Object knote
3243 @param so Object socket
3244 @param socklabel Policy label for socket
3245
3246 Determine whether the subject identified by the credential can
3247 receive the knote on the passed socket.
3248
3249 @return Return 0 if access if granted, otherwise an appropriate
3250 value for errno should be returned.
3251 */
3252 typedef int mpo_socket_check_kqfilter_t(
3253 kauth_cred_t cred,
3254 struct knote *kn,
3255 socket_t so,
3256 struct label *socklabel
3257 );
3258 /**
3259 @brief Access control check for socket relabel
3260 @param cred Subject credential
3261 @param so Object socket
3262 @param so_label The current label of so
3263 @param newlabel The label to be assigned to so
3264
3265 Determine whether the subject identified by the credential can
3266 change the label on the socket.
3267
3268 @return Return 0 if access if granted, otherwise an appropriate
3269 value for errno should be returned.
3270 */
3271 typedef int mpo_socket_check_label_update_t(
3272 kauth_cred_t cred,
3273 socket_t so,
3274 struct label *so_label,
3275 struct label *newlabel
3276 );
3277 /**
3278 @brief Access control check for socket listen
3279 @param cred Subject credential
3280 @param so Object socket
3281 @param socklabel Policy label for socket
3282
3283 Determine whether the subject identified by the credential can
3284 listen() on the passed socket.
3285
3286 @return Return 0 if access if granted, otherwise an appropriate
3287 value for errno should be returned.
3288 */
3289 typedef int mpo_socket_check_listen_t(
3290 kauth_cred_t cred,
3291 socket_t so,
3292 struct label *socklabel
3293 );
3294 /**
3295 @brief Access control check for socket receive
3296 @param cred Subject credential
3297 @param so Object socket
3298 @param socklabel Policy label for socket
3299
3300 Determine whether the subject identified by the credential can
3301 receive data from the socket.
3302
3303 @return Return 0 if access if granted, otherwise an appropriate
3304 value for errno should be returned.
3305 */
3306 typedef int mpo_socket_check_receive_t(
3307 kauth_cred_t cred,
3308 socket_t so,
3309 struct label *socklabel
3310 );
3311
3312 /**
3313 @brief Access control check for socket receive
3314 @param cred Subject credential
3315 @param sock Object socket
3316 @param socklabel Policy label for socket
3317 @param saddr Name of the remote socket
3318
3319 Determine whether the subject identified by the credential can
3320 receive data from the remote host specified by addr.
3321
3322 @return Return 0 if access if granted, otherwise an appropriate
3323 value for errno should be returned.
3324 */
3325 typedef int mpo_socket_check_received_t(
3326 kauth_cred_t cred,
3327 struct socket *sock,
3328 struct label *socklabel,
3329 struct sockaddr *saddr
3330 );
3331
3332
3333 /**
3334 @brief Access control check for socket select
3335 @param cred Subject credential
3336 @param so Object socket
3337 @param socklabel Policy label for socket
3338 @param which The operation selected on: FREAD or FWRITE
3339
3340 Determine whether the subject identified by the credential can use the
3341 socket in a call to select().
3342
3343 @return Return 0 if access if granted, otherwise an appropriate
3344 value for errno should be returned.
3345 */
3346 typedef int mpo_socket_check_select_t(
3347 kauth_cred_t cred,
3348 socket_t so,
3349 struct label *socklabel,
3350 int which
3351 );
3352 /**
3353 @brief Access control check for socket send
3354 @param cred Subject credential
3355 @param so Object socket
3356 @param socklabel Policy label for socket
3357 @param addr Address being sent to
3358
3359 Determine whether the subject identified by the credential can send
3360 data to the socket.
3361
3362 @return Return 0 if access if granted, otherwise an appropriate
3363 value for errno should be returned.
3364 */
3365 typedef int mpo_socket_check_send_t(
3366 kauth_cred_t cred,
3367 socket_t so,
3368 struct label *socklabel,
3369 struct sockaddr *addr
3370 );
3371 /**
3372 @brief Access control check for retrieving socket status
3373 @param cred Subject credential
3374 @param so Object socket
3375 @param socklabel Policy label for so
3376
3377 Determine whether the subject identified by the credential can
3378 execute the stat() system call on the given socket.
3379
3380 @return Return 0 if access if granted, otherwise an appropriate
3381 value for errno should be returned.
3382 */
3383 typedef int mpo_socket_check_stat_t(
3384 kauth_cred_t cred,
3385 socket_t so,
3386 struct label *socklabel
3387 );
3388 /**
3389 @brief Access control check for setting socket options
3390 @param cred Subject credential
3391 @param so Object socket
3392 @param socklabel Policy label for so
3393 @param sopt The options being set
3394
3395 Determine whether the subject identified by the credential can
3396 execute the setsockopt system call on the given socket.
3397
3398 @return Return 0 if access if granted, otherwise an appropriate
3399 value for errno should be returned.
3400 */
3401 typedef int mpo_socket_check_setsockopt_t(
3402 kauth_cred_t cred,
3403 socket_t so,
3404 struct label *socklabel,
3405 struct sockopt *sopt
3406 );
3407 /**
3408 @brief Access control check for getting socket options
3409 @param cred Subject credential
3410 @param so Object socket
3411 @param socklabel Policy label for so
3412 @param sopt The options to get
3413
3414 Determine whether the subject identified by the credential can
3415 execute the getsockopt system call on the given socket.
3416
3417 @return Return 0 if access if granted, otherwise an appropriate
3418 value for errno should be returned.
3419 */
3420 typedef int mpo_socket_check_getsockopt_t(
3421 kauth_cred_t cred,
3422 socket_t so,
3423 struct label *socklabel,
3424 struct sockopt *sopt
3425 );
3426 /**
3427 @brief Label a socket
3428 @param oldsock Listening socket
3429 @param oldlabel Policy label associated with oldsock
3430 @param newsock New socket
3431 @param newlabel Policy label associated with newsock
3432
3433 A new socket is created when a connection is accept(2)ed. This
3434 function labels the new socket based on the existing listen(2)ing
3435 socket.
3436 */
3437 typedef void mpo_socket_label_associate_accept_t(
3438 socket_t oldsock,
3439 struct label *oldlabel,
3440 socket_t newsock,
3441 struct label *newlabel
3442 );
3443 /**
3444 @brief Assign a label to a new socket
3445 @param cred Credential of the owning process
3446 @param so The socket being labeled
3447 @param solabel The label
3448 @warning cred can be NULL
3449
3450 Set the label on a newly created socket from the passed subject
3451 credential. This call is made when a socket is created. The
3452 credentials may be null if the socket is being created by the
3453 kernel.
3454 */
3455 typedef void mpo_socket_label_associate_t(
3456 kauth_cred_t cred,
3457 socket_t so,
3458 struct label *solabel
3459 );
3460 /**
3461 @brief Copy a socket label
3462 @param src Source label
3463 @param dest Destination label
3464
3465 Copy the socket label information in src into dest.
3466 */
3467 typedef void mpo_socket_label_copy_t(
3468 struct label *src,
3469 struct label *dest
3470 );
3471 /**
3472 @brief Destroy socket label
3473 @param label The label to be destroyed
3474
3475 Destroy a socket label. Since the object is going out of
3476 scope, policy modules should free any internal storage associated
3477 with the label so that it may be destroyed.
3478 */
3479 typedef void mpo_socket_label_destroy_t(
3480 struct label *label
3481 );
3482 /**
3483 @brief Externalize a socket label
3484 @param label Label to be externalized
3485 @param element_name Name of the label namespace for which labels should be
3486 externalized
3487 @param sb String buffer to be filled with a text representation of label
3488
3489 Produce an externalized socket label based on the label structure passed.
3490 An externalized label consists of a text representation of the label
3491 contents that can be used with userland applications and read by the
3492 user. If element_name does not match a namespace managed by the policy,
3493 simply return 0. Only return nonzero if an error occurs while externalizing
3494 the label data.
3495
3496 @return In the event of an error, an appropriate value for errno
3497 should be returned, otherwise return 0 upon success.
3498 */
3499 typedef int mpo_socket_label_externalize_t(
3500 struct label *label,
3501 char *element_name,
3502 struct sbuf *sb
3503 );
3504 /**
3505 @brief Initialize socket label
3506 @param label New label to initialize
3507 @param waitok Malloc flags
3508
3509 Initialize the label of a newly instantiated socket. The waitok
3510 field may be one of M_WAITOK and M_NOWAIT, and should be employed to
3511 avoid performing a sleeping malloc(9) during this initialization
3512 call. It it not always safe to sleep during this entry point.
3513
3514 @warning Since it is possible for the waitok flags to be set to
3515 M_NOWAIT, the malloc operation may fail.
3516
3517 @return In the event of an error, an appropriate value for errno
3518 should be returned, otherwise return 0 upon success.
3519 */
3520 typedef int mpo_socket_label_init_t(
3521 struct label *label,
3522 int waitok
3523 );
3524 /**
3525 @brief Internalize a socket label
3526 @param label Label to be filled in
3527 @param element_name Name of the label namespace for which the label should
3528 be internalized
3529 @param element_data Text data to be internalized
3530
3531 Produce an internal socket label structure based on externalized label
3532 data in text format.
3533
3534 The policy's internalize entry points will be called only if the
3535 policy has registered interest in the label namespace.
3536
3537 @return In the event of an error, an appropriate value for errno
3538 should be returned, otherwise return 0 upon success.
3539 */
3540 typedef int mpo_socket_label_internalize_t(
3541 struct label *label,
3542 char *element_name,
3543 char *element_data
3544 );
3545 /**
3546 @brief Relabel socket
3547 @param cred Subject credential
3548 @param so Object; socket
3549 @param so_label Current label of the socket
3550 @param newlabel The label to be assigned to so
3551
3552 The subject identified by the credential has previously requested
3553 and was authorized to relabel the socket; this entry point allows
3554 policies to perform the actual label update operation.
3555
3556 @warning XXX This entry point will likely change in future versions.
3557 */
3558 typedef void mpo_socket_label_update_t(
3559 kauth_cred_t cred,
3560 socket_t so,
3561 struct label *so_label,
3562 struct label *newlabel
3563 );
3564 /**
3565 @brief Set the peer label on a socket from mbuf
3566 @param m Mbuf chain received on socket so
3567 @param m_label Label for m
3568 @param so Current label for the socket
3569 @param so_label Policy label to be filled out for the socket
3570
3571 Set the peer label of a socket based on the label of the sender of the
3572 mbuf.
3573
3574 This is called for every TCP/IP packet received. The first call for a given
3575 socket operates on a newly initialized label, and subsequent calls operate
3576 on existing label data.
3577
3578 @warning Because this can affect performance significantly, it has
3579 different sematics than other 'set' operations. Typically, 'set' operations
3580 operate on newly initialzed labels and policies do not need to worry about
3581 clobbering existing values. In this case, it is too inefficient to
3582 initialize and destroy a label every time data is received for the socket.
3583 Instead, it is up to the policies to determine how to replace the label data.
3584 Most policies should be able to replace the data inline.
3585 */
3586 typedef void mpo_socketpeer_label_associate_mbuf_t(
3587 struct mbuf *m,
3588 struct label *m_label,
3589 socket_t so,
3590 struct label *so_label
3591 );
3592 /**
3593 @brief Set the peer label on a socket from socket
3594 @param source Local socket
3595 @param sourcelabel Policy label for source
3596 @param target Peer socket
3597 @param targetlabel Policy label to fill in for target
3598
3599 Set the peer label on a stream UNIX domain socket from the passed
3600 remote socket endpoint. This call will be made when the socket pair
3601 is connected, and will be made for both endpoints.
3602
3603 Note that this call is only made on connection; it is currently not updated
3604 during communication.
3605 */
3606 typedef void mpo_socketpeer_label_associate_socket_t(
3607 socket_t source,
3608 struct label *sourcelabel,
3609 socket_t target,
3610 struct label *targetlabel
3611 );
3612 /**
3613 @brief Destroy socket peer label
3614 @param label The peer label to be destroyed
3615
3616 Destroy a socket peer label. Since the object is going out of
3617 scope, policy modules should free any internal storage associated
3618 with the label so that it may be destroyed.
3619 */
3620 typedef void mpo_socketpeer_label_destroy_t(
3621 struct label *label
3622 );
3623 /**
3624 @brief Externalize a socket peer label
3625 @param label Label to be externalized
3626 @param element_name Name of the label namespace for which labels should be
3627 externalized
3628 @param sb String buffer to be filled with a text representation of label
3629
3630 Produce an externalized socket peer label based on the label structure
3631 passed. An externalized label consists of a text representation of the
3632 label contents that can be used with userland applications and read by the
3633 user. If element_name does not match a namespace managed by the policy,
3634 simply return 0. Only return nonzero if an error occurs while externalizing
3635 the label data.
3636
3637 @return In the event of an error, an appropriate value for errno
3638 should be returned, otherwise return 0 upon success.
3639 */
3640 typedef int mpo_socketpeer_label_externalize_t(
3641 struct label *label,
3642 char *element_name,
3643 struct sbuf *sb
3644 );
3645 /**
3646 @brief Initialize socket peer label
3647 @param label New label to initialize
3648 @param waitok Malloc flags
3649
3650 Initialize the peer label of a newly instantiated socket. The
3651 waitok field may be one of M_WAITOK and M_NOWAIT, and should be
3652 employed to avoid performing a sleeping malloc(9) during this
3653 initialization call. It it not always safe to sleep during this
3654 entry point.
3655
3656 @warning Since it is possible for the waitok flags to be set to
3657 M_NOWAIT, the malloc operation may fail.
3658
3659 @return In the event of an error, an appropriate value for errno
3660 should be returned, otherwise return 0 upon success.
3661 */
3662 typedef int mpo_socketpeer_label_init_t(
3663 struct label *label,
3664 int waitok
3665 );
3666 /**
3667 @brief Access control check for enabling accounting
3668 @param cred Subject credential
3669 @param vp Accounting file
3670 @param vlabel Label associated with vp
3671
3672 Determine whether the subject should be allowed to enable accounting,
3673 based on its label and the label of the accounting log file. See
3674 acct(5) for more information.
3675
3676 As accounting is disabled by passing NULL to the acct(2) system call,
3677 the policy should be prepared for both 'vp' and 'vlabel' to be NULL.
3678
3679 @return Return 0 if access is granted, otherwise an appropriate value for
3680 errno should be returned.
3681 */
3682 typedef int mpo_system_check_acct_t(
3683 kauth_cred_t cred,
3684 struct vnode *vp,
3685 struct label *vlabel
3686 );
3687 /**
3688 @brief Access control check for audit
3689 @param cred Subject credential
3690 @param record Audit record
3691 @param length Audit record length
3692
3693 Determine whether the subject identified by the credential can submit
3694 an audit record for inclusion in the audit log via the audit() system call.
3695
3696 @return Return 0 if access is granted, otherwise an appropriate value for
3697 errno should be returned.
3698 */
3699 typedef int mpo_system_check_audit_t(
3700 kauth_cred_t cred,
3701 void *record,
3702 int length
3703 );
3704 /**
3705 @brief Access control check for controlling audit
3706 @param cred Subject credential
3707 @param vp Audit file
3708 @param vl Label associated with vp
3709
3710 Determine whether the subject should be allowed to enable auditing using
3711 the auditctl() system call, based on its label and the label of the proposed
3712 audit file.
3713
3714 @return Return 0 if access is granted, otherwise an appropriate value for
3715 errno should be returned.
3716 */
3717 typedef int mpo_system_check_auditctl_t(
3718 kauth_cred_t cred,
3719 struct vnode *vp,
3720 struct label *vl
3721 );
3722 /**
3723 @brief Access control check for manipulating auditing
3724 @param cred Subject credential
3725 @param cmd Audit control command
3726
3727 Determine whether the subject identified by the credential can perform
3728 the audit subsystem control operation cmd via the auditon() system call.
3729
3730 @return Return 0 if access is granted, otherwise an appropriate value for
3731 errno should be returned.
3732 */
3733 typedef int mpo_system_check_auditon_t(
3734 kauth_cred_t cred,
3735 int cmd
3736 );
3737 /**
3738 @brief Access control check for using CHUD facilities
3739 @param cred Subject credential
3740
3741 Determine whether the subject identified by the credential can perform
3742 performance-related tasks using the CHUD system call.
3743
3744 @return Return 0 if access is granted, otherwise an appropriate value for
3745 errno should be returned.
3746 */
3747 typedef int mpo_system_check_chud_t(
3748 kauth_cred_t cred
3749 );
3750 /**
3751 @brief Access control check for obtaining the host control port
3752 @param cred Subject credential
3753
3754 Determine whether the subject identified by the credential can
3755 obtain the host control port.
3756
3757 @return Return 0 if access is granted, or non-zero otherwise.
3758 */
3759 typedef int mpo_system_check_host_priv_t(
3760 kauth_cred_t cred
3761 );
3762 /**
3763 @brief Access control check for obtaining system information
3764 @param cred Subject credential
3765 @param info_type A description of the information requested
3766
3767 Determine whether the subject identified by the credential should be
3768 allowed to obtain information about the system.
3769
3770 This is a generic hook that can be used in a variety of situations where
3771 information is being returned that might be considered sensitive.
3772 Rather than adding a new MAC hook for every such interface, this hook can
3773 be called with a string identifying the type of information requested.
3774
3775 @return Return 0 if access is granted, otherwise an appropriate value for
3776 errno should be returned.
3777 */
3778 typedef int mpo_system_check_info_t(
3779 kauth_cred_t cred,
3780 const char *info_type
3781 );
3782 /**
3783 @brief Access control check for calling NFS services
3784 @param cred Subject credential
3785
3786 Determine whether the subject identified by the credential should be
3787 allowed to call nfssrv(2).
3788
3789 @return Return 0 if access is granted, otherwise an appropriate value for
3790 errno should be returned.
3791 */
3792 typedef int mpo_system_check_nfsd_t(
3793 kauth_cred_t cred
3794 );
3795 /**
3796 @brief Access control check for reboot
3797 @param cred Subject credential
3798 @param howto howto parameter from reboot(2)
3799
3800 Determine whether the subject identified by the credential should be
3801 allowed to reboot the system in the specified manner.
3802
3803 @return Return 0 if access is granted, otherwise an appropriate value for
3804 errno should be returned.
3805 */
3806 typedef int mpo_system_check_reboot_t(
3807 kauth_cred_t cred,
3808 int howto
3809 );
3810 /**
3811 @brief Access control check for setting system clock
3812 @param cred Subject credential
3813
3814 Determine whether the subject identified by the credential should be
3815 allowed to set the system clock.
3816
3817 @return Return 0 if access is granted, otherwise an appropriate value for
3818 errno should be returned.
3819 */
3820 typedef int mpo_system_check_settime_t(
3821 kauth_cred_t cred
3822 );
3823 /**
3824 @brief Access control check for removing swap devices
3825 @param cred Subject credential
3826 @param vp Swap device
3827 @param label Label associated with vp
3828
3829 Determine whether the subject identified by the credential should be
3830 allowed to remove vp as a swap device.
3831
3832 @return Return 0 if access is granted, otherwise an appropriate value for
3833 errno should be returned.
3834 */
3835 typedef int mpo_system_check_swapoff_t(
3836 kauth_cred_t cred,
3837 struct vnode *vp,
3838 struct label *label
3839 );
3840 /**
3841 @brief Access control check for adding swap devices
3842 @param cred Subject credential
3843 @param vp Swap device
3844 @param label Label associated with vp
3845
3846 Determine whether the subject identified by the credential should be
3847 allowed to add vp as a swap device.
3848
3849 @return Return 0 if access is granted, otherwise an appropriate value for
3850 errno should be returned.
3851 */
3852 typedef int mpo_system_check_swapon_t(
3853 kauth_cred_t cred,
3854 struct vnode *vp,
3855 struct label *label
3856 );
3857 /**
3858 @brief Access control check for sysctl
3859 @param cred Subject credential
3860 @param namestring String representation of sysctl name.
3861 @param name Integer name; see sysctl(3)
3862 @param namelen Length of name array of integers; see sysctl(3)
3863 @param old 0 or address where to store old value; see sysctl(3)
3864 @param oldlen Length of old buffer; see sysctl(3)
3865 @param newvalue 0 or address of new value; see sysctl(3)
3866 @param newlen Length of new buffer; see sysctl(3)
3867
3868 Determine whether the subject identified by the credential should be
3869 allowed to make the specified sysctl(3) transaction.
3870
3871 The sysctl(3) call specifies that if the old value is not desired,
3872 oldp and oldlenp should be set to NULL. Likewise, if a new value is
3873 not to be set, newp should be set to NULL and newlen set to 0.
3874
3875 @return Return 0 if access is granted, otherwise an appropriate value for
3876 errno should be returned.
3877 */
3878 typedef int mpo_system_check_sysctlbyname_t(
3879 kauth_cred_t cred,
3880 const char *namestring,
3881 int *name,
3882 u_int namelen,
3883 user_addr_t old, /* NULLOK */
3884 size_t oldlen,
3885 user_addr_t newvalue, /* NULLOK */
3886 size_t newlen
3887 );
3888 /**
3889 @brief Access control check for kas_info
3890 @param cred Subject credential
3891 @param selector Category of information to return. See kas_info.h
3892
3893 Determine whether the subject identified by the credential can perform
3894 introspection of the kernel address space layout for
3895 debugging/performance analysis.
3896
3897 @return Return 0 if access is granted, otherwise an appropriate value for
3898 errno should be returned.
3899 */
3900 typedef int mpo_system_check_kas_info_t(
3901 kauth_cred_t cred,
3902 int selector
3903 );
3904 /**
3905 @brief Create a System V message label
3906 @param cred Subject credential
3907 @param msqptr The message queue the message will be placed in
3908 @param msqlabel The label of the message queue
3909 @param msgptr The message
3910 @param msglabel The label of the message
3911
3912 Label the message as its placed in the message queue.
3913 */
3914 typedef void mpo_sysvmsg_label_associate_t(
3915 kauth_cred_t cred,
3916 struct msqid_kernel *msqptr,
3917 struct label *msqlabel,
3918 struct msg *msgptr,
3919 struct label *msglabel
3920 );
3921 /**
3922 @brief Destroy System V message label
3923 @param label The label to be destroyed
3924
3925 Destroy a System V message label. Since the object is
3926 going out of scope, policy modules should free any internal storage
3927 associated with the label so that it may be destroyed.
3928 */
3929 typedef void mpo_sysvmsg_label_destroy_t(
3930 struct label *label
3931 );
3932 /**
3933 @brief Initialize System V message label
3934 @param label New label to initialize
3935
3936 Initialize the label for a newly instantiated System V message.
3937 */
3938 typedef void mpo_sysvmsg_label_init_t(
3939 struct label *label
3940 );
3941 /**
3942 @brief Clean up a System V message label
3943 @param label The label to be destroyed
3944
3945 Clean up a System V message label. Darwin pre-allocates
3946 messages at system boot time and re-uses them rather than
3947 allocating new ones. Before messages are returned to the "free
3948 pool", policies can cleanup or overwrite any information present in
3949 the label.
3950 */
3951 typedef void mpo_sysvmsg_label_recycle_t(
3952 struct label *label
3953 );
3954 /**
3955 @brief Access control check for System V message enqueuing
3956 @param cred Subject credential
3957 @param msgptr The message
3958 @param msglabel The message's label
3959 @param msqptr The message queue
3960 @param msqlabel The message queue's label
3961
3962 Determine whether the subject identified by the credential can add the
3963 given message to the given message queue.
3964
3965 @return Return 0 if access is granted, otherwise an appropriate value for
3966 errno should be returned.
3967 */
3968 typedef int mpo_sysvmsq_check_enqueue_t(
3969 kauth_cred_t cred,
3970 struct msg *msgptr,
3971 struct label *msglabel,
3972 struct msqid_kernel *msqptr,
3973 struct label *msqlabel
3974 );
3975 /**
3976 @brief Access control check for System V message reception
3977 @param cred The credential of the intended recipient
3978 @param msgptr The message
3979 @param msglabel The message's label
3980
3981 Determine whether the subject identified by the credential can receive
3982 the given message.
3983
3984 @return Return 0 if access is granted, otherwise an appropriate value for
3985 errno should be returned.
3986 */
3987 typedef int mpo_sysvmsq_check_msgrcv_t(
3988 kauth_cred_t cred,
3989 struct msg *msgptr,
3990 struct label *msglabel
3991 );
3992 /**
3993 @brief Access control check for System V message queue removal
3994 @param cred The credential of the caller
3995 @param msgptr The message
3996 @param msglabel The message's label
3997
3998 System V message queues are removed using the msgctl() system call.
3999 The system will iterate over each messsage in the queue, calling this
4000 function for each, to determine whether the caller has the appropriate
4001 credentials.
4002
4003 @return Return 0 if access is granted, otherwise an appropriate value for
4004 errno should be returned.
4005 */
4006 typedef int mpo_sysvmsq_check_msgrmid_t(
4007 kauth_cred_t cred,
4008 struct msg *msgptr,
4009 struct label *msglabel
4010 );
4011 /**
4012 @brief Access control check for msgctl()
4013 @param cred The credential of the caller
4014 @param msqptr The message queue
4015 @param msqlabel The message queue's label
4016
4017 This access check is performed to validate calls to msgctl().
4018
4019 @return Return 0 if access is granted, otherwise an appropriate value for
4020 errno should be returned.
4021 */
4022 typedef int mpo_sysvmsq_check_msqctl_t(
4023 kauth_cred_t cred,
4024 struct msqid_kernel *msqptr,
4025 struct label *msqlabel,
4026 int cmd
4027 );
4028 /**
4029 @brief Access control check to get a System V message queue
4030 @param cred The credential of the caller
4031 @param msqptr The message queue requested
4032 @param msqlabel The message queue's label
4033
4034 On a call to msgget(), if the queue requested already exists,
4035 and it is a public queue, this check will be performed before the
4036 queue's ID is returned to the user.
4037
4038 @return Return 0 if access is granted, otherwise an appropriate value for
4039 errno should be returned.
4040 */
4041 typedef int mpo_sysvmsq_check_msqget_t(
4042 kauth_cred_t cred,
4043 struct msqid_kernel *msqptr,
4044 struct label *msqlabel
4045 );
4046 /**
4047 @brief Access control check to receive a System V message from the given queue
4048 @param cred The credential of the caller
4049 @param msqptr The message queue to receive from
4050 @param msqlabel The message queue's label
4051
4052 On a call to msgrcv(), this check is performed to determine whether the
4053 caller has receive rights on the given queue.
4054
4055 @return Return 0 if access is granted, otherwise an appropriate value for
4056 errno should be returned.
4057 */
4058 typedef int mpo_sysvmsq_check_msqrcv_t(
4059 kauth_cred_t cred,
4060 struct msqid_kernel *msqptr,
4061 struct label *msqlabel
4062 );
4063 /**
4064 @brief Access control check to send a System V message to the given queue
4065 @param cred The credential of the caller
4066 @param msqptr The message queue to send to
4067 @param msqlabel The message queue's label
4068
4069 On a call to msgsnd(), this check is performed to determine whether the
4070 caller has send rights on the given queue.
4071
4072 @return Return 0 if access is granted, otherwise an appropriate value for
4073 errno should be returned.
4074 */
4075 typedef int mpo_sysvmsq_check_msqsnd_t(
4076 kauth_cred_t cred,
4077 struct msqid_kernel *msqptr,
4078 struct label *msqlabel
4079 );
4080 /**
4081 @brief Create a System V message queue label
4082 @param cred Subject credential
4083 @param msqptr The message queue
4084 @param msqlabel The label of the message queue
4085
4086 */
4087 typedef void mpo_sysvmsq_label_associate_t(
4088 kauth_cred_t cred,
4089 struct msqid_kernel *msqptr,
4090 struct label *msqlabel
4091 );
4092 /**
4093 @brief Destroy System V message queue label
4094 @param label The label to be destroyed
4095
4096 Destroy a System V message queue label. Since the object is
4097 going out of scope, policy modules should free any internal storage
4098 associated with the label so that it may be destroyed.
4099 */
4100 typedef void mpo_sysvmsq_label_destroy_t(
4101 struct label *label
4102 );
4103 /**
4104 @brief Initialize System V message queue label
4105 @param label New label to initialize
4106
4107 Initialize the label for a newly instantiated System V message queue.
4108 */
4109 typedef void mpo_sysvmsq_label_init_t(
4110 struct label *label
4111 );
4112 /**
4113 @brief Clean up a System V message queue label
4114 @param label The label to be destroyed
4115
4116 Clean up a System V message queue label. Darwin pre-allocates
4117 message queues at system boot time and re-uses them rather than
4118 allocating new ones. Before message queues are returned to the "free
4119 pool", policies can cleanup or overwrite any information present in
4120 the label.
4121 */
4122 typedef void mpo_sysvmsq_label_recycle_t(
4123 struct label *label
4124 );
4125 /**
4126 @brief Access control check for System V semaphore control operation
4127 @param cred Subject credential
4128 @param semakptr Pointer to semaphore identifier
4129 @param semaklabel Label associated with semaphore
4130 @param cmd Control operation to be performed; see semctl(2)
4131
4132 Determine whether the subject identified by the credential can perform
4133 the operation indicated by cmd on the System V semaphore semakptr.
4134
4135 @return Return 0 if access is granted, otherwise an appropriate value for
4136 errno should be returned.
4137 */
4138 typedef int mpo_sysvsem_check_semctl_t(
4139 kauth_cred_t cred,
4140 struct semid_kernel *semakptr,
4141 struct label *semaklabel,
4142 int cmd
4143 );
4144 /**
4145 @brief Access control check for obtaining a System V semaphore
4146 @param cred Subject credential
4147 @param semakptr Pointer to semaphore identifier
4148 @param semaklabel Label to associate with the semaphore
4149
4150 Determine whether the subject identified by the credential can
4151 obtain a System V semaphore.
4152
4153 @return Return 0 if access is granted, otherwise an appropriate value for
4154 errno should be returned.
4155 */
4156 typedef int mpo_sysvsem_check_semget_t(
4157 kauth_cred_t cred,
4158 struct semid_kernel *semakptr,
4159 struct label *semaklabel
4160 );
4161 /**
4162 @brief Access control check for System V semaphore operations
4163 @param cred Subject credential
4164 @param semakptr Pointer to semaphore identifier
4165 @param semaklabel Label associated with the semaphore
4166 @param accesstype Flags to indicate access (read and/or write)
4167
4168 Determine whether the subject identified by the credential can
4169 perform the operations on the System V semaphore indicated by
4170 semakptr. The accesstype flags hold the maximum set of permissions
4171 from the sem_op array passed to the semop system call. It may
4172 contain SEM_R for read-only operations or SEM_A for read/write
4173 operations.
4174
4175 @return Return 0 if access is granted, otherwise an appropriate value for
4176 errno should be returned.
4177 */
4178 typedef int mpo_sysvsem_check_semop_t(
4179 kauth_cred_t cred,
4180 struct semid_kernel *semakptr,
4181 struct label *semaklabel,
4182 size_t accesstype
4183 );
4184 /**
4185 @brief Create a System V semaphore label
4186 @param cred Subject credential
4187 @param semakptr The semaphore being created
4188 @param semalabel Label to associate with the new semaphore
4189
4190 Label a new System V semaphore. The label was previously
4191 initialized and associated with the semaphore. At this time, an
4192 appropriate initial label value should be assigned to the object and
4193 stored in semalabel.
4194 */
4195 typedef void mpo_sysvsem_label_associate_t(
4196 kauth_cred_t cred,
4197 struct semid_kernel *semakptr,
4198 struct label *semalabel
4199 );
4200 /**
4201 @brief Destroy System V semaphore label
4202 @param label The label to be destroyed
4203
4204 Destroy a System V semaphore label. Since the object is
4205 going out of scope, policy modules should free any internal storage
4206 associated with the label so that it may be destroyed.
4207 */
4208 typedef void mpo_sysvsem_label_destroy_t(
4209 struct label *label
4210 );
4211 /**
4212 @brief Initialize System V semaphore label
4213 @param label New label to initialize
4214
4215 Initialize the label for a newly instantiated System V semaphore. Sleeping
4216 is permitted.
4217 */
4218 typedef void mpo_sysvsem_label_init_t(
4219 struct label *label
4220 );
4221 /**
4222 @brief Clean up a System V semaphore label
4223 @param label The label to be cleaned
4224
4225 Clean up a System V semaphore label. Darwin pre-allocates
4226 semaphores at system boot time and re-uses them rather than
4227 allocating new ones. Before semaphores are returned to the "free
4228 pool", policies can cleanup or overwrite any information present in
4229 the label.
4230 */
4231 typedef void mpo_sysvsem_label_recycle_t(
4232 struct label *label
4233 );
4234 /**
4235 @brief Access control check for mapping System V shared memory
4236 @param cred Subject credential
4237 @param shmsegptr Pointer to shared memory segment identifier
4238 @param shmseglabel Label associated with the shared memory segment
4239 @param shmflg shmat flags; see shmat(2)
4240
4241 Determine whether the subject identified by the credential can map
4242 the System V shared memory segment associated with shmsegptr.
4243
4244 @return Return 0 if access is granted, otherwise an appropriate value for
4245 errno should be returned.
4246 */
4247 typedef int mpo_sysvshm_check_shmat_t(
4248 kauth_cred_t cred,
4249 struct shmid_kernel *shmsegptr,
4250 struct label *shmseglabel,
4251 int shmflg
4252 );
4253 /**
4254 @brief Access control check for System V shared memory control operation
4255 @param cred Subject credential
4256 @param shmsegptr Pointer to shared memory segment identifier
4257 @param shmseglabel Label associated with the shared memory segment
4258 @param cmd Control operation to be performed; see shmctl(2)
4259
4260 Determine whether the subject identified by the credential can perform
4261 the operation indicated by cmd on the System V shared memory segment
4262 shmsegptr.
4263
4264 @return Return 0 if access is granted, otherwise an appropriate value for
4265 errno should be returned.
4266 */
4267 typedef int mpo_sysvshm_check_shmctl_t(
4268 kauth_cred_t cred,
4269 struct shmid_kernel *shmsegptr,
4270 struct label *shmseglabel,
4271 int cmd
4272 );
4273 /**
4274 @brief Access control check for unmapping System V shared memory
4275 @param cred Subject credential
4276 @param shmsegptr Pointer to shared memory segment identifier
4277 @param shmseglabel Label associated with the shared memory segment
4278
4279 Determine whether the subject identified by the credential can unmap
4280 the System V shared memory segment associated with shmsegptr.
4281
4282 @return Return 0 if access is granted, otherwise an appropriate value for
4283 errno should be returned.
4284 */
4285 typedef int mpo_sysvshm_check_shmdt_t(
4286 kauth_cred_t cred,
4287 struct shmid_kernel *shmsegptr,
4288 struct label *shmseglabel
4289 );
4290 /**
4291 @brief Access control check obtaining System V shared memory identifier
4292 @param cred Subject credential
4293 @param shmsegptr Pointer to shared memory segment identifier
4294 @param shmseglabel Label associated with the shared memory segment
4295 @param shmflg shmget flags; see shmget(2)
4296
4297 Determine whether the subject identified by the credential can get
4298 the System V shared memory segment address.
4299
4300 @return Return 0 if access is granted, otherwise an appropriate value for
4301 errno should be returned.
4302 */
4303 typedef int mpo_sysvshm_check_shmget_t(
4304 kauth_cred_t cred,
4305 struct shmid_kernel *shmsegptr,
4306 struct label *shmseglabel,
4307 int shmflg
4308 );
4309 /**
4310 @brief Create a System V shared memory region label
4311 @param cred Subject credential
4312 @param shmsegptr The shared memory region being created
4313 @param shmlabel Label to associate with the new shared memory region
4314
4315 Label a new System V shared memory region. The label was previously
4316 initialized and associated with the shared memory region. At this
4317 time, an appropriate initial label value should be assigned to the
4318 object and stored in shmlabel.
4319 */
4320 typedef void mpo_sysvshm_label_associate_t(
4321 kauth_cred_t cred,
4322 struct shmid_kernel *shmsegptr,
4323 struct label *shmlabel
4324 );
4325 /**
4326 @brief Destroy System V shared memory label
4327 @param label The label to be destroyed
4328
4329 Destroy a System V shared memory region label. Since the
4330 object is going out of scope, policy modules should free any
4331 internal storage associated with the label so that it may be
4332 destroyed.
4333 */
4334 typedef void mpo_sysvshm_label_destroy_t(
4335 struct label *label
4336 );
4337 /**
4338 @brief Initialize System V Shared Memory region label
4339 @param label New label to initialize
4340
4341 Initialize the label for a newly instantiated System V Shared Memory
4342 region. Sleeping is permitted.
4343 */
4344 typedef void mpo_sysvshm_label_init_t(
4345 struct label *label
4346 );
4347 /**
4348 @brief Clean up a System V Share Memory Region label
4349 @param shmlabel The label to be cleaned
4350
4351 Clean up a System V Shared Memory Region label. Darwin
4352 pre-allocates these objects at system boot time and re-uses them
4353 rather than allocating new ones. Before the memory regions are
4354 returned to the "free pool", policies can cleanup or overwrite any
4355 information present in the label.
4356 */
4357 typedef void mpo_sysvshm_label_recycle_t(
4358 struct label *shmlabel
4359 );
4360 /**
4361 @brief Access control check for getting a process's task name
4362 @param cred Subject credential
4363 @param p Object process
4364
4365 Determine whether the subject identified by the credential can get
4366 the passed process's task name port.
4367 This call is used by the task_name_for_pid(2) API.
4368
4369 @return Return 0 if access is granted, otherwise an appropriate value for
4370 errno should be returned. Suggested failure: EACCES for label mismatch,
4371 EPERM for lack of privilege, or ESRCH to hide visibility of the target.
4372 */
4373 typedef int mpo_proc_check_get_task_name_t(
4374 kauth_cred_t cred,
4375 struct proc *p
4376 );
4377 /**
4378 @brief Access control check for getting a process's task port
4379 @param cred Subject credential
4380 @param p Object process
4381
4382 Determine whether the subject identified by the credential can get
4383 the passed process's task control port.
4384 This call is used by the task_for_pid(2) API.
4385
4386 @return Return 0 if access is granted, otherwise an appropriate value for
4387 errno should be returned. Suggested failure: EACCES for label mismatch,
4388 EPERM for lack of privilege, or ESRCH to hide visibility of the target.
4389 */
4390 typedef int mpo_proc_check_get_task_t(
4391 kauth_cred_t cred,
4392 struct proc *p
4393 );
4394
4395 /**
4396 @brief Access control check for exposing a process's task port
4397 @param cred Subject credential
4398 @param p Object process
4399
4400 Determine whether the subject identified by the credential can expose
4401 the passed process's task control port.
4402 This call is used by the accessor APIs like processor_set_tasks() and
4403 processor_set_threads().
4404
4405 @return Return 0 if access is granted, otherwise an appropriate value for
4406 errno should be returned. Suggested failure: EACCES for label mismatch,
4407 EPERM for lack of privilege, or ESRCH to hide visibility of the target.
4408 */
4409 typedef int mpo_proc_check_expose_task_t(
4410 kauth_cred_t cred,
4411 struct proc *p
4412 );
4413
4414 /**
4415 @brief Check whether task's IPC may inherit across process exec
4416 @param p current process instance
4417 @param cur_vp vnode pointer to current instance
4418 @param cur_offset offset of binary of currently executing image
4419 @param img_vp vnode pointer to to be exec'ed image
4420 @param img_offset offset into file which is selected for execution
4421 @param scriptvp vnode pointer of script file if any.
4422 @return Return 0 if access is granted.
4423 EPERM if parent does not have any entitlements.
4424 EACCESS if mismatch in entitlements
4425 */
4426 typedef int mpo_proc_check_inherit_ipc_ports_t(
4427 struct proc *p,
4428 struct vnode *cur_vp,
4429 off_t cur_offset,
4430 struct vnode *img_vp,
4431 off_t img_offset,
4432 struct vnode *scriptvp
4433 );
4434
4435 /**
4436 @brief Privilege check for a process to run invalid
4437 @param p Object process
4438
4439 Determine whether the process may execute even though the system determined
4440 that it is untrusted (eg unidentified / modified code).
4441
4442 @return Return 0 if access is granted, otherwise an appropriate value for
4443 errno should be returned.
4444 */
4445 typedef int mpo_proc_check_run_cs_invalid_t(
4446 struct proc *p
4447 );
4448
4449 /**
4450 @brief Perform MAC-related events when a thread returns to user space
4451 @param thread Mach (not BSD) thread that is returning
4452
4453 This entry point permits policy modules to perform MAC-related
4454 events when a thread returns to user space, via a system call
4455 return or trap return.
4456 */
4457 typedef void mpo_thread_userret_t(
4458 struct thread *thread
4459 );
4460
4461 /**
4462 @brief Check vnode access
4463 @param cred Subject credential
4464 @param vp Object vnode
4465 @param label Label for vp
4466 @param acc_mode access(2) flags
4467
4468 Determine how invocations of access(2) and related calls by the
4469 subject identified by the credential should return when performed
4470 on the passed vnode using the passed access flags. This should
4471 generally be implemented using the same semantics used in
4472 mpo_vnode_check_open.
4473
4474 @return Return 0 if access is granted, otherwise an appropriate value for
4475 errno should be returned. Suggested failure: EACCES for label mismatch or
4476 EPERM for lack of privilege.
4477 */
4478 typedef int mpo_vnode_check_access_t(
4479 kauth_cred_t cred,
4480 struct vnode *vp,
4481 struct label *label,
4482 int acc_mode
4483 );
4484 /**
4485 @brief Access control check for changing working directory
4486 @param cred Subject credential
4487 @param dvp Object; vnode to chdir(2) into
4488 @param dlabel Policy label for dvp
4489
4490 Determine whether the subject identified by the credential can change
4491 the process working directory to the passed vnode.
4492
4493 @return Return 0 if access is granted, otherwise an appropriate value for
4494 errno should be returned. Suggested failure: EACCES for label mismatch or
4495 EPERM for lack of privilege.
4496 */
4497 typedef int mpo_vnode_check_chdir_t(
4498 kauth_cred_t cred,
4499 struct vnode *dvp,
4500 struct label *dlabel
4501 );
4502 /**
4503 @brief Access control check for changing root directory
4504 @param cred Subject credential
4505 @param dvp Directory vnode
4506 @param dlabel Policy label associated with dvp
4507 @param cnp Component name for dvp
4508
4509 Determine whether the subject identified by the credential should be
4510 allowed to chroot(2) into the specified directory (dvp).
4511
4512 @return In the event of an error, an appropriate value for errno
4513 should be returned, otherwise return 0 upon success.
4514 */
4515 typedef int mpo_vnode_check_chroot_t(
4516 kauth_cred_t cred,
4517 struct vnode *dvp,
4518 struct label *dlabel,
4519 struct componentname *cnp
4520 );
4521 /**
4522 @brief Access control check for creating clone
4523 @param cred Subject credential
4524 @param dvp Vnode of directory to create the clone in
4525 @param dlabel Policy label associated with dvp
4526 @param vp Vnode of the file to clone from
4527 @param label Policy label associated with vp
4528 @param cnp Component name for the clone being created
4529
4530 Determine whether the subject identified by the credential should be
4531 allowed to create a clone of the vnode vp with the name specified by cnp.
4532
4533 @return Return 0 if access is granted, otherwise an appropriate value for
4534 errno should be returned.
4535 */
4536 typedef int mpo_vnode_check_clone_t(
4537 kauth_cred_t cred,
4538 struct vnode *dvp,
4539 struct label *dlabel,
4540 struct vnode *vp,
4541 struct label *label,
4542 struct componentname *cnp
4543 );
4544 /**
4545 @brief Access control check for creating vnode
4546 @param cred Subject credential
4547 @param dvp Directory vnode
4548 @param dlabel Policy label for dvp
4549 @param cnp Component name for dvp
4550 @param vap vnode attributes for vap
4551
4552 Determine whether the subject identified by the credential can create
4553 a vnode with the passed parent directory, passed name information,
4554 and passed attribute information. This call may be made in a number of
4555 situations, including as a result of calls to open(2) with O_CREAT,
4556 mknod(2), mkfifo(2), and others.
4557
4558 @return Return 0 if access is granted, otherwise an appropriate value for
4559 errno should be returned. Suggested failure: EACCES for label mismatch or
4560 EPERM for lack of privilege.
4561 */
4562 typedef int mpo_vnode_check_create_t(
4563 kauth_cred_t cred,
4564 struct vnode *dvp,
4565 struct label *dlabel,
4566 struct componentname *cnp,
4567 struct vnode_attr *vap
4568 );
4569 /**
4570 @brief Access control check for deleting extended attribute
4571 @param cred Subject credential
4572 @param vp Object vnode
4573 @param vlabel Label associated with vp
4574 @param name Extended attribute name
4575
4576 Determine whether the subject identified by the credential can delete
4577 the extended attribute from the passed vnode.
4578
4579 @return Return 0 if access is granted, otherwise an appropriate value for
4580 errno should be returned. Suggested failure: EACCES for label mismatch or
4581 EPERM for lack of privilege.
4582 */
4583 typedef int mpo_vnode_check_deleteextattr_t(
4584 kauth_cred_t cred,
4585 struct vnode *vp,
4586 struct label *vlabel,
4587 const char *name
4588 );
4589 /**
4590 @brief Access control check for exchanging file data
4591 @param cred Subject credential
4592 @param v1 vnode 1 to swap
4593 @param vl1 Policy label for v1
4594 @param v2 vnode 2 to swap
4595 @param vl2 Policy label for v2
4596
4597 Determine whether the subject identified by the credential can swap the data
4598 in the two supplied vnodes.
4599
4600 @return Return 0 if access is granted, otherwise an appropriate value for
4601 errno should be returned. Suggested failure: EACCES for label mismatch or
4602 EPERM for lack of privilege.
4603 */
4604 typedef int mpo_vnode_check_exchangedata_t(
4605 kauth_cred_t cred,
4606 struct vnode *v1,
4607 struct label *vl1,
4608 struct vnode *v2,
4609 struct label *vl2
4610 );
4611 /**
4612 @brief Access control check for executing the vnode
4613 @param cred Subject credential
4614 @param vp Object vnode to execute
4615 @param scriptvp Script being executed by interpreter, if any.
4616 @param vnodelabel Label corresponding to vp
4617 @param scriptlabel Script vnode label
4618 @param execlabel Userspace provided execution label
4619 @param cnp Component name for file being executed
4620 @param macpolicyattr MAC policy-specific spawn attribute data.
4621 @param macpolicyattrlen Length of policy-specific spawn attribute data.
4622
4623 Determine whether the subject identified by the credential can execute
4624 the passed vnode. Determination of execute privilege is made separately
4625 from decisions about any process label transitioning event.
4626
4627 The final label, execlabel, corresponds to a label supplied by a
4628 user space application through the use of the mac_execve system call.
4629 This label will be NULL if the user application uses the the vendor
4630 execve(2) call instead of the MAC Framework mac_execve() call.
4631
4632 @return Return 0 if access is granted, otherwise an appropriate value for
4633 errno should be returned. Suggested failure: EACCES for label mismatch or
4634 EPERM for lack of privilege.
4635 */
4636 typedef int mpo_vnode_check_exec_t(
4637 kauth_cred_t cred,
4638 struct vnode *vp,
4639 struct vnode *scriptvp,
4640 struct label *vnodelabel,
4641 struct label *scriptlabel,
4642 struct label *execlabel, /* NULLOK */
4643 struct componentname *cnp,
4644 u_int *csflags,
4645 void *macpolicyattr,
4646 size_t macpolicyattrlen
4647 );
4648 /**
4649 @brief Access control check for fsgetpath
4650 @param cred Subject credential
4651 @param vp Vnode for which a path will be returned
4652 @param label Label associated with the vnode
4653
4654 Determine whether the subject identified by the credential can get the path
4655 of the given vnode with fsgetpath.
4656
4657 @return Return 0 if access is granted, otherwise an appropriate value for
4658 errno should be returned.
4659 */
4660 typedef int mpo_vnode_check_fsgetpath_t(
4661 kauth_cred_t cred,
4662 struct vnode *vp,
4663 struct label *label
4664 );
4665 /**
4666 @brief Access control check for retrieving file attributes
4667 @param active_cred Subject credential
4668 @param file_cred Credential associated with the struct fileproc
4669 @param vp Object vnode
4670 @param vlabel Policy label for vp
4671 @param va Vnode attributes to retrieve
4672
4673 Determine whether the subject identified by the credential can
4674 get information about the passed vnode. The active_cred hold
4675 the credentials of the subject performing the operation, and
4676 file_cred holds the credentials of the subject that originally
4677 opened the file. This check happens during stat(), lstat(),
4678 fstat(), and getattrlist() syscalls. See <sys/vnode.h> for
4679 definitions of the attributes.
4680
4681 @return Return 0 if access is granted, otherwise an appropriate value for
4682 errno should be returned.
4683
4684 @note Policies may change the contents of va to alter the list of
4685 file attributes returned.
4686 */
4687 typedef int mpo_vnode_check_getattr_t(
4688 kauth_cred_t active_cred,
4689 kauth_cred_t file_cred, /* NULLOK */
4690 struct vnode *vp,
4691 struct label *vlabel,
4692 struct vnode_attr *va
4693 );
4694 /**
4695 @brief Access control check for retrieving file attributes
4696 @param cred Subject credential
4697 @param vp Object vnode
4698 @param vlabel Policy label for vp
4699 @param alist List of attributes to retrieve
4700
4701 Determine whether the subject identified by the credential can read
4702 various attributes of the specified vnode, or the filesystem or volume on
4703 which that vnode resides. See <sys/attr.h> for definitions of the
4704 attributes.
4705
4706 @return Return 0 if access is granted, otherwise an appropriate value for
4707 errno should be returned. Suggested failure: EACCES for label mismatch or
4708 EPERM for lack of privilege. Access control covers all attributes requested
4709 with this call; the security policy is not permitted to change the set of
4710 attributes requested.
4711 */
4712 typedef int mpo_vnode_check_getattrlist_t(
4713 kauth_cred_t cred,
4714 struct vnode *vp,
4715 struct label *vlabel,
4716 struct attrlist *alist
4717 );
4718 /**
4719 @brief Access control check for retrieving an extended attribute
4720 @param cred Subject credential
4721 @param vp Object vnode
4722 @param label Policy label for vp
4723 @param name Extended attribute name
4724 @param uio I/O structure pointer
4725
4726 Determine whether the subject identified by the credential can retrieve
4727 the extended attribute from the passed vnode. The uio parameter
4728 will be NULL when the getxattr(2) call has been made with a NULL data
4729 value; this is done to request the size of the data only.
4730
4731 @return Return 0 if access is granted, otherwise an appropriate value for
4732 errno should be returned. Suggested failure: EACCES for label mismatch or
4733 EPERM for lack of privilege.
4734 */
4735 typedef int mpo_vnode_check_getextattr_t(
4736 kauth_cred_t cred,
4737 struct vnode *vp,
4738 struct label *label, /* NULLOK */
4739 const char *name,
4740 struct uio *uio /* NULLOK */
4741 );
4742 /**
4743 @brief Access control check for ioctl
4744 @param cred Subject credential
4745 @param vp Object vnode
4746 @param label Policy label for vp
4747 @param cmd Device-dependent request code; see ioctl(2)
4748
4749 Determine whether the subject identified by the credential can perform
4750 the ioctl operation indicated by com.
4751
4752 @warning Since ioctl data is opaque from the standpoint of the MAC
4753 framework, and since ioctls can affect many aspects of system
4754 operation, policies must exercise extreme care when implementing
4755 access control checks.
4756
4757 @return Return 0 if access is granted, otherwise an appropriate value for
4758 errno should be returned.
4759 */
4760 typedef int mpo_vnode_check_ioctl_t(
4761 kauth_cred_t cred,
4762 struct vnode *vp,
4763 struct label *label,
4764 unsigned int cmd
4765 );
4766 /**
4767 @brief Access control check for vnode kqfilter
4768 @param active_cred Subject credential
4769 @param kn Object knote
4770 @param vp Object vnode
4771 @param label Policy label for vp
4772
4773 Determine whether the subject identified by the credential can
4774 receive the knote on the passed vnode.
4775
4776 @return Return 0 if access if granted, otherwise an appropriate
4777 value for errno should be returned.
4778 */
4779 typedef int mpo_vnode_check_kqfilter_t(
4780 kauth_cred_t active_cred,
4781 kauth_cred_t file_cred, /* NULLOK */
4782 struct knote *kn,
4783 struct vnode *vp,
4784 struct label *label
4785 );
4786 /**
4787 @brief Access control check for relabel
4788 @param cred Subject credential
4789 @param vp Object vnode
4790 @param vnodelabel Existing policy label for vp
4791 @param newlabel Policy label update to later be applied to vp
4792 @see mpo_relable_vnode_t
4793
4794 Determine whether the subject identified by the credential can relabel
4795 the passed vnode to the passed label update. If all policies permit
4796 the label change, the actual relabel entry point (mpo_vnode_label_update)
4797 will follow.
4798
4799 @return Return 0 if access is granted, otherwise an appropriate value for
4800 errno should be returned.
4801 */
4802 typedef int mpo_vnode_check_label_update_t(
4803 struct ucred *cred,
4804 struct vnode *vp,
4805 struct label *vnodelabel,
4806 struct label *newlabel
4807 );
4808 /**
4809 @brief Access control check for creating link
4810 @param cred Subject credential
4811 @param dvp Directory vnode
4812 @param dlabel Policy label associated with dvp
4813 @param vp Link destination vnode
4814 @param label Policy label associated with vp
4815 @param cnp Component name for the link being created
4816
4817 Determine whether the subject identified by the credential should be
4818 allowed to create a link to the vnode vp with the name specified by cnp.
4819
4820 @return Return 0 if access is granted, otherwise an appropriate value for
4821 errno should be returned.
4822 */
4823 typedef int mpo_vnode_check_link_t(
4824 kauth_cred_t cred,
4825 struct vnode *dvp,
4826 struct label *dlabel,
4827 struct vnode *vp,
4828 struct label *label,
4829 struct componentname *cnp
4830 );
4831 /**
4832 @brief Access control check for listing extended attributes
4833 @param cred Subject credential
4834 @param vp Object vnode
4835 @param vlabel Policy label associated with vp
4836
4837 Determine whether the subject identified by the credential can retrieve
4838 a list of named extended attributes from a vnode.
4839
4840 @return Return 0 if access is granted, otherwise an appropriate value for
4841 errno should be returned.
4842 */
4843 typedef int mpo_vnode_check_listextattr_t(
4844 kauth_cred_t cred,
4845 struct vnode *vp,
4846 struct label *vlabel
4847 );
4848 /**
4849 @brief Access control check for lookup
4850 @param cred Subject credential
4851 @param dvp Object vnode
4852 @param dlabel Policy label for dvp
4853 @param cnp Component name being looked up
4854
4855 Determine whether the subject identified by the credential can perform
4856 a lookup in the passed directory vnode for the passed name (cnp).
4857
4858 @return Return 0 if access is granted, otherwise an appropriate value for
4859 errno should be returned. Suggested failure: EACCES for label mismatch or
4860 EPERM for lack of privilege.
4861 */
4862 typedef int mpo_vnode_check_lookup_t(
4863 kauth_cred_t cred,
4864 struct vnode *dvp,
4865 struct label *dlabel,
4866 struct componentname *cnp
4867 );
4868 /**
4869 @brief Access control check for open
4870 @param cred Subject credential
4871 @param vp Object vnode
4872 @param label Policy label associated with vp
4873 @param acc_mode open(2) access mode
4874
4875 Determine whether the subject identified by the credential can perform
4876 an open operation on the passed vnode with the passed access mode.
4877
4878 @return Return 0 if access is granted, otherwise an appropriate value for
4879 errno should be returned. Suggested failure: EACCES for label mismatch or
4880 EPERM for lack of privilege.
4881 */
4882 typedef int mpo_vnode_check_open_t(
4883 kauth_cred_t cred,
4884 struct vnode *vp,
4885 struct label *label,
4886 int acc_mode
4887 );
4888 /**
4889 @brief Access control check for read
4890 @param active_cred Subject credential
4891 @param file_cred Credential associated with the struct fileproc
4892 @param vp Object vnode
4893 @param label Policy label for vp
4894
4895 Determine whether the subject identified by the credential can perform
4896 a read operation on the passed vnode. The active_cred hold the credentials
4897 of the subject performing the operation, and file_cred holds the
4898 credentials of the subject that originally opened the file.
4899
4900 @return Return 0 if access is granted, otherwise an appropriate value for
4901 errno should be returned. Suggested failure: EACCES for label mismatch or
4902 EPERM for lack of privilege.
4903 */
4904 typedef int mpo_vnode_check_read_t(
4905 kauth_cred_t active_cred, /* SUBJECT */
4906 kauth_cred_t file_cred, /* NULLOK */
4907 struct vnode *vp, /* OBJECT */
4908 struct label *label /* LABEL */
4909 );
4910 /**
4911 @brief Access control check for read directory
4912 @param cred Subject credential
4913 @param dvp Object directory vnode
4914 @param dlabel Policy label for dvp
4915
4916 Determine whether the subject identified by the credential can
4917 perform a readdir operation on the passed directory vnode.
4918
4919 @return Return 0 if access is granted, otherwise an appropriate value for
4920 errno should be returned. Suggested failure: EACCES for label mismatch or
4921 EPERM for lack of privilege.
4922 */
4923 typedef int mpo_vnode_check_readdir_t(
4924 kauth_cred_t cred, /* SUBJECT */
4925 struct vnode *dvp, /* OBJECT */
4926 struct label *dlabel /* LABEL */
4927 );
4928 /**
4929 @brief Access control check for read link
4930 @param cred Subject credential
4931 @param vp Object vnode
4932 @param label Policy label for vp
4933
4934 Determine whether the subject identified by the credential can perform
4935 a readlink operation on the passed symlink vnode. This call can be made
4936 in a number of situations, including an explicit readlink call by the
4937 user process, or as a result of an implicit readlink during a name
4938 lookup by the process.
4939
4940 @return Return 0 if access is granted, otherwise an appropriate value for
4941 errno should be returned. Suggested failure: EACCES for label mismatch or
4942 EPERM for lack of privilege.
4943 */
4944 typedef int mpo_vnode_check_readlink_t(
4945 kauth_cred_t cred,
4946 struct vnode *vp,
4947 struct label *label
4948 );
4949 /**
4950 @brief Access control check for rename
4951 @param cred Subject credential
4952 @param dvp Directory vnode
4953 @param dlabel Policy label associated with dvp
4954 @param vp vnode to be renamed
4955 @param label Policy label associated with vp
4956 @param cnp Component name for vp
4957 @param tdvp Destination directory vnode
4958 @param tdlabel Policy label associated with tdvp
4959 @param tvp Overwritten vnode
4960 @param tlabel Policy label associated with tvp
4961 @param tcnp Destination component name
4962
4963 Determine whether the subject identified by the credential should be allowed
4964 to rename the vnode vp to something else.
4965
4966 @return Return 0 if access is granted, otherwise an appropriate value for
4967 errno should be returned.
4968 */
4969 typedef int mpo_vnode_check_rename_t(
4970 kauth_cred_t cred,
4971 struct vnode *dvp,
4972 struct label *dlabel,
4973 struct vnode *vp,
4974 struct label *label,
4975 struct componentname *cnp,
4976 struct vnode *tdvp,
4977 struct label *tdlabel,
4978 struct vnode *tvp,
4979 struct label *tlabel,
4980 struct componentname *tcnp
4981 );
4982 /**
4983 @brief Access control check for rename from
4984 @param cred Subject credential
4985 @param dvp Directory vnode
4986 @param dlabel Policy label associated with dvp
4987 @param vp vnode to be renamed
4988 @param label Policy label associated with vp
4989 @param cnp Component name for vp
4990 @see mpo_vnode_check_rename_t
4991 @see mpo_vnode_check_rename_to_t
4992
4993 Determine whether the subject identified by the credential should be
4994 allowed to rename the vnode vp to something else.
4995
4996 Due to VFS locking constraints (to make sure proper vnode locks are
4997 held during this entry point), the vnode relabel checks had to be
4998 split into two parts: relabel_from and relabel to.
4999
5000 This hook is deprecated, mpo_vnode_check_rename_t should be used instead.
5001
5002 @return Return 0 if access is granted, otherwise an appropriate value for
5003 errno should be returned.
5004 */
5005 typedef int mpo_vnode_check_rename_from_t(
5006 kauth_cred_t cred,
5007 struct vnode *dvp,
5008 struct label *dlabel,
5009 struct vnode *vp,
5010 struct label *label,
5011 struct componentname *cnp
5012 );
5013 /**
5014 @brief Access control check for rename to
5015 @param cred Subject credential
5016 @param dvp Directory vnode
5017 @param dlabel Policy label associated with dvp
5018 @param vp Overwritten vnode
5019 @param label Policy label associated with vp
5020 @param samedir Boolean; 1 if the source and destination directories are the same
5021 @param cnp Destination component name
5022 @see mpo_vnode_check_rename_t
5023 @see mpo_vnode_check_rename_from_t
5024
5025 Determine whether the subject identified by the credential should be
5026 allowed to rename to the vnode vp, into the directory dvp, or to the
5027 name represented by cnp. If there is no existing file to overwrite,
5028 vp and label will be NULL.
5029
5030 Due to VFS locking constraints (to make sure proper vnode locks are
5031 held during this entry point), the vnode relabel checks had to be
5032 split into two parts: relabel_from and relabel to.
5033
5034 This hook is deprecated, mpo_vnode_check_rename_t should be used instead.
5035
5036 @return Return 0 if access is granted, otherwise an appropriate value for
5037 errno should be returned.
5038 */
5039 typedef int mpo_vnode_check_rename_to_t(
5040 kauth_cred_t cred,
5041 struct vnode *dvp,
5042 struct label *dlabel,
5043 struct vnode *vp, /* NULLOK */
5044 struct label *label, /* NULLOK */
5045 int samedir,
5046 struct componentname *cnp
5047 );
5048 /**
5049 @brief Access control check for revoke
5050 @param cred Subject credential
5051 @param vp Object vnode
5052 @param label Policy label for vp
5053
5054 Determine whether the subject identified by the credential can revoke
5055 access to the passed vnode.
5056
5057 @return Return 0 if access is granted, otherwise an appropriate value for
5058 errno should be returned. Suggested failure: EACCES for label mismatch or
5059 EPERM for lack of privilege.
5060 */
5061 typedef int mpo_vnode_check_revoke_t(
5062 kauth_cred_t cred,
5063 struct vnode *vp,
5064 struct label *label
5065 );
5066 /**
5067 @brief Access control check for searchfs
5068 @param cred Subject credential
5069 @param vp Object vnode
5070 @param vlabel Policy label for vp
5071 @param alist List of attributes used as search criteria
5072
5073 Determine whether the subject identified by the credential can search the
5074 vnode using the searchfs system call.
5075
5076 @return Return 0 if access is granted, otherwise an appropriate value for
5077 errno should be returned.
5078 */
5079 typedef int mpo_vnode_check_searchfs_t(
5080 kauth_cred_t cred,
5081 struct vnode *vp,
5082 struct label *vlabel,
5083 struct attrlist *alist
5084 );
5085 /**
5086 @brief Access control check for select
5087 @param cred Subject credential
5088 @param vp Object vnode
5089 @param label Policy label for vp
5090 @param which The operation selected on: FREAD or FWRITE
5091
5092 Determine whether the subject identified by the credential can select
5093 the vnode.
5094
5095 @return Return 0 if access is granted, otherwise an appropriate value for
5096 errno should be returned.
5097 */
5098 typedef int mpo_vnode_check_select_t(
5099 kauth_cred_t cred,
5100 struct vnode *vp,
5101 struct label *label,
5102 int which
5103 );
5104 /**
5105 @brief Access control check for setting ACL
5106 @param cred Subject credential
5107 @param vp Object node
5108 @param label Policy label for vp
5109 @param acl ACL structure pointer
5110
5111 Determine whether the subject identified by the credential can set an ACL
5112 on the specified vnode. The ACL pointer will be NULL when removing an ACL.
5113
5114 @return Return 0 if access is granted, otherwise an appropriate value for
5115 errno should be returned. Suggested failure: EACCES for label mismatch or
5116 EPERM for lack of privilege.
5117 */
5118 typedef int mpo_vnode_check_setacl_t(
5119 kauth_cred_t cred,
5120 struct vnode *vp,
5121 struct label *label,
5122 struct kauth_acl *acl
5123 );
5124 /**
5125 @brief Access control check for setting file attributes
5126 @param cred Subject credential
5127 @param vp Object vnode
5128 @param vlabel Policy label for vp
5129 @param alist List of attributes to set
5130
5131 Determine whether the subject identified by the credential can set
5132 various attributes of the specified vnode, or the filesystem or volume on
5133 which that vnode resides. See <sys/attr.h> for definitions of the
5134 attributes.
5135
5136 @return Return 0 if access is granted, otherwise an appropriate value for
5137 errno should be returned. Suggested failure: EACCES for label mismatch or
5138 EPERM for lack of privilege. Access control covers all attributes requested
5139 with this call.
5140 */
5141 typedef int mpo_vnode_check_setattrlist_t(
5142 kauth_cred_t cred,
5143 struct vnode *vp,
5144 struct label *vlabel,
5145 struct attrlist *alist
5146 );
5147 /**
5148 @brief Access control check for setting extended attribute
5149 @param cred Subject credential
5150 @param vp Object vnode
5151 @param label Policy label for vp
5152 @param name Extended attribute name
5153 @param uio I/O structure pointer
5154
5155 Determine whether the subject identified by the credential can set the
5156 extended attribute of passed name and passed namespace on the passed
5157 vnode. Policies implementing security labels backed into extended
5158 attributes may want to provide additional protections for those
5159 attributes. Additionally, policies should avoid making decisions based
5160 on the data referenced from uio, as there is a potential race condition
5161 between this check and the actual operation. The uio may also be NULL
5162 if a delete operation is being performed.
5163
5164 @return Return 0 if access is granted, otherwise an appropriate value for
5165 errno should be returned. Suggested failure: EACCES for label mismatch or
5166 EPERM for lack of privilege.
5167 */
5168 typedef int mpo_vnode_check_setextattr_t(
5169 kauth_cred_t cred,
5170 struct vnode *vp,
5171 struct label *label,
5172 const char *name,
5173 struct uio *uio
5174 );
5175 /**
5176 @brief Access control check for setting flags
5177 @param cred Subject credential
5178 @param vp Object vnode
5179 @param label Policy label for vp
5180 @param flags File flags; see chflags(2)
5181
5182 Determine whether the subject identified by the credential can set
5183 the passed flags on the passed vnode.
5184
5185 @return Return 0 if access is granted, otherwise an appropriate value for
5186 errno should be returned. Suggested failure: EACCES for label mismatch or
5187 EPERM for lack of privilege.
5188 */
5189 typedef int mpo_vnode_check_setflags_t(
5190 kauth_cred_t cred,
5191 struct vnode *vp,
5192 struct label *label,
5193 u_long flags
5194 );
5195 /**
5196 @brief Access control check for setting mode
5197 @param cred Subject credential
5198 @param vp Object vnode
5199 @param label Policy label for vp
5200 @param mode File mode; see chmod(2)
5201
5202 Determine whether the subject identified by the credential can set
5203 the passed mode on the passed vnode.
5204
5205 @return Return 0 if access is granted, otherwise an appropriate value for
5206 errno should be returned. Suggested failure: EACCES for label mismatch or
5207 EPERM for lack of privilege.
5208 */
5209 typedef int mpo_vnode_check_setmode_t(
5210 kauth_cred_t cred,
5211 struct vnode *vp,
5212 struct label *label,
5213 mode_t mode
5214 );
5215 /**
5216 @brief Access control check for setting uid and gid
5217 @param cred Subject credential
5218 @param vp Object vnode
5219 @param label Policy label for vp
5220 @param uid User ID
5221 @param gid Group ID
5222
5223 Determine whether the subject identified by the credential can set
5224 the passed uid and passed gid as file uid and file gid on the passed
5225 vnode. The IDs may be set to (-1) to request no update.
5226
5227 @return Return 0 if access is granted, otherwise an appropriate value for
5228 errno should be returned. Suggested failure: EACCES for label mismatch or
5229 EPERM for lack of privilege.
5230 */
5231 typedef int mpo_vnode_check_setowner_t(
5232 kauth_cred_t cred,
5233 struct vnode *vp,
5234 struct label *label,
5235 uid_t uid,
5236 gid_t gid
5237 );
5238 /**
5239 @brief Access control check for setting timestamps
5240 @param cred Subject credential
5241 @param vp Object vnode
5242 @param label Policy label for vp
5243 @param atime Access time; see utimes(2)
5244 @param mtime Modification time; see utimes(2)
5245
5246 Determine whether the subject identified by the credential can set
5247 the passed access timestamps on the passed vnode.
5248
5249 @return Return 0 if access is granted, otherwise an appropriate value for
5250 errno should be returned. Suggested failure: EACCES for label mismatch or
5251 EPERM for lack of privilege.
5252 */
5253 typedef int mpo_vnode_check_setutimes_t(
5254 kauth_cred_t cred,
5255 struct vnode *vp,
5256 struct label *label,
5257 struct timespec atime,
5258 struct timespec mtime
5259 );
5260 /**
5261 @brief Access control check after determining the code directory hash
5262 @param vp vnode vnode to combine into proc
5263 @param label label associated with the vnode
5264 @param cs_blob the code signature to check
5265 @param cs_flags update code signing flags if needed
5266 @param flags operational flag to mpo_vnode_check_signature
5267 @param fatal_failure_desc description of fatal failure
5268 @param fatal_failure_desc_len failure description len, failure is fatal if non-0
5269
5270 @return Return 0 if access is granted, otherwise an appropriate value for
5271 errno should be returned.
5272 */
5273 typedef int mpo_vnode_check_signature_t(
5274 struct vnode *vp,
5275 struct label *label,
5276 struct cs_blob *cs_blob,
5277 unsigned int *cs_flags,
5278 int flags,
5279 char **fatal_failure_desc, size_t *fatal_failure_desc_len
5280 );
5281 /**
5282 @brief Access control check for stat
5283 @param active_cred Subject credential
5284 @param file_cred Credential associated with the struct fileproc
5285 @param vp Object vnode
5286 @param label Policy label for vp
5287
5288 Determine whether the subject identified by the credential can stat
5289 the passed vnode. See stat(2) for more information. The active_cred
5290 hold the credentials of the subject performing the operation, and
5291 file_cred holds the credentials of the subject that originally
5292 opened the file.
5293
5294 @return Return 0 if access is granted, otherwise an appropriate value for
5295 errno should be returned. Suggested failure: EACCES for label mismatch or
5296 EPERM for lack of privilege.
5297 */
5298 typedef int mpo_vnode_check_stat_t(
5299 struct ucred *active_cred,
5300 struct ucred *file_cred, /* NULLOK */
5301 struct vnode *vp,
5302 struct label *label
5303 );
5304 /**
5305 @brief Access control check for truncate/ftruncate
5306 @param active_cred Subject credential
5307 @param file_cred Credential associated with the struct fileproc
5308 @param vp Object vnode
5309 @param label Policy label for vp
5310
5311 Determine whether the subject identified by the credential can
5312 perform a truncate operation on the passed vnode. The active_cred hold
5313 the credentials of the subject performing the operation, and
5314 file_cred holds the credentials of the subject that originally
5315 opened the file.
5316
5317 @return Return 0 if access is granted, otherwise an appropriate value for
5318 errno should be returned. Suggested failure: EACCES for label mismatch or
5319 EPERM for lack of privilege.
5320 */
5321 typedef int mpo_vnode_check_truncate_t(
5322 kauth_cred_t active_cred,
5323 kauth_cred_t file_cred, /* NULLOK */
5324 struct vnode *vp,
5325 struct label *label
5326 );
5327 /**
5328 @brief Access control check for binding UNIX domain socket
5329 @param cred Subject credential
5330 @param dvp Directory vnode
5331 @param dlabel Policy label for dvp
5332 @param cnp Component name for dvp
5333 @param vap vnode attributes for vap
5334
5335 Determine whether the subject identified by the credential can perform a
5336 bind operation on a UNIX domain socket with the passed parent directory,
5337 passed name information, and passed attribute information.
5338
5339 @return Return 0 if access is granted, otherwise an appropriate value for
5340 errno should be returned. Suggested failure: EACCES for label mismatch or
5341 EPERM for lack of privilege.
5342 */
5343 typedef int mpo_vnode_check_uipc_bind_t(
5344 kauth_cred_t cred,
5345 struct vnode *dvp,
5346 struct label *dlabel,
5347 struct componentname *cnp,
5348 struct vnode_attr *vap
5349 );
5350 /**
5351 @brief Access control check for connecting UNIX domain socket
5352 @param cred Subject credential
5353 @param vp Object vnode
5354 @param label Policy label associated with vp
5355 @param so Socket
5356
5357 Determine whether the subject identified by the credential can perform a
5358 connect operation on the passed UNIX domain socket vnode.
5359
5360 @return Return 0 if access is granted, otherwise an appropriate value for
5361 errno should be returned. Suggested failure: EACCES for label mismatch or
5362 EPERM for lack of privilege.
5363 */
5364 typedef int mpo_vnode_check_uipc_connect_t(
5365 kauth_cred_t cred,
5366 struct vnode *vp,
5367 struct label *label,
5368 socket_t so
5369 );
5370 /**
5371 @brief Access control check for deleting vnode
5372 @param cred Subject credential
5373 @param dvp Parent directory vnode
5374 @param dlabel Policy label for dvp
5375 @param vp Object vnode to delete
5376 @param label Policy label for vp
5377 @param cnp Component name for vp
5378 @see mpo_check_rename_to_t
5379
5380 Determine whether the subject identified by the credential can delete
5381 a vnode from the passed parent directory and passed name information.
5382 This call may be made in a number of situations, including as a
5383 results of calls to unlink(2) and rmdir(2). Policies implementing
5384 this entry point should also implement mpo_check_rename_to to
5385 authorize deletion of objects as a result of being the target of a rename.
5386
5387 @return Return 0 if access is granted, otherwise an appropriate value for
5388 errno should be returned. Suggested failure: EACCES for label mismatch or
5389 EPERM for lack of privilege.
5390 */
5391 typedef int mpo_vnode_check_unlink_t(
5392 kauth_cred_t cred,
5393 struct vnode *dvp,
5394 struct label *dlabel,
5395 struct vnode *vp,
5396 struct label *label,
5397 struct componentname *cnp
5398 );
5399 /**
5400 @brief Access control check for write
5401 @param active_cred Subject credential
5402 @param file_cred Credential associated with the struct fileproc
5403 @param vp Object vnode
5404 @param label Policy label for vp
5405
5406 Determine whether the subject identified by the credential can
5407 perform a write operation on the passed vnode. The active_cred hold
5408 the credentials of the subject performing the operation, and
5409 file_cred holds the credentials of the subject that originally
5410 opened the file.
5411
5412 @return Return 0 if access is granted, otherwise an appropriate value for
5413 errno should be returned. Suggested failure: EACCES for label mismatch or
5414 EPERM for lack of privilege.
5415 */
5416 typedef int mpo_vnode_check_write_t(
5417 kauth_cred_t active_cred,
5418 kauth_cred_t file_cred, /* NULLOK */
5419 struct vnode *vp,
5420 struct label *label
5421 );
5422 /**
5423 @brief Associate a vnode with a devfs entry
5424 @param mp Devfs mount point
5425 @param mntlabel Devfs mount point label
5426 @param de Devfs directory entry
5427 @param delabel Label associated with de
5428 @param vp vnode associated with de
5429 @param vlabel Label associated with vp
5430
5431 Fill in the label (vlabel) for a newly created devfs vnode. The
5432 label is typically derived from the label on the devfs directory
5433 entry or the label on the filesystem, supplied as parameters.
5434 */
5435 typedef void mpo_vnode_label_associate_devfs_t(
5436 struct mount *mp,
5437 struct label *mntlabel,
5438 struct devnode *de,
5439 struct label *delabel,
5440 struct vnode *vp,
5441 struct label *vlabel
5442 );
5443 /**
5444 @brief Associate a label with a vnode
5445 @param mp File system mount point
5446 @param mntlabel File system mount point label
5447 @param vp Vnode to label
5448 @param vlabel Label associated with vp
5449
5450 Attempt to retrieve label information for the vnode, vp, from the
5451 file system extended attribute store. The label should be stored in
5452 the supplied vlabel parameter. If a policy cannot retrieve an
5453 extended attribute, sometimes it is acceptible to fallback to using
5454 the mntlabel.
5455
5456 If the policy requires vnodes to have a valid label elsewhere it
5457 MUST NOT return other than temporary errors, and must always provide
5458 a valid label of some sort. Returning an error will cause vnode
5459 labeling to be retried at a later access. Failure to handle policy
5460 centric errors internally (corrupt labels etc.) will result in
5461 inaccessible files.
5462
5463 @return In the event of an error, an appropriate value for errno
5464 should be returned, otherwise return 0 upon success.
5465 */
5466 typedef int mpo_vnode_label_associate_extattr_t(
5467 struct mount *mp,
5468 struct label *mntlabel,
5469 struct vnode *vp,
5470 struct label *vlabel
5471 );
5472 /**
5473 @brief Associate a file label with a vnode
5474 @param cred User credential
5475 @param mp Fdesc mount point
5476 @param mntlabel Fdesc mount point label
5477 @param fg Fileglob structure
5478 @param label Policy label for fg
5479 @param vp Vnode to label
5480 @param vlabel Label associated with vp
5481
5482 Associate label information for the vnode, vp, with the label of
5483 the open file descriptor described by fg.
5484 The label should be stored in the supplied vlabel parameter.
5485 */
5486 typedef void mpo_vnode_label_associate_file_t(
5487 struct ucred *cred,
5488 struct mount *mp,
5489 struct label *mntlabel,
5490 struct fileglob *fg,
5491 struct label *label,
5492 struct vnode *vp,
5493 struct label *vlabel
5494 );
5495 /**
5496 @brief Associate a pipe label with a vnode
5497 @param cred User credential for the process that opened the pipe
5498 @param cpipe Pipe structure
5499 @param pipelabel Label associated with pipe
5500 @param vp Vnode to label
5501 @param vlabel Label associated with vp
5502
5503 Associate label information for the vnode, vp, with the label of
5504 the pipe described by the pipe structure cpipe.
5505 The label should be stored in the supplied vlabel parameter.
5506 */
5507 typedef void mpo_vnode_label_associate_pipe_t(
5508 struct ucred *cred,
5509 struct pipe *cpipe,
5510 struct label *pipelabel,
5511 struct vnode *vp,
5512 struct label *vlabel
5513 );
5514 /**
5515 @brief Associate a POSIX semaphore label with a vnode
5516 @param cred User credential for the process that create psem
5517 @param psem POSIX semaphore structure
5518 @param psemlabel Label associated with psem
5519 @param vp Vnode to label
5520 @param vlabel Label associated with vp
5521
5522 Associate label information for the vnode, vp, with the label of
5523 the POSIX semaphore described by psem.
5524 The label should be stored in the supplied vlabel parameter.
5525 */
5526 typedef void mpo_vnode_label_associate_posixsem_t(
5527 struct ucred *cred,
5528 struct pseminfo *psem,
5529 struct label *psemlabel,
5530 struct vnode *vp,
5531 struct label *vlabel
5532 );
5533 /**
5534 @brief Associate a POSIX shared memory label with a vnode
5535 @param cred User credential for the process that created pshm
5536 @param pshm POSIX shared memory structure
5537 @param pshmlabel Label associated with pshm
5538 @param vp Vnode to label
5539 @param vlabel Label associated with vp
5540
5541 Associate label information for the vnode, vp, with the label of
5542 the POSIX shared memory region described by pshm.
5543 The label should be stored in the supplied vlabel parameter.
5544 */
5545 typedef void mpo_vnode_label_associate_posixshm_t(
5546 struct ucred *cred,
5547 struct pshminfo *pshm,
5548 struct label *pshmlabel,
5549 struct vnode *vp,
5550 struct label *vlabel
5551 );
5552 /**
5553 @brief Associate a label with a vnode
5554 @param mp File system mount point
5555 @param mntlabel File system mount point label
5556 @param vp Vnode to label
5557 @param vlabel Label associated with vp
5558
5559 On non-multilabel file systems, set the label for a vnode. The
5560 label will most likely be based on the file system label.
5561 */
5562 typedef void mpo_vnode_label_associate_singlelabel_t(
5563 struct mount *mp,
5564 struct label *mntlabel,
5565 struct vnode *vp,
5566 struct label *vlabel
5567 );
5568 /**
5569 @brief Associate a socket label with a vnode
5570 @param cred User credential for the process that opened the socket
5571 @param so Socket structure
5572 @param solabel Label associated with so
5573 @param vp Vnode to label
5574 @param vlabel Label associated with vp
5575
5576 Associate label information for the vnode, vp, with the label of
5577 the open socket described by the socket structure so.
5578 The label should be stored in the supplied vlabel parameter.
5579 */
5580 typedef void mpo_vnode_label_associate_socket_t(
5581 kauth_cred_t cred,
5582 socket_t so,
5583 struct label *solabel,
5584 struct vnode *vp,
5585 struct label *vlabel
5586 );
5587 /**
5588 @brief Copy a vnode label
5589 @param src Source vnode label
5590 @param dest Destination vnode label
5591
5592 Copy the vnode label information from src to dest. On Darwin, this
5593 is currently only necessary when executing interpreted scripts, but
5594 will later be used if vnode label externalization cannot be an
5595 atomic operation.
5596 */
5597 typedef void mpo_vnode_label_copy_t(
5598 struct label *src,
5599 struct label *dest
5600 );
5601 /**
5602 @brief Destroy vnode label
5603 @param label The label to be destroyed
5604
5605 Destroy a vnode label. Since the object is going out of scope,
5606 policy modules should free any internal storage associated with the
5607 label so that it may be destroyed.
5608 */
5609 typedef void mpo_vnode_label_destroy_t(
5610 struct label *label
5611 );
5612 /**
5613 @brief Externalize a vnode label for auditing
5614 @param label Label to be externalized
5615 @param element_name Name of the label namespace for which labels should be
5616 externalized
5617 @param sb String buffer to be filled with a text representation of the label
5618
5619 Produce an external representation of the label on a vnode suitable for
5620 inclusion in an audit record. An externalized label consists of a text
5621 representation of the label contents that will be added to the audit record
5622 as part of a text token. Policy-agnostic user space tools will display
5623 this externalized version.
5624
5625 @return 0 on success, return non-zero if an error occurs while
5626 externalizing the label data.
5627
5628 */
5629 typedef int mpo_vnode_label_externalize_audit_t(
5630 struct label *label,
5631 char *element_name,
5632 struct sbuf *sb
5633 );
5634 /**
5635 @brief Externalize a vnode label
5636 @param label Label to be externalized
5637 @param element_name Name of the label namespace for which labels should be
5638 externalized
5639 @param sb String buffer to be filled with a text representation of the label
5640
5641 Produce an external representation of the label on a vnode. An
5642 externalized label consists of a text representation of the label
5643 contents that can be used with user applications. Policy-agnostic
5644 user space tools will display this externalized version.
5645
5646 @return 0 on success, return non-zero if an error occurs while
5647 externalizing the label data.
5648
5649 */
5650 typedef int mpo_vnode_label_externalize_t(
5651 struct label *label,
5652 char *element_name,
5653 struct sbuf *sb
5654 );
5655 /**
5656 @brief Initialize vnode label
5657 @param label New label to initialize
5658
5659 Initialize label storage for use with a newly instantiated vnode, or
5660 for temporary storage associated with the copying in or out of a
5661 vnode label. While it is necessary to allocate space for a
5662 kernel-resident vnode label, it is not yet necessary to link this vnode
5663 with persistent label storage facilities, such as extended attributes.
5664 Sleeping is permitted.
5665 */
5666 typedef void mpo_vnode_label_init_t(
5667 struct label *label
5668 );
5669 /**
5670 @brief Internalize a vnode label
5671 @param label Label to be internalized
5672 @param element_name Name of the label namespace for which the label should
5673 be internalized
5674 @param element_data Text data to be internalized
5675
5676 Produce a vnode label from an external representation. An
5677 externalized label consists of a text representation of the label
5678 contents that can be used with user applications. Policy-agnostic
5679 user space tools will forward text version to the kernel for
5680 processing by individual policy modules.
5681
5682 The policy's internalize entry points will be called only if the
5683 policy has registered interest in the label namespace.
5684
5685 @return 0 on success, Otherwise, return non-zero if an error occurs
5686 while internalizing the label data.
5687 */
5688 typedef int mpo_vnode_label_internalize_t(
5689 struct label *label,
5690 char *element_name,
5691 char *element_data
5692 );
5693 /**
5694 @brief Clean up a vnode label
5695 @param label The label to be cleaned for re-use
5696
5697 Clean up a vnode label. Darwin (Tiger, 8.x) allocates vnodes on demand, but
5698 typically never frees them. Before vnodes are placed back on free lists for
5699 re-use, policies can cleanup or overwrite any information present in the label.
5700 */
5701 typedef void mpo_vnode_label_recycle_t(
5702 struct label *label
5703 );
5704 /**
5705 @brief Write a label to a extended attribute
5706 @param cred Subject credential
5707 @param vp The vnode for which the label is being stored
5708 @param vlabel Label associated with vp
5709 @param intlabel The new label to store
5710
5711 Store a new label in the extended attribute corresponding to the
5712 supplied vnode. The policy has already authorized the operation;
5713 this call must be implemented in order to perform the actual
5714 operation.
5715
5716 @return In the event of an error, an appropriate value for errno
5717 should be returned, otherwise return 0 upon success.
5718
5719 @warning XXX After examining the extended attribute implementation on
5720 Apple's future release, this entry point may be changed.
5721 */
5722 typedef int mpo_vnode_label_store_t(
5723 kauth_cred_t cred,
5724 struct vnode *vp,
5725 struct label *vlabel,
5726 struct label *intlabel
5727 );
5728 /**
5729 @brief Update vnode label from extended attributes
5730 @param mp File system mount point
5731 @param mntlabel Mount point label
5732 @param vp Vnode to label
5733 @param vlabel Label associated with vp
5734 @param name Name of the xattr
5735 @see mpo_vnode_check_setextattr_t
5736
5737 When an extended attribute is updated via the Vendor attribute management
5738 functions, the MAC vnode label might also require an update.
5739 Policies should first determine if 'name' matches their xattr label
5740 name. If it does, the kernel is has either replaced or removed the
5741 named extended attribute that was previously associated with the
5742 vnode. Normally labels should only be modified via MAC Framework label
5743 management calls, but sometimes the user space components will directly
5744 modify extended attributes. For example, 'cp', 'tar', etc. manage
5745 extended attributes in userspace, not the kernel.
5746
5747 This entry point is called after the label update has occurred, so
5748 it cannot return a failure. However, the operation is preceded by
5749 the mpo_vnode_check_setextattr() access control check.
5750
5751 If the vnode label needs to be updated the policy should return
5752 a non-zero value. The vnode label will be marked for re-association
5753 by the framework.
5754 */
5755 typedef int mpo_vnode_label_update_extattr_t(
5756 struct mount *mp,
5757 struct label *mntlabel,
5758 struct vnode *vp,
5759 struct label *vlabel,
5760 const char *name
5761 );
5762 /**
5763 @brief Update a vnode label
5764 @param cred Subject credential
5765 @param vp The vnode to relabel
5766 @param vnodelabel Existing vnode label
5767 @param label New label to replace existing label
5768 @see mpo_vnode_check_label_update_t
5769
5770 The subject identified by the credential has previously requested
5771 and was authorized to relabel the vnode; this entry point allows
5772 policies to perform the actual relabel operation. Policies should
5773 update vnodelabel using the label stored in the label parameter.
5774 */
5775 typedef void mpo_vnode_label_update_t(
5776 kauth_cred_t cred,
5777 struct vnode *vp,
5778 struct label *vnodelabel,
5779 struct label *label
5780 );
5781 /**
5782 @brief Find deatched signatures for a shared library
5783 @param p file trying to find the signature
5784 @param vp The vnode to relabel
5785 @param offset offset in the macho that the signature is requested for (for fat binaries)
5786 @param label Existing vnode label
5787
5788 */
5789 typedef int mpo_vnode_find_sigs_t(
5790 struct proc *p,
5791 struct vnode *vp,
5792 off_t offset,
5793 struct label *label
5794 );
5795 /**
5796 @brief Create a new vnode, backed by extended attributes
5797 @param cred User credential for the creating process
5798 @param mp File system mount point
5799 @param mntlabel File system mount point label
5800 @param dvp Parent directory vnode
5801 @param dlabel Parent directory vnode label
5802 @param vp Newly created vnode
5803 @param vlabel Label to associate with the new vnode
5804 @param cnp Component name for vp
5805
5806 Write out the label for the newly created vnode, most likely storing
5807 the results in a file system extended attribute. Most policies will
5808 derive the new vnode label using information from a combination
5809 of the subject (user) credential, the file system label, the parent
5810 directory label, and potentially the path name component.
5811
5812 @return If the operation succeeds, store the new label in vlabel and
5813 return 0. Otherwise, return an appropriate errno value.
5814 */
5815 typedef int mpo_vnode_notify_create_t(
5816 kauth_cred_t cred,
5817 struct mount *mp,
5818 struct label *mntlabel,
5819 struct vnode *dvp,
5820 struct label *dlabel,
5821 struct vnode *vp,
5822 struct label *vlabel,
5823 struct componentname *cnp
5824 );
5825
5826 /**
5827 @brief Inform MAC policies that a vnode has been opened
5828 @param cred User credential for the creating process
5829 @param vp vnode opened
5830 @param label Policy label for the vp
5831 @param acc_mode open(2) access mode used
5832
5833 Inform Mac policies that a vnode have been successfully opened
5834 (passing all MAC polices and DAC).
5835 */
5836 typedef void mpo_vnode_notify_open_t(
5837 kauth_cred_t cred,
5838 struct vnode *vp,
5839 struct label *label,
5840 int acc_mode
5841 );
5842
5843 /**
5844 @brief Inform MAC policies that a vnode has been renamed
5845 @param cred User credential for the renaming process
5846 @param vp Vnode that's being renamed
5847 @param label Policy label for vp
5848 @param dvp Parent directory for the destination
5849 @param dlabel Policy label for dvp
5850 @param cnp Component name for the destination
5851
5852 Inform MAC policies that a vnode has been renamed.
5853 */
5854 typedef void mpo_vnode_notify_rename_t(
5855 kauth_cred_t cred,
5856 struct vnode *vp,
5857 struct label *label,
5858 struct vnode *dvp,
5859 struct label *dlabel,
5860 struct componentname *cnp
5861 );
5862
5863 /**
5864 @brief Inform MAC policies that a vnode has been linked
5865 @param cred User credential for the renaming process
5866 @param dvp Parent directory for the destination
5867 @param dlabel Policy label for dvp
5868 @param vp Vnode that's being linked
5869 @param vlabel Policy label for vp
5870 @param cnp Component name for the destination
5871
5872 Inform MAC policies that a vnode has been linked.
5873 */
5874 typedef void mpo_vnode_notify_link_t(
5875 kauth_cred_t cred,
5876 struct vnode *dvp,
5877 struct label *dlabel,
5878 struct vnode *vp,
5879 struct label *vlabel,
5880 struct componentname *cnp
5881 );
5882
5883 /**
5884 @brief Inform MAC policies that an extended attribute has been removed from a vnode
5885 @param cred Subject credential
5886 @param vp Object node
5887 @param label Policy label for vp
5888 @param name Extended attribute name
5889
5890 Inform MAC policies that an extended attribute has been removed from a vnode.
5891 */
5892 typedef void mpo_vnode_notify_deleteextattr_t(
5893 kauth_cred_t cred,
5894 struct vnode *vp,
5895 struct label *label,
5896 const char *name
5897 );
5898
5899
5900 /**
5901 @brief Inform MAC policies that an ACL has been set on a vnode
5902 @param cred Subject credential
5903 @param vp Object node
5904 @param label Policy label for vp
5905 @param acl ACL structure pointer
5906
5907 Inform MAC policies that an ACL has been set on a vnode.
5908 */
5909 typedef void mpo_vnode_notify_setacl_t(
5910 kauth_cred_t cred,
5911 struct vnode *vp,
5912 struct label *label,
5913 struct kauth_acl *acl
5914 );
5915
5916 /**
5917 @brief Inform MAC policies that an attributes have been set on a vnode
5918 @param cred Subject credential
5919 @param vp Object vnode
5920 @param label Policy label for vp
5921 @param alist List of attributes to set
5922
5923 Inform MAC policies that an attributes have been set on a vnode.
5924 */
5925 typedef void mpo_vnode_notify_setattrlist_t(
5926 kauth_cred_t cred,
5927 struct vnode *vp,
5928 struct label *label,
5929 struct attrlist *alist
5930 );
5931
5932 /**
5933 @brief Inform MAC policies that an extended attribute has been set on a vnode
5934 @param cred Subject credential
5935 @param vp Object vnode
5936 @param label Policy label for vp
5937 @param name Extended attribute name
5938 @param uio I/O structure pointer
5939
5940 Inform MAC policies that an extended attribute has been set on a vnode.
5941 */
5942 typedef void mpo_vnode_notify_setextattr_t(
5943 kauth_cred_t cred,
5944 struct vnode *vp,
5945 struct label *label,
5946 const char *name,
5947 struct uio *uio
5948 );
5949
5950 /**
5951 @brief Inform MAC policies that flags have been set on a vnode
5952 @param cred Subject credential
5953 @param vp Object vnode
5954 @param label Policy label for vp
5955 @param flags File flags; see chflags(2)
5956
5957 Inform MAC policies that flags have been set on a vnode.
5958 */
5959 typedef void mpo_vnode_notify_setflags_t(
5960 kauth_cred_t cred,
5961 struct vnode *vp,
5962 struct label *label,
5963 u_long flags
5964 );
5965
5966 /**
5967 @brief Inform MAC policies that a new mode has been set on a vnode
5968 @param cred Subject credential
5969 @param vp Object vnode
5970 @param label Policy label for vp
5971 @param mode File mode; see chmod(2)
5972
5973 Inform MAC policies that a new mode has been set on a vnode.
5974 */
5975 typedef void mpo_vnode_notify_setmode_t(
5976 kauth_cred_t cred,
5977 struct vnode *vp,
5978 struct label *label,
5979 mode_t mode
5980 );
5981
5982 /**
5983 @brief Inform MAC policies that new uid/gid have been set on a vnode
5984 @param cred Subject credential
5985 @param vp Object vnode
5986 @param label Policy label for vp
5987 @param uid User ID
5988 @param gid Group ID
5989
5990 Inform MAC policies that new uid/gid have been set on a vnode.
5991 */
5992 typedef void mpo_vnode_notify_setowner_t(
5993 kauth_cred_t cred,
5994 struct vnode *vp,
5995 struct label *label,
5996 uid_t uid,
5997 gid_t gid
5998 );
5999
6000 /**
6001 @brief Inform MAC policies that new timestamps have been set on a vnode
6002 @param cred Subject credential
6003 @param vp Object vnode
6004 @param label Policy label for vp
6005 @param atime Access time; see utimes(2)
6006 @param mtime Modification time; see utimes(2)
6007
6008 Inform MAC policies that new timestamps have been set on a vnode.
6009 */
6010 typedef void mpo_vnode_notify_setutimes_t(
6011 kauth_cred_t cred,
6012 struct vnode *vp,
6013 struct label *label,
6014 struct timespec atime,
6015 struct timespec mtime
6016 );
6017
6018 /**
6019 @brief Inform MAC policies that a vnode has been truncated
6020 @param cred Subject credential
6021 @param file_cred Credential associated with the struct fileproc
6022 @param vp Object vnode
6023 @param label Policy label for vp
6024
6025 Inform MAC policies that a vnode has been truncated.
6026 */
6027 typedef void mpo_vnode_notify_truncate_t(
6028 kauth_cred_t cred,
6029 kauth_cred_t file_cred,
6030 struct vnode *vp,
6031 struct label *label
6032 );
6033
6034
6035 /**
6036 @brief Inform MAC policies that a pty slave has been granted
6037 @param p Responsible process
6038 @param tp tty data structure
6039 @param dev Major and minor numbers of device
6040 @param label Policy label for tp
6041
6042 Inform MAC policies that a pty slave has been granted.
6043 */
6044 typedef void mpo_pty_notify_grant_t(
6045 proc_t p,
6046 struct tty *tp,
6047 dev_t dev,
6048 struct label *label
6049 );
6050
6051 /**
6052 @brief Inform MAC policies that a pty master has been closed
6053 @param p Responsible process
6054 @param tp tty data structure
6055 @param dev Major and minor numbers of device
6056 @param label Policy label for tp
6057
6058 Inform MAC policies that a pty master has been closed.
6059 */
6060 typedef void mpo_pty_notify_close_t(
6061 proc_t p,
6062 struct tty *tp,
6063 dev_t dev,
6064 struct label *label
6065 );
6066
6067 /**
6068 @brief Access control check for kext loading
6069 @param cred Subject credential
6070 @param identifier Kext identifier
6071
6072 Determine whether the subject identified by the credential can load the
6073 specified kext.
6074
6075 @return Return 0 if access is granted, otherwise an appropriate value for
6076 errno should be returned. Suggested failure: EPERM for lack of privilege.
6077 */
6078 typedef int mpo_kext_check_load_t(
6079 kauth_cred_t cred,
6080 const char *identifier
6081 );
6082
6083 /**
6084 @brief Access control check for kext unloading
6085 @param cred Subject credential
6086 @param identifier Kext identifier
6087
6088 Determine whether the subject identified by the credential can unload the
6089 specified kext.
6090
6091 @return Return 0 if access is granted, otherwise an appropriate value for
6092 errno should be returned. Suggested failure: EPERM for lack of privilege.
6093 */
6094 typedef int mpo_kext_check_unload_t(
6095 kauth_cred_t cred,
6096 const char *identifier
6097 );
6098
6099 /**
6100 @brief Access control check for querying information about loaded kexts
6101 @param cred Subject credential
6102
6103 Determine whether the subject identified by the credential can query
6104 information about loaded kexts.
6105
6106 @return Return 0 if access is granted, otherwise an appropriate value for
6107 errno should be returned. Suggested failure: EPERM for lack of privilege.
6108 */
6109 typedef int mpo_kext_check_query_t(
6110 kauth_cred_t cred
6111 );
6112
6113 /**
6114 @brief Access control check for getting NVRAM variables.
6115 @param cred Subject credential
6116 @param name NVRAM variable to get
6117
6118 Determine whether the subject identifier by the credential can get the
6119 value of the named NVRAM variable.
6120
6121 @return Return 0 if access is granted, otherwise an appropriate value for
6122 errno should be returned. Suggested failure: EPERM for lack of privilege.
6123 */
6124 typedef int mpo_iokit_check_nvram_get_t(
6125 kauth_cred_t cred,
6126 const char *name
6127 );
6128
6129 /**
6130 @brief Access control check for setting NVRAM variables.
6131 @param cred Subject credential
6132 @param name NVRAM variable to set
6133 @param value The new value for the NVRAM variable
6134
6135 Determine whether the subject identifier by the credential can set the
6136 value of the named NVRAM variable.
6137
6138 @return Return 0 if access is granted, otherwise an appropriate value for
6139 errno should be returned. Suggested failure: EPERM for lack of privilege.
6140 */
6141 typedef int mpo_iokit_check_nvram_set_t(
6142 kauth_cred_t cred,
6143 const char *name,
6144 io_object_t value
6145 );
6146
6147 /**
6148 @brief Access control check for deleting NVRAM variables.
6149 @param cred Subject credential
6150 @param name NVRAM variable to delete
6151
6152 Determine whether the subject identifier by the credential can delete the
6153 named NVRAM variable.
6154
6155 @return Return 0 if access is granted, otherwise an appropriate value for
6156 errno should be returned. Suggested failure: EPERM for lack of privilege.
6157 */
6158 typedef int mpo_iokit_check_nvram_delete_t(
6159 kauth_cred_t cred,
6160 const char *name
6161 );
6162
6163 /*
6164 * Placeholder for future events that may need mac hooks.
6165 */
6166 typedef void mpo_reserved_hook_t(void);
6167
6168 /*
6169 * Policy module operations.
6170 *
6171 * Please note that this should be kept in sync with the check assumptions
6172 * policy in bsd/kern/policy_check.c (policy_ops struct).
6173 */
6174 #define MAC_POLICY_OPS_VERSION 46 /* inc when new reserved slots are taken */
6175 struct mac_policy_ops {
6176 mpo_audit_check_postselect_t *mpo_audit_check_postselect;
6177 mpo_audit_check_preselect_t *mpo_audit_check_preselect;
6178
6179 mpo_bpfdesc_label_associate_t *mpo_bpfdesc_label_associate;
6180 mpo_bpfdesc_label_destroy_t *mpo_bpfdesc_label_destroy;
6181 mpo_bpfdesc_label_init_t *mpo_bpfdesc_label_init;
6182 mpo_bpfdesc_check_receive_t *mpo_bpfdesc_check_receive;
6183
6184 mpo_cred_check_label_update_execve_t *mpo_cred_check_label_update_execve;
6185 mpo_cred_check_label_update_t *mpo_cred_check_label_update;
6186 mpo_cred_check_visible_t *mpo_cred_check_visible;
6187 mpo_cred_label_associate_fork_t *mpo_cred_label_associate_fork;
6188 mpo_cred_label_associate_kernel_t *mpo_cred_label_associate_kernel;
6189 mpo_cred_label_associate_t *mpo_cred_label_associate;
6190 mpo_cred_label_associate_user_t *mpo_cred_label_associate_user;
6191 mpo_cred_label_destroy_t *mpo_cred_label_destroy;
6192 mpo_cred_label_externalize_audit_t *mpo_cred_label_externalize_audit;
6193 mpo_cred_label_externalize_t *mpo_cred_label_externalize;
6194 mpo_cred_label_init_t *mpo_cred_label_init;
6195 mpo_cred_label_internalize_t *mpo_cred_label_internalize;
6196 mpo_cred_label_update_execve_t *mpo_cred_label_update_execve;
6197 mpo_cred_label_update_t *mpo_cred_label_update;
6198
6199 mpo_devfs_label_associate_device_t *mpo_devfs_label_associate_device;
6200 mpo_devfs_label_associate_directory_t *mpo_devfs_label_associate_directory;
6201 mpo_devfs_label_copy_t *mpo_devfs_label_copy;
6202 mpo_devfs_label_destroy_t *mpo_devfs_label_destroy;
6203 mpo_devfs_label_init_t *mpo_devfs_label_init;
6204 mpo_devfs_label_update_t *mpo_devfs_label_update;
6205
6206 mpo_file_check_change_offset_t *mpo_file_check_change_offset;
6207 mpo_file_check_create_t *mpo_file_check_create;
6208 mpo_file_check_dup_t *mpo_file_check_dup;
6209 mpo_file_check_fcntl_t *mpo_file_check_fcntl;
6210 mpo_file_check_get_offset_t *mpo_file_check_get_offset;
6211 mpo_file_check_get_t *mpo_file_check_get;
6212 mpo_file_check_inherit_t *mpo_file_check_inherit;
6213 mpo_file_check_ioctl_t *mpo_file_check_ioctl;
6214 mpo_file_check_lock_t *mpo_file_check_lock;
6215 mpo_file_check_mmap_downgrade_t *mpo_file_check_mmap_downgrade;
6216 mpo_file_check_mmap_t *mpo_file_check_mmap;
6217 mpo_file_check_receive_t *mpo_file_check_receive;
6218 mpo_file_check_set_t *mpo_file_check_set;
6219 mpo_file_label_init_t *mpo_file_label_init;
6220 mpo_file_label_destroy_t *mpo_file_label_destroy;
6221 mpo_file_label_associate_t *mpo_file_label_associate;
6222
6223 mpo_ifnet_check_label_update_t *mpo_ifnet_check_label_update;
6224 mpo_ifnet_check_transmit_t *mpo_ifnet_check_transmit;
6225 mpo_ifnet_label_associate_t *mpo_ifnet_label_associate;
6226 mpo_ifnet_label_copy_t *mpo_ifnet_label_copy;
6227 mpo_ifnet_label_destroy_t *mpo_ifnet_label_destroy;
6228 mpo_ifnet_label_externalize_t *mpo_ifnet_label_externalize;
6229 mpo_ifnet_label_init_t *mpo_ifnet_label_init;
6230 mpo_ifnet_label_internalize_t *mpo_ifnet_label_internalize;
6231 mpo_ifnet_label_update_t *mpo_ifnet_label_update;
6232 mpo_ifnet_label_recycle_t *mpo_ifnet_label_recycle;
6233
6234 mpo_inpcb_check_deliver_t *mpo_inpcb_check_deliver;
6235 mpo_inpcb_label_associate_t *mpo_inpcb_label_associate;
6236 mpo_inpcb_label_destroy_t *mpo_inpcb_label_destroy;
6237 mpo_inpcb_label_init_t *mpo_inpcb_label_init;
6238 mpo_inpcb_label_recycle_t *mpo_inpcb_label_recycle;
6239 mpo_inpcb_label_update_t *mpo_inpcb_label_update;
6240
6241 mpo_iokit_check_device_t *mpo_iokit_check_device;
6242
6243 mpo_ipq_label_associate_t *mpo_ipq_label_associate;
6244 mpo_ipq_label_compare_t *mpo_ipq_label_compare;
6245 mpo_ipq_label_destroy_t *mpo_ipq_label_destroy;
6246 mpo_ipq_label_init_t *mpo_ipq_label_init;
6247 mpo_ipq_label_update_t *mpo_ipq_label_update;
6248
6249 mpo_file_check_library_validation_t *mpo_file_check_library_validation;
6250 mpo_vnode_notify_setacl_t *mpo_vnode_notify_setacl;
6251 mpo_vnode_notify_setattrlist_t *mpo_vnode_notify_setattrlist;
6252 mpo_vnode_notify_setextattr_t *mpo_vnode_notify_setextattr;
6253 mpo_vnode_notify_setflags_t *mpo_vnode_notify_setflags;
6254 mpo_vnode_notify_setmode_t *mpo_vnode_notify_setmode;
6255 mpo_vnode_notify_setowner_t *mpo_vnode_notify_setowner;
6256 mpo_vnode_notify_setutimes_t *mpo_vnode_notify_setutimes;
6257 mpo_vnode_notify_truncate_t *mpo_vnode_notify_truncate;
6258
6259 mpo_mbuf_label_associate_bpfdesc_t *mpo_mbuf_label_associate_bpfdesc;
6260 mpo_mbuf_label_associate_ifnet_t *mpo_mbuf_label_associate_ifnet;
6261 mpo_mbuf_label_associate_inpcb_t *mpo_mbuf_label_associate_inpcb;
6262 mpo_mbuf_label_associate_ipq_t *mpo_mbuf_label_associate_ipq;
6263 mpo_mbuf_label_associate_linklayer_t *mpo_mbuf_label_associate_linklayer;
6264 mpo_mbuf_label_associate_multicast_encap_t *mpo_mbuf_label_associate_multicast_encap;
6265 mpo_mbuf_label_associate_netlayer_t *mpo_mbuf_label_associate_netlayer;
6266 mpo_mbuf_label_associate_socket_t *mpo_mbuf_label_associate_socket;
6267 mpo_mbuf_label_copy_t *mpo_mbuf_label_copy;
6268 mpo_mbuf_label_destroy_t *mpo_mbuf_label_destroy;
6269 mpo_mbuf_label_init_t *mpo_mbuf_label_init;
6270
6271 mpo_mount_check_fsctl_t *mpo_mount_check_fsctl;
6272 mpo_mount_check_getattr_t *mpo_mount_check_getattr;
6273 mpo_mount_check_label_update_t *mpo_mount_check_label_update;
6274 mpo_mount_check_mount_t *mpo_mount_check_mount;
6275 mpo_mount_check_remount_t *mpo_mount_check_remount;
6276 mpo_mount_check_setattr_t *mpo_mount_check_setattr;
6277 mpo_mount_check_stat_t *mpo_mount_check_stat;
6278 mpo_mount_check_umount_t *mpo_mount_check_umount;
6279 mpo_mount_label_associate_t *mpo_mount_label_associate;
6280 mpo_mount_label_destroy_t *mpo_mount_label_destroy;
6281 mpo_mount_label_externalize_t *mpo_mount_label_externalize;
6282 mpo_mount_label_init_t *mpo_mount_label_init;
6283 mpo_mount_label_internalize_t *mpo_mount_label_internalize;
6284
6285 mpo_netinet_fragment_t *mpo_netinet_fragment;
6286 mpo_netinet_icmp_reply_t *mpo_netinet_icmp_reply;
6287 mpo_netinet_tcp_reply_t *mpo_netinet_tcp_reply;
6288
6289 mpo_pipe_check_ioctl_t *mpo_pipe_check_ioctl;
6290 mpo_pipe_check_kqfilter_t *mpo_pipe_check_kqfilter;
6291 mpo_pipe_check_label_update_t *mpo_pipe_check_label_update;
6292 mpo_pipe_check_read_t *mpo_pipe_check_read;
6293 mpo_pipe_check_select_t *mpo_pipe_check_select;
6294 mpo_pipe_check_stat_t *mpo_pipe_check_stat;
6295 mpo_pipe_check_write_t *mpo_pipe_check_write;
6296 mpo_pipe_label_associate_t *mpo_pipe_label_associate;
6297 mpo_pipe_label_copy_t *mpo_pipe_label_copy;
6298 mpo_pipe_label_destroy_t *mpo_pipe_label_destroy;
6299 mpo_pipe_label_externalize_t *mpo_pipe_label_externalize;
6300 mpo_pipe_label_init_t *mpo_pipe_label_init;
6301 mpo_pipe_label_internalize_t *mpo_pipe_label_internalize;
6302 mpo_pipe_label_update_t *mpo_pipe_label_update;
6303
6304 mpo_policy_destroy_t *mpo_policy_destroy;
6305 mpo_policy_init_t *mpo_policy_init;
6306 mpo_policy_initbsd_t *mpo_policy_initbsd;
6307 mpo_policy_syscall_t *mpo_policy_syscall;
6308
6309 mpo_system_check_sysctlbyname_t *mpo_system_check_sysctlbyname;
6310 mpo_proc_check_inherit_ipc_ports_t *mpo_proc_check_inherit_ipc_ports;
6311 mpo_vnode_check_rename_t *mpo_vnode_check_rename;
6312 mpo_kext_check_query_t *mpo_kext_check_query;
6313 mpo_iokit_check_nvram_get_t *mpo_iokit_check_nvram_get;
6314 mpo_iokit_check_nvram_set_t *mpo_iokit_check_nvram_set;
6315 mpo_iokit_check_nvram_delete_t *mpo_iokit_check_nvram_delete;
6316 mpo_proc_check_expose_task_t *mpo_proc_check_expose_task;
6317 mpo_proc_check_set_host_special_port_t *mpo_proc_check_set_host_special_port;
6318 mpo_proc_check_set_host_exception_port_t *mpo_proc_check_set_host_exception_port;
6319 mpo_exc_action_check_exception_send_t *mpo_exc_action_check_exception_send;
6320 mpo_exc_action_label_associate_t *mpo_exc_action_label_associate;
6321 mpo_exc_action_label_copy_t *mpo_exc_action_label_copy;
6322 mpo_exc_action_label_destroy_t *mpo_exc_action_label_destroy;
6323 mpo_exc_action_label_init_t *mpo_exc_action_label_init;
6324 mpo_exc_action_label_update_t *mpo_exc_action_label_update;
6325
6326 mpo_reserved_hook_t *mpo_reserved1;
6327 mpo_reserved_hook_t *mpo_reserved2;
6328 mpo_reserved_hook_t *mpo_reserved3;
6329 mpo_reserved_hook_t *mpo_reserved4;
6330 mpo_reserved_hook_t *mpo_reserved5;
6331 mpo_reserved_hook_t *mpo_reserved6;
6332
6333 mpo_posixsem_check_create_t *mpo_posixsem_check_create;
6334 mpo_posixsem_check_open_t *mpo_posixsem_check_open;
6335 mpo_posixsem_check_post_t *mpo_posixsem_check_post;
6336 mpo_posixsem_check_unlink_t *mpo_posixsem_check_unlink;
6337 mpo_posixsem_check_wait_t *mpo_posixsem_check_wait;
6338 mpo_posixsem_label_associate_t *mpo_posixsem_label_associate;
6339 mpo_posixsem_label_destroy_t *mpo_posixsem_label_destroy;
6340 mpo_posixsem_label_init_t *mpo_posixsem_label_init;
6341 mpo_posixshm_check_create_t *mpo_posixshm_check_create;
6342 mpo_posixshm_check_mmap_t *mpo_posixshm_check_mmap;
6343 mpo_posixshm_check_open_t *mpo_posixshm_check_open;
6344 mpo_posixshm_check_stat_t *mpo_posixshm_check_stat;
6345 mpo_posixshm_check_truncate_t *mpo_posixshm_check_truncate;
6346 mpo_posixshm_check_unlink_t *mpo_posixshm_check_unlink;
6347 mpo_posixshm_label_associate_t *mpo_posixshm_label_associate;
6348 mpo_posixshm_label_destroy_t *mpo_posixshm_label_destroy;
6349 mpo_posixshm_label_init_t *mpo_posixshm_label_init;
6350
6351 mpo_proc_check_debug_t *mpo_proc_check_debug;
6352 mpo_proc_check_fork_t *mpo_proc_check_fork;
6353 mpo_proc_check_get_task_name_t *mpo_proc_check_get_task_name;
6354 mpo_proc_check_get_task_t *mpo_proc_check_get_task;
6355 mpo_proc_check_getaudit_t *mpo_proc_check_getaudit;
6356 mpo_proc_check_getauid_t *mpo_proc_check_getauid;
6357 mpo_proc_check_getlcid_t *mpo_proc_check_getlcid;
6358 mpo_proc_check_mprotect_t *mpo_proc_check_mprotect;
6359 mpo_proc_check_sched_t *mpo_proc_check_sched;
6360 mpo_proc_check_setaudit_t *mpo_proc_check_setaudit;
6361 mpo_proc_check_setauid_t *mpo_proc_check_setauid;
6362 mpo_proc_check_setlcid_t *mpo_proc_check_setlcid;
6363 mpo_proc_check_signal_t *mpo_proc_check_signal;
6364 mpo_proc_check_wait_t *mpo_proc_check_wait;
6365 mpo_proc_label_destroy_t *mpo_proc_label_destroy;
6366 mpo_proc_label_init_t *mpo_proc_label_init;
6367
6368 mpo_socket_check_accept_t *mpo_socket_check_accept;
6369 mpo_socket_check_accepted_t *mpo_socket_check_accepted;
6370 mpo_socket_check_bind_t *mpo_socket_check_bind;
6371 mpo_socket_check_connect_t *mpo_socket_check_connect;
6372 mpo_socket_check_create_t *mpo_socket_check_create;
6373 mpo_socket_check_deliver_t *mpo_socket_check_deliver;
6374 mpo_socket_check_kqfilter_t *mpo_socket_check_kqfilter;
6375 mpo_socket_check_label_update_t *mpo_socket_check_label_update;
6376 mpo_socket_check_listen_t *mpo_socket_check_listen;
6377 mpo_socket_check_receive_t *mpo_socket_check_receive;
6378 mpo_socket_check_received_t *mpo_socket_check_received;
6379 mpo_socket_check_select_t *mpo_socket_check_select;
6380 mpo_socket_check_send_t *mpo_socket_check_send;
6381 mpo_socket_check_stat_t *mpo_socket_check_stat;
6382 mpo_socket_check_setsockopt_t *mpo_socket_check_setsockopt;
6383 mpo_socket_check_getsockopt_t *mpo_socket_check_getsockopt;
6384 mpo_socket_label_associate_accept_t *mpo_socket_label_associate_accept;
6385 mpo_socket_label_associate_t *mpo_socket_label_associate;
6386 mpo_socket_label_copy_t *mpo_socket_label_copy;
6387 mpo_socket_label_destroy_t *mpo_socket_label_destroy;
6388 mpo_socket_label_externalize_t *mpo_socket_label_externalize;
6389 mpo_socket_label_init_t *mpo_socket_label_init;
6390 mpo_socket_label_internalize_t *mpo_socket_label_internalize;
6391 mpo_socket_label_update_t *mpo_socket_label_update;
6392
6393 mpo_socketpeer_label_associate_mbuf_t *mpo_socketpeer_label_associate_mbuf;
6394 mpo_socketpeer_label_associate_socket_t *mpo_socketpeer_label_associate_socket;
6395 mpo_socketpeer_label_destroy_t *mpo_socketpeer_label_destroy;
6396 mpo_socketpeer_label_externalize_t *mpo_socketpeer_label_externalize;
6397 mpo_socketpeer_label_init_t *mpo_socketpeer_label_init;
6398
6399 mpo_system_check_acct_t *mpo_system_check_acct;
6400 mpo_system_check_audit_t *mpo_system_check_audit;
6401 mpo_system_check_auditctl_t *mpo_system_check_auditctl;
6402 mpo_system_check_auditon_t *mpo_system_check_auditon;
6403 mpo_system_check_host_priv_t *mpo_system_check_host_priv;
6404 mpo_system_check_nfsd_t *mpo_system_check_nfsd;
6405 mpo_system_check_reboot_t *mpo_system_check_reboot;
6406 mpo_system_check_settime_t *mpo_system_check_settime;
6407 mpo_system_check_swapoff_t *mpo_system_check_swapoff;
6408 mpo_system_check_swapon_t *mpo_system_check_swapon;
6409 mpo_reserved_hook_t *mpo_reserved7;
6410
6411 mpo_sysvmsg_label_associate_t *mpo_sysvmsg_label_associate;
6412 mpo_sysvmsg_label_destroy_t *mpo_sysvmsg_label_destroy;
6413 mpo_sysvmsg_label_init_t *mpo_sysvmsg_label_init;
6414 mpo_sysvmsg_label_recycle_t *mpo_sysvmsg_label_recycle;
6415 mpo_sysvmsq_check_enqueue_t *mpo_sysvmsq_check_enqueue;
6416 mpo_sysvmsq_check_msgrcv_t *mpo_sysvmsq_check_msgrcv;
6417 mpo_sysvmsq_check_msgrmid_t *mpo_sysvmsq_check_msgrmid;
6418 mpo_sysvmsq_check_msqctl_t *mpo_sysvmsq_check_msqctl;
6419 mpo_sysvmsq_check_msqget_t *mpo_sysvmsq_check_msqget;
6420 mpo_sysvmsq_check_msqrcv_t *mpo_sysvmsq_check_msqrcv;
6421 mpo_sysvmsq_check_msqsnd_t *mpo_sysvmsq_check_msqsnd;
6422 mpo_sysvmsq_label_associate_t *mpo_sysvmsq_label_associate;
6423 mpo_sysvmsq_label_destroy_t *mpo_sysvmsq_label_destroy;
6424 mpo_sysvmsq_label_init_t *mpo_sysvmsq_label_init;
6425 mpo_sysvmsq_label_recycle_t *mpo_sysvmsq_label_recycle;
6426 mpo_sysvsem_check_semctl_t *mpo_sysvsem_check_semctl;
6427 mpo_sysvsem_check_semget_t *mpo_sysvsem_check_semget;
6428 mpo_sysvsem_check_semop_t *mpo_sysvsem_check_semop;
6429 mpo_sysvsem_label_associate_t *mpo_sysvsem_label_associate;
6430 mpo_sysvsem_label_destroy_t *mpo_sysvsem_label_destroy;
6431 mpo_sysvsem_label_init_t *mpo_sysvsem_label_init;
6432 mpo_sysvsem_label_recycle_t *mpo_sysvsem_label_recycle;
6433 mpo_sysvshm_check_shmat_t *mpo_sysvshm_check_shmat;
6434 mpo_sysvshm_check_shmctl_t *mpo_sysvshm_check_shmctl;
6435 mpo_sysvshm_check_shmdt_t *mpo_sysvshm_check_shmdt;
6436 mpo_sysvshm_check_shmget_t *mpo_sysvshm_check_shmget;
6437 mpo_sysvshm_label_associate_t *mpo_sysvshm_label_associate;
6438 mpo_sysvshm_label_destroy_t *mpo_sysvshm_label_destroy;
6439 mpo_sysvshm_label_init_t *mpo_sysvshm_label_init;
6440 mpo_sysvshm_label_recycle_t *mpo_sysvshm_label_recycle;
6441
6442 mpo_reserved_hook_t *mpo_reserved8;
6443 mpo_reserved_hook_t *mpo_reserved9;
6444 mpo_vnode_check_getattr_t *mpo_vnode_check_getattr;
6445 mpo_mount_check_snapshot_create_t *mpo_mount_check_snapshot_create;
6446 mpo_mount_check_snapshot_delete_t *mpo_mount_check_snapshot_delete;
6447 mpo_vnode_check_clone_t *mpo_vnode_check_clone;
6448 mpo_proc_check_get_cs_info_t *mpo_proc_check_get_cs_info;
6449 mpo_proc_check_set_cs_info_t *mpo_proc_check_set_cs_info;
6450
6451 mpo_iokit_check_hid_control_t *mpo_iokit_check_hid_control;
6452
6453 mpo_vnode_check_access_t *mpo_vnode_check_access;
6454 mpo_vnode_check_chdir_t *mpo_vnode_check_chdir;
6455 mpo_vnode_check_chroot_t *mpo_vnode_check_chroot;
6456 mpo_vnode_check_create_t *mpo_vnode_check_create;
6457 mpo_vnode_check_deleteextattr_t *mpo_vnode_check_deleteextattr;
6458 mpo_vnode_check_exchangedata_t *mpo_vnode_check_exchangedata;
6459 mpo_vnode_check_exec_t *mpo_vnode_check_exec;
6460 mpo_vnode_check_getattrlist_t *mpo_vnode_check_getattrlist;
6461 mpo_vnode_check_getextattr_t *mpo_vnode_check_getextattr;
6462 mpo_vnode_check_ioctl_t *mpo_vnode_check_ioctl;
6463 mpo_vnode_check_kqfilter_t *mpo_vnode_check_kqfilter;
6464 mpo_vnode_check_label_update_t *mpo_vnode_check_label_update;
6465 mpo_vnode_check_link_t *mpo_vnode_check_link;
6466 mpo_vnode_check_listextattr_t *mpo_vnode_check_listextattr;
6467 mpo_vnode_check_lookup_t *mpo_vnode_check_lookup;
6468 mpo_vnode_check_open_t *mpo_vnode_check_open;
6469 mpo_vnode_check_read_t *mpo_vnode_check_read;
6470 mpo_vnode_check_readdir_t *mpo_vnode_check_readdir;
6471 mpo_vnode_check_readlink_t *mpo_vnode_check_readlink;
6472 mpo_vnode_check_rename_from_t *mpo_vnode_check_rename_from;
6473 mpo_vnode_check_rename_to_t *mpo_vnode_check_rename_to;
6474 mpo_vnode_check_revoke_t *mpo_vnode_check_revoke;
6475 mpo_vnode_check_select_t *mpo_vnode_check_select;
6476 mpo_vnode_check_setattrlist_t *mpo_vnode_check_setattrlist;
6477 mpo_vnode_check_setextattr_t *mpo_vnode_check_setextattr;
6478 mpo_vnode_check_setflags_t *mpo_vnode_check_setflags;
6479 mpo_vnode_check_setmode_t *mpo_vnode_check_setmode;
6480 mpo_vnode_check_setowner_t *mpo_vnode_check_setowner;
6481 mpo_vnode_check_setutimes_t *mpo_vnode_check_setutimes;
6482 mpo_vnode_check_stat_t *mpo_vnode_check_stat;
6483 mpo_vnode_check_truncate_t *mpo_vnode_check_truncate;
6484 mpo_vnode_check_unlink_t *mpo_vnode_check_unlink;
6485 mpo_vnode_check_write_t *mpo_vnode_check_write;
6486 mpo_vnode_label_associate_devfs_t *mpo_vnode_label_associate_devfs;
6487 mpo_vnode_label_associate_extattr_t *mpo_vnode_label_associate_extattr;
6488 mpo_vnode_label_associate_file_t *mpo_vnode_label_associate_file;
6489 mpo_vnode_label_associate_pipe_t *mpo_vnode_label_associate_pipe;
6490 mpo_vnode_label_associate_posixsem_t *mpo_vnode_label_associate_posixsem;
6491 mpo_vnode_label_associate_posixshm_t *mpo_vnode_label_associate_posixshm;
6492 mpo_vnode_label_associate_singlelabel_t *mpo_vnode_label_associate_singlelabel;
6493 mpo_vnode_label_associate_socket_t *mpo_vnode_label_associate_socket;
6494 mpo_vnode_label_copy_t *mpo_vnode_label_copy;
6495 mpo_vnode_label_destroy_t *mpo_vnode_label_destroy;
6496 mpo_vnode_label_externalize_audit_t *mpo_vnode_label_externalize_audit;
6497 mpo_vnode_label_externalize_t *mpo_vnode_label_externalize;
6498 mpo_vnode_label_init_t *mpo_vnode_label_init;
6499 mpo_vnode_label_internalize_t *mpo_vnode_label_internalize;
6500 mpo_vnode_label_recycle_t *mpo_vnode_label_recycle;
6501 mpo_vnode_label_store_t *mpo_vnode_label_store;
6502 mpo_vnode_label_update_extattr_t *mpo_vnode_label_update_extattr;
6503 mpo_vnode_label_update_t *mpo_vnode_label_update;
6504 mpo_vnode_notify_create_t *mpo_vnode_notify_create;
6505 mpo_vnode_check_signature_t *mpo_vnode_check_signature;
6506 mpo_vnode_check_uipc_bind_t *mpo_vnode_check_uipc_bind;
6507 mpo_vnode_check_uipc_connect_t *mpo_vnode_check_uipc_connect;
6508
6509 mpo_proc_check_run_cs_invalid_t *mpo_proc_check_run_cs_invalid;
6510 mpo_proc_check_suspend_resume_t *mpo_proc_check_suspend_resume;
6511
6512 mpo_thread_userret_t *mpo_thread_userret;
6513
6514 mpo_iokit_check_set_properties_t *mpo_iokit_check_set_properties;
6515
6516 mpo_system_check_chud_t *mpo_system_check_chud;
6517
6518 mpo_vnode_check_searchfs_t *mpo_vnode_check_searchfs;
6519
6520 mpo_priv_check_t *mpo_priv_check;
6521 mpo_priv_grant_t *mpo_priv_grant;
6522
6523 mpo_proc_check_map_anon_t *mpo_proc_check_map_anon;
6524
6525 mpo_vnode_check_fsgetpath_t *mpo_vnode_check_fsgetpath;
6526
6527 mpo_iokit_check_open_t *mpo_iokit_check_open;
6528
6529 mpo_proc_check_ledger_t *mpo_proc_check_ledger;
6530
6531 mpo_vnode_notify_rename_t *mpo_vnode_notify_rename;
6532
6533 mpo_vnode_check_setacl_t *mpo_vnode_check_setacl;
6534
6535 mpo_vnode_notify_deleteextattr_t *mpo_vnode_notify_deleteextattr;
6536
6537 mpo_system_check_kas_info_t *mpo_system_check_kas_info;
6538
6539 mpo_proc_check_cpumon_t *mpo_proc_check_cpumon;
6540
6541 mpo_vnode_notify_open_t *mpo_vnode_notify_open;
6542
6543 mpo_system_check_info_t *mpo_system_check_info;
6544
6545 mpo_pty_notify_grant_t *mpo_pty_notify_grant;
6546 mpo_pty_notify_close_t *mpo_pty_notify_close;
6547
6548 mpo_vnode_find_sigs_t *mpo_vnode_find_sigs;
6549
6550 mpo_kext_check_load_t *mpo_kext_check_load;
6551 mpo_kext_check_unload_t *mpo_kext_check_unload;
6552
6553 mpo_proc_check_proc_info_t *mpo_proc_check_proc_info;
6554 mpo_vnode_notify_link_t *mpo_vnode_notify_link;
6555 mpo_iokit_check_filter_properties_t *mpo_iokit_check_filter_properties;
6556 mpo_iokit_check_get_property_t *mpo_iokit_check_get_property;
6557 };
6558
6559 /**
6560 @brief MAC policy handle type
6561
6562 The MAC handle is used to uniquely identify a loaded policy within
6563 the MAC Framework.
6564
6565 A variable of this type is set by mac_policy_register().
6566 */
6567 typedef unsigned int mac_policy_handle_t;
6568
6569 #define mpc_t struct mac_policy_conf *
6570
6571 /**
6572 @brief Mac policy configuration
6573
6574 This structure specifies the configuration information for a
6575 MAC policy module. A policy module developer must supply
6576 a short unique policy name, a more descriptive full name, a list of label
6577 namespaces and count, a pointer to the registered enty point operations,
6578 any load time flags, and optionally, a pointer to a label slot identifier.
6579
6580 The Framework will update the runtime flags (mpc_runtime_flags) to
6581 indicate that the module has been registered.
6582
6583 If the label slot identifier (mpc_field_off) is NULL, the Framework
6584 will not provide label storage for the policy. Otherwise, the
6585 Framework will store the label location (slot) in this field.
6586
6587 The mpc_list field is used by the Framework and should not be
6588 modified by policies.
6589 */
6590 /* XXX - reorder these for better aligment on 64bit platforms */
6591 struct mac_policy_conf {
6592 const char *mpc_name; /** policy name */
6593 const char *mpc_fullname; /** full name */
6594 const char **mpc_labelnames; /** managed label namespaces */
6595 unsigned int mpc_labelname_count; /** number of managed label namespaces */
6596 struct mac_policy_ops *mpc_ops; /** operation vector */
6597 int mpc_loadtime_flags; /** load time flags */
6598 int *mpc_field_off; /** label slot */
6599 int mpc_runtime_flags; /** run time flags */
6600 mpc_t mpc_list; /** List reference */
6601 void *mpc_data; /** module data */
6602 };
6603
6604 /**
6605 @brief MAC policy module registration routine
6606
6607 This function is called to register a policy with the
6608 MAC framework. A policy module will typically call this from the
6609 Darwin KEXT registration routine.
6610 */
6611 int mac_policy_register(struct mac_policy_conf *mpc,
6612 mac_policy_handle_t *handlep, void *xd);
6613
6614 /**
6615 @brief MAC policy module de-registration routine
6616
6617 This function is called to de-register a policy with theD
6618 MAC framework. A policy module will typically call this from the
6619 Darwin KEXT de-registration routine.
6620 */
6621 int mac_policy_unregister(mac_policy_handle_t handle);
6622
6623 /*
6624 * Framework entry points for the policies to add audit data.
6625 */
6626 int mac_audit_text(char *text, mac_policy_handle_t handle);
6627
6628 /*
6629 * Calls to assist with use of Apple XATTRs within policy modules.
6630 */
6631 int mac_vnop_setxattr(struct vnode *, const char *, char *, size_t);
6632 int mac_vnop_getxattr(struct vnode *, const char *, char *, size_t,
6633 size_t *);
6634 int mac_vnop_removexattr(struct vnode *, const char *);
6635
6636 /**
6637 @brief Set an extended attribute on a vnode-based fileglob.
6638 @param fg fileglob representing file to attach the extended attribute
6639 @param name extended attribute name
6640 @param buf buffer of data to use as the extended attribute value
6641 @param len size of buffer
6642
6643 Sets the value of an extended attribute on a file.
6644
6645 Caller must hold an iocount on the vnode represented by the fileglob.
6646 */
6647 int mac_file_setxattr(struct fileglob *fg, const char *name, char *buf, size_t len);
6648
6649 /**
6650 @brief Get an extended attribute from a vnode-based fileglob.
6651 @param fg fileglob representing file to read the extended attribute
6652 @param name extended attribute name
6653 @param buf buffer of data to hold the extended attribute value
6654 @param len size of buffer
6655 @param attrlen size of full extended attribute value
6656
6657 Gets the value of an extended attribute on a file.
6658
6659 Caller must hold an iocount on the vnode represented by the fileglob.
6660 */
6661 int mac_file_getxattr(struct fileglob *fg, const char *name, char *buf, size_t len,
6662 size_t *attrlen);
6663
6664 /**
6665 @brief Remove an extended attribute from a vnode-based fileglob.
6666 @param fg fileglob representing file to remove the extended attribute
6667 @param name extended attribute name
6668
6669 Removes the named extended attribute from the file.
6670
6671 Caller must hold an iocount on the vnode represented by the fileglob.
6672 */
6673 int mac_file_removexattr(struct fileglob *fg, const char *name);
6674
6675
6676 /*
6677 * Arbitrary limit on how much data will be logged by the audit
6678 * entry points above.
6679 */
6680 #define MAC_AUDIT_DATA_LIMIT 1024
6681
6682 /*
6683 * Values returned by mac_audit_{pre,post}select. To combine the responses
6684 * of the security policies into a single decision,
6685 * mac_audit_{pre,post}select() choose the greatest value returned.
6686 */
6687 #define MAC_AUDIT_DEFAULT 0 /* use system behavior */
6688 #define MAC_AUDIT_NO 1 /* force not auditing this event */
6689 #define MAC_AUDIT_YES 2 /* force auditing this event */
6690
6691 // \defgroup mpc_loadtime_flags Flags for the mpc_loadtime_flags field
6692
6693 /**
6694 @name Flags for the mpc_loadtime_flags field
6695 @see mac_policy_conf
6696
6697 This is the complete list of flags that are supported by the
6698 mpc_loadtime_flags field of the mac_policy_conf structure. These
6699 flags specify the load time behavior of MAC Framework policy
6700 modules.
6701 */
6702
6703 /*@{*/
6704
6705 /**
6706 @brief Flag to indicate registration preference
6707
6708 This flag indicates that the policy module must be loaded and
6709 initialized early in the boot process. If the flag is specified,
6710 attempts to register the module following boot will be rejected. The
6711 flag may be used by policies that require pervasive labeling of all
6712 system objects, and cannot handle objects that have not been
6713 properly initialized by the policy.
6714 */
6715 #define MPC_LOADTIME_FLAG_NOTLATE 0x00000001
6716
6717 /**
6718 @brief Flag to indicate unload preference
6719
6720 This flag indicates that the policy module may be unloaded. If this
6721 flag is not set, then the policy framework will reject requests to
6722 unload the module. This flag might be used by modules that allocate
6723 label state and are unable to free that state at runtime, or for
6724 modules that simply do not want to permit unload operations.
6725 */
6726 #define MPC_LOADTIME_FLAG_UNLOADOK 0x00000002
6727
6728 /**
6729 @brief Unsupported
6730
6731 XXX This flag is not yet supported.
6732 */
6733 #define MPC_LOADTIME_FLAG_LABELMBUFS 0x00000004
6734
6735 /**
6736 @brief Flag to indicate a base policy
6737
6738 This flag indicates that the policy module is a base policy. Only
6739 one module can declare itself as base, otherwise the boot process
6740 will be halted.
6741 */
6742 #define MPC_LOADTIME_BASE_POLICY 0x00000008
6743
6744 /*@}*/
6745
6746 /**
6747 @brief Policy registration flag
6748 @see mac_policy_conf
6749
6750 This flag indicates that the policy module has been successfully
6751 registered with the TrustedBSD MAC Framework. The Framework will
6752 set this flag in the mpc_runtime_flags field of the policy's
6753 mac_policy_conf structure after registering the policy.
6754 */
6755 #define MPC_RUNTIME_FLAG_REGISTERED 0x00000001
6756
6757 /*
6758 * Depends on POLICY_VER
6759 */
6760
6761 #ifndef POLICY_VER
6762 #define POLICY_VER 1.0
6763 #endif
6764
6765 #define MAC_POLICY_SET(handle, mpops, mpname, mpfullname, lnames, lcount, slot, lflags, rflags) \
6766 static struct mac_policy_conf mpname##_mac_policy_conf = { \
6767 .mpc_name = #mpname, \
6768 .mpc_fullname = mpfullname, \
6769 .mpc_labelnames = lnames, \
6770 .mpc_labelname_count = lcount, \
6771 .mpc_ops = mpops, \
6772 .mpc_loadtime_flags = lflags, \
6773 .mpc_field_off = slot, \
6774 .mpc_runtime_flags = rflags \
6775 }; \
6776 \
6777 static kern_return_t \
6778 kmod_start(kmod_info_t *ki, void *xd) \
6779 { \
6780 return mac_policy_register(&mpname##_mac_policy_conf, \
6781 &handle, xd); \
6782 } \
6783 \
6784 static kern_return_t \
6785 kmod_stop(kmod_info_t *ki, void *xd) \
6786 { \
6787 return mac_policy_unregister(handle); \
6788 } \
6789 \
6790 extern kern_return_t _start(kmod_info_t *ki, void *data); \
6791 extern kern_return_t _stop(kmod_info_t *ki, void *data); \
6792 \
6793 KMOD_EXPLICIT_DECL(security.mpname, POLICY_VER, _start, _stop) \
6794 kmod_start_func_t *_realmain = kmod_start; \
6795 kmod_stop_func_t *_antimain = kmod_stop; \
6796 int _kext_apple_cc = __APPLE_CC__
6797
6798
6799 #define LABEL_TO_SLOT(l, s) (l)->l_perpolicy[s]
6800
6801 /*
6802 * Policy interface to map a struct label pointer to per-policy data.
6803 * Typically, policies wrap this in their own accessor macro that casts an
6804 * intptr_t to a policy-specific data type.
6805 */
6806 intptr_t mac_label_get(struct label *l, int slot);
6807 void mac_label_set(struct label *l, int slot, intptr_t v);
6808
6809 #define mac_get_mpc(h) (mac_policy_list.entries[h].mpc)
6810
6811 /**
6812 @name Flags for MAC allocator interfaces
6813
6814 These flags are passed to the Darwin kernel allocator routines to
6815 indicate whether the allocation is permitted to block or not.
6816 Caution should be taken; some operations are not permitted to sleep,
6817 and some types of locks cannot be held when sleeping.
6818 */
6819
6820 /*@{*/
6821
6822 /**
6823 @brief Allocation operations may block
6824
6825 If memory is not immediately available, the allocation routine
6826 will block (typically sleeping) until memory is available.
6827
6828 @warning Inappropriate use of this flag may cause kernel panics.
6829 */
6830 #define MAC_WAITOK 0
6831
6832 /**
6833 @brief Allocation operations may not block
6834
6835 Rather than blocking, the allocator may return an error if memory
6836 is not immediately available. This type of allocation will not
6837 sleep, preserving locking semantics.
6838 */
6839 #define MAC_NOWAIT 1
6840
6841 /*@}*/
6842
6843 #endif /* !_SECURITY_MAC_POLICY_H_ */