]> git.saurik.com Git - apple/xnu.git/blob - security/mac_policy.h
dad8d90171cea2a57c013ffe09580f7179e4e456
[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 for fs_snapshot_revert
1827 @param cred Subject credential
1828 @mp Filesystem mount point to revert to snapshot
1829 @name Name of snapshot to revert to
1830
1831 Determine whether the subject identified by the credential can
1832 revert the filesystem at the given mount point to the named snapshot.
1833
1834 @return Return 0 if access is granted, otherwise an appropriate value
1835 for errno should be returned.
1836 */
1837 typedef int mpo_mount_check_snapshot_revert_t(
1838 kauth_cred_t cred,
1839 struct mount *mp,
1840 const char *name
1841 );
1842 /**
1843 @brief Access control check remounting a filesystem
1844 @param cred Subject credential
1845 @param mp The mount point
1846 @param mlabel Label currently associated with the mount point
1847
1848 Determine whether the subject identified by the credential can perform
1849 the remount operation on the target vnode.
1850
1851 @return Return 0 if access is granted, otherwise an appropriate value for
1852 errno should be returned.
1853 */
1854 typedef int mpo_mount_check_remount_t(
1855 kauth_cred_t cred,
1856 struct mount *mp,
1857 struct label *mlabel
1858 );
1859 /**
1860 @brief Access control check for the settting of file system attributes
1861 @param cred Subject credential
1862 @param mp The mount structure of the file system
1863 @param vfa The attributes requested
1864
1865 This entry point determines whether given subject can set information
1866 about the given file system, for example the volume name.
1867
1868 @return Return 0 if access is granted, otherwise an appropriate value for
1869 errno should be returned.
1870 */
1871
1872 typedef int mpo_mount_check_setattr_t(
1873 kauth_cred_t cred,
1874 struct mount *mp,
1875 struct label *mp_label,
1876 struct vfs_attr *vfa
1877 );
1878 /**
1879 @brief Access control check for file system statistics
1880 @param cred Subject credential
1881 @param mp Object file system mount
1882 @param mntlabel Policy label for mp
1883
1884 Determine whether the subject identified by the credential can see
1885 the results of a statfs performed on the file system. This call may
1886 be made in a number of situations, including during invocations of
1887 statfs(2) and related calls, as well as to determine what file systems
1888 to exclude from listings of file systems, such as when getfsstat(2)
1889 is invoked.
1890
1891 @return Return 0 if access is granted, otherwise an appropriate value for
1892 errno should be returned. Suggested failure: EACCES for label mismatch
1893 or EPERM for lack of privilege.
1894 */
1895 typedef int mpo_mount_check_stat_t(
1896 kauth_cred_t cred,
1897 struct mount *mp,
1898 struct label *mntlabel
1899 );
1900 /**
1901 @brief Access control check for unmounting a filesystem
1902 @param cred Subject credential
1903 @param mp The mount point
1904 @param mlabel Label associated with the mount point
1905
1906 Determine whether the subject identified by the credential can perform
1907 the unmount operation on the target vnode.
1908
1909 @return Return 0 if access is granted, otherwise an appropriate value for
1910 errno should be returned.
1911 */
1912 typedef int mpo_mount_check_umount_t(
1913 kauth_cred_t cred,
1914 struct mount *mp,
1915 struct label *mlabel
1916 );
1917 /**
1918 @brief Create mount labels
1919 @param cred Subject credential
1920 @param mp Mount point of file system being mounted
1921 @param mntlabel Label to associate with the new mount point
1922 @see mpo_mount_label_init_t
1923
1924 Fill out the labels on the mount point being created by the supplied
1925 user credential. This call is made when file systems are first mounted.
1926 */
1927 typedef void mpo_mount_label_associate_t(
1928 kauth_cred_t cred,
1929 struct mount *mp,
1930 struct label *mntlabel
1931 );
1932 /**
1933 @brief Destroy mount label
1934 @param label The label to be destroyed
1935
1936 Destroy a file system mount label. Since the
1937 object is going out of scope, policy modules should free any
1938 internal storage associated with the label so that it may be
1939 destroyed.
1940 */
1941 typedef void mpo_mount_label_destroy_t(
1942 struct label *label
1943 );
1944 /**
1945 @brief Externalize a mount point label
1946 @param label Label to be externalized
1947 @param element_name Name of the label namespace for which labels should be
1948 externalized
1949 @param sb String buffer to be filled with a text representation of the label
1950
1951 Produce an external representation of the mount point label. An
1952 externalized label consists of a text representation of the label
1953 contents that can be used with user applications. Policy-agnostic
1954 user space tools will display this externalized version.
1955
1956 The policy's externalize entry points will be called only if the
1957 policy has registered interest in the label namespace.
1958
1959 @return 0 on success, return non-zero if an error occurs while
1960 externalizing the label data.
1961
1962 */
1963 typedef int mpo_mount_label_externalize_t(
1964 struct label *label,
1965 char *element_name,
1966 struct sbuf *sb
1967 );
1968 /**
1969 @brief Initialize mount point label
1970 @param label New label to initialize
1971
1972 Initialize the label for a newly instantiated mount structure.
1973 This label is typically used to store a default label in the case
1974 that the file system has been mounted singlelabel. Since some
1975 file systems do not support persistent labels (extended attributes)
1976 or are read-only (such as CD-ROMs), it is often necessary to store
1977 a default label separately from the label of the mount point
1978 itself. Sleeping is permitted.
1979 */
1980 typedef void mpo_mount_label_init_t(
1981 struct label *label
1982 );
1983 /**
1984 @brief Internalize a mount point label
1985 @param label Label to be internalized
1986 @param element_name Name of the label namespace for which the label should
1987 be internalized
1988 @param element_data Text data to be internalized
1989
1990 Produce a mount point file system label from an external representation.
1991 An externalized label consists of a text representation of the label
1992 contents that can be used with user applications. Policy-agnostic
1993 user space tools will forward text version to the kernel for
1994 processing by individual policy modules.
1995
1996 The policy's internalize entry points will be called only if the
1997 policy has registered interest in the label namespace.
1998
1999 @return 0 on success, Otherwise, return non-zero if an error occurs
2000 while internalizing the label data.
2001
2002 */
2003 typedef int mpo_mount_label_internalize_t(
2004 struct label *label,
2005 char *element_name,
2006 char *element_data
2007 );
2008 /**
2009 @brief Set the label on an IPv4 datagram fragment
2010 @param datagram Datagram being fragmented
2011 @param datagramlabel Policy label for datagram
2012 @param fragment New fragment
2013 @param fragmentlabel Policy label for fragment
2014
2015 Called when an IPv4 datagram is fragmented into several smaller datagrams.
2016 Policies implementing mbuf labels will typically copy the label from the
2017 source datagram to the new fragment.
2018 */
2019 typedef void mpo_netinet_fragment_t(
2020 struct mbuf *datagram,
2021 struct label *datagramlabel,
2022 struct mbuf *fragment,
2023 struct label *fragmentlabel
2024 );
2025 /**
2026 @brief Set the label on an ICMP reply
2027 @param m mbuf containing the ICMP reply
2028 @param mlabel Policy label for m
2029
2030 A policy may wish to update the label of an mbuf that refers to
2031 an ICMP packet being sent in response to an IP packet. This may
2032 be called in response to a bad packet or an ICMP request.
2033 */
2034 typedef void mpo_netinet_icmp_reply_t(
2035 struct mbuf *m,
2036 struct label *mlabel
2037 );
2038 /**
2039 @brief Set the label on a TCP reply
2040 @param m mbuf containing the TCP reply
2041 @param mlabel Policy label for m
2042
2043 Called for outgoing TCP packets not associated with an actual socket.
2044 */
2045 typedef void mpo_netinet_tcp_reply_t(
2046 struct mbuf *m,
2047 struct label *mlabel
2048 );
2049 /**
2050 @brief Access control check for pipe ioctl
2051 @param cred Subject credential
2052 @param cpipe Object to be accessed
2053 @param pipelabel The label on the pipe
2054 @param cmd The ioctl command; see ioctl(2)
2055
2056 Determine whether the subject identified by the credential can perform
2057 the ioctl operation indicated by cmd.
2058
2059 @warning Since ioctl data is opaque from the standpoint of the MAC
2060 framework, policies must exercise extreme care when implementing
2061 access control checks.
2062
2063 @return Return 0 if access is granted, otherwise an appropriate value for
2064 errno should be returned.
2065
2066 */
2067 typedef int mpo_pipe_check_ioctl_t(
2068 kauth_cred_t cred,
2069 struct pipe *cpipe,
2070 struct label *pipelabel,
2071 unsigned int cmd
2072 );
2073 /**
2074 @brief Access control check for pipe kqfilter
2075 @param cred Subject credential
2076 @param kn Object knote
2077 @param cpipe Object to be accessed
2078 @param pipelabel Policy label for the pipe
2079
2080 Determine whether the subject identified by the credential can
2081 receive the knote on the passed pipe.
2082
2083 @return Return 0 if access if granted, otherwise an appropriate
2084 value for errno should be returned.
2085 */
2086 typedef int mpo_pipe_check_kqfilter_t(
2087 kauth_cred_t cred,
2088 struct knote *kn,
2089 struct pipe *cpipe,
2090 struct label *pipelabel
2091 );
2092 /**
2093 @brief Access control check for pipe relabel
2094 @param cred Subject credential
2095 @param cpipe Object to be accessed
2096 @param pipelabel The current label on the pipe
2097 @param newlabel The new label to be used
2098
2099 Determine whether the subject identified by the credential can
2100 perform a relabel operation on the passed pipe. The cred object holds
2101 the credentials of the subject performing the operation.
2102
2103 @return Return 0 if access is granted, otherwise an appropriate value for
2104 errno should be returned.
2105
2106 */
2107 typedef int mpo_pipe_check_label_update_t(
2108 kauth_cred_t cred,
2109 struct pipe *cpipe,
2110 struct label *pipelabel,
2111 struct label *newlabel
2112 );
2113 /**
2114 @brief Access control check for pipe read
2115 @param cred Subject credential
2116 @param cpipe Object to be accessed
2117 @param pipelabel The label on the pipe
2118
2119 Determine whether the subject identified by the credential can
2120 perform a read operation on the passed pipe. The cred object holds
2121 the credentials of the subject performing the operation.
2122
2123 @return Return 0 if access is granted, otherwise an appropriate value for
2124 errno should be returned.
2125
2126 */
2127 typedef int mpo_pipe_check_read_t(
2128 kauth_cred_t cred,
2129 struct pipe *cpipe,
2130 struct label *pipelabel
2131 );
2132 /**
2133 @brief Access control check for pipe select
2134 @param cred Subject credential
2135 @param cpipe Object to be accessed
2136 @param pipelabel The label on the pipe
2137 @param which The operation selected on: FREAD or FWRITE
2138
2139 Determine whether the subject identified by the credential can
2140 perform a select operation on the passed pipe. The cred object holds
2141 the credentials of the subject performing the operation.
2142
2143 @return Return 0 if access is granted, otherwise an appropriate value for
2144 errno should be returned.
2145
2146 */
2147 typedef int mpo_pipe_check_select_t(
2148 kauth_cred_t cred,
2149 struct pipe *cpipe,
2150 struct label *pipelabel,
2151 int which
2152 );
2153 /**
2154 @brief Access control check for pipe stat
2155 @param cred Subject credential
2156 @param cpipe Object to be accessed
2157 @param pipelabel The label on the pipe
2158
2159 Determine whether the subject identified by the credential can
2160 perform a stat operation on the passed pipe. The cred object holds
2161 the credentials of the subject performing the operation.
2162
2163 @return Return 0 if access is granted, otherwise an appropriate value for
2164 errno should be returned.
2165
2166 */
2167 typedef int mpo_pipe_check_stat_t(
2168 kauth_cred_t cred,
2169 struct pipe *cpipe,
2170 struct label *pipelabel
2171 );
2172 /**
2173 @brief Access control check for pipe write
2174 @param cred Subject credential
2175 @param cpipe Object to be accessed
2176 @param pipelabel The label on the pipe
2177
2178 Determine whether the subject identified by the credential can
2179 perform a write operation on the passed pipe. The cred object holds
2180 the credentials of the subject performing the operation.
2181
2182 @return Return 0 if access is granted, otherwise an appropriate value for
2183 errno should be returned.
2184
2185 */
2186 typedef int mpo_pipe_check_write_t(
2187 kauth_cred_t cred,
2188 struct pipe *cpipe,
2189 struct label *pipelabel
2190 );
2191 /**
2192 @brief Create a pipe label
2193 @param cred Subject credential
2194 @param cpipe object to be labeled
2195 @param pipelabel Label for the pipe object
2196
2197 Create a label for the pipe object being created by the supplied
2198 user credential. This call is made when the pipe is being created
2199 XXXPIPE(for one or both sides of the pipe?).
2200
2201 */
2202 typedef void mpo_pipe_label_associate_t(
2203 kauth_cred_t cred,
2204 struct pipe *cpipe,
2205 struct label *pipelabel
2206 );
2207 /**
2208 @brief Copy a pipe label
2209 @param src Source pipe label
2210 @param dest Destination pipe label
2211
2212 Copy the pipe label associated with src to dest.
2213 XXXPIPE Describe when this is used: most likely during pipe creation to
2214 copy from rpipe to wpipe.
2215 */
2216 typedef void mpo_pipe_label_copy_t(
2217 struct label *src,
2218 struct label *dest
2219 );
2220 /**
2221 @brief Destroy pipe label
2222 @param label The label to be destroyed
2223
2224 Destroy a pipe label. Since the object is going out of scope,
2225 policy modules should free any internal storage associated with the
2226 label so that it may be destroyed.
2227 */
2228 typedef void mpo_pipe_label_destroy_t(
2229 struct label *label
2230 );
2231 /**
2232 @brief Externalize a pipe label
2233 @param label Label to be externalized
2234 @param element_name Name of the label namespace for which labels should be
2235 externalized
2236 @param sb String buffer to be filled with a text representation of the label
2237
2238 Produce an external representation of the label on a pipe.
2239 An externalized label consists of a text representation
2240 of the label contents that can be used with user applications.
2241 Policy-agnostic user space tools will display this externalized
2242 version.
2243
2244 The policy's externalize entry points will be called only if the
2245 policy has registered interest in the label namespace.
2246
2247 @return 0 on success, return non-zero if an error occurs while
2248 externalizing the label data.
2249
2250 */
2251 typedef int mpo_pipe_label_externalize_t(
2252 struct label *label,
2253 char *element_name,
2254 struct sbuf *sb
2255 );
2256 /**
2257 @brief Initialize pipe label
2258 @param label New label to initialize
2259
2260 Initialize label storage for use with a newly instantiated pipe object.
2261 Sleeping is permitted.
2262 */
2263 typedef void mpo_pipe_label_init_t(
2264 struct label *label
2265 );
2266 /**
2267 @brief Internalize a pipe label
2268 @param label Label to be internalized
2269 @param element_name Name of the label namespace for which the label should
2270 be internalized
2271 @param element_data Text data to be internalized
2272
2273 Produce a pipe label from an external representation. An
2274 externalized label consists of a text representation of the label
2275 contents that can be used with user applications. Policy-agnostic
2276 user space tools will forward text version to the kernel for
2277 processing by individual policy modules.
2278
2279 The policy's internalize entry points will be called only if the
2280 policy has registered interest in the label namespace.
2281
2282 @return 0 on success, Otherwise, return non-zero if an error occurs
2283 while internalizing the label data.
2284
2285 */
2286 typedef int mpo_pipe_label_internalize_t(
2287 struct label *label,
2288 char *element_name,
2289 char *element_data
2290 );
2291 /**
2292 @brief Update a pipe label
2293 @param cred Subject credential
2294 @param cpipe Object to be labeled
2295 @param oldlabel Existing pipe label
2296 @param newlabel New label to replace existing label
2297 @see mpo_pipe_check_label_update_t
2298
2299 The subject identified by the credential has previously requested
2300 and was authorized to relabel the pipe; this entry point allows
2301 policies to perform the actual relabel operation. Policies should
2302 update oldlabel using the label stored in the newlabel parameter.
2303
2304 */
2305 typedef void mpo_pipe_label_update_t(
2306 kauth_cred_t cred,
2307 struct pipe *cpipe,
2308 struct label *oldlabel,
2309 struct label *newlabel
2310 );
2311 /**
2312 @brief Policy unload event
2313 @param mpc MAC policy configuration
2314
2315 This is the MAC Framework policy unload event. This entry point will
2316 only be called if the module's policy configuration allows unload (if
2317 the MPC_LOADTIME_FLAG_UNLOADOK is set). Most security policies won't
2318 want to be unloaded; they should set their flags to prevent this
2319 entry point from being called.
2320
2321 @warning During this call, the mac policy list mutex is held, so
2322 sleep operations cannot be performed, and calls out to other kernel
2323 subsystems must be made with caution.
2324
2325 @see MPC_LOADTIME_FLAG_UNLOADOK
2326 */
2327 typedef void mpo_policy_destroy_t(
2328 struct mac_policy_conf *mpc
2329 );
2330 /**
2331 @brief Policy initialization event
2332 @param mpc MAC policy configuration
2333 @see mac_policy_register
2334 @see mpo_policy_initbsd_t
2335
2336 This is the MAC Framework policy initialization event. This entry
2337 point is called during mac_policy_register, when the policy module
2338 is first registered with the MAC Framework. This is often done very
2339 early in the boot process, after the kernel Mach subsystem has been
2340 initialized, but prior to the BSD subsystem being initialized.
2341 Since the kernel BSD services are not yet available, it is possible
2342 that some initialization must occur later, possibly in the
2343 mpo_policy_initbsd_t policy entry point, such as registering BSD system
2344 controls (sysctls). Policy modules loaded at boot time will be
2345 registered and initialized before labeled Mach objects are created.
2346
2347 @warning During this call, the mac policy list mutex is held, so
2348 sleep operations cannot be performed, and calls out to other kernel
2349 subsystems must be made with caution.
2350 */
2351 typedef void mpo_policy_init_t(
2352 struct mac_policy_conf *mpc
2353 );
2354 /**
2355 @brief Policy BSD initialization event
2356 @param mpc MAC policy configuration
2357 @see mpo_policy_init_t
2358
2359 This entry point is called after the kernel BSD subsystem has been
2360 initialized. By this point, the module should already be loaded,
2361 registered, and initialized. Since policy modules are initialized
2362 before kernel BSD services are available, this second initialization
2363 phase is necessary. At this point, BSD services (memory management,
2364 synchronization primitives, vfs, etc.) are available, but the first
2365 process has not yet been created. Mach-related objects and tasks
2366 will already be fully initialized and may be in use--policies requiring
2367 ubiquitous labeling may also want to implement mpo_policy_init_t.
2368
2369 @warning During this call, the mac policy list mutex is held, so
2370 sleep operations cannot be performed, and calls out to other kernel
2371 subsystems must be made with caution.
2372 */
2373 typedef void mpo_policy_initbsd_t(
2374 struct mac_policy_conf *mpc
2375 );
2376 /**
2377 @brief Policy extension service
2378 @param p Calling process
2379 @param call Policy-specific syscall number
2380 @param arg Pointer to syscall arguments
2381
2382 This entry point provides a policy-multiplexed system call so that
2383 policies may provide additional services to user processes without
2384 registering specific system calls. The policy name provided during
2385 registration is used to demux calls from userland, and the arguments
2386 will be forwarded to this entry point. When implementing new
2387 services, security modules should be sure to invoke appropriate
2388 access control checks from the MAC framework as needed. For
2389 example, if a policy implements an augmented signal functionality,
2390 it should call the necessary signal access control checks to invoke
2391 the MAC framework and other registered policies.
2392
2393 @warning Since the format and contents of the policy-specific
2394 arguments are unknown to the MAC Framework, modules must perform the
2395 required copyin() of the syscall data on their own. No policy
2396 mediation is performed, so policies must perform any necessary
2397 access control checks themselves. If multiple policies are loaded,
2398 they will currently be unable to mediate calls to other policies.
2399
2400 @return In the event of an error, an appropriate value for errno
2401 should be returned, otherwise return 0 upon success.
2402 */
2403 typedef int mpo_policy_syscall_t(
2404 struct proc *p,
2405 int call,
2406 user_addr_t arg
2407 );
2408 /**
2409 @brief Access control check for POSIX semaphore create
2410 @param cred Subject credential
2411 @param name String name of the semaphore
2412
2413 Determine whether the subject identified by the credential can create
2414 a POSIX semaphore specified by name.
2415
2416 @return Return 0 if access is granted, otherwise an appropriate value for
2417 errno should be returned.
2418 */
2419 typedef int mpo_posixsem_check_create_t(
2420 kauth_cred_t cred,
2421 const char *name
2422 );
2423 /**
2424 @brief Access control check for POSIX semaphore open
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 open
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_open_t(
2436 kauth_cred_t cred,
2437 struct pseminfo *ps,
2438 struct label *semlabel
2439 );
2440 /**
2441 @brief Access control check for POSIX semaphore post
2442 @param cred Subject credential
2443 @param ps Pointer to semaphore information structure
2444 @param semlabel Label associated with the semaphore
2445
2446 Determine whether the subject identified by the credential can unlock
2447 the named POSIX semaphore with label semlabel.
2448
2449 @return Return 0 if access is granted, otherwise an appropriate value for
2450 errno should be returned.
2451 */
2452 typedef int mpo_posixsem_check_post_t(
2453 kauth_cred_t cred,
2454 struct pseminfo *ps,
2455 struct label *semlabel
2456 );
2457 /**
2458 @brief Access control check for POSIX semaphore unlink
2459 @param cred Subject credential
2460 @param ps Pointer to semaphore information structure
2461 @param semlabel Label associated with the semaphore
2462 @param name String name of the semaphore
2463
2464 Determine whether the subject identified by the credential can remove
2465 the named POSIX semaphore with label semlabel.
2466
2467 @return Return 0 if access is granted, otherwise an appropriate value for
2468 errno should be returned.
2469 */
2470 typedef int mpo_posixsem_check_unlink_t(
2471 kauth_cred_t cred,
2472 struct pseminfo *ps,
2473 struct label *semlabel,
2474 const char *name
2475 );
2476 /**
2477 @brief Access control check for POSIX semaphore wait
2478 @param cred Subject credential
2479 @param ps Pointer to semaphore information structure
2480 @param semlabel Label associated with the semaphore
2481
2482 Determine whether the subject identified by the credential can lock
2483 the named POSIX semaphore with label semlabel.
2484
2485 @return Return 0 if access is granted, otherwise an appropriate value for
2486 errno should be returned.
2487 */
2488 typedef int mpo_posixsem_check_wait_t(
2489 kauth_cred_t cred,
2490 struct pseminfo *ps,
2491 struct label *semlabel
2492 );
2493 /**
2494 @brief Create a POSIX semaphore label
2495 @param cred Subject credential
2496 @param ps Pointer to semaphore information structure
2497 @param semlabel Label to associate with the new semaphore
2498 @param name String name of the semaphore
2499
2500 Label a new POSIX semaphore. The label was previously
2501 initialized and associated with the semaphore. At this time, an
2502 appropriate initial label value should be assigned to the object and
2503 stored in semalabel.
2504 */
2505 typedef void mpo_posixsem_label_associate_t(
2506 kauth_cred_t cred,
2507 struct pseminfo *ps,
2508 struct label *semlabel,
2509 const char *name
2510 );
2511 /**
2512 @brief Destroy POSIX semaphore label
2513 @param label The label to be destroyed
2514
2515 Destroy a POSIX semaphore label. Since the object is
2516 going out of scope, policy modules should free any internal storage
2517 associated with the label so that it may be destroyed.
2518 */
2519 typedef void mpo_posixsem_label_destroy_t(
2520 struct label *label
2521 );
2522 /**
2523 @brief Initialize POSIX semaphore label
2524 @param label New label to initialize
2525
2526 Initialize the label for a newly instantiated POSIX semaphore. Sleeping
2527 is permitted.
2528 */
2529 typedef void mpo_posixsem_label_init_t(
2530 struct label *label
2531 );
2532 /**
2533 @brief Access control check for POSIX shared memory region create
2534 @param cred Subject credential
2535 @param name String name of the shared memory region
2536
2537 Determine whether the subject identified by the credential can create
2538 the POSIX shared memory region referenced by name.
2539
2540 @return Return 0 if access is granted, otherwise an appropriate value for
2541 errno should be returned.
2542 */
2543 typedef int mpo_posixshm_check_create_t(
2544 kauth_cred_t cred,
2545 const char *name
2546 );
2547 /**
2548 @brief Access control check for mapping POSIX shared memory
2549 @param cred Subject credential
2550 @param ps Pointer to shared memory information structure
2551 @param shmlabel Label associated with the shared memory region
2552 @param prot mmap protections; see mmap(2)
2553 @param flags shmat flags; see shmat(2)
2554
2555 Determine whether the subject identified by the credential can map
2556 the POSIX shared memory segment associated with shmlabel.
2557
2558 @return Return 0 if access is granted, otherwise an appropriate value for
2559 errno should be returned.
2560 */
2561 typedef int mpo_posixshm_check_mmap_t(
2562 kauth_cred_t cred,
2563 struct pshminfo *ps,
2564 struct label *shmlabel,
2565 int prot,
2566 int flags
2567 );
2568 /**
2569 @brief Access control check for POSIX shared memory region open
2570 @param cred Subject credential
2571 @param ps Pointer to shared memory information structure
2572 @param shmlabel Label associated with the shared memory region
2573 @param fflags shm_open(2) open flags ('fflags' encoded)
2574
2575 Determine whether the subject identified by the credential can open
2576 the POSIX shared memory region.
2577
2578 @return Return 0 if access is granted, otherwise an appropriate value for
2579 errno should be returned.
2580 */
2581 typedef int mpo_posixshm_check_open_t(
2582 kauth_cred_t cred,
2583 struct pshminfo *ps,
2584 struct label *shmlabel,
2585 int fflags
2586 );
2587 /**
2588 @brief Access control check for POSIX shared memory stat
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
2593 Determine whether the subject identified by the credential can obtain
2594 status for the POSIX shared memory segment associated with shmlabel.
2595
2596 @return Return 0 if access is granted, otherwise an appropriate value for
2597 errno should be returned.
2598 */
2599 typedef int mpo_posixshm_check_stat_t(
2600 kauth_cred_t cred,
2601 struct pshminfo *ps,
2602 struct label *shmlabel
2603 );
2604 /**
2605 @brief Access control check for POSIX shared memory truncate
2606 @param cred Subject credential
2607 @param ps Pointer to shared memory information structure
2608 @param shmlabel Label associated with the shared memory region
2609 @param len Length to truncate or extend shared memory segment
2610
2611 Determine whether the subject identified by the credential can truncate
2612 or extend (to len) the POSIX shared memory segment associated with shmlabel.
2613
2614 @return Return 0 if access is granted, otherwise an appropriate value for
2615 errno should be returned.
2616 */
2617 typedef int mpo_posixshm_check_truncate_t(
2618 kauth_cred_t cred,
2619 struct pshminfo *ps,
2620 struct label *shmlabel,
2621 off_t len
2622 );
2623 /**
2624 @brief Access control check for POSIX shared memory unlink
2625 @param cred Subject credential
2626 @param ps Pointer to shared memory information structure
2627 @param shmlabel Label associated with the shared memory region
2628 @param name String name of the shared memory region
2629
2630 Determine whether the subject identified by the credential can delete
2631 the POSIX shared memory segment associated with shmlabel.
2632
2633 @return Return 0 if access is granted, otherwise an appropriate value for
2634 errno should be returned.
2635 */
2636 typedef int mpo_posixshm_check_unlink_t(
2637 kauth_cred_t cred,
2638 struct pshminfo *ps,
2639 struct label *shmlabel,
2640 const char *name
2641 );
2642 /**
2643 @brief Create a POSIX shared memory region label
2644 @param cred Subject credential
2645 @param ps Pointer to shared memory information structure
2646 @param shmlabel Label to associate with the new shared memory region
2647 @param name String name of the shared memory region
2648
2649 Label a new POSIX shared memory region. The label was previously
2650 initialized and associated with the shared memory region. At this
2651 time, an appropriate initial label value should be assigned to the
2652 object and stored in shmlabel.
2653 */
2654 typedef void mpo_posixshm_label_associate_t(
2655 kauth_cred_t cred,
2656 struct pshminfo *ps,
2657 struct label *shmlabel,
2658 const char *name
2659 );
2660 /**
2661 @brief Destroy POSIX shared memory label
2662 @param label The label to be destroyed
2663
2664 Destroy a POSIX shared memory region label. Since the
2665 object is going out of scope, policy modules should free any
2666 internal storage associated with the label so that it may be
2667 destroyed.
2668 */
2669 typedef void mpo_posixshm_label_destroy_t(
2670 struct label *label
2671 );
2672 /**
2673 @brief Initialize POSIX Shared Memory region label
2674 @param label New label to initialize
2675
2676 Initialize the label for newly a instantiated POSIX Shared Memory
2677 region. Sleeping is permitted.
2678 */
2679 typedef void mpo_posixshm_label_init_t(
2680 struct label *label
2681 );
2682 /**
2683 @brief Access control check for privileged operations
2684 @param cred Subject credential
2685 @param priv Requested privilege (see sys/priv.h)
2686
2687 Determine whether the subject identified by the credential can perform
2688 a privileged operation. Privileged operations are allowed if the cred
2689 is the superuser or any policy returns zero for mpo_priv_grant, unless
2690 any policy returns nonzero for mpo_priv_check.
2691
2692 @return Return 0 if access is granted, otherwise EPERM should be returned.
2693 */
2694 typedef int mpo_priv_check_t(
2695 kauth_cred_t cred,
2696 int priv
2697 );
2698 /**
2699 @brief Grant regular users the ability to perform privileged operations
2700 @param cred Subject credential
2701 @param priv Requested privilege (see sys/priv.h)
2702
2703 Determine whether the subject identified by the credential should be
2704 allowed to perform a privileged operation that in the absense of any
2705 MAC policy it would not be able to perform. Privileged operations are
2706 allowed if the cred is the superuser or any policy returns zero for
2707 mpo_priv_grant, unless any policy returns nonzero for mpo_priv_check.
2708
2709 Unlike other MAC hooks which can only reduce the privilege of a
2710 credential, this hook raises the privilege of a credential when it
2711 returns 0. Extreme care must be taken when implementing this hook to
2712 avoid undermining the security of the system.
2713
2714 @return Return 0 if additional privilege is granted, otherwise EPERM
2715 should be returned.
2716 */
2717 typedef int mpo_priv_grant_t(
2718 kauth_cred_t cred,
2719 int priv
2720 );
2721 /**
2722 @brief Access control check for debugging process
2723 @param cred Subject credential
2724 @param proc Object process
2725
2726 Determine whether the subject identified by the credential can debug
2727 the passed process. This call may be made in a number of situations,
2728 including use of the ptrace(2) and ktrace(2) APIs, as well as for some
2729 types of procfs operations.
2730
2731 @return Return 0 if access is granted, otherwise an appropriate value for
2732 errno should be returned. Suggested failure: EACCES for label mismatch,
2733 EPERM for lack of privilege, or ESRCH to hide visibility of the target.
2734 */
2735 typedef int mpo_proc_check_debug_t(
2736 kauth_cred_t cred,
2737 struct proc *proc
2738 );
2739 /**
2740 @brief Access control over fork
2741 @param cred Subject credential
2742 @param proc Subject process trying to fork
2743
2744 Determine whether the subject identified is allowed to fork.
2745
2746 @return Return 0 if access is granted, otherwise an appropriate value for
2747 errno should be returned.
2748 */
2749 typedef int mpo_proc_check_fork_t(
2750 kauth_cred_t cred,
2751 struct proc *proc
2752 );
2753 /**
2754 @brief Access control check for setting host special ports.
2755 @param cred Subject credential
2756 @param id The host special port to set
2757 @param port The new value to set for the special port
2758
2759 @return Return 0 if access is granted, otherwise an appropriate value for
2760 errno should be returned.
2761 */
2762 typedef int mpo_proc_check_set_host_special_port_t(
2763 kauth_cred_t cred,
2764 int id,
2765 struct ipc_port *port
2766 );
2767 /**
2768 @brief Access control check for setting host exception ports.
2769 @param cred Subject credential
2770 @param exception Exception port to set
2771
2772 @return Return 0 if access is granted, otherwise an appropriate value for
2773 errno should be returned.
2774 */
2775 typedef int mpo_proc_check_set_host_exception_port_t(
2776 kauth_cred_t cred,
2777 unsigned int exception
2778 );
2779 /**
2780 @brief Access control over pid_suspend and pid_resume
2781 @param cred Subject credential
2782 @param proc Subject process trying to run pid_suspend or pid_resume
2783 @param sr Call is suspend (0) or resume (1)
2784
2785 Determine whether the subject identified is allowed to suspend or resume
2786 other processes.
2787
2788 @return Return 0 if access is granted, otherwise an appropriate value for
2789 errno should be returned.
2790 */
2791 typedef int mpo_proc_check_suspend_resume_t(
2792 kauth_cred_t cred,
2793 struct proc *proc,
2794 int sr
2795 );
2796 /**
2797 @brief Access control check for retrieving audit information
2798 @param cred Subject credential
2799
2800 Determine whether the subject identified by the credential can get
2801 audit information such as the audit user ID, the preselection mask,
2802 the terminal ID and the audit session ID, using the getaudit() system call.
2803
2804 @return Return 0 if access is granted, otherwise an appropriate value for
2805 errno should be returned.
2806 */
2807 typedef int mpo_proc_check_getaudit_t(
2808 kauth_cred_t cred
2809 );
2810 /**
2811 @brief Access control check for retrieving audit user ID
2812 @param cred Subject credential
2813
2814 Determine whether the subject identified by the credential can get
2815 the user identity being used by the auditing system, using the getauid()
2816 system call.
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_getauid_t(
2822 kauth_cred_t cred
2823 );
2824 /**
2825 @brief Access control check for retrieving Login Context ID
2826 @param p0 Calling process
2827 @param p Effected process
2828 @param pid syscall PID argument
2829
2830 Determine if getlcid(2) system call is permitted.
2831
2832 Information returned by this system call is similar to that returned via
2833 process listings etc.
2834
2835 @return Return 0 if access is granted, otherwise an appropriate value for
2836 errno should be returned.
2837 */
2838 typedef int mpo_proc_check_getlcid_t(
2839 struct proc *p0,
2840 struct proc *p,
2841 pid_t pid
2842 );
2843 /**
2844 @brief Access control check for retrieving ledger information
2845 @param cred Subject credential
2846 @param target Object process
2847 @param op ledger operation
2848
2849 Determine if ledger(2) system call is permitted.
2850
2851 Information returned by this system call is similar to that returned via
2852 process listings etc.
2853
2854 @return Return 0 if access is granted, otherwise an appropriate value for
2855 errno should be returned.
2856 */
2857 typedef int mpo_proc_check_ledger_t(
2858 kauth_cred_t cred,
2859 struct proc *target,
2860 int op
2861 );
2862 /**
2863 @brief Access control check for escaping default CPU usage monitor parameters.
2864 @param cred Subject credential
2865
2866 Determine if a credential has permission to program CPU usage monitor parameters
2867 that are less restrictive than the global system-wide defaults.
2868
2869 @return Return 0 if access is granted, otherwise an appropriate value for
2870 errno should be returned.
2871 */
2872 typedef int mpo_proc_check_cpumon_t(
2873 kauth_cred_t cred
2874 );
2875 /**
2876 @brief Access control check for retrieving process information.
2877 @param cred Subject credential
2878 @param target Target process (may be null, may be zombie)
2879
2880 Determine if a credential has permission to access process information as defined
2881 by call number and flavor on target process
2882
2883 @return Return 0 if access is granted, otherwise an appropriate value for
2884 errno should be returned.
2885 */
2886 typedef int mpo_proc_check_proc_info_t(
2887 kauth_cred_t cred,
2888 struct proc *target,
2889 int callnum,
2890 int flavor
2891 );
2892 /**
2893 @brief Access control check for retrieving 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 get code signing information about the target process.
2900
2901 @return Return 0 if access is granted, otherwise an appropriate value for
2902 errno should be returned.
2903 */
2904 typedef int mpo_proc_check_get_cs_info_t(
2905 kauth_cred_t cred,
2906 struct proc *target,
2907 unsigned int op
2908 );
2909 /**
2910 @brief Access control check for setting code signing information.
2911 @param cred Subject credential
2912 @param target Target process
2913 @param op Code signing operation being performed.
2914
2915 Determine whether the subject identified by the credential should be
2916 allowed to set code signing information about the target process.
2917
2918 @return Return 0 if permission is granted, otherwise an appropriate
2919 value of errno should be returned.
2920 */
2921 typedef int mpo_proc_check_set_cs_info_t(
2922 kauth_cred_t cred,
2923 struct proc *target,
2924 unsigned int op
2925 );
2926 /**
2927 @brief Access control check for mmap MAP_ANON
2928 @param proc User process requesting the memory
2929 @param cred Subject credential
2930 @param u_addr Start address of the memory range
2931 @param u_size Length address of the memory range
2932 @param prot mmap protections; see mmap(2)
2933 @param flags Type of mapped object; see mmap(2)
2934 @param maxprot Maximum rights
2935
2936 Determine whether the subject identified by the credential should be
2937 allowed to obtain anonymous memory using the specified flags and
2938 protections on the new mapping. MAP_ANON will always be present in the
2939 flags. Certain combinations of flags with a non-NULL addr may
2940 cause a mapping to be rejected before this hook is called. The maxprot field
2941 holds the maximum permissions on the new mapping, a combination of
2942 VM_PROT_READ, VM_PROT_WRITE and VM_PROT_EXECUTE. To avoid overriding prior
2943 access control checks, a policy should only remove flags from maxprot.
2944
2945 @return Return 0 if access is granted, otherwise an appropriate value for
2946 errno should be returned. Suggested failure: EPERM for lack of privilege.
2947 */
2948 typedef int mpo_proc_check_map_anon_t(
2949 struct proc *proc,
2950 kauth_cred_t cred,
2951 user_addr_t u_addr,
2952 user_size_t u_size,
2953 int prot,
2954 int flags,
2955 int *maxprot
2956 );
2957 /**
2958 @brief Access control check for setting memory protections
2959 @param cred Subject credential
2960 @param proc User process requesting the change
2961 @param addr Start address of the memory range
2962 @param size Length address of the memory range
2963 @param prot Memory protections, see mmap(2)
2964
2965 Determine whether the subject identified by the credential should
2966 be allowed to set the specified memory protections on memory mapped
2967 in the process proc.
2968
2969 @return Return 0 if access is granted, otherwise an appropriate value for
2970 errno should be returned.
2971 */
2972 typedef int mpo_proc_check_mprotect_t(
2973 kauth_cred_t cred,
2974 struct proc *proc,
2975 user_addr_t addr,
2976 user_size_t size,
2977 int prot
2978 );
2979 /**
2980 @brief Access control check for changing scheduling parameters
2981 @param cred Subject credential
2982 @param proc Object process
2983
2984 Determine whether the subject identified by the credential can change
2985 the scheduling parameters of the passed process.
2986
2987 @return Return 0 if access is granted, otherwise an appropriate value for
2988 errno should be returned. Suggested failure: EACCES for label mismatch,
2989 EPERM for lack of privilege, or ESRCH to limit visibility.
2990 */
2991 typedef int mpo_proc_check_sched_t(
2992 kauth_cred_t cred,
2993 struct proc *proc
2994 );
2995 /**
2996 @brief Access control check for setting audit information
2997 @param cred Subject credential
2998 @param ai Audit information
2999
3000 Determine whether the subject identified by the credential can set
3001 audit information such as the the preselection mask, the terminal ID
3002 and the audit session ID, using the setaudit() system call.
3003
3004 @return Return 0 if access is granted, otherwise an appropriate value for
3005 errno should be returned.
3006 */
3007 typedef int mpo_proc_check_setaudit_t(
3008 kauth_cred_t cred,
3009 struct auditinfo_addr *ai
3010 );
3011 /**
3012 @brief Access control check for setting audit user ID
3013 @param cred Subject credential
3014 @param auid Audit user ID
3015
3016 Determine whether the subject identified by the credential can set
3017 the user identity used by the auditing system, using the setauid()
3018 system call.
3019
3020 @return Return 0 if access is granted, otherwise an appropriate value for
3021 errno should be returned.
3022 */
3023 typedef int mpo_proc_check_setauid_t(
3024 kauth_cred_t cred,
3025 uid_t auid
3026 );
3027 /**
3028 @brief Access control check for setting the Login Context
3029 @param p0 Calling process
3030 @param p Effected process
3031 @param pid syscall PID argument
3032 @param lcid syscall LCID argument
3033
3034 Determine if setlcid(2) system call is permitted.
3035
3036 See xnu/bsd/kern/kern_prot.c:setlcid() implementation for example of
3037 decoding syscall arguments to determine action desired by caller.
3038
3039 Five distinct actions are possible: CREATE JOIN LEAVE ADOPT ORPHAN
3040
3041 @return Return 0 if access is granted, otherwise an appropriate value for
3042 errno should be returned.
3043 */
3044 typedef int mpo_proc_check_setlcid_t(
3045 struct proc *p0,
3046 struct proc *p,
3047 pid_t pid,
3048 pid_t lcid
3049 );
3050 /**
3051 @brief Access control check for delivering signal
3052 @param cred Subject credential
3053 @param proc Object process
3054 @param signum Signal number; see kill(2)
3055
3056 Determine whether the subject identified by the credential can deliver
3057 the passed signal to the passed process.
3058
3059 @warning Programs typically expect to be able to send and receive
3060 signals as part or their normal process lifecycle; caution should be
3061 exercised when implementing access controls over signal events.
3062
3063 @return Return 0 if access is granted, otherwise an appropriate value for
3064 errno should be returned. Suggested failure: EACCES for label mismatch,
3065 EPERM for lack of privilege, or ESRCH to limit visibility.
3066 */
3067 typedef int mpo_proc_check_signal_t(
3068 kauth_cred_t cred,
3069 struct proc *proc,
3070 int signum
3071 );
3072 /**
3073 @brief Access control check for wait
3074 @param cred Subject credential
3075 @param proc Object process
3076
3077 Determine whether the subject identified by the credential can wait
3078 for process termination.
3079
3080 @warning Caution should be exercised when implementing access
3081 controls for wait, since programs often wait for child processes to
3082 exit. Failure to be notified of a child process terminating may
3083 cause the parent process to hang, or may produce zombie processes.
3084
3085 @return Return 0 if access is granted, otherwise an appropriate value for
3086 errno should be returned.
3087 */
3088 typedef int mpo_proc_check_wait_t(
3089 kauth_cred_t cred,
3090 struct proc *proc
3091 );
3092 /**
3093 @brief Destroy process label
3094 @param label The label to be destroyed
3095
3096 Destroy a process label. Since the object is going
3097 out of scope, policy modules should free any internal storage
3098 associated with the label so that it may be destroyed.
3099 */
3100 typedef void mpo_proc_label_destroy_t(
3101 struct label *label
3102 );
3103 /**
3104 @brief Initialize process label
3105 @param label New label to initialize
3106 @see mpo_cred_label_init_t
3107
3108 Initialize the label for a newly instantiated BSD process structure.
3109 Normally, security policies will store the process label in the user
3110 credential rather than here in the process structure. However,
3111 there are some floating label policies that may need to temporarily
3112 store a label in the process structure until it is safe to update
3113 the user credential label. Sleeping is permitted.
3114 */
3115 typedef void mpo_proc_label_init_t(
3116 struct label *label
3117 );
3118 /**
3119 @brief Access control check for socket accept
3120 @param cred Subject credential
3121 @param so Object socket
3122 @param socklabel Policy label for socket
3123
3124 Determine whether the subject identified by the credential can accept()
3125 a new connection on the socket from the host specified by addr.
3126
3127 @return Return 0 if access if granted, otherwise an appropriate
3128 value for errno should be returned.
3129 */
3130 typedef int mpo_socket_check_accept_t(
3131 kauth_cred_t cred,
3132 socket_t so,
3133 struct label *socklabel
3134 );
3135 /**
3136 @brief Access control check for a pending socket accept
3137 @param cred Subject credential
3138 @param so Object socket
3139 @param socklabel Policy label for socket
3140 @param addr Address of the listening socket (coming soon)
3141
3142 Determine whether the subject identified by the credential can accept()
3143 a pending connection on the socket from the host specified by addr.
3144
3145 @return Return 0 if access if granted, otherwise an appropriate
3146 value for errno should be returned.
3147 */
3148 typedef int mpo_socket_check_accepted_t(
3149 kauth_cred_t cred,
3150 socket_t so,
3151 struct label *socklabel,
3152 struct sockaddr *addr
3153 );
3154 /**
3155 @brief Access control check for socket bind
3156 @param cred Subject credential
3157 @param so Object socket
3158 @param socklabel Policy label for socket
3159 @param addr Name to assign to the socket
3160
3161 Determine whether the subject identified by the credential can bind()
3162 the name (addr) to the socket.
3163
3164 @return Return 0 if access if granted, otherwise an appropriate
3165 value for errno should be returned.
3166 */
3167 typedef int mpo_socket_check_bind_t(
3168 kauth_cred_t cred,
3169 socket_t so,
3170 struct label *socklabel,
3171 struct sockaddr *addr
3172 );
3173 /**
3174 @brief Access control check for socket connect
3175 @param cred Subject credential
3176 @param so Object socket
3177 @param socklabel Policy label for socket
3178 @param addr Name to assign to the socket
3179
3180 Determine whether the subject identified by the credential can
3181 connect() the passed socket to the remote host specified by addr.
3182
3183 @return Return 0 if access if granted, otherwise an appropriate
3184 value for errno should be returned.
3185 */
3186 typedef int mpo_socket_check_connect_t(
3187 kauth_cred_t cred,
3188 socket_t so,
3189 struct label *socklabel,
3190 struct sockaddr *addr
3191 );
3192 /**
3193 @brief Access control check for socket() system call.
3194 @param cred Subject credential
3195 @param domain communication domain
3196 @param type socket type
3197 @param protocol socket protocol
3198
3199 Determine whether the subject identified by the credential can
3200 make the socket() call.
3201
3202 @return Return 0 if access if granted, otherwise an appropriate
3203 value for errno should be returned.
3204 */
3205 typedef int mpo_socket_check_create_t(
3206 kauth_cred_t cred,
3207 int domain,
3208 int type,
3209 int protocol
3210 );
3211 /**
3212 @brief Access control check for delivering data to a user's receieve queue
3213 @param so The socket data is being delivered to
3214 @param so_label The label of so
3215 @param m The mbuf whose data will be deposited into the receive queue
3216 @param m_label The label of the sender of the data.
3217
3218 A socket has a queue for receiving incoming data. When a packet arrives
3219 on the wire, it eventually gets deposited into this queue, which the
3220 owner of the socket drains when they read from the socket's file descriptor.
3221
3222 This function determines whether the socket can receive data from
3223 the sender specified by m_label.
3224
3225 @warning There is an outstanding design issue surrounding the placement
3226 of this function. The check must be placed either before or after the
3227 TCP sequence and ACK counters are updated. Placing the check before
3228 the counters are updated causes the incoming packet to be resent by
3229 the remote if the check rejects it. Placing the check after the counters
3230 are updated results in a completely silent drop. As far as each TCP stack
3231 is concerned the packet was received, however, the data will not be in the
3232 socket's receive queue. Another consideration is that the current design
3233 requires using the "failed label" occasionally. In that case, on rejection,
3234 we want the remote TCP to resend the data. Because of this, we chose to
3235 place this check before the counters are updated, so rejected packets will be
3236 resent by the remote host.
3237
3238 If a policy keeps rejecting the same packet, eventually the connection will
3239 be dropped. Policies have several options if this design causes problems.
3240 For example, one options is to sanitize the mbuf such that it is acceptable,
3241 then accept it. That may require negotiation between policies as the
3242 Framework will not know to re-check the packet.
3243
3244 The policy must handle NULL MBUF labels. This will likely be the case
3245 for non-local TCP sockets for example.
3246
3247 @return Return 0 if access if granted, otherwise an appropriate
3248 value for errno should be returned.
3249 */
3250 typedef int mpo_socket_check_deliver_t(
3251 socket_t so,
3252 struct label *so_label,
3253 struct mbuf *m,
3254 struct label *m_label
3255 );
3256 /**
3257 @brief Access control check for socket kqfilter
3258 @param cred Subject credential
3259 @param kn Object knote
3260 @param so Object socket
3261 @param socklabel Policy label for socket
3262
3263 Determine whether the subject identified by the credential can
3264 receive the knote on the passed socket.
3265
3266 @return Return 0 if access if granted, otherwise an appropriate
3267 value for errno should be returned.
3268 */
3269 typedef int mpo_socket_check_kqfilter_t(
3270 kauth_cred_t cred,
3271 struct knote *kn,
3272 socket_t so,
3273 struct label *socklabel
3274 );
3275 /**
3276 @brief Access control check for socket relabel
3277 @param cred Subject credential
3278 @param so Object socket
3279 @param so_label The current label of so
3280 @param newlabel The label to be assigned to so
3281
3282 Determine whether the subject identified by the credential can
3283 change the label on the socket.
3284
3285 @return Return 0 if access if granted, otherwise an appropriate
3286 value for errno should be returned.
3287 */
3288 typedef int mpo_socket_check_label_update_t(
3289 kauth_cred_t cred,
3290 socket_t so,
3291 struct label *so_label,
3292 struct label *newlabel
3293 );
3294 /**
3295 @brief Access control check for socket listen
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 listen() on the passed 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_listen_t(
3307 kauth_cred_t cred,
3308 socket_t so,
3309 struct label *socklabel
3310 );
3311 /**
3312 @brief Access control check for socket receive
3313 @param cred Subject credential
3314 @param so Object socket
3315 @param socklabel Policy label for socket
3316
3317 Determine whether the subject identified by the credential can
3318 receive data from the socket.
3319
3320 @return Return 0 if access if granted, otherwise an appropriate
3321 value for errno should be returned.
3322 */
3323 typedef int mpo_socket_check_receive_t(
3324 kauth_cred_t cred,
3325 socket_t so,
3326 struct label *socklabel
3327 );
3328
3329 /**
3330 @brief Access control check for socket receive
3331 @param cred Subject credential
3332 @param sock Object socket
3333 @param socklabel Policy label for socket
3334 @param saddr Name of the remote socket
3335
3336 Determine whether the subject identified by the credential can
3337 receive data from the remote host specified by addr.
3338
3339 @return Return 0 if access if granted, otherwise an appropriate
3340 value for errno should be returned.
3341 */
3342 typedef int mpo_socket_check_received_t(
3343 kauth_cred_t cred,
3344 struct socket *sock,
3345 struct label *socklabel,
3346 struct sockaddr *saddr
3347 );
3348
3349
3350 /**
3351 @brief Access control check for socket select
3352 @param cred Subject credential
3353 @param so Object socket
3354 @param socklabel Policy label for socket
3355 @param which The operation selected on: FREAD or FWRITE
3356
3357 Determine whether the subject identified by the credential can use the
3358 socket in a call to select().
3359
3360 @return Return 0 if access if granted, otherwise an appropriate
3361 value for errno should be returned.
3362 */
3363 typedef int mpo_socket_check_select_t(
3364 kauth_cred_t cred,
3365 socket_t so,
3366 struct label *socklabel,
3367 int which
3368 );
3369 /**
3370 @brief Access control check for socket send
3371 @param cred Subject credential
3372 @param so Object socket
3373 @param socklabel Policy label for socket
3374 @param addr Address being sent to
3375
3376 Determine whether the subject identified by the credential can send
3377 data to the socket.
3378
3379 @return Return 0 if access if granted, otherwise an appropriate
3380 value for errno should be returned.
3381 */
3382 typedef int mpo_socket_check_send_t(
3383 kauth_cred_t cred,
3384 socket_t so,
3385 struct label *socklabel,
3386 struct sockaddr *addr
3387 );
3388 /**
3389 @brief Access control check for retrieving socket status
3390 @param cred Subject credential
3391 @param so Object socket
3392 @param socklabel Policy label for so
3393
3394 Determine whether the subject identified by the credential can
3395 execute the stat() system call on the given socket.
3396
3397 @return Return 0 if access if granted, otherwise an appropriate
3398 value for errno should be returned.
3399 */
3400 typedef int mpo_socket_check_stat_t(
3401 kauth_cred_t cred,
3402 socket_t so,
3403 struct label *socklabel
3404 );
3405 /**
3406 @brief Access control check for setting socket options
3407 @param cred Subject credential
3408 @param so Object socket
3409 @param socklabel Policy label for so
3410 @param sopt The options being set
3411
3412 Determine whether the subject identified by the credential can
3413 execute the setsockopt system call on the given socket.
3414
3415 @return Return 0 if access if granted, otherwise an appropriate
3416 value for errno should be returned.
3417 */
3418 typedef int mpo_socket_check_setsockopt_t(
3419 kauth_cred_t cred,
3420 socket_t so,
3421 struct label *socklabel,
3422 struct sockopt *sopt
3423 );
3424 /**
3425 @brief Access control check for getting socket options
3426 @param cred Subject credential
3427 @param so Object socket
3428 @param socklabel Policy label for so
3429 @param sopt The options to get
3430
3431 Determine whether the subject identified by the credential can
3432 execute the getsockopt system call on the given socket.
3433
3434 @return Return 0 if access if granted, otherwise an appropriate
3435 value for errno should be returned.
3436 */
3437 typedef int mpo_socket_check_getsockopt_t(
3438 kauth_cred_t cred,
3439 socket_t so,
3440 struct label *socklabel,
3441 struct sockopt *sopt
3442 );
3443 /**
3444 @brief Label a socket
3445 @param oldsock Listening socket
3446 @param oldlabel Policy label associated with oldsock
3447 @param newsock New socket
3448 @param newlabel Policy label associated with newsock
3449
3450 A new socket is created when a connection is accept(2)ed. This
3451 function labels the new socket based on the existing listen(2)ing
3452 socket.
3453 */
3454 typedef void mpo_socket_label_associate_accept_t(
3455 socket_t oldsock,
3456 struct label *oldlabel,
3457 socket_t newsock,
3458 struct label *newlabel
3459 );
3460 /**
3461 @brief Assign a label to a new socket
3462 @param cred Credential of the owning process
3463 @param so The socket being labeled
3464 @param solabel The label
3465 @warning cred can be NULL
3466
3467 Set the label on a newly created socket from the passed subject
3468 credential. This call is made when a socket is created. The
3469 credentials may be null if the socket is being created by the
3470 kernel.
3471 */
3472 typedef void mpo_socket_label_associate_t(
3473 kauth_cred_t cred,
3474 socket_t so,
3475 struct label *solabel
3476 );
3477 /**
3478 @brief Copy a socket label
3479 @param src Source label
3480 @param dest Destination label
3481
3482 Copy the socket label information in src into dest.
3483 */
3484 typedef void mpo_socket_label_copy_t(
3485 struct label *src,
3486 struct label *dest
3487 );
3488 /**
3489 @brief Destroy socket label
3490 @param label The label to be destroyed
3491
3492 Destroy a socket label. Since the object is going out of
3493 scope, policy modules should free any internal storage associated
3494 with the label so that it may be destroyed.
3495 */
3496 typedef void mpo_socket_label_destroy_t(
3497 struct label *label
3498 );
3499 /**
3500 @brief Externalize a socket label
3501 @param label Label to be externalized
3502 @param element_name Name of the label namespace for which labels should be
3503 externalized
3504 @param sb String buffer to be filled with a text representation of label
3505
3506 Produce an externalized socket label based on the label structure passed.
3507 An externalized label consists of a text representation of the label
3508 contents that can be used with userland applications and read by the
3509 user. If element_name does not match a namespace managed by the policy,
3510 simply return 0. Only return nonzero if an error occurs while externalizing
3511 the label data.
3512
3513 @return In the event of an error, an appropriate value for errno
3514 should be returned, otherwise return 0 upon success.
3515 */
3516 typedef int mpo_socket_label_externalize_t(
3517 struct label *label,
3518 char *element_name,
3519 struct sbuf *sb
3520 );
3521 /**
3522 @brief Initialize socket label
3523 @param label New label to initialize
3524 @param waitok Malloc flags
3525
3526 Initialize the label of a newly instantiated socket. The waitok
3527 field may be one of M_WAITOK and M_NOWAIT, and should be employed to
3528 avoid performing a sleeping malloc(9) during this initialization
3529 call. It it not always safe to sleep during this entry point.
3530
3531 @warning Since it is possible for the waitok flags to be set to
3532 M_NOWAIT, the malloc operation may fail.
3533
3534 @return In the event of an error, an appropriate value for errno
3535 should be returned, otherwise return 0 upon success.
3536 */
3537 typedef int mpo_socket_label_init_t(
3538 struct label *label,
3539 int waitok
3540 );
3541 /**
3542 @brief Internalize a socket label
3543 @param label Label to be filled in
3544 @param element_name Name of the label namespace for which the label should
3545 be internalized
3546 @param element_data Text data to be internalized
3547
3548 Produce an internal socket label structure based on externalized label
3549 data in text format.
3550
3551 The policy's internalize entry points will be called only if the
3552 policy has registered interest in the label namespace.
3553
3554 @return In the event of an error, an appropriate value for errno
3555 should be returned, otherwise return 0 upon success.
3556 */
3557 typedef int mpo_socket_label_internalize_t(
3558 struct label *label,
3559 char *element_name,
3560 char *element_data
3561 );
3562 /**
3563 @brief Relabel socket
3564 @param cred Subject credential
3565 @param so Object; socket
3566 @param so_label Current label of the socket
3567 @param newlabel The label to be assigned to so
3568
3569 The subject identified by the credential has previously requested
3570 and was authorized to relabel the socket; this entry point allows
3571 policies to perform the actual label update operation.
3572
3573 @warning XXX This entry point will likely change in future versions.
3574 */
3575 typedef void mpo_socket_label_update_t(
3576 kauth_cred_t cred,
3577 socket_t so,
3578 struct label *so_label,
3579 struct label *newlabel
3580 );
3581 /**
3582 @brief Set the peer label on a socket from mbuf
3583 @param m Mbuf chain received on socket so
3584 @param m_label Label for m
3585 @param so Current label for the socket
3586 @param so_label Policy label to be filled out for the socket
3587
3588 Set the peer label of a socket based on the label of the sender of the
3589 mbuf.
3590
3591 This is called for every TCP/IP packet received. The first call for a given
3592 socket operates on a newly initialized label, and subsequent calls operate
3593 on existing label data.
3594
3595 @warning Because this can affect performance significantly, it has
3596 different sematics than other 'set' operations. Typically, 'set' operations
3597 operate on newly initialzed labels and policies do not need to worry about
3598 clobbering existing values. In this case, it is too inefficient to
3599 initialize and destroy a label every time data is received for the socket.
3600 Instead, it is up to the policies to determine how to replace the label data.
3601 Most policies should be able to replace the data inline.
3602 */
3603 typedef void mpo_socketpeer_label_associate_mbuf_t(
3604 struct mbuf *m,
3605 struct label *m_label,
3606 socket_t so,
3607 struct label *so_label
3608 );
3609 /**
3610 @brief Set the peer label on a socket from socket
3611 @param source Local socket
3612 @param sourcelabel Policy label for source
3613 @param target Peer socket
3614 @param targetlabel Policy label to fill in for target
3615
3616 Set the peer label on a stream UNIX domain socket from the passed
3617 remote socket endpoint. This call will be made when the socket pair
3618 is connected, and will be made for both endpoints.
3619
3620 Note that this call is only made on connection; it is currently not updated
3621 during communication.
3622 */
3623 typedef void mpo_socketpeer_label_associate_socket_t(
3624 socket_t source,
3625 struct label *sourcelabel,
3626 socket_t target,
3627 struct label *targetlabel
3628 );
3629 /**
3630 @brief Destroy socket peer label
3631 @param label The peer label to be destroyed
3632
3633 Destroy a socket peer label. Since the object is going out of
3634 scope, policy modules should free any internal storage associated
3635 with the label so that it may be destroyed.
3636 */
3637 typedef void mpo_socketpeer_label_destroy_t(
3638 struct label *label
3639 );
3640 /**
3641 @brief Externalize a socket peer label
3642 @param label Label to be externalized
3643 @param element_name Name of the label namespace for which labels should be
3644 externalized
3645 @param sb String buffer to be filled with a text representation of label
3646
3647 Produce an externalized socket peer label based on the label structure
3648 passed. An externalized label consists of a text representation of the
3649 label contents that can be used with userland applications and read by the
3650 user. If element_name does not match a namespace managed by the policy,
3651 simply return 0. Only return nonzero if an error occurs while externalizing
3652 the label data.
3653
3654 @return In the event of an error, an appropriate value for errno
3655 should be returned, otherwise return 0 upon success.
3656 */
3657 typedef int mpo_socketpeer_label_externalize_t(
3658 struct label *label,
3659 char *element_name,
3660 struct sbuf *sb
3661 );
3662 /**
3663 @brief Initialize socket peer label
3664 @param label New label to initialize
3665 @param waitok Malloc flags
3666
3667 Initialize the peer label of a newly instantiated socket. The
3668 waitok field may be one of M_WAITOK and M_NOWAIT, and should be
3669 employed to avoid performing a sleeping malloc(9) during this
3670 initialization call. It it not always safe to sleep during this
3671 entry point.
3672
3673 @warning Since it is possible for the waitok flags to be set to
3674 M_NOWAIT, the malloc operation may fail.
3675
3676 @return In the event of an error, an appropriate value for errno
3677 should be returned, otherwise return 0 upon success.
3678 */
3679 typedef int mpo_socketpeer_label_init_t(
3680 struct label *label,
3681 int waitok
3682 );
3683 /**
3684 @brief Access control check for enabling accounting
3685 @param cred Subject credential
3686 @param vp Accounting file
3687 @param vlabel Label associated with vp
3688
3689 Determine whether the subject should be allowed to enable accounting,
3690 based on its label and the label of the accounting log file. See
3691 acct(5) for more information.
3692
3693 As accounting is disabled by passing NULL to the acct(2) system call,
3694 the policy should be prepared for both 'vp' and 'vlabel' to be NULL.
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_acct_t(
3700 kauth_cred_t cred,
3701 struct vnode *vp,
3702 struct label *vlabel
3703 );
3704 /**
3705 @brief Access control check for audit
3706 @param cred Subject credential
3707 @param record Audit record
3708 @param length Audit record length
3709
3710 Determine whether the subject identified by the credential can submit
3711 an audit record for inclusion in the audit log via the audit() system call.
3712
3713 @return Return 0 if access is granted, otherwise an appropriate value for
3714 errno should be returned.
3715 */
3716 typedef int mpo_system_check_audit_t(
3717 kauth_cred_t cred,
3718 void *record,
3719 int length
3720 );
3721 /**
3722 @brief Access control check for controlling audit
3723 @param cred Subject credential
3724 @param vp Audit file
3725 @param vl Label associated with vp
3726
3727 Determine whether the subject should be allowed to enable auditing using
3728 the auditctl() system call, based on its label and the label of the proposed
3729 audit file.
3730
3731 @return Return 0 if access is granted, otherwise an appropriate value for
3732 errno should be returned.
3733 */
3734 typedef int mpo_system_check_auditctl_t(
3735 kauth_cred_t cred,
3736 struct vnode *vp,
3737 struct label *vl
3738 );
3739 /**
3740 @brief Access control check for manipulating auditing
3741 @param cred Subject credential
3742 @param cmd Audit control command
3743
3744 Determine whether the subject identified by the credential can perform
3745 the audit subsystem control operation cmd via the auditon() system call.
3746
3747 @return Return 0 if access is granted, otherwise an appropriate value for
3748 errno should be returned.
3749 */
3750 typedef int mpo_system_check_auditon_t(
3751 kauth_cred_t cred,
3752 int cmd
3753 );
3754 /**
3755 @brief Access control check for using CHUD facilities
3756 @param cred Subject credential
3757
3758 Determine whether the subject identified by the credential can perform
3759 performance-related tasks using the CHUD system call.
3760
3761 @return Return 0 if access is granted, otherwise an appropriate value for
3762 errno should be returned.
3763 */
3764 typedef int mpo_system_check_chud_t(
3765 kauth_cred_t cred
3766 );
3767 /**
3768 @brief Access control check for obtaining the host control port
3769 @param cred Subject credential
3770
3771 Determine whether the subject identified by the credential can
3772 obtain the host control port.
3773
3774 @return Return 0 if access is granted, or non-zero otherwise.
3775 */
3776 typedef int mpo_system_check_host_priv_t(
3777 kauth_cred_t cred
3778 );
3779 /**
3780 @brief Access control check for obtaining system information
3781 @param cred Subject credential
3782 @param info_type A description of the information requested
3783
3784 Determine whether the subject identified by the credential should be
3785 allowed to obtain information about the system.
3786
3787 This is a generic hook that can be used in a variety of situations where
3788 information is being returned that might be considered sensitive.
3789 Rather than adding a new MAC hook for every such interface, this hook can
3790 be called with a string identifying the type of information requested.
3791
3792 @return Return 0 if access is granted, otherwise an appropriate value for
3793 errno should be returned.
3794 */
3795 typedef int mpo_system_check_info_t(
3796 kauth_cred_t cred,
3797 const char *info_type
3798 );
3799 /**
3800 @brief Access control check for calling NFS services
3801 @param cred Subject credential
3802
3803 Determine whether the subject identified by the credential should be
3804 allowed to call nfssrv(2).
3805
3806 @return Return 0 if access is granted, otherwise an appropriate value for
3807 errno should be returned.
3808 */
3809 typedef int mpo_system_check_nfsd_t(
3810 kauth_cred_t cred
3811 );
3812 /**
3813 @brief Access control check for reboot
3814 @param cred Subject credential
3815 @param howto howto parameter from reboot(2)
3816
3817 Determine whether the subject identified by the credential should be
3818 allowed to reboot the system in the specified manner.
3819
3820 @return Return 0 if access is granted, otherwise an appropriate value for
3821 errno should be returned.
3822 */
3823 typedef int mpo_system_check_reboot_t(
3824 kauth_cred_t cred,
3825 int howto
3826 );
3827 /**
3828 @brief Access control check for setting system clock
3829 @param cred Subject credential
3830
3831 Determine whether the subject identified by the credential should be
3832 allowed to set the system clock.
3833
3834 @return Return 0 if access is granted, otherwise an appropriate value for
3835 errno should be returned.
3836 */
3837 typedef int mpo_system_check_settime_t(
3838 kauth_cred_t cred
3839 );
3840 /**
3841 @brief Access control check for removing 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 remove 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_swapoff_t(
3853 kauth_cred_t cred,
3854 struct vnode *vp,
3855 struct label *label
3856 );
3857 /**
3858 @brief Access control check for adding swap devices
3859 @param cred Subject credential
3860 @param vp Swap device
3861 @param label Label associated with vp
3862
3863 Determine whether the subject identified by the credential should be
3864 allowed to add vp as a swap device.
3865
3866 @return Return 0 if access is granted, otherwise an appropriate value for
3867 errno should be returned.
3868 */
3869 typedef int mpo_system_check_swapon_t(
3870 kauth_cred_t cred,
3871 struct vnode *vp,
3872 struct label *label
3873 );
3874 /**
3875 @brief Access control check for sysctl
3876 @param cred Subject credential
3877 @param namestring String representation of sysctl name.
3878 @param name Integer name; see sysctl(3)
3879 @param namelen Length of name array of integers; see sysctl(3)
3880 @param old 0 or address where to store old value; see sysctl(3)
3881 @param oldlen Length of old buffer; see sysctl(3)
3882 @param newvalue 0 or address of new value; see sysctl(3)
3883 @param newlen Length of new buffer; see sysctl(3)
3884
3885 Determine whether the subject identified by the credential should be
3886 allowed to make the specified sysctl(3) transaction.
3887
3888 The sysctl(3) call specifies that if the old value is not desired,
3889 oldp and oldlenp should be set to NULL. Likewise, if a new value is
3890 not to be set, newp should be set to NULL and newlen set to 0.
3891
3892 @return Return 0 if access is granted, otherwise an appropriate value for
3893 errno should be returned.
3894 */
3895 typedef int mpo_system_check_sysctlbyname_t(
3896 kauth_cred_t cred,
3897 const char *namestring,
3898 int *name,
3899 u_int namelen,
3900 user_addr_t old, /* NULLOK */
3901 size_t oldlen,
3902 user_addr_t newvalue, /* NULLOK */
3903 size_t newlen
3904 );
3905 /**
3906 @brief Access control check for kas_info
3907 @param cred Subject credential
3908 @param selector Category of information to return. See kas_info.h
3909
3910 Determine whether the subject identified by the credential can perform
3911 introspection of the kernel address space layout for
3912 debugging/performance analysis.
3913
3914 @return Return 0 if access is granted, otherwise an appropriate value for
3915 errno should be returned.
3916 */
3917 typedef int mpo_system_check_kas_info_t(
3918 kauth_cred_t cred,
3919 int selector
3920 );
3921 /**
3922 @brief Create a System V message label
3923 @param cred Subject credential
3924 @param msqptr The message queue the message will be placed in
3925 @param msqlabel The label of the message queue
3926 @param msgptr The message
3927 @param msglabel The label of the message
3928
3929 Label the message as its placed in the message queue.
3930 */
3931 typedef void mpo_sysvmsg_label_associate_t(
3932 kauth_cred_t cred,
3933 struct msqid_kernel *msqptr,
3934 struct label *msqlabel,
3935 struct msg *msgptr,
3936 struct label *msglabel
3937 );
3938 /**
3939 @brief Destroy System V message label
3940 @param label The label to be destroyed
3941
3942 Destroy a System V message label. Since the object is
3943 going out of scope, policy modules should free any internal storage
3944 associated with the label so that it may be destroyed.
3945 */
3946 typedef void mpo_sysvmsg_label_destroy_t(
3947 struct label *label
3948 );
3949 /**
3950 @brief Initialize System V message label
3951 @param label New label to initialize
3952
3953 Initialize the label for a newly instantiated System V message.
3954 */
3955 typedef void mpo_sysvmsg_label_init_t(
3956 struct label *label
3957 );
3958 /**
3959 @brief Clean up a System V message label
3960 @param label The label to be destroyed
3961
3962 Clean up a System V message label. Darwin pre-allocates
3963 messages at system boot time and re-uses them rather than
3964 allocating new ones. Before messages are returned to the "free
3965 pool", policies can cleanup or overwrite any information present in
3966 the label.
3967 */
3968 typedef void mpo_sysvmsg_label_recycle_t(
3969 struct label *label
3970 );
3971 /**
3972 @brief Access control check for System V message enqueuing
3973 @param cred Subject credential
3974 @param msgptr The message
3975 @param msglabel The message's label
3976 @param msqptr The message queue
3977 @param msqlabel The message queue's label
3978
3979 Determine whether the subject identified by the credential can add the
3980 given message to the given message queue.
3981
3982 @return Return 0 if access is granted, otherwise an appropriate value for
3983 errno should be returned.
3984 */
3985 typedef int mpo_sysvmsq_check_enqueue_t(
3986 kauth_cred_t cred,
3987 struct msg *msgptr,
3988 struct label *msglabel,
3989 struct msqid_kernel *msqptr,
3990 struct label *msqlabel
3991 );
3992 /**
3993 @brief Access control check for System V message reception
3994 @param cred The credential of the intended recipient
3995 @param msgptr The message
3996 @param msglabel The message's label
3997
3998 Determine whether the subject identified by the credential can receive
3999 the given message.
4000
4001 @return Return 0 if access is granted, otherwise an appropriate value for
4002 errno should be returned.
4003 */
4004 typedef int mpo_sysvmsq_check_msgrcv_t(
4005 kauth_cred_t cred,
4006 struct msg *msgptr,
4007 struct label *msglabel
4008 );
4009 /**
4010 @brief Access control check for System V message queue removal
4011 @param cred The credential of the caller
4012 @param msgptr The message
4013 @param msglabel The message's label
4014
4015 System V message queues are removed using the msgctl() system call.
4016 The system will iterate over each messsage in the queue, calling this
4017 function for each, to determine whether the caller has the appropriate
4018 credentials.
4019
4020 @return Return 0 if access is granted, otherwise an appropriate value for
4021 errno should be returned.
4022 */
4023 typedef int mpo_sysvmsq_check_msgrmid_t(
4024 kauth_cred_t cred,
4025 struct msg *msgptr,
4026 struct label *msglabel
4027 );
4028 /**
4029 @brief Access control check for msgctl()
4030 @param cred The credential of the caller
4031 @param msqptr The message queue
4032 @param msqlabel The message queue's label
4033
4034 This access check is performed to validate calls to msgctl().
4035
4036 @return Return 0 if access is granted, otherwise an appropriate value for
4037 errno should be returned.
4038 */
4039 typedef int mpo_sysvmsq_check_msqctl_t(
4040 kauth_cred_t cred,
4041 struct msqid_kernel *msqptr,
4042 struct label *msqlabel,
4043 int cmd
4044 );
4045 /**
4046 @brief Access control check to get a System V message queue
4047 @param cred The credential of the caller
4048 @param msqptr The message queue requested
4049 @param msqlabel The message queue's label
4050
4051 On a call to msgget(), if the queue requested already exists,
4052 and it is a public queue, this check will be performed before the
4053 queue's ID is returned to the user.
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_msqget_t(
4059 kauth_cred_t cred,
4060 struct msqid_kernel *msqptr,
4061 struct label *msqlabel
4062 );
4063 /**
4064 @brief Access control check to receive a System V message from the given queue
4065 @param cred The credential of the caller
4066 @param msqptr The message queue to receive from
4067 @param msqlabel The message queue's label
4068
4069 On a call to msgrcv(), this check is performed to determine whether the
4070 caller has receive 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_msqrcv_t(
4076 kauth_cred_t cred,
4077 struct msqid_kernel *msqptr,
4078 struct label *msqlabel
4079 );
4080 /**
4081 @brief Access control check to send a System V message to the given queue
4082 @param cred The credential of the caller
4083 @param msqptr The message queue to send to
4084 @param msqlabel The message queue's label
4085
4086 On a call to msgsnd(), this check is performed to determine whether the
4087 caller has send rights on the given queue.
4088
4089 @return Return 0 if access is granted, otherwise an appropriate value for
4090 errno should be returned.
4091 */
4092 typedef int mpo_sysvmsq_check_msqsnd_t(
4093 kauth_cred_t cred,
4094 struct msqid_kernel *msqptr,
4095 struct label *msqlabel
4096 );
4097 /**
4098 @brief Create a System V message queue label
4099 @param cred Subject credential
4100 @param msqptr The message queue
4101 @param msqlabel The label of the message queue
4102
4103 */
4104 typedef void mpo_sysvmsq_label_associate_t(
4105 kauth_cred_t cred,
4106 struct msqid_kernel *msqptr,
4107 struct label *msqlabel
4108 );
4109 /**
4110 @brief Destroy System V message queue label
4111 @param label The label to be destroyed
4112
4113 Destroy a System V message queue label. Since the object is
4114 going out of scope, policy modules should free any internal storage
4115 associated with the label so that it may be destroyed.
4116 */
4117 typedef void mpo_sysvmsq_label_destroy_t(
4118 struct label *label
4119 );
4120 /**
4121 @brief Initialize System V message queue label
4122 @param label New label to initialize
4123
4124 Initialize the label for a newly instantiated System V message queue.
4125 */
4126 typedef void mpo_sysvmsq_label_init_t(
4127 struct label *label
4128 );
4129 /**
4130 @brief Clean up a System V message queue label
4131 @param label The label to be destroyed
4132
4133 Clean up a System V message queue label. Darwin pre-allocates
4134 message queues at system boot time and re-uses them rather than
4135 allocating new ones. Before message queues are returned to the "free
4136 pool", policies can cleanup or overwrite any information present in
4137 the label.
4138 */
4139 typedef void mpo_sysvmsq_label_recycle_t(
4140 struct label *label
4141 );
4142 /**
4143 @brief Access control check for System V semaphore control operation
4144 @param cred Subject credential
4145 @param semakptr Pointer to semaphore identifier
4146 @param semaklabel Label associated with semaphore
4147 @param cmd Control operation to be performed; see semctl(2)
4148
4149 Determine whether the subject identified by the credential can perform
4150 the operation indicated by cmd on the System V semaphore semakptr.
4151
4152 @return Return 0 if access is granted, otherwise an appropriate value for
4153 errno should be returned.
4154 */
4155 typedef int mpo_sysvsem_check_semctl_t(
4156 kauth_cred_t cred,
4157 struct semid_kernel *semakptr,
4158 struct label *semaklabel,
4159 int cmd
4160 );
4161 /**
4162 @brief Access control check for obtaining a System V semaphore
4163 @param cred Subject credential
4164 @param semakptr Pointer to semaphore identifier
4165 @param semaklabel Label to associate with the semaphore
4166
4167 Determine whether the subject identified by the credential can
4168 obtain a System V semaphore.
4169
4170 @return Return 0 if access is granted, otherwise an appropriate value for
4171 errno should be returned.
4172 */
4173 typedef int mpo_sysvsem_check_semget_t(
4174 kauth_cred_t cred,
4175 struct semid_kernel *semakptr,
4176 struct label *semaklabel
4177 );
4178 /**
4179 @brief Access control check for System V semaphore operations
4180 @param cred Subject credential
4181 @param semakptr Pointer to semaphore identifier
4182 @param semaklabel Label associated with the semaphore
4183 @param accesstype Flags to indicate access (read and/or write)
4184
4185 Determine whether the subject identified by the credential can
4186 perform the operations on the System V semaphore indicated by
4187 semakptr. The accesstype flags hold the maximum set of permissions
4188 from the sem_op array passed to the semop system call. It may
4189 contain SEM_R for read-only operations or SEM_A for read/write
4190 operations.
4191
4192 @return Return 0 if access is granted, otherwise an appropriate value for
4193 errno should be returned.
4194 */
4195 typedef int mpo_sysvsem_check_semop_t(
4196 kauth_cred_t cred,
4197 struct semid_kernel *semakptr,
4198 struct label *semaklabel,
4199 size_t accesstype
4200 );
4201 /**
4202 @brief Create a System V semaphore label
4203 @param cred Subject credential
4204 @param semakptr The semaphore being created
4205 @param semalabel Label to associate with the new semaphore
4206
4207 Label a new System V semaphore. The label was previously
4208 initialized and associated with the semaphore. At this time, an
4209 appropriate initial label value should be assigned to the object and
4210 stored in semalabel.
4211 */
4212 typedef void mpo_sysvsem_label_associate_t(
4213 kauth_cred_t cred,
4214 struct semid_kernel *semakptr,
4215 struct label *semalabel
4216 );
4217 /**
4218 @brief Destroy System V semaphore label
4219 @param label The label to be destroyed
4220
4221 Destroy a System V semaphore label. Since the object is
4222 going out of scope, policy modules should free any internal storage
4223 associated with the label so that it may be destroyed.
4224 */
4225 typedef void mpo_sysvsem_label_destroy_t(
4226 struct label *label
4227 );
4228 /**
4229 @brief Initialize System V semaphore label
4230 @param label New label to initialize
4231
4232 Initialize the label for a newly instantiated System V semaphore. Sleeping
4233 is permitted.
4234 */
4235 typedef void mpo_sysvsem_label_init_t(
4236 struct label *label
4237 );
4238 /**
4239 @brief Clean up a System V semaphore label
4240 @param label The label to be cleaned
4241
4242 Clean up a System V semaphore label. Darwin pre-allocates
4243 semaphores at system boot time and re-uses them rather than
4244 allocating new ones. Before semaphores are returned to the "free
4245 pool", policies can cleanup or overwrite any information present in
4246 the label.
4247 */
4248 typedef void mpo_sysvsem_label_recycle_t(
4249 struct label *label
4250 );
4251 /**
4252 @brief Access control check for mapping System V shared memory
4253 @param cred Subject credential
4254 @param shmsegptr Pointer to shared memory segment identifier
4255 @param shmseglabel Label associated with the shared memory segment
4256 @param shmflg shmat flags; see shmat(2)
4257
4258 Determine whether the subject identified by the credential can map
4259 the System V shared memory segment associated with shmsegptr.
4260
4261 @return Return 0 if access is granted, otherwise an appropriate value for
4262 errno should be returned.
4263 */
4264 typedef int mpo_sysvshm_check_shmat_t(
4265 kauth_cred_t cred,
4266 struct shmid_kernel *shmsegptr,
4267 struct label *shmseglabel,
4268 int shmflg
4269 );
4270 /**
4271 @brief Access control check for System V shared memory control operation
4272 @param cred Subject credential
4273 @param shmsegptr Pointer to shared memory segment identifier
4274 @param shmseglabel Label associated with the shared memory segment
4275 @param cmd Control operation to be performed; see shmctl(2)
4276
4277 Determine whether the subject identified by the credential can perform
4278 the operation indicated by cmd on the System V shared memory segment
4279 shmsegptr.
4280
4281 @return Return 0 if access is granted, otherwise an appropriate value for
4282 errno should be returned.
4283 */
4284 typedef int mpo_sysvshm_check_shmctl_t(
4285 kauth_cred_t cred,
4286 struct shmid_kernel *shmsegptr,
4287 struct label *shmseglabel,
4288 int cmd
4289 );
4290 /**
4291 @brief Access control check for unmapping System V shared memory
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
4296 Determine whether the subject identified by the credential can unmap
4297 the System V shared memory segment associated with shmsegptr.
4298
4299 @return Return 0 if access is granted, otherwise an appropriate value for
4300 errno should be returned.
4301 */
4302 typedef int mpo_sysvshm_check_shmdt_t(
4303 kauth_cred_t cred,
4304 struct shmid_kernel *shmsegptr,
4305 struct label *shmseglabel
4306 );
4307 /**
4308 @brief Access control check obtaining System V shared memory identifier
4309 @param cred Subject credential
4310 @param shmsegptr Pointer to shared memory segment identifier
4311 @param shmseglabel Label associated with the shared memory segment
4312 @param shmflg shmget flags; see shmget(2)
4313
4314 Determine whether the subject identified by the credential can get
4315 the System V shared memory segment address.
4316
4317 @return Return 0 if access is granted, otherwise an appropriate value for
4318 errno should be returned.
4319 */
4320 typedef int mpo_sysvshm_check_shmget_t(
4321 kauth_cred_t cred,
4322 struct shmid_kernel *shmsegptr,
4323 struct label *shmseglabel,
4324 int shmflg
4325 );
4326 /**
4327 @brief Create a System V shared memory region label
4328 @param cred Subject credential
4329 @param shmsegptr The shared memory region being created
4330 @param shmlabel Label to associate with the new shared memory region
4331
4332 Label a new System V shared memory region. The label was previously
4333 initialized and associated with the shared memory region. At this
4334 time, an appropriate initial label value should be assigned to the
4335 object and stored in shmlabel.
4336 */
4337 typedef void mpo_sysvshm_label_associate_t(
4338 kauth_cred_t cred,
4339 struct shmid_kernel *shmsegptr,
4340 struct label *shmlabel
4341 );
4342 /**
4343 @brief Destroy System V shared memory label
4344 @param label The label to be destroyed
4345
4346 Destroy a System V shared memory region label. Since the
4347 object is going out of scope, policy modules should free any
4348 internal storage associated with the label so that it may be
4349 destroyed.
4350 */
4351 typedef void mpo_sysvshm_label_destroy_t(
4352 struct label *label
4353 );
4354 /**
4355 @brief Initialize System V Shared Memory region label
4356 @param label New label to initialize
4357
4358 Initialize the label for a newly instantiated System V Shared Memory
4359 region. Sleeping is permitted.
4360 */
4361 typedef void mpo_sysvshm_label_init_t(
4362 struct label *label
4363 );
4364 /**
4365 @brief Clean up a System V Share Memory Region label
4366 @param shmlabel The label to be cleaned
4367
4368 Clean up a System V Shared Memory Region label. Darwin
4369 pre-allocates these objects at system boot time and re-uses them
4370 rather than allocating new ones. Before the memory regions are
4371 returned to the "free pool", policies can cleanup or overwrite any
4372 information present in the label.
4373 */
4374 typedef void mpo_sysvshm_label_recycle_t(
4375 struct label *shmlabel
4376 );
4377 /**
4378 @brief Access control check for getting a process's task name
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 name port.
4384 This call is used by the task_name_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_name_t(
4391 kauth_cred_t cred,
4392 struct proc *p
4393 );
4394 /**
4395 @brief Access control check for getting a process's task port
4396 @param cred Subject credential
4397 @param p Object process
4398
4399 Determine whether the subject identified by the credential can get
4400 the passed process's task control port.
4401 This call is used by the task_for_pid(2) API.
4402
4403 @return Return 0 if access is granted, otherwise an appropriate value for
4404 errno should be returned. Suggested failure: EACCES for label mismatch,
4405 EPERM for lack of privilege, or ESRCH to hide visibility of the target.
4406 */
4407 typedef int mpo_proc_check_get_task_t(
4408 kauth_cred_t cred,
4409 struct proc *p
4410 );
4411
4412 /**
4413 @brief Access control check for exposing a process's task port
4414 @param cred Subject credential
4415 @param p Object process
4416
4417 Determine whether the subject identified by the credential can expose
4418 the passed process's task control port.
4419 This call is used by the accessor APIs like processor_set_tasks() and
4420 processor_set_threads().
4421
4422 @return Return 0 if access is granted, otherwise an appropriate value for
4423 errno should be returned. Suggested failure: EACCES for label mismatch,
4424 EPERM for lack of privilege, or ESRCH to hide visibility of the target.
4425 */
4426 typedef int mpo_proc_check_expose_task_t(
4427 kauth_cred_t cred,
4428 struct proc *p
4429 );
4430
4431 /**
4432 @brief Check whether task's IPC may inherit across process exec
4433 @param p current process instance
4434 @param cur_vp vnode pointer to current instance
4435 @param cur_offset offset of binary of currently executing image
4436 @param img_vp vnode pointer to to be exec'ed image
4437 @param img_offset offset into file which is selected for execution
4438 @param scriptvp vnode pointer of script file if any.
4439 @return Return 0 if access is granted.
4440 EPERM if parent does not have any entitlements.
4441 EACCESS if mismatch in entitlements
4442 */
4443 typedef int mpo_proc_check_inherit_ipc_ports_t(
4444 struct proc *p,
4445 struct vnode *cur_vp,
4446 off_t cur_offset,
4447 struct vnode *img_vp,
4448 off_t img_offset,
4449 struct vnode *scriptvp
4450 );
4451
4452 /**
4453 @brief Privilege check for a process to run invalid
4454 @param p Object process
4455
4456 Determine whether the process may execute even though the system determined
4457 that it is untrusted (eg unidentified / modified code).
4458
4459 @return Return 0 if access is granted, otherwise an appropriate value for
4460 errno should be returned.
4461 */
4462 typedef int mpo_proc_check_run_cs_invalid_t(
4463 struct proc *p
4464 );
4465
4466 /**
4467 @brief Perform MAC-related events when a thread returns to user space
4468 @param thread Mach (not BSD) thread that is returning
4469
4470 This entry point permits policy modules to perform MAC-related
4471 events when a thread returns to user space, via a system call
4472 return or trap return.
4473 */
4474 typedef void mpo_thread_userret_t(
4475 struct thread *thread
4476 );
4477
4478 /**
4479 @brief Check vnode access
4480 @param cred Subject credential
4481 @param vp Object vnode
4482 @param label Label for vp
4483 @param acc_mode access(2) flags
4484
4485 Determine how invocations of access(2) and related calls by the
4486 subject identified by the credential should return when performed
4487 on the passed vnode using the passed access flags. This should
4488 generally be implemented using the same semantics used in
4489 mpo_vnode_check_open.
4490
4491 @return Return 0 if access is granted, otherwise an appropriate value for
4492 errno should be returned. Suggested failure: EACCES for label mismatch or
4493 EPERM for lack of privilege.
4494 */
4495 typedef int mpo_vnode_check_access_t(
4496 kauth_cred_t cred,
4497 struct vnode *vp,
4498 struct label *label,
4499 int acc_mode
4500 );
4501 /**
4502 @brief Access control check for changing working directory
4503 @param cred Subject credential
4504 @param dvp Object; vnode to chdir(2) into
4505 @param dlabel Policy label for dvp
4506
4507 Determine whether the subject identified by the credential can change
4508 the process working directory to the passed vnode.
4509
4510 @return Return 0 if access is granted, otherwise an appropriate value for
4511 errno should be returned. Suggested failure: EACCES for label mismatch or
4512 EPERM for lack of privilege.
4513 */
4514 typedef int mpo_vnode_check_chdir_t(
4515 kauth_cred_t cred,
4516 struct vnode *dvp,
4517 struct label *dlabel
4518 );
4519 /**
4520 @brief Access control check for changing root directory
4521 @param cred Subject credential
4522 @param dvp Directory vnode
4523 @param dlabel Policy label associated with dvp
4524 @param cnp Component name for dvp
4525
4526 Determine whether the subject identified by the credential should be
4527 allowed to chroot(2) into the specified directory (dvp).
4528
4529 @return In the event of an error, an appropriate value for errno
4530 should be returned, otherwise return 0 upon success.
4531 */
4532 typedef int mpo_vnode_check_chroot_t(
4533 kauth_cred_t cred,
4534 struct vnode *dvp,
4535 struct label *dlabel,
4536 struct componentname *cnp
4537 );
4538 /**
4539 @brief Access control check for creating clone
4540 @param cred Subject credential
4541 @param dvp Vnode of directory to create the clone in
4542 @param dlabel Policy label associated with dvp
4543 @param vp Vnode of the file to clone from
4544 @param label Policy label associated with vp
4545 @param cnp Component name for the clone being created
4546
4547 Determine whether the subject identified by the credential should be
4548 allowed to create a clone of the vnode vp with the name specified by cnp.
4549
4550 @return Return 0 if access is granted, otherwise an appropriate value for
4551 errno should be returned.
4552 */
4553 typedef int mpo_vnode_check_clone_t(
4554 kauth_cred_t cred,
4555 struct vnode *dvp,
4556 struct label *dlabel,
4557 struct vnode *vp,
4558 struct label *label,
4559 struct componentname *cnp
4560 );
4561 /**
4562 @brief Access control check for creating vnode
4563 @param cred Subject credential
4564 @param dvp Directory vnode
4565 @param dlabel Policy label for dvp
4566 @param cnp Component name for dvp
4567 @param vap vnode attributes for vap
4568
4569 Determine whether the subject identified by the credential can create
4570 a vnode with the passed parent directory, passed name information,
4571 and passed attribute information. This call may be made in a number of
4572 situations, including as a result of calls to open(2) with O_CREAT,
4573 mknod(2), mkfifo(2), and others.
4574
4575 @return Return 0 if access is granted, otherwise an appropriate value for
4576 errno should be returned. Suggested failure: EACCES for label mismatch or
4577 EPERM for lack of privilege.
4578 */
4579 typedef int mpo_vnode_check_create_t(
4580 kauth_cred_t cred,
4581 struct vnode *dvp,
4582 struct label *dlabel,
4583 struct componentname *cnp,
4584 struct vnode_attr *vap
4585 );
4586 /**
4587 @brief Access control check for deleting extended attribute
4588 @param cred Subject credential
4589 @param vp Object vnode
4590 @param vlabel Label associated with vp
4591 @param name Extended attribute name
4592
4593 Determine whether the subject identified by the credential can delete
4594 the extended attribute from the passed vnode.
4595
4596 @return Return 0 if access is granted, otherwise an appropriate value for
4597 errno should be returned. Suggested failure: EACCES for label mismatch or
4598 EPERM for lack of privilege.
4599 */
4600 typedef int mpo_vnode_check_deleteextattr_t(
4601 kauth_cred_t cred,
4602 struct vnode *vp,
4603 struct label *vlabel,
4604 const char *name
4605 );
4606 /**
4607 @brief Access control check for exchanging file data
4608 @param cred Subject credential
4609 @param v1 vnode 1 to swap
4610 @param vl1 Policy label for v1
4611 @param v2 vnode 2 to swap
4612 @param vl2 Policy label for v2
4613
4614 Determine whether the subject identified by the credential can swap the data
4615 in the two supplied vnodes.
4616
4617 @return Return 0 if access is granted, otherwise an appropriate value for
4618 errno should be returned. Suggested failure: EACCES for label mismatch or
4619 EPERM for lack of privilege.
4620 */
4621 typedef int mpo_vnode_check_exchangedata_t(
4622 kauth_cred_t cred,
4623 struct vnode *v1,
4624 struct label *vl1,
4625 struct vnode *v2,
4626 struct label *vl2
4627 );
4628 /**
4629 @brief Access control check for executing the vnode
4630 @param cred Subject credential
4631 @param vp Object vnode to execute
4632 @param scriptvp Script being executed by interpreter, if any.
4633 @param vnodelabel Label corresponding to vp
4634 @param scriptlabel Script vnode label
4635 @param execlabel Userspace provided execution label
4636 @param cnp Component name for file being executed
4637 @param macpolicyattr MAC policy-specific spawn attribute data.
4638 @param macpolicyattrlen Length of policy-specific spawn attribute data.
4639
4640 Determine whether the subject identified by the credential can execute
4641 the passed vnode. Determination of execute privilege is made separately
4642 from decisions about any process label transitioning event.
4643
4644 The final label, execlabel, corresponds to a label supplied by a
4645 user space application through the use of the mac_execve system call.
4646 This label will be NULL if the user application uses the the vendor
4647 execve(2) call instead of the MAC Framework mac_execve() call.
4648
4649 @return Return 0 if access is granted, otherwise an appropriate value for
4650 errno should be returned. Suggested failure: EACCES for label mismatch or
4651 EPERM for lack of privilege.
4652 */
4653 typedef int mpo_vnode_check_exec_t(
4654 kauth_cred_t cred,
4655 struct vnode *vp,
4656 struct vnode *scriptvp,
4657 struct label *vnodelabel,
4658 struct label *scriptlabel,
4659 struct label *execlabel, /* NULLOK */
4660 struct componentname *cnp,
4661 u_int *csflags,
4662 void *macpolicyattr,
4663 size_t macpolicyattrlen
4664 );
4665 /**
4666 @brief Access control check for fsgetpath
4667 @param cred Subject credential
4668 @param vp Vnode for which a path will be returned
4669 @param label Label associated with the vnode
4670
4671 Determine whether the subject identified by the credential can get the path
4672 of the given vnode with fsgetpath.
4673
4674 @return Return 0 if access is granted, otherwise an appropriate value for
4675 errno should be returned.
4676 */
4677 typedef int mpo_vnode_check_fsgetpath_t(
4678 kauth_cred_t cred,
4679 struct vnode *vp,
4680 struct label *label
4681 );
4682 /**
4683 @brief Access control check for retrieving file attributes
4684 @param active_cred Subject credential
4685 @param file_cred Credential associated with the struct fileproc
4686 @param vp Object vnode
4687 @param vlabel Policy label for vp
4688 @param va Vnode attributes to retrieve
4689
4690 Determine whether the subject identified by the credential can
4691 get information about the passed vnode. The active_cred hold
4692 the credentials of the subject performing the operation, and
4693 file_cred holds the credentials of the subject that originally
4694 opened the file. This check happens during stat(), lstat(),
4695 fstat(), and getattrlist() syscalls. See <sys/vnode.h> for
4696 definitions of the attributes.
4697
4698 @return Return 0 if access is granted, otherwise an appropriate value for
4699 errno should be returned.
4700
4701 @note Policies may change the contents of va to alter the list of
4702 file attributes returned.
4703 */
4704 typedef int mpo_vnode_check_getattr_t(
4705 kauth_cred_t active_cred,
4706 kauth_cred_t file_cred, /* NULLOK */
4707 struct vnode *vp,
4708 struct label *vlabel,
4709 struct vnode_attr *va
4710 );
4711 /**
4712 @brief Access control check for retrieving file attributes
4713 @param cred Subject credential
4714 @param vp Object vnode
4715 @param vlabel Policy label for vp
4716 @param alist List of attributes to retrieve
4717
4718 Determine whether the subject identified by the credential can read
4719 various attributes of the specified vnode, or the filesystem or volume on
4720 which that vnode resides. See <sys/attr.h> for definitions of the
4721 attributes.
4722
4723 @return Return 0 if access is granted, otherwise an appropriate value for
4724 errno should be returned. Suggested failure: EACCES for label mismatch or
4725 EPERM for lack of privilege. Access control covers all attributes requested
4726 with this call; the security policy is not permitted to change the set of
4727 attributes requested.
4728 */
4729 typedef int mpo_vnode_check_getattrlist_t(
4730 kauth_cred_t cred,
4731 struct vnode *vp,
4732 struct label *vlabel,
4733 struct attrlist *alist
4734 );
4735 /**
4736 @brief Access control check for retrieving an extended attribute
4737 @param cred Subject credential
4738 @param vp Object vnode
4739 @param label Policy label for vp
4740 @param name Extended attribute name
4741 @param uio I/O structure pointer
4742
4743 Determine whether the subject identified by the credential can retrieve
4744 the extended attribute from the passed vnode. The uio parameter
4745 will be NULL when the getxattr(2) call has been made with a NULL data
4746 value; this is done to request the size of the data only.
4747
4748 @return Return 0 if access is granted, otherwise an appropriate value for
4749 errno should be returned. Suggested failure: EACCES for label mismatch or
4750 EPERM for lack of privilege.
4751 */
4752 typedef int mpo_vnode_check_getextattr_t(
4753 kauth_cred_t cred,
4754 struct vnode *vp,
4755 struct label *label, /* NULLOK */
4756 const char *name,
4757 struct uio *uio /* NULLOK */
4758 );
4759 /**
4760 @brief Access control check for ioctl
4761 @param cred Subject credential
4762 @param vp Object vnode
4763 @param label Policy label for vp
4764 @param cmd Device-dependent request code; see ioctl(2)
4765
4766 Determine whether the subject identified by the credential can perform
4767 the ioctl operation indicated by com.
4768
4769 @warning Since ioctl data is opaque from the standpoint of the MAC
4770 framework, and since ioctls can affect many aspects of system
4771 operation, policies must exercise extreme care when implementing
4772 access control checks.
4773
4774 @return Return 0 if access is granted, otherwise an appropriate value for
4775 errno should be returned.
4776 */
4777 typedef int mpo_vnode_check_ioctl_t(
4778 kauth_cred_t cred,
4779 struct vnode *vp,
4780 struct label *label,
4781 unsigned int cmd
4782 );
4783 /**
4784 @brief Access control check for vnode kqfilter
4785 @param active_cred Subject credential
4786 @param kn Object knote
4787 @param vp Object vnode
4788 @param label Policy label for vp
4789
4790 Determine whether the subject identified by the credential can
4791 receive the knote on the passed vnode.
4792
4793 @return Return 0 if access if granted, otherwise an appropriate
4794 value for errno should be returned.
4795 */
4796 typedef int mpo_vnode_check_kqfilter_t(
4797 kauth_cred_t active_cred,
4798 kauth_cred_t file_cred, /* NULLOK */
4799 struct knote *kn,
4800 struct vnode *vp,
4801 struct label *label
4802 );
4803 /**
4804 @brief Access control check for relabel
4805 @param cred Subject credential
4806 @param vp Object vnode
4807 @param vnodelabel Existing policy label for vp
4808 @param newlabel Policy label update to later be applied to vp
4809 @see mpo_relable_vnode_t
4810
4811 Determine whether the subject identified by the credential can relabel
4812 the passed vnode to the passed label update. If all policies permit
4813 the label change, the actual relabel entry point (mpo_vnode_label_update)
4814 will follow.
4815
4816 @return Return 0 if access is granted, otherwise an appropriate value for
4817 errno should be returned.
4818 */
4819 typedef int mpo_vnode_check_label_update_t(
4820 struct ucred *cred,
4821 struct vnode *vp,
4822 struct label *vnodelabel,
4823 struct label *newlabel
4824 );
4825 /**
4826 @brief Access control check for creating link
4827 @param cred Subject credential
4828 @param dvp Directory vnode
4829 @param dlabel Policy label associated with dvp
4830 @param vp Link destination vnode
4831 @param label Policy label associated with vp
4832 @param cnp Component name for the link being created
4833
4834 Determine whether the subject identified by the credential should be
4835 allowed to create a link to the vnode vp with the name specified by cnp.
4836
4837 @return Return 0 if access is granted, otherwise an appropriate value for
4838 errno should be returned.
4839 */
4840 typedef int mpo_vnode_check_link_t(
4841 kauth_cred_t cred,
4842 struct vnode *dvp,
4843 struct label *dlabel,
4844 struct vnode *vp,
4845 struct label *label,
4846 struct componentname *cnp
4847 );
4848 /**
4849 @brief Access control check for listing extended attributes
4850 @param cred Subject credential
4851 @param vp Object vnode
4852 @param vlabel Policy label associated with vp
4853
4854 Determine whether the subject identified by the credential can retrieve
4855 a list of named extended attributes from a vnode.
4856
4857 @return Return 0 if access is granted, otherwise an appropriate value for
4858 errno should be returned.
4859 */
4860 typedef int mpo_vnode_check_listextattr_t(
4861 kauth_cred_t cred,
4862 struct vnode *vp,
4863 struct label *vlabel
4864 );
4865 /**
4866 @brief Access control check for lookup
4867 @param cred Subject credential
4868 @param dvp Object vnode
4869 @param dlabel Policy label for dvp
4870 @param cnp Component name being looked up
4871
4872 Determine whether the subject identified by the credential can perform
4873 a lookup in the passed directory vnode for the passed name (cnp).
4874
4875 @return Return 0 if access is granted, otherwise an appropriate value for
4876 errno should be returned. Suggested failure: EACCES for label mismatch or
4877 EPERM for lack of privilege.
4878 */
4879 typedef int mpo_vnode_check_lookup_t(
4880 kauth_cred_t cred,
4881 struct vnode *dvp,
4882 struct label *dlabel,
4883 struct componentname *cnp
4884 );
4885 /**
4886 @brief Access control check for open
4887 @param cred Subject credential
4888 @param vp Object vnode
4889 @param label Policy label associated with vp
4890 @param acc_mode open(2) access mode
4891
4892 Determine whether the subject identified by the credential can perform
4893 an open operation on the passed vnode with the passed access mode.
4894
4895 @return Return 0 if access is granted, otherwise an appropriate value for
4896 errno should be returned. Suggested failure: EACCES for label mismatch or
4897 EPERM for lack of privilege.
4898 */
4899 typedef int mpo_vnode_check_open_t(
4900 kauth_cred_t cred,
4901 struct vnode *vp,
4902 struct label *label,
4903 int acc_mode
4904 );
4905 /**
4906 @brief Access control check for read
4907 @param active_cred Subject credential
4908 @param file_cred Credential associated with the struct fileproc
4909 @param vp Object vnode
4910 @param label Policy label for vp
4911
4912 Determine whether the subject identified by the credential can perform
4913 a read operation on the passed vnode. The active_cred hold the credentials
4914 of the subject performing the operation, and file_cred holds the
4915 credentials of the subject that originally opened the file.
4916
4917 @return Return 0 if access is granted, otherwise an appropriate value for
4918 errno should be returned. Suggested failure: EACCES for label mismatch or
4919 EPERM for lack of privilege.
4920 */
4921 typedef int mpo_vnode_check_read_t(
4922 kauth_cred_t active_cred, /* SUBJECT */
4923 kauth_cred_t file_cred, /* NULLOK */
4924 struct vnode *vp, /* OBJECT */
4925 struct label *label /* LABEL */
4926 );
4927 /**
4928 @brief Access control check for read directory
4929 @param cred Subject credential
4930 @param dvp Object directory vnode
4931 @param dlabel Policy label for dvp
4932
4933 Determine whether the subject identified by the credential can
4934 perform a readdir operation on the passed directory vnode.
4935
4936 @return Return 0 if access is granted, otherwise an appropriate value for
4937 errno should be returned. Suggested failure: EACCES for label mismatch or
4938 EPERM for lack of privilege.
4939 */
4940 typedef int mpo_vnode_check_readdir_t(
4941 kauth_cred_t cred, /* SUBJECT */
4942 struct vnode *dvp, /* OBJECT */
4943 struct label *dlabel /* LABEL */
4944 );
4945 /**
4946 @brief Access control check for read link
4947 @param cred Subject credential
4948 @param vp Object vnode
4949 @param label Policy label for vp
4950
4951 Determine whether the subject identified by the credential can perform
4952 a readlink operation on the passed symlink vnode. This call can be made
4953 in a number of situations, including an explicit readlink call by the
4954 user process, or as a result of an implicit readlink during a name
4955 lookup by the process.
4956
4957 @return Return 0 if access is granted, otherwise an appropriate value for
4958 errno should be returned. Suggested failure: EACCES for label mismatch or
4959 EPERM for lack of privilege.
4960 */
4961 typedef int mpo_vnode_check_readlink_t(
4962 kauth_cred_t cred,
4963 struct vnode *vp,
4964 struct label *label
4965 );
4966 /**
4967 @brief Access control check for rename
4968 @param cred Subject credential
4969 @param dvp Directory vnode
4970 @param dlabel Policy label associated with dvp
4971 @param vp vnode to be renamed
4972 @param label Policy label associated with vp
4973 @param cnp Component name for vp
4974 @param tdvp Destination directory vnode
4975 @param tdlabel Policy label associated with tdvp
4976 @param tvp Overwritten vnode
4977 @param tlabel Policy label associated with tvp
4978 @param tcnp Destination component name
4979
4980 Determine whether the subject identified by the credential should be allowed
4981 to rename the vnode vp to something else.
4982
4983 @return Return 0 if access is granted, otherwise an appropriate value for
4984 errno should be returned.
4985 */
4986 typedef int mpo_vnode_check_rename_t(
4987 kauth_cred_t cred,
4988 struct vnode *dvp,
4989 struct label *dlabel,
4990 struct vnode *vp,
4991 struct label *label,
4992 struct componentname *cnp,
4993 struct vnode *tdvp,
4994 struct label *tdlabel,
4995 struct vnode *tvp,
4996 struct label *tlabel,
4997 struct componentname *tcnp
4998 );
4999 /**
5000 @brief Access control check for rename from
5001 @param cred Subject credential
5002 @param dvp Directory vnode
5003 @param dlabel Policy label associated with dvp
5004 @param vp vnode to be renamed
5005 @param label Policy label associated with vp
5006 @param cnp Component name for vp
5007 @see mpo_vnode_check_rename_t
5008 @see mpo_vnode_check_rename_to_t
5009
5010 Determine whether the subject identified by the credential should be
5011 allowed to rename the vnode vp to something else.
5012
5013 Due to VFS locking constraints (to make sure proper vnode locks are
5014 held during this entry point), the vnode relabel checks had to be
5015 split into two parts: relabel_from and relabel to.
5016
5017 This hook is deprecated, mpo_vnode_check_rename_t should be used instead.
5018
5019 @return Return 0 if access is granted, otherwise an appropriate value for
5020 errno should be returned.
5021 */
5022 typedef int mpo_vnode_check_rename_from_t(
5023 kauth_cred_t cred,
5024 struct vnode *dvp,
5025 struct label *dlabel,
5026 struct vnode *vp,
5027 struct label *label,
5028 struct componentname *cnp
5029 );
5030 /**
5031 @brief Access control check for rename to
5032 @param cred Subject credential
5033 @param dvp Directory vnode
5034 @param dlabel Policy label associated with dvp
5035 @param vp Overwritten vnode
5036 @param label Policy label associated with vp
5037 @param samedir Boolean; 1 if the source and destination directories are the same
5038 @param cnp Destination component name
5039 @see mpo_vnode_check_rename_t
5040 @see mpo_vnode_check_rename_from_t
5041
5042 Determine whether the subject identified by the credential should be
5043 allowed to rename to the vnode vp, into the directory dvp, or to the
5044 name represented by cnp. If there is no existing file to overwrite,
5045 vp and label will be NULL.
5046
5047 Due to VFS locking constraints (to make sure proper vnode locks are
5048 held during this entry point), the vnode relabel checks had to be
5049 split into two parts: relabel_from and relabel to.
5050
5051 This hook is deprecated, mpo_vnode_check_rename_t should be used instead.
5052
5053 @return Return 0 if access is granted, otherwise an appropriate value for
5054 errno should be returned.
5055 */
5056 typedef int mpo_vnode_check_rename_to_t(
5057 kauth_cred_t cred,
5058 struct vnode *dvp,
5059 struct label *dlabel,
5060 struct vnode *vp, /* NULLOK */
5061 struct label *label, /* NULLOK */
5062 int samedir,
5063 struct componentname *cnp
5064 );
5065 /**
5066 @brief Access control check for revoke
5067 @param cred Subject credential
5068 @param vp Object vnode
5069 @param label Policy label for vp
5070
5071 Determine whether the subject identified by the credential can revoke
5072 access to the passed vnode.
5073
5074 @return Return 0 if access is granted, otherwise an appropriate value for
5075 errno should be returned. Suggested failure: EACCES for label mismatch or
5076 EPERM for lack of privilege.
5077 */
5078 typedef int mpo_vnode_check_revoke_t(
5079 kauth_cred_t cred,
5080 struct vnode *vp,
5081 struct label *label
5082 );
5083 /**
5084 @brief Access control check for searchfs
5085 @param cred Subject credential
5086 @param vp Object vnode
5087 @param vlabel Policy label for vp
5088 @param alist List of attributes used as search criteria
5089
5090 Determine whether the subject identified by the credential can search the
5091 vnode using the searchfs system call.
5092
5093 @return Return 0 if access is granted, otherwise an appropriate value for
5094 errno should be returned.
5095 */
5096 typedef int mpo_vnode_check_searchfs_t(
5097 kauth_cred_t cred,
5098 struct vnode *vp,
5099 struct label *vlabel,
5100 struct attrlist *alist
5101 );
5102 /**
5103 @brief Access control check for select
5104 @param cred Subject credential
5105 @param vp Object vnode
5106 @param label Policy label for vp
5107 @param which The operation selected on: FREAD or FWRITE
5108
5109 Determine whether the subject identified by the credential can select
5110 the vnode.
5111
5112 @return Return 0 if access is granted, otherwise an appropriate value for
5113 errno should be returned.
5114 */
5115 typedef int mpo_vnode_check_select_t(
5116 kauth_cred_t cred,
5117 struct vnode *vp,
5118 struct label *label,
5119 int which
5120 );
5121 /**
5122 @brief Access control check for setting ACL
5123 @param cred Subject credential
5124 @param vp Object node
5125 @param label Policy label for vp
5126 @param acl ACL structure pointer
5127
5128 Determine whether the subject identified by the credential can set an ACL
5129 on the specified vnode. The ACL pointer will be NULL when removing an ACL.
5130
5131 @return Return 0 if access is granted, otherwise an appropriate value for
5132 errno should be returned. Suggested failure: EACCES for label mismatch or
5133 EPERM for lack of privilege.
5134 */
5135 typedef int mpo_vnode_check_setacl_t(
5136 kauth_cred_t cred,
5137 struct vnode *vp,
5138 struct label *label,
5139 struct kauth_acl *acl
5140 );
5141 /**
5142 @brief Access control check for setting file attributes
5143 @param cred Subject credential
5144 @param vp Object vnode
5145 @param vlabel Policy label for vp
5146 @param alist List of attributes to set
5147
5148 Determine whether the subject identified by the credential can set
5149 various attributes of the specified vnode, or the filesystem or volume on
5150 which that vnode resides. See <sys/attr.h> for definitions of the
5151 attributes.
5152
5153 @return Return 0 if access is granted, otherwise an appropriate value for
5154 errno should be returned. Suggested failure: EACCES for label mismatch or
5155 EPERM for lack of privilege. Access control covers all attributes requested
5156 with this call.
5157 */
5158 typedef int mpo_vnode_check_setattrlist_t(
5159 kauth_cred_t cred,
5160 struct vnode *vp,
5161 struct label *vlabel,
5162 struct attrlist *alist
5163 );
5164 /**
5165 @brief Access control check for setting extended attribute
5166 @param cred Subject credential
5167 @param vp Object vnode
5168 @param label Policy label for vp
5169 @param name Extended attribute name
5170 @param uio I/O structure pointer
5171
5172 Determine whether the subject identified by the credential can set the
5173 extended attribute of passed name and passed namespace on the passed
5174 vnode. Policies implementing security labels backed into extended
5175 attributes may want to provide additional protections for those
5176 attributes. Additionally, policies should avoid making decisions based
5177 on the data referenced from uio, as there is a potential race condition
5178 between this check and the actual operation. The uio may also be NULL
5179 if a delete operation is being performed.
5180
5181 @return Return 0 if access is granted, otherwise an appropriate value for
5182 errno should be returned. Suggested failure: EACCES for label mismatch or
5183 EPERM for lack of privilege.
5184 */
5185 typedef int mpo_vnode_check_setextattr_t(
5186 kauth_cred_t cred,
5187 struct vnode *vp,
5188 struct label *label,
5189 const char *name,
5190 struct uio *uio
5191 );
5192 /**
5193 @brief Access control check for setting flags
5194 @param cred Subject credential
5195 @param vp Object vnode
5196 @param label Policy label for vp
5197 @param flags File flags; see chflags(2)
5198
5199 Determine whether the subject identified by the credential can set
5200 the passed flags on the passed vnode.
5201
5202 @return Return 0 if access is granted, otherwise an appropriate value for
5203 errno should be returned. Suggested failure: EACCES for label mismatch or
5204 EPERM for lack of privilege.
5205 */
5206 typedef int mpo_vnode_check_setflags_t(
5207 kauth_cred_t cred,
5208 struct vnode *vp,
5209 struct label *label,
5210 u_long flags
5211 );
5212 /**
5213 @brief Access control check for setting mode
5214 @param cred Subject credential
5215 @param vp Object vnode
5216 @param label Policy label for vp
5217 @param mode File mode; see chmod(2)
5218
5219 Determine whether the subject identified by the credential can set
5220 the passed mode on the passed vnode.
5221
5222 @return Return 0 if access is granted, otherwise an appropriate value for
5223 errno should be returned. Suggested failure: EACCES for label mismatch or
5224 EPERM for lack of privilege.
5225 */
5226 typedef int mpo_vnode_check_setmode_t(
5227 kauth_cred_t cred,
5228 struct vnode *vp,
5229 struct label *label,
5230 mode_t mode
5231 );
5232 /**
5233 @brief Access control check for setting uid and gid
5234 @param cred Subject credential
5235 @param vp Object vnode
5236 @param label Policy label for vp
5237 @param uid User ID
5238 @param gid Group ID
5239
5240 Determine whether the subject identified by the credential can set
5241 the passed uid and passed gid as file uid and file gid on the passed
5242 vnode. The IDs may be set to (-1) to request no update.
5243
5244 @return Return 0 if access is granted, otherwise an appropriate value for
5245 errno should be returned. Suggested failure: EACCES for label mismatch or
5246 EPERM for lack of privilege.
5247 */
5248 typedef int mpo_vnode_check_setowner_t(
5249 kauth_cred_t cred,
5250 struct vnode *vp,
5251 struct label *label,
5252 uid_t uid,
5253 gid_t gid
5254 );
5255 /**
5256 @brief Access control check for setting timestamps
5257 @param cred Subject credential
5258 @param vp Object vnode
5259 @param label Policy label for vp
5260 @param atime Access time; see utimes(2)
5261 @param mtime Modification time; see utimes(2)
5262
5263 Determine whether the subject identified by the credential can set
5264 the passed access timestamps on the passed vnode.
5265
5266 @return Return 0 if access is granted, otherwise an appropriate value for
5267 errno should be returned. Suggested failure: EACCES for label mismatch or
5268 EPERM for lack of privilege.
5269 */
5270 typedef int mpo_vnode_check_setutimes_t(
5271 kauth_cred_t cred,
5272 struct vnode *vp,
5273 struct label *label,
5274 struct timespec atime,
5275 struct timespec mtime
5276 );
5277 /**
5278 @brief Access control check after determining the code directory hash
5279 @param vp vnode vnode to combine into proc
5280 @param label label associated with the vnode
5281 @param cs_blob the code signature to check
5282 @param cs_flags update code signing flags if needed
5283 @param flags operational flag to mpo_vnode_check_signature
5284 @param fatal_failure_desc description of fatal failure
5285 @param fatal_failure_desc_len failure description len, failure is fatal if non-0
5286
5287 @return Return 0 if access is granted, otherwise an appropriate value for
5288 errno should be returned.
5289 */
5290 typedef int mpo_vnode_check_signature_t(
5291 struct vnode *vp,
5292 struct label *label,
5293 struct cs_blob *cs_blob,
5294 unsigned int *cs_flags,
5295 int flags,
5296 char **fatal_failure_desc, size_t *fatal_failure_desc_len
5297 );
5298 /**
5299 @brief Access control check for stat
5300 @param active_cred Subject credential
5301 @param file_cred Credential associated with the struct fileproc
5302 @param vp Object vnode
5303 @param label Policy label for vp
5304
5305 Determine whether the subject identified by the credential can stat
5306 the passed vnode. See stat(2) for more information. The active_cred
5307 hold the credentials of the subject performing the operation, and
5308 file_cred holds the credentials of the subject that originally
5309 opened the file.
5310
5311 @return Return 0 if access is granted, otherwise an appropriate value for
5312 errno should be returned. Suggested failure: EACCES for label mismatch or
5313 EPERM for lack of privilege.
5314 */
5315 typedef int mpo_vnode_check_stat_t(
5316 struct ucred *active_cred,
5317 struct ucred *file_cred, /* NULLOK */
5318 struct vnode *vp,
5319 struct label *label
5320 );
5321 /**
5322 @brief Access control check for truncate/ftruncate
5323 @param active_cred Subject credential
5324 @param file_cred Credential associated with the struct fileproc
5325 @param vp Object vnode
5326 @param label Policy label for vp
5327
5328 Determine whether the subject identified by the credential can
5329 perform a truncate operation on the passed vnode. The active_cred hold
5330 the credentials of the subject performing the operation, and
5331 file_cred holds the credentials of the subject that originally
5332 opened the file.
5333
5334 @return Return 0 if access is granted, otherwise an appropriate value for
5335 errno should be returned. Suggested failure: EACCES for label mismatch or
5336 EPERM for lack of privilege.
5337 */
5338 typedef int mpo_vnode_check_truncate_t(
5339 kauth_cred_t active_cred,
5340 kauth_cred_t file_cred, /* NULLOK */
5341 struct vnode *vp,
5342 struct label *label
5343 );
5344 /**
5345 @brief Access control check for binding UNIX domain socket
5346 @param cred Subject credential
5347 @param dvp Directory vnode
5348 @param dlabel Policy label for dvp
5349 @param cnp Component name for dvp
5350 @param vap vnode attributes for vap
5351
5352 Determine whether the subject identified by the credential can perform a
5353 bind operation on a UNIX domain socket with the passed parent directory,
5354 passed name information, and passed attribute information.
5355
5356 @return Return 0 if access is granted, otherwise an appropriate value for
5357 errno should be returned. Suggested failure: EACCES for label mismatch or
5358 EPERM for lack of privilege.
5359 */
5360 typedef int mpo_vnode_check_uipc_bind_t(
5361 kauth_cred_t cred,
5362 struct vnode *dvp,
5363 struct label *dlabel,
5364 struct componentname *cnp,
5365 struct vnode_attr *vap
5366 );
5367 /**
5368 @brief Access control check for connecting UNIX domain socket
5369 @param cred Subject credential
5370 @param vp Object vnode
5371 @param label Policy label associated with vp
5372 @param so Socket
5373
5374 Determine whether the subject identified by the credential can perform a
5375 connect operation on the passed UNIX domain socket vnode.
5376
5377 @return Return 0 if access is granted, otherwise an appropriate value for
5378 errno should be returned. Suggested failure: EACCES for label mismatch or
5379 EPERM for lack of privilege.
5380 */
5381 typedef int mpo_vnode_check_uipc_connect_t(
5382 kauth_cred_t cred,
5383 struct vnode *vp,
5384 struct label *label,
5385 socket_t so
5386 );
5387 /**
5388 @brief Access control check for deleting vnode
5389 @param cred Subject credential
5390 @param dvp Parent directory vnode
5391 @param dlabel Policy label for dvp
5392 @param vp Object vnode to delete
5393 @param label Policy label for vp
5394 @param cnp Component name for vp
5395 @see mpo_check_rename_to_t
5396
5397 Determine whether the subject identified by the credential can delete
5398 a vnode from the passed parent directory and passed name information.
5399 This call may be made in a number of situations, including as a
5400 results of calls to unlink(2) and rmdir(2). Policies implementing
5401 this entry point should also implement mpo_check_rename_to to
5402 authorize deletion of objects as a result of being the target of a rename.
5403
5404 @return Return 0 if access is granted, otherwise an appropriate value for
5405 errno should be returned. Suggested failure: EACCES for label mismatch or
5406 EPERM for lack of privilege.
5407 */
5408 typedef int mpo_vnode_check_unlink_t(
5409 kauth_cred_t cred,
5410 struct vnode *dvp,
5411 struct label *dlabel,
5412 struct vnode *vp,
5413 struct label *label,
5414 struct componentname *cnp
5415 );
5416 /**
5417 @brief Access control check for write
5418 @param active_cred Subject credential
5419 @param file_cred Credential associated with the struct fileproc
5420 @param vp Object vnode
5421 @param label Policy label for vp
5422
5423 Determine whether the subject identified by the credential can
5424 perform a write operation on the passed vnode. The active_cred hold
5425 the credentials of the subject performing the operation, and
5426 file_cred holds the credentials of the subject that originally
5427 opened the file.
5428
5429 @return Return 0 if access is granted, otherwise an appropriate value for
5430 errno should be returned. Suggested failure: EACCES for label mismatch or
5431 EPERM for lack of privilege.
5432 */
5433 typedef int mpo_vnode_check_write_t(
5434 kauth_cred_t active_cred,
5435 kauth_cred_t file_cred, /* NULLOK */
5436 struct vnode *vp,
5437 struct label *label
5438 );
5439 /**
5440 @brief Associate a vnode with a devfs entry
5441 @param mp Devfs mount point
5442 @param mntlabel Devfs mount point label
5443 @param de Devfs directory entry
5444 @param delabel Label associated with de
5445 @param vp vnode associated with de
5446 @param vlabel Label associated with vp
5447
5448 Fill in the label (vlabel) for a newly created devfs vnode. The
5449 label is typically derived from the label on the devfs directory
5450 entry or the label on the filesystem, supplied as parameters.
5451 */
5452 typedef void mpo_vnode_label_associate_devfs_t(
5453 struct mount *mp,
5454 struct label *mntlabel,
5455 struct devnode *de,
5456 struct label *delabel,
5457 struct vnode *vp,
5458 struct label *vlabel
5459 );
5460 /**
5461 @brief Associate a label with a vnode
5462 @param mp File system mount point
5463 @param mntlabel File system mount point label
5464 @param vp Vnode to label
5465 @param vlabel Label associated with vp
5466
5467 Attempt to retrieve label information for the vnode, vp, from the
5468 file system extended attribute store. The label should be stored in
5469 the supplied vlabel parameter. If a policy cannot retrieve an
5470 extended attribute, sometimes it is acceptible to fallback to using
5471 the mntlabel.
5472
5473 If the policy requires vnodes to have a valid label elsewhere it
5474 MUST NOT return other than temporary errors, and must always provide
5475 a valid label of some sort. Returning an error will cause vnode
5476 labeling to be retried at a later access. Failure to handle policy
5477 centric errors internally (corrupt labels etc.) will result in
5478 inaccessible files.
5479
5480 @return In the event of an error, an appropriate value for errno
5481 should be returned, otherwise return 0 upon success.
5482 */
5483 typedef int mpo_vnode_label_associate_extattr_t(
5484 struct mount *mp,
5485 struct label *mntlabel,
5486 struct vnode *vp,
5487 struct label *vlabel
5488 );
5489 /**
5490 @brief Associate a file label with a vnode
5491 @param cred User credential
5492 @param mp Fdesc mount point
5493 @param mntlabel Fdesc mount point label
5494 @param fg Fileglob structure
5495 @param label Policy label for fg
5496 @param vp Vnode to label
5497 @param vlabel Label associated with vp
5498
5499 Associate label information for the vnode, vp, with the label of
5500 the open file descriptor described by fg.
5501 The label should be stored in the supplied vlabel parameter.
5502 */
5503 typedef void mpo_vnode_label_associate_file_t(
5504 struct ucred *cred,
5505 struct mount *mp,
5506 struct label *mntlabel,
5507 struct fileglob *fg,
5508 struct label *label,
5509 struct vnode *vp,
5510 struct label *vlabel
5511 );
5512 /**
5513 @brief Associate a pipe label with a vnode
5514 @param cred User credential for the process that opened the pipe
5515 @param cpipe Pipe structure
5516 @param pipelabel Label associated with pipe
5517 @param vp Vnode to label
5518 @param vlabel Label associated with vp
5519
5520 Associate label information for the vnode, vp, with the label of
5521 the pipe described by the pipe structure cpipe.
5522 The label should be stored in the supplied vlabel parameter.
5523 */
5524 typedef void mpo_vnode_label_associate_pipe_t(
5525 struct ucred *cred,
5526 struct pipe *cpipe,
5527 struct label *pipelabel,
5528 struct vnode *vp,
5529 struct label *vlabel
5530 );
5531 /**
5532 @brief Associate a POSIX semaphore label with a vnode
5533 @param cred User credential for the process that create psem
5534 @param psem POSIX semaphore structure
5535 @param psemlabel Label associated with psem
5536 @param vp Vnode to label
5537 @param vlabel Label associated with vp
5538
5539 Associate label information for the vnode, vp, with the label of
5540 the POSIX semaphore described by psem.
5541 The label should be stored in the supplied vlabel parameter.
5542 */
5543 typedef void mpo_vnode_label_associate_posixsem_t(
5544 struct ucred *cred,
5545 struct pseminfo *psem,
5546 struct label *psemlabel,
5547 struct vnode *vp,
5548 struct label *vlabel
5549 );
5550 /**
5551 @brief Associate a POSIX shared memory label with a vnode
5552 @param cred User credential for the process that created pshm
5553 @param pshm POSIX shared memory structure
5554 @param pshmlabel Label associated with pshm
5555 @param vp Vnode to label
5556 @param vlabel Label associated with vp
5557
5558 Associate label information for the vnode, vp, with the label of
5559 the POSIX shared memory region described by pshm.
5560 The label should be stored in the supplied vlabel parameter.
5561 */
5562 typedef void mpo_vnode_label_associate_posixshm_t(
5563 struct ucred *cred,
5564 struct pshminfo *pshm,
5565 struct label *pshmlabel,
5566 struct vnode *vp,
5567 struct label *vlabel
5568 );
5569 /**
5570 @brief Associate a label with a vnode
5571 @param mp File system mount point
5572 @param mntlabel File system mount point label
5573 @param vp Vnode to label
5574 @param vlabel Label associated with vp
5575
5576 On non-multilabel file systems, set the label for a vnode. The
5577 label will most likely be based on the file system label.
5578 */
5579 typedef void mpo_vnode_label_associate_singlelabel_t(
5580 struct mount *mp,
5581 struct label *mntlabel,
5582 struct vnode *vp,
5583 struct label *vlabel
5584 );
5585 /**
5586 @brief Associate a socket label with a vnode
5587 @param cred User credential for the process that opened the socket
5588 @param so Socket structure
5589 @param solabel Label associated with so
5590 @param vp Vnode to label
5591 @param vlabel Label associated with vp
5592
5593 Associate label information for the vnode, vp, with the label of
5594 the open socket described by the socket structure so.
5595 The label should be stored in the supplied vlabel parameter.
5596 */
5597 typedef void mpo_vnode_label_associate_socket_t(
5598 kauth_cred_t cred,
5599 socket_t so,
5600 struct label *solabel,
5601 struct vnode *vp,
5602 struct label *vlabel
5603 );
5604 /**
5605 @brief Copy a vnode label
5606 @param src Source vnode label
5607 @param dest Destination vnode label
5608
5609 Copy the vnode label information from src to dest. On Darwin, this
5610 is currently only necessary when executing interpreted scripts, but
5611 will later be used if vnode label externalization cannot be an
5612 atomic operation.
5613 */
5614 typedef void mpo_vnode_label_copy_t(
5615 struct label *src,
5616 struct label *dest
5617 );
5618 /**
5619 @brief Destroy vnode label
5620 @param label The label to be destroyed
5621
5622 Destroy a vnode label. Since the object is going out of scope,
5623 policy modules should free any internal storage associated with the
5624 label so that it may be destroyed.
5625 */
5626 typedef void mpo_vnode_label_destroy_t(
5627 struct label *label
5628 );
5629 /**
5630 @brief Externalize a vnode label for auditing
5631 @param label Label to be externalized
5632 @param element_name Name of the label namespace for which labels should be
5633 externalized
5634 @param sb String buffer to be filled with a text representation of the label
5635
5636 Produce an external representation of the label on a vnode suitable for
5637 inclusion in an audit record. An externalized label consists of a text
5638 representation of the label contents that will be added to the audit record
5639 as part of a text token. Policy-agnostic user space tools will display
5640 this externalized version.
5641
5642 @return 0 on success, return non-zero if an error occurs while
5643 externalizing the label data.
5644
5645 */
5646 typedef int mpo_vnode_label_externalize_audit_t(
5647 struct label *label,
5648 char *element_name,
5649 struct sbuf *sb
5650 );
5651 /**
5652 @brief Externalize a vnode label
5653 @param label Label to be externalized
5654 @param element_name Name of the label namespace for which labels should be
5655 externalized
5656 @param sb String buffer to be filled with a text representation of the label
5657
5658 Produce an external representation of the label on a vnode. An
5659 externalized label consists of a text representation of the label
5660 contents that can be used with user applications. Policy-agnostic
5661 user space tools will display this externalized version.
5662
5663 @return 0 on success, return non-zero if an error occurs while
5664 externalizing the label data.
5665
5666 */
5667 typedef int mpo_vnode_label_externalize_t(
5668 struct label *label,
5669 char *element_name,
5670 struct sbuf *sb
5671 );
5672 /**
5673 @brief Initialize vnode label
5674 @param label New label to initialize
5675
5676 Initialize label storage for use with a newly instantiated vnode, or
5677 for temporary storage associated with the copying in or out of a
5678 vnode label. While it is necessary to allocate space for a
5679 kernel-resident vnode label, it is not yet necessary to link this vnode
5680 with persistent label storage facilities, such as extended attributes.
5681 Sleeping is permitted.
5682 */
5683 typedef void mpo_vnode_label_init_t(
5684 struct label *label
5685 );
5686 /**
5687 @brief Internalize a vnode label
5688 @param label Label to be internalized
5689 @param element_name Name of the label namespace for which the label should
5690 be internalized
5691 @param element_data Text data to be internalized
5692
5693 Produce a vnode label from an external representation. An
5694 externalized label consists of a text representation of the label
5695 contents that can be used with user applications. Policy-agnostic
5696 user space tools will forward text version to the kernel for
5697 processing by individual policy modules.
5698
5699 The policy's internalize entry points will be called only if the
5700 policy has registered interest in the label namespace.
5701
5702 @return 0 on success, Otherwise, return non-zero if an error occurs
5703 while internalizing the label data.
5704 */
5705 typedef int mpo_vnode_label_internalize_t(
5706 struct label *label,
5707 char *element_name,
5708 char *element_data
5709 );
5710 /**
5711 @brief Clean up a vnode label
5712 @param label The label to be cleaned for re-use
5713
5714 Clean up a vnode label. Darwin (Tiger, 8.x) allocates vnodes on demand, but
5715 typically never frees them. Before vnodes are placed back on free lists for
5716 re-use, policies can cleanup or overwrite any information present in the label.
5717 */
5718 typedef void mpo_vnode_label_recycle_t(
5719 struct label *label
5720 );
5721 /**
5722 @brief Write a label to a extended attribute
5723 @param cred Subject credential
5724 @param vp The vnode for which the label is being stored
5725 @param vlabel Label associated with vp
5726 @param intlabel The new label to store
5727
5728 Store a new label in the extended attribute corresponding to the
5729 supplied vnode. The policy has already authorized the operation;
5730 this call must be implemented in order to perform the actual
5731 operation.
5732
5733 @return In the event of an error, an appropriate value for errno
5734 should be returned, otherwise return 0 upon success.
5735
5736 @warning XXX After examining the extended attribute implementation on
5737 Apple's future release, this entry point may be changed.
5738 */
5739 typedef int mpo_vnode_label_store_t(
5740 kauth_cred_t cred,
5741 struct vnode *vp,
5742 struct label *vlabel,
5743 struct label *intlabel
5744 );
5745 /**
5746 @brief Update vnode label from extended attributes
5747 @param mp File system mount point
5748 @param mntlabel Mount point label
5749 @param vp Vnode to label
5750 @param vlabel Label associated with vp
5751 @param name Name of the xattr
5752 @see mpo_vnode_check_setextattr_t
5753
5754 When an extended attribute is updated via the Vendor attribute management
5755 functions, the MAC vnode label might also require an update.
5756 Policies should first determine if 'name' matches their xattr label
5757 name. If it does, the kernel is has either replaced or removed the
5758 named extended attribute that was previously associated with the
5759 vnode. Normally labels should only be modified via MAC Framework label
5760 management calls, but sometimes the user space components will directly
5761 modify extended attributes. For example, 'cp', 'tar', etc. manage
5762 extended attributes in userspace, not the kernel.
5763
5764 This entry point is called after the label update has occurred, so
5765 it cannot return a failure. However, the operation is preceded by
5766 the mpo_vnode_check_setextattr() access control check.
5767
5768 If the vnode label needs to be updated the policy should return
5769 a non-zero value. The vnode label will be marked for re-association
5770 by the framework.
5771 */
5772 typedef int mpo_vnode_label_update_extattr_t(
5773 struct mount *mp,
5774 struct label *mntlabel,
5775 struct vnode *vp,
5776 struct label *vlabel,
5777 const char *name
5778 );
5779 /**
5780 @brief Update a vnode label
5781 @param cred Subject credential
5782 @param vp The vnode to relabel
5783 @param vnodelabel Existing vnode label
5784 @param label New label to replace existing label
5785 @see mpo_vnode_check_label_update_t
5786
5787 The subject identified by the credential has previously requested
5788 and was authorized to relabel the vnode; this entry point allows
5789 policies to perform the actual relabel operation. Policies should
5790 update vnodelabel using the label stored in the label parameter.
5791 */
5792 typedef void mpo_vnode_label_update_t(
5793 kauth_cred_t cred,
5794 struct vnode *vp,
5795 struct label *vnodelabel,
5796 struct label *label
5797 );
5798 /**
5799 @brief Find deatched signatures for a shared library
5800 @param p file trying to find the signature
5801 @param vp The vnode to relabel
5802 @param offset offset in the macho that the signature is requested for (for fat binaries)
5803 @param label Existing vnode label
5804
5805 */
5806 typedef int mpo_vnode_find_sigs_t(
5807 struct proc *p,
5808 struct vnode *vp,
5809 off_t offset,
5810 struct label *label
5811 );
5812 /**
5813 @brief Create a new vnode, backed by extended attributes
5814 @param cred User credential for the creating process
5815 @param mp File system mount point
5816 @param mntlabel File system mount point label
5817 @param dvp Parent directory vnode
5818 @param dlabel Parent directory vnode label
5819 @param vp Newly created vnode
5820 @param vlabel Label to associate with the new vnode
5821 @param cnp Component name for vp
5822
5823 Write out the label for the newly created vnode, most likely storing
5824 the results in a file system extended attribute. Most policies will
5825 derive the new vnode label using information from a combination
5826 of the subject (user) credential, the file system label, the parent
5827 directory label, and potentially the path name component.
5828
5829 @return If the operation succeeds, store the new label in vlabel and
5830 return 0. Otherwise, return an appropriate errno value.
5831 */
5832 typedef int mpo_vnode_notify_create_t(
5833 kauth_cred_t cred,
5834 struct mount *mp,
5835 struct label *mntlabel,
5836 struct vnode *dvp,
5837 struct label *dlabel,
5838 struct vnode *vp,
5839 struct label *vlabel,
5840 struct componentname *cnp
5841 );
5842
5843 /**
5844 @brief Inform MAC policies that a vnode has been opened
5845 @param cred User credential for the creating process
5846 @param vp vnode opened
5847 @param label Policy label for the vp
5848 @param acc_mode open(2) access mode used
5849
5850 Inform Mac policies that a vnode have been successfully opened
5851 (passing all MAC polices and DAC).
5852 */
5853 typedef void mpo_vnode_notify_open_t(
5854 kauth_cred_t cred,
5855 struct vnode *vp,
5856 struct label *label,
5857 int acc_mode
5858 );
5859
5860 /**
5861 @brief Inform MAC policies that a vnode has been renamed
5862 @param cred User credential for the renaming process
5863 @param vp Vnode that's being renamed
5864 @param label Policy label for vp
5865 @param dvp Parent directory for the destination
5866 @param dlabel Policy label for dvp
5867 @param cnp Component name for the destination
5868
5869 Inform MAC policies that a vnode has been renamed.
5870 */
5871 typedef void mpo_vnode_notify_rename_t(
5872 kauth_cred_t cred,
5873 struct vnode *vp,
5874 struct label *label,
5875 struct vnode *dvp,
5876 struct label *dlabel,
5877 struct componentname *cnp
5878 );
5879
5880 /**
5881 @brief Inform MAC policies that a vnode has been linked
5882 @param cred User credential for the renaming process
5883 @param dvp Parent directory for the destination
5884 @param dlabel Policy label for dvp
5885 @param vp Vnode that's being linked
5886 @param vlabel Policy label for vp
5887 @param cnp Component name for the destination
5888
5889 Inform MAC policies that a vnode has been linked.
5890 */
5891 typedef void mpo_vnode_notify_link_t(
5892 kauth_cred_t cred,
5893 struct vnode *dvp,
5894 struct label *dlabel,
5895 struct vnode *vp,
5896 struct label *vlabel,
5897 struct componentname *cnp
5898 );
5899
5900 /**
5901 @brief Inform MAC policies that an extended attribute has been removed from a vnode
5902 @param cred Subject credential
5903 @param vp Object node
5904 @param label Policy label for vp
5905 @param name Extended attribute name
5906
5907 Inform MAC policies that an extended attribute has been removed from a vnode.
5908 */
5909 typedef void mpo_vnode_notify_deleteextattr_t(
5910 kauth_cred_t cred,
5911 struct vnode *vp,
5912 struct label *label,
5913 const char *name
5914 );
5915
5916
5917 /**
5918 @brief Inform MAC policies that an ACL has been set on a vnode
5919 @param cred Subject credential
5920 @param vp Object node
5921 @param label Policy label for vp
5922 @param acl ACL structure pointer
5923
5924 Inform MAC policies that an ACL has been set on a vnode.
5925 */
5926 typedef void mpo_vnode_notify_setacl_t(
5927 kauth_cred_t cred,
5928 struct vnode *vp,
5929 struct label *label,
5930 struct kauth_acl *acl
5931 );
5932
5933 /**
5934 @brief Inform MAC policies that an attributes have been set on a vnode
5935 @param cred Subject credential
5936 @param vp Object vnode
5937 @param label Policy label for vp
5938 @param alist List of attributes to set
5939
5940 Inform MAC policies that an attributes have been set on a vnode.
5941 */
5942 typedef void mpo_vnode_notify_setattrlist_t(
5943 kauth_cred_t cred,
5944 struct vnode *vp,
5945 struct label *label,
5946 struct attrlist *alist
5947 );
5948
5949 /**
5950 @brief Inform MAC policies that an extended attribute has been set on a vnode
5951 @param cred Subject credential
5952 @param vp Object vnode
5953 @param label Policy label for vp
5954 @param name Extended attribute name
5955 @param uio I/O structure pointer
5956
5957 Inform MAC policies that an extended attribute has been set on a vnode.
5958 */
5959 typedef void mpo_vnode_notify_setextattr_t(
5960 kauth_cred_t cred,
5961 struct vnode *vp,
5962 struct label *label,
5963 const char *name,
5964 struct uio *uio
5965 );
5966
5967 /**
5968 @brief Inform MAC policies that flags have been set on a vnode
5969 @param cred Subject credential
5970 @param vp Object vnode
5971 @param label Policy label for vp
5972 @param flags File flags; see chflags(2)
5973
5974 Inform MAC policies that flags have been set on a vnode.
5975 */
5976 typedef void mpo_vnode_notify_setflags_t(
5977 kauth_cred_t cred,
5978 struct vnode *vp,
5979 struct label *label,
5980 u_long flags
5981 );
5982
5983 /**
5984 @brief Inform MAC policies that a new mode has been set on a vnode
5985 @param cred Subject credential
5986 @param vp Object vnode
5987 @param label Policy label for vp
5988 @param mode File mode; see chmod(2)
5989
5990 Inform MAC policies that a new mode has been set on a vnode.
5991 */
5992 typedef void mpo_vnode_notify_setmode_t(
5993 kauth_cred_t cred,
5994 struct vnode *vp,
5995 struct label *label,
5996 mode_t mode
5997 );
5998
5999 /**
6000 @brief Inform MAC policies that new uid/gid have been set on a vnode
6001 @param cred Subject credential
6002 @param vp Object vnode
6003 @param label Policy label for vp
6004 @param uid User ID
6005 @param gid Group ID
6006
6007 Inform MAC policies that new uid/gid have been set on a vnode.
6008 */
6009 typedef void mpo_vnode_notify_setowner_t(
6010 kauth_cred_t cred,
6011 struct vnode *vp,
6012 struct label *label,
6013 uid_t uid,
6014 gid_t gid
6015 );
6016
6017 /**
6018 @brief Inform MAC policies that new timestamps have been set on a vnode
6019 @param cred Subject credential
6020 @param vp Object vnode
6021 @param label Policy label for vp
6022 @param atime Access time; see utimes(2)
6023 @param mtime Modification time; see utimes(2)
6024
6025 Inform MAC policies that new timestamps have been set on a vnode.
6026 */
6027 typedef void mpo_vnode_notify_setutimes_t(
6028 kauth_cred_t cred,
6029 struct vnode *vp,
6030 struct label *label,
6031 struct timespec atime,
6032 struct timespec mtime
6033 );
6034
6035 /**
6036 @brief Inform MAC policies that a vnode has been truncated
6037 @param cred Subject credential
6038 @param file_cred Credential associated with the struct fileproc
6039 @param vp Object vnode
6040 @param label Policy label for vp
6041
6042 Inform MAC policies that a vnode has been truncated.
6043 */
6044 typedef void mpo_vnode_notify_truncate_t(
6045 kauth_cred_t cred,
6046 kauth_cred_t file_cred,
6047 struct vnode *vp,
6048 struct label *label
6049 );
6050
6051
6052 /**
6053 @brief Inform MAC policies that a pty slave has been granted
6054 @param p Responsible process
6055 @param tp tty data structure
6056 @param dev Major and minor numbers of device
6057 @param label Policy label for tp
6058
6059 Inform MAC policies that a pty slave has been granted.
6060 */
6061 typedef void mpo_pty_notify_grant_t(
6062 proc_t p,
6063 struct tty *tp,
6064 dev_t dev,
6065 struct label *label
6066 );
6067
6068 /**
6069 @brief Inform MAC policies that a pty master has been closed
6070 @param p Responsible process
6071 @param tp tty data structure
6072 @param dev Major and minor numbers of device
6073 @param label Policy label for tp
6074
6075 Inform MAC policies that a pty master has been closed.
6076 */
6077 typedef void mpo_pty_notify_close_t(
6078 proc_t p,
6079 struct tty *tp,
6080 dev_t dev,
6081 struct label *label
6082 );
6083
6084 /**
6085 @brief Access control check for kext loading
6086 @param cred Subject credential
6087 @param identifier Kext identifier
6088
6089 Determine whether the subject identified by the credential can load the
6090 specified kext.
6091
6092 @return Return 0 if access is granted, otherwise an appropriate value for
6093 errno should be returned. Suggested failure: EPERM for lack of privilege.
6094 */
6095 typedef int mpo_kext_check_load_t(
6096 kauth_cred_t cred,
6097 const char *identifier
6098 );
6099
6100 /**
6101 @brief Access control check for kext unloading
6102 @param cred Subject credential
6103 @param identifier Kext identifier
6104
6105 Determine whether the subject identified by the credential can unload the
6106 specified kext.
6107
6108 @return Return 0 if access is granted, otherwise an appropriate value for
6109 errno should be returned. Suggested failure: EPERM for lack of privilege.
6110 */
6111 typedef int mpo_kext_check_unload_t(
6112 kauth_cred_t cred,
6113 const char *identifier
6114 );
6115
6116 /**
6117 @brief Access control check for querying information about loaded kexts
6118 @param cred Subject credential
6119
6120 Determine whether the subject identified by the credential can query
6121 information about loaded kexts.
6122
6123 @return Return 0 if access is granted, otherwise an appropriate value for
6124 errno should be returned. Suggested failure: EPERM for lack of privilege.
6125 */
6126 typedef int mpo_kext_check_query_t(
6127 kauth_cred_t cred
6128 );
6129
6130 /**
6131 @brief Access control check for getting NVRAM variables.
6132 @param cred Subject credential
6133 @param name NVRAM variable to get
6134
6135 Determine whether the subject identifier by the credential can get 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_get_t(
6142 kauth_cred_t cred,
6143 const char *name
6144 );
6145
6146 /**
6147 @brief Access control check for setting NVRAM variables.
6148 @param cred Subject credential
6149 @param name NVRAM variable to set
6150 @param value The new value for the NVRAM variable
6151
6152 Determine whether the subject identifier by the credential can set the
6153 value of the 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_set_t(
6159 kauth_cred_t cred,
6160 const char *name,
6161 io_object_t value
6162 );
6163
6164 /**
6165 @brief Access control check for deleting NVRAM variables.
6166 @param cred Subject credential
6167 @param name NVRAM variable to delete
6168
6169 Determine whether the subject identifier by the credential can delete the
6170 named NVRAM variable.
6171
6172 @return Return 0 if access is granted, otherwise an appropriate value for
6173 errno should be returned. Suggested failure: EPERM for lack of privilege.
6174 */
6175 typedef int mpo_iokit_check_nvram_delete_t(
6176 kauth_cred_t cred,
6177 const char *name
6178 );
6179
6180 /*
6181 * Placeholder for future events that may need mac hooks.
6182 */
6183 typedef void mpo_reserved_hook_t(void);
6184
6185 /*
6186 * Policy module operations.
6187 *
6188 * Please note that this should be kept in sync with the check assumptions
6189 * policy in bsd/kern/policy_check.c (policy_ops struct).
6190 */
6191 #define MAC_POLICY_OPS_VERSION 47 /* inc when new reserved slots are taken */
6192 struct mac_policy_ops {
6193 mpo_audit_check_postselect_t *mpo_audit_check_postselect;
6194 mpo_audit_check_preselect_t *mpo_audit_check_preselect;
6195
6196 mpo_bpfdesc_label_associate_t *mpo_bpfdesc_label_associate;
6197 mpo_bpfdesc_label_destroy_t *mpo_bpfdesc_label_destroy;
6198 mpo_bpfdesc_label_init_t *mpo_bpfdesc_label_init;
6199 mpo_bpfdesc_check_receive_t *mpo_bpfdesc_check_receive;
6200
6201 mpo_cred_check_label_update_execve_t *mpo_cred_check_label_update_execve;
6202 mpo_cred_check_label_update_t *mpo_cred_check_label_update;
6203 mpo_cred_check_visible_t *mpo_cred_check_visible;
6204 mpo_cred_label_associate_fork_t *mpo_cred_label_associate_fork;
6205 mpo_cred_label_associate_kernel_t *mpo_cred_label_associate_kernel;
6206 mpo_cred_label_associate_t *mpo_cred_label_associate;
6207 mpo_cred_label_associate_user_t *mpo_cred_label_associate_user;
6208 mpo_cred_label_destroy_t *mpo_cred_label_destroy;
6209 mpo_cred_label_externalize_audit_t *mpo_cred_label_externalize_audit;
6210 mpo_cred_label_externalize_t *mpo_cred_label_externalize;
6211 mpo_cred_label_init_t *mpo_cred_label_init;
6212 mpo_cred_label_internalize_t *mpo_cred_label_internalize;
6213 mpo_cred_label_update_execve_t *mpo_cred_label_update_execve;
6214 mpo_cred_label_update_t *mpo_cred_label_update;
6215
6216 mpo_devfs_label_associate_device_t *mpo_devfs_label_associate_device;
6217 mpo_devfs_label_associate_directory_t *mpo_devfs_label_associate_directory;
6218 mpo_devfs_label_copy_t *mpo_devfs_label_copy;
6219 mpo_devfs_label_destroy_t *mpo_devfs_label_destroy;
6220 mpo_devfs_label_init_t *mpo_devfs_label_init;
6221 mpo_devfs_label_update_t *mpo_devfs_label_update;
6222
6223 mpo_file_check_change_offset_t *mpo_file_check_change_offset;
6224 mpo_file_check_create_t *mpo_file_check_create;
6225 mpo_file_check_dup_t *mpo_file_check_dup;
6226 mpo_file_check_fcntl_t *mpo_file_check_fcntl;
6227 mpo_file_check_get_offset_t *mpo_file_check_get_offset;
6228 mpo_file_check_get_t *mpo_file_check_get;
6229 mpo_file_check_inherit_t *mpo_file_check_inherit;
6230 mpo_file_check_ioctl_t *mpo_file_check_ioctl;
6231 mpo_file_check_lock_t *mpo_file_check_lock;
6232 mpo_file_check_mmap_downgrade_t *mpo_file_check_mmap_downgrade;
6233 mpo_file_check_mmap_t *mpo_file_check_mmap;
6234 mpo_file_check_receive_t *mpo_file_check_receive;
6235 mpo_file_check_set_t *mpo_file_check_set;
6236 mpo_file_label_init_t *mpo_file_label_init;
6237 mpo_file_label_destroy_t *mpo_file_label_destroy;
6238 mpo_file_label_associate_t *mpo_file_label_associate;
6239
6240 mpo_ifnet_check_label_update_t *mpo_ifnet_check_label_update;
6241 mpo_ifnet_check_transmit_t *mpo_ifnet_check_transmit;
6242 mpo_ifnet_label_associate_t *mpo_ifnet_label_associate;
6243 mpo_ifnet_label_copy_t *mpo_ifnet_label_copy;
6244 mpo_ifnet_label_destroy_t *mpo_ifnet_label_destroy;
6245 mpo_ifnet_label_externalize_t *mpo_ifnet_label_externalize;
6246 mpo_ifnet_label_init_t *mpo_ifnet_label_init;
6247 mpo_ifnet_label_internalize_t *mpo_ifnet_label_internalize;
6248 mpo_ifnet_label_update_t *mpo_ifnet_label_update;
6249 mpo_ifnet_label_recycle_t *mpo_ifnet_label_recycle;
6250
6251 mpo_inpcb_check_deliver_t *mpo_inpcb_check_deliver;
6252 mpo_inpcb_label_associate_t *mpo_inpcb_label_associate;
6253 mpo_inpcb_label_destroy_t *mpo_inpcb_label_destroy;
6254 mpo_inpcb_label_init_t *mpo_inpcb_label_init;
6255 mpo_inpcb_label_recycle_t *mpo_inpcb_label_recycle;
6256 mpo_inpcb_label_update_t *mpo_inpcb_label_update;
6257
6258 mpo_iokit_check_device_t *mpo_iokit_check_device;
6259
6260 mpo_ipq_label_associate_t *mpo_ipq_label_associate;
6261 mpo_ipq_label_compare_t *mpo_ipq_label_compare;
6262 mpo_ipq_label_destroy_t *mpo_ipq_label_destroy;
6263 mpo_ipq_label_init_t *mpo_ipq_label_init;
6264 mpo_ipq_label_update_t *mpo_ipq_label_update;
6265
6266 mpo_file_check_library_validation_t *mpo_file_check_library_validation;
6267 mpo_vnode_notify_setacl_t *mpo_vnode_notify_setacl;
6268 mpo_vnode_notify_setattrlist_t *mpo_vnode_notify_setattrlist;
6269 mpo_vnode_notify_setextattr_t *mpo_vnode_notify_setextattr;
6270 mpo_vnode_notify_setflags_t *mpo_vnode_notify_setflags;
6271 mpo_vnode_notify_setmode_t *mpo_vnode_notify_setmode;
6272 mpo_vnode_notify_setowner_t *mpo_vnode_notify_setowner;
6273 mpo_vnode_notify_setutimes_t *mpo_vnode_notify_setutimes;
6274 mpo_vnode_notify_truncate_t *mpo_vnode_notify_truncate;
6275
6276 mpo_mbuf_label_associate_bpfdesc_t *mpo_mbuf_label_associate_bpfdesc;
6277 mpo_mbuf_label_associate_ifnet_t *mpo_mbuf_label_associate_ifnet;
6278 mpo_mbuf_label_associate_inpcb_t *mpo_mbuf_label_associate_inpcb;
6279 mpo_mbuf_label_associate_ipq_t *mpo_mbuf_label_associate_ipq;
6280 mpo_mbuf_label_associate_linklayer_t *mpo_mbuf_label_associate_linklayer;
6281 mpo_mbuf_label_associate_multicast_encap_t *mpo_mbuf_label_associate_multicast_encap;
6282 mpo_mbuf_label_associate_netlayer_t *mpo_mbuf_label_associate_netlayer;
6283 mpo_mbuf_label_associate_socket_t *mpo_mbuf_label_associate_socket;
6284 mpo_mbuf_label_copy_t *mpo_mbuf_label_copy;
6285 mpo_mbuf_label_destroy_t *mpo_mbuf_label_destroy;
6286 mpo_mbuf_label_init_t *mpo_mbuf_label_init;
6287
6288 mpo_mount_check_fsctl_t *mpo_mount_check_fsctl;
6289 mpo_mount_check_getattr_t *mpo_mount_check_getattr;
6290 mpo_mount_check_label_update_t *mpo_mount_check_label_update;
6291 mpo_mount_check_mount_t *mpo_mount_check_mount;
6292 mpo_mount_check_remount_t *mpo_mount_check_remount;
6293 mpo_mount_check_setattr_t *mpo_mount_check_setattr;
6294 mpo_mount_check_stat_t *mpo_mount_check_stat;
6295 mpo_mount_check_umount_t *mpo_mount_check_umount;
6296 mpo_mount_label_associate_t *mpo_mount_label_associate;
6297 mpo_mount_label_destroy_t *mpo_mount_label_destroy;
6298 mpo_mount_label_externalize_t *mpo_mount_label_externalize;
6299 mpo_mount_label_init_t *mpo_mount_label_init;
6300 mpo_mount_label_internalize_t *mpo_mount_label_internalize;
6301
6302 mpo_netinet_fragment_t *mpo_netinet_fragment;
6303 mpo_netinet_icmp_reply_t *mpo_netinet_icmp_reply;
6304 mpo_netinet_tcp_reply_t *mpo_netinet_tcp_reply;
6305
6306 mpo_pipe_check_ioctl_t *mpo_pipe_check_ioctl;
6307 mpo_pipe_check_kqfilter_t *mpo_pipe_check_kqfilter;
6308 mpo_pipe_check_label_update_t *mpo_pipe_check_label_update;
6309 mpo_pipe_check_read_t *mpo_pipe_check_read;
6310 mpo_pipe_check_select_t *mpo_pipe_check_select;
6311 mpo_pipe_check_stat_t *mpo_pipe_check_stat;
6312 mpo_pipe_check_write_t *mpo_pipe_check_write;
6313 mpo_pipe_label_associate_t *mpo_pipe_label_associate;
6314 mpo_pipe_label_copy_t *mpo_pipe_label_copy;
6315 mpo_pipe_label_destroy_t *mpo_pipe_label_destroy;
6316 mpo_pipe_label_externalize_t *mpo_pipe_label_externalize;
6317 mpo_pipe_label_init_t *mpo_pipe_label_init;
6318 mpo_pipe_label_internalize_t *mpo_pipe_label_internalize;
6319 mpo_pipe_label_update_t *mpo_pipe_label_update;
6320
6321 mpo_policy_destroy_t *mpo_policy_destroy;
6322 mpo_policy_init_t *mpo_policy_init;
6323 mpo_policy_initbsd_t *mpo_policy_initbsd;
6324 mpo_policy_syscall_t *mpo_policy_syscall;
6325
6326 mpo_system_check_sysctlbyname_t *mpo_system_check_sysctlbyname;
6327 mpo_proc_check_inherit_ipc_ports_t *mpo_proc_check_inherit_ipc_ports;
6328 mpo_vnode_check_rename_t *mpo_vnode_check_rename;
6329 mpo_kext_check_query_t *mpo_kext_check_query;
6330 mpo_iokit_check_nvram_get_t *mpo_iokit_check_nvram_get;
6331 mpo_iokit_check_nvram_set_t *mpo_iokit_check_nvram_set;
6332 mpo_iokit_check_nvram_delete_t *mpo_iokit_check_nvram_delete;
6333 mpo_proc_check_expose_task_t *mpo_proc_check_expose_task;
6334 mpo_proc_check_set_host_special_port_t *mpo_proc_check_set_host_special_port;
6335 mpo_proc_check_set_host_exception_port_t *mpo_proc_check_set_host_exception_port;
6336 mpo_exc_action_check_exception_send_t *mpo_exc_action_check_exception_send;
6337 mpo_exc_action_label_associate_t *mpo_exc_action_label_associate;
6338 mpo_exc_action_label_copy_t *mpo_exc_action_label_copy;
6339 mpo_exc_action_label_destroy_t *mpo_exc_action_label_destroy;
6340 mpo_exc_action_label_init_t *mpo_exc_action_label_init;
6341 mpo_exc_action_label_update_t *mpo_exc_action_label_update;
6342
6343 mpo_reserved_hook_t *mpo_reserved1;
6344 mpo_reserved_hook_t *mpo_reserved2;
6345 mpo_reserved_hook_t *mpo_reserved3;
6346 mpo_reserved_hook_t *mpo_reserved4;
6347 mpo_reserved_hook_t *mpo_reserved5;
6348 mpo_reserved_hook_t *mpo_reserved6;
6349
6350 mpo_posixsem_check_create_t *mpo_posixsem_check_create;
6351 mpo_posixsem_check_open_t *mpo_posixsem_check_open;
6352 mpo_posixsem_check_post_t *mpo_posixsem_check_post;
6353 mpo_posixsem_check_unlink_t *mpo_posixsem_check_unlink;
6354 mpo_posixsem_check_wait_t *mpo_posixsem_check_wait;
6355 mpo_posixsem_label_associate_t *mpo_posixsem_label_associate;
6356 mpo_posixsem_label_destroy_t *mpo_posixsem_label_destroy;
6357 mpo_posixsem_label_init_t *mpo_posixsem_label_init;
6358 mpo_posixshm_check_create_t *mpo_posixshm_check_create;
6359 mpo_posixshm_check_mmap_t *mpo_posixshm_check_mmap;
6360 mpo_posixshm_check_open_t *mpo_posixshm_check_open;
6361 mpo_posixshm_check_stat_t *mpo_posixshm_check_stat;
6362 mpo_posixshm_check_truncate_t *mpo_posixshm_check_truncate;
6363 mpo_posixshm_check_unlink_t *mpo_posixshm_check_unlink;
6364 mpo_posixshm_label_associate_t *mpo_posixshm_label_associate;
6365 mpo_posixshm_label_destroy_t *mpo_posixshm_label_destroy;
6366 mpo_posixshm_label_init_t *mpo_posixshm_label_init;
6367
6368 mpo_proc_check_debug_t *mpo_proc_check_debug;
6369 mpo_proc_check_fork_t *mpo_proc_check_fork;
6370 mpo_proc_check_get_task_name_t *mpo_proc_check_get_task_name;
6371 mpo_proc_check_get_task_t *mpo_proc_check_get_task;
6372 mpo_proc_check_getaudit_t *mpo_proc_check_getaudit;
6373 mpo_proc_check_getauid_t *mpo_proc_check_getauid;
6374 mpo_proc_check_getlcid_t *mpo_proc_check_getlcid;
6375 mpo_proc_check_mprotect_t *mpo_proc_check_mprotect;
6376 mpo_proc_check_sched_t *mpo_proc_check_sched;
6377 mpo_proc_check_setaudit_t *mpo_proc_check_setaudit;
6378 mpo_proc_check_setauid_t *mpo_proc_check_setauid;
6379 mpo_proc_check_setlcid_t *mpo_proc_check_setlcid;
6380 mpo_proc_check_signal_t *mpo_proc_check_signal;
6381 mpo_proc_check_wait_t *mpo_proc_check_wait;
6382 mpo_proc_label_destroy_t *mpo_proc_label_destroy;
6383 mpo_proc_label_init_t *mpo_proc_label_init;
6384
6385 mpo_socket_check_accept_t *mpo_socket_check_accept;
6386 mpo_socket_check_accepted_t *mpo_socket_check_accepted;
6387 mpo_socket_check_bind_t *mpo_socket_check_bind;
6388 mpo_socket_check_connect_t *mpo_socket_check_connect;
6389 mpo_socket_check_create_t *mpo_socket_check_create;
6390 mpo_socket_check_deliver_t *mpo_socket_check_deliver;
6391 mpo_socket_check_kqfilter_t *mpo_socket_check_kqfilter;
6392 mpo_socket_check_label_update_t *mpo_socket_check_label_update;
6393 mpo_socket_check_listen_t *mpo_socket_check_listen;
6394 mpo_socket_check_receive_t *mpo_socket_check_receive;
6395 mpo_socket_check_received_t *mpo_socket_check_received;
6396 mpo_socket_check_select_t *mpo_socket_check_select;
6397 mpo_socket_check_send_t *mpo_socket_check_send;
6398 mpo_socket_check_stat_t *mpo_socket_check_stat;
6399 mpo_socket_check_setsockopt_t *mpo_socket_check_setsockopt;
6400 mpo_socket_check_getsockopt_t *mpo_socket_check_getsockopt;
6401 mpo_socket_label_associate_accept_t *mpo_socket_label_associate_accept;
6402 mpo_socket_label_associate_t *mpo_socket_label_associate;
6403 mpo_socket_label_copy_t *mpo_socket_label_copy;
6404 mpo_socket_label_destroy_t *mpo_socket_label_destroy;
6405 mpo_socket_label_externalize_t *mpo_socket_label_externalize;
6406 mpo_socket_label_init_t *mpo_socket_label_init;
6407 mpo_socket_label_internalize_t *mpo_socket_label_internalize;
6408 mpo_socket_label_update_t *mpo_socket_label_update;
6409
6410 mpo_socketpeer_label_associate_mbuf_t *mpo_socketpeer_label_associate_mbuf;
6411 mpo_socketpeer_label_associate_socket_t *mpo_socketpeer_label_associate_socket;
6412 mpo_socketpeer_label_destroy_t *mpo_socketpeer_label_destroy;
6413 mpo_socketpeer_label_externalize_t *mpo_socketpeer_label_externalize;
6414 mpo_socketpeer_label_init_t *mpo_socketpeer_label_init;
6415
6416 mpo_system_check_acct_t *mpo_system_check_acct;
6417 mpo_system_check_audit_t *mpo_system_check_audit;
6418 mpo_system_check_auditctl_t *mpo_system_check_auditctl;
6419 mpo_system_check_auditon_t *mpo_system_check_auditon;
6420 mpo_system_check_host_priv_t *mpo_system_check_host_priv;
6421 mpo_system_check_nfsd_t *mpo_system_check_nfsd;
6422 mpo_system_check_reboot_t *mpo_system_check_reboot;
6423 mpo_system_check_settime_t *mpo_system_check_settime;
6424 mpo_system_check_swapoff_t *mpo_system_check_swapoff;
6425 mpo_system_check_swapon_t *mpo_system_check_swapon;
6426 mpo_reserved_hook_t *mpo_reserved7;
6427
6428 mpo_sysvmsg_label_associate_t *mpo_sysvmsg_label_associate;
6429 mpo_sysvmsg_label_destroy_t *mpo_sysvmsg_label_destroy;
6430 mpo_sysvmsg_label_init_t *mpo_sysvmsg_label_init;
6431 mpo_sysvmsg_label_recycle_t *mpo_sysvmsg_label_recycle;
6432 mpo_sysvmsq_check_enqueue_t *mpo_sysvmsq_check_enqueue;
6433 mpo_sysvmsq_check_msgrcv_t *mpo_sysvmsq_check_msgrcv;
6434 mpo_sysvmsq_check_msgrmid_t *mpo_sysvmsq_check_msgrmid;
6435 mpo_sysvmsq_check_msqctl_t *mpo_sysvmsq_check_msqctl;
6436 mpo_sysvmsq_check_msqget_t *mpo_sysvmsq_check_msqget;
6437 mpo_sysvmsq_check_msqrcv_t *mpo_sysvmsq_check_msqrcv;
6438 mpo_sysvmsq_check_msqsnd_t *mpo_sysvmsq_check_msqsnd;
6439 mpo_sysvmsq_label_associate_t *mpo_sysvmsq_label_associate;
6440 mpo_sysvmsq_label_destroy_t *mpo_sysvmsq_label_destroy;
6441 mpo_sysvmsq_label_init_t *mpo_sysvmsq_label_init;
6442 mpo_sysvmsq_label_recycle_t *mpo_sysvmsq_label_recycle;
6443 mpo_sysvsem_check_semctl_t *mpo_sysvsem_check_semctl;
6444 mpo_sysvsem_check_semget_t *mpo_sysvsem_check_semget;
6445 mpo_sysvsem_check_semop_t *mpo_sysvsem_check_semop;
6446 mpo_sysvsem_label_associate_t *mpo_sysvsem_label_associate;
6447 mpo_sysvsem_label_destroy_t *mpo_sysvsem_label_destroy;
6448 mpo_sysvsem_label_init_t *mpo_sysvsem_label_init;
6449 mpo_sysvsem_label_recycle_t *mpo_sysvsem_label_recycle;
6450 mpo_sysvshm_check_shmat_t *mpo_sysvshm_check_shmat;
6451 mpo_sysvshm_check_shmctl_t *mpo_sysvshm_check_shmctl;
6452 mpo_sysvshm_check_shmdt_t *mpo_sysvshm_check_shmdt;
6453 mpo_sysvshm_check_shmget_t *mpo_sysvshm_check_shmget;
6454 mpo_sysvshm_label_associate_t *mpo_sysvshm_label_associate;
6455 mpo_sysvshm_label_destroy_t *mpo_sysvshm_label_destroy;
6456 mpo_sysvshm_label_init_t *mpo_sysvshm_label_init;
6457 mpo_sysvshm_label_recycle_t *mpo_sysvshm_label_recycle;
6458
6459 mpo_reserved_hook_t *mpo_reserved8;
6460 mpo_mount_check_snapshot_revert_t *mpo_mount_check_snapshot_revert;
6461 mpo_vnode_check_getattr_t *mpo_vnode_check_getattr;
6462 mpo_mount_check_snapshot_create_t *mpo_mount_check_snapshot_create;
6463 mpo_mount_check_snapshot_delete_t *mpo_mount_check_snapshot_delete;
6464 mpo_vnode_check_clone_t *mpo_vnode_check_clone;
6465 mpo_proc_check_get_cs_info_t *mpo_proc_check_get_cs_info;
6466 mpo_proc_check_set_cs_info_t *mpo_proc_check_set_cs_info;
6467
6468 mpo_iokit_check_hid_control_t *mpo_iokit_check_hid_control;
6469
6470 mpo_vnode_check_access_t *mpo_vnode_check_access;
6471 mpo_vnode_check_chdir_t *mpo_vnode_check_chdir;
6472 mpo_vnode_check_chroot_t *mpo_vnode_check_chroot;
6473 mpo_vnode_check_create_t *mpo_vnode_check_create;
6474 mpo_vnode_check_deleteextattr_t *mpo_vnode_check_deleteextattr;
6475 mpo_vnode_check_exchangedata_t *mpo_vnode_check_exchangedata;
6476 mpo_vnode_check_exec_t *mpo_vnode_check_exec;
6477 mpo_vnode_check_getattrlist_t *mpo_vnode_check_getattrlist;
6478 mpo_vnode_check_getextattr_t *mpo_vnode_check_getextattr;
6479 mpo_vnode_check_ioctl_t *mpo_vnode_check_ioctl;
6480 mpo_vnode_check_kqfilter_t *mpo_vnode_check_kqfilter;
6481 mpo_vnode_check_label_update_t *mpo_vnode_check_label_update;
6482 mpo_vnode_check_link_t *mpo_vnode_check_link;
6483 mpo_vnode_check_listextattr_t *mpo_vnode_check_listextattr;
6484 mpo_vnode_check_lookup_t *mpo_vnode_check_lookup;
6485 mpo_vnode_check_open_t *mpo_vnode_check_open;
6486 mpo_vnode_check_read_t *mpo_vnode_check_read;
6487 mpo_vnode_check_readdir_t *mpo_vnode_check_readdir;
6488 mpo_vnode_check_readlink_t *mpo_vnode_check_readlink;
6489 mpo_vnode_check_rename_from_t *mpo_vnode_check_rename_from;
6490 mpo_vnode_check_rename_to_t *mpo_vnode_check_rename_to;
6491 mpo_vnode_check_revoke_t *mpo_vnode_check_revoke;
6492 mpo_vnode_check_select_t *mpo_vnode_check_select;
6493 mpo_vnode_check_setattrlist_t *mpo_vnode_check_setattrlist;
6494 mpo_vnode_check_setextattr_t *mpo_vnode_check_setextattr;
6495 mpo_vnode_check_setflags_t *mpo_vnode_check_setflags;
6496 mpo_vnode_check_setmode_t *mpo_vnode_check_setmode;
6497 mpo_vnode_check_setowner_t *mpo_vnode_check_setowner;
6498 mpo_vnode_check_setutimes_t *mpo_vnode_check_setutimes;
6499 mpo_vnode_check_stat_t *mpo_vnode_check_stat;
6500 mpo_vnode_check_truncate_t *mpo_vnode_check_truncate;
6501 mpo_vnode_check_unlink_t *mpo_vnode_check_unlink;
6502 mpo_vnode_check_write_t *mpo_vnode_check_write;
6503 mpo_vnode_label_associate_devfs_t *mpo_vnode_label_associate_devfs;
6504 mpo_vnode_label_associate_extattr_t *mpo_vnode_label_associate_extattr;
6505 mpo_vnode_label_associate_file_t *mpo_vnode_label_associate_file;
6506 mpo_vnode_label_associate_pipe_t *mpo_vnode_label_associate_pipe;
6507 mpo_vnode_label_associate_posixsem_t *mpo_vnode_label_associate_posixsem;
6508 mpo_vnode_label_associate_posixshm_t *mpo_vnode_label_associate_posixshm;
6509 mpo_vnode_label_associate_singlelabel_t *mpo_vnode_label_associate_singlelabel;
6510 mpo_vnode_label_associate_socket_t *mpo_vnode_label_associate_socket;
6511 mpo_vnode_label_copy_t *mpo_vnode_label_copy;
6512 mpo_vnode_label_destroy_t *mpo_vnode_label_destroy;
6513 mpo_vnode_label_externalize_audit_t *mpo_vnode_label_externalize_audit;
6514 mpo_vnode_label_externalize_t *mpo_vnode_label_externalize;
6515 mpo_vnode_label_init_t *mpo_vnode_label_init;
6516 mpo_vnode_label_internalize_t *mpo_vnode_label_internalize;
6517 mpo_vnode_label_recycle_t *mpo_vnode_label_recycle;
6518 mpo_vnode_label_store_t *mpo_vnode_label_store;
6519 mpo_vnode_label_update_extattr_t *mpo_vnode_label_update_extattr;
6520 mpo_vnode_label_update_t *mpo_vnode_label_update;
6521 mpo_vnode_notify_create_t *mpo_vnode_notify_create;
6522 mpo_vnode_check_signature_t *mpo_vnode_check_signature;
6523 mpo_vnode_check_uipc_bind_t *mpo_vnode_check_uipc_bind;
6524 mpo_vnode_check_uipc_connect_t *mpo_vnode_check_uipc_connect;
6525
6526 mpo_proc_check_run_cs_invalid_t *mpo_proc_check_run_cs_invalid;
6527 mpo_proc_check_suspend_resume_t *mpo_proc_check_suspend_resume;
6528
6529 mpo_thread_userret_t *mpo_thread_userret;
6530
6531 mpo_iokit_check_set_properties_t *mpo_iokit_check_set_properties;
6532
6533 mpo_system_check_chud_t *mpo_system_check_chud;
6534
6535 mpo_vnode_check_searchfs_t *mpo_vnode_check_searchfs;
6536
6537 mpo_priv_check_t *mpo_priv_check;
6538 mpo_priv_grant_t *mpo_priv_grant;
6539
6540 mpo_proc_check_map_anon_t *mpo_proc_check_map_anon;
6541
6542 mpo_vnode_check_fsgetpath_t *mpo_vnode_check_fsgetpath;
6543
6544 mpo_iokit_check_open_t *mpo_iokit_check_open;
6545
6546 mpo_proc_check_ledger_t *mpo_proc_check_ledger;
6547
6548 mpo_vnode_notify_rename_t *mpo_vnode_notify_rename;
6549
6550 mpo_vnode_check_setacl_t *mpo_vnode_check_setacl;
6551
6552 mpo_vnode_notify_deleteextattr_t *mpo_vnode_notify_deleteextattr;
6553
6554 mpo_system_check_kas_info_t *mpo_system_check_kas_info;
6555
6556 mpo_proc_check_cpumon_t *mpo_proc_check_cpumon;
6557
6558 mpo_vnode_notify_open_t *mpo_vnode_notify_open;
6559
6560 mpo_system_check_info_t *mpo_system_check_info;
6561
6562 mpo_pty_notify_grant_t *mpo_pty_notify_grant;
6563 mpo_pty_notify_close_t *mpo_pty_notify_close;
6564
6565 mpo_vnode_find_sigs_t *mpo_vnode_find_sigs;
6566
6567 mpo_kext_check_load_t *mpo_kext_check_load;
6568 mpo_kext_check_unload_t *mpo_kext_check_unload;
6569
6570 mpo_proc_check_proc_info_t *mpo_proc_check_proc_info;
6571 mpo_vnode_notify_link_t *mpo_vnode_notify_link;
6572 mpo_iokit_check_filter_properties_t *mpo_iokit_check_filter_properties;
6573 mpo_iokit_check_get_property_t *mpo_iokit_check_get_property;
6574 };
6575
6576 /**
6577 @brief MAC policy handle type
6578
6579 The MAC handle is used to uniquely identify a loaded policy within
6580 the MAC Framework.
6581
6582 A variable of this type is set by mac_policy_register().
6583 */
6584 typedef unsigned int mac_policy_handle_t;
6585
6586 #define mpc_t struct mac_policy_conf *
6587
6588 /**
6589 @brief Mac policy configuration
6590
6591 This structure specifies the configuration information for a
6592 MAC policy module. A policy module developer must supply
6593 a short unique policy name, a more descriptive full name, a list of label
6594 namespaces and count, a pointer to the registered enty point operations,
6595 any load time flags, and optionally, a pointer to a label slot identifier.
6596
6597 The Framework will update the runtime flags (mpc_runtime_flags) to
6598 indicate that the module has been registered.
6599
6600 If the label slot identifier (mpc_field_off) is NULL, the Framework
6601 will not provide label storage for the policy. Otherwise, the
6602 Framework will store the label location (slot) in this field.
6603
6604 The mpc_list field is used by the Framework and should not be
6605 modified by policies.
6606 */
6607 /* XXX - reorder these for better aligment on 64bit platforms */
6608 struct mac_policy_conf {
6609 const char *mpc_name; /** policy name */
6610 const char *mpc_fullname; /** full name */
6611 char const * const *mpc_labelnames; /** managed label namespaces */
6612 unsigned int mpc_labelname_count; /** number of managed label namespaces */
6613 struct mac_policy_ops *mpc_ops; /** operation vector */
6614 int mpc_loadtime_flags; /** load time flags */
6615 int *mpc_field_off; /** label slot */
6616 int mpc_runtime_flags; /** run time flags */
6617 mpc_t mpc_list; /** List reference */
6618 void *mpc_data; /** module data */
6619 };
6620
6621 /**
6622 @brief MAC policy module registration routine
6623
6624 This function is called to register a policy with the
6625 MAC framework. A policy module will typically call this from the
6626 Darwin KEXT registration routine.
6627 */
6628 int mac_policy_register(struct mac_policy_conf *mpc,
6629 mac_policy_handle_t *handlep, void *xd);
6630
6631 /**
6632 @brief MAC policy module de-registration routine
6633
6634 This function is called to de-register a policy with theD
6635 MAC framework. A policy module will typically call this from the
6636 Darwin KEXT de-registration routine.
6637 */
6638 int mac_policy_unregister(mac_policy_handle_t handle);
6639
6640 /*
6641 * Framework entry points for the policies to add audit data.
6642 */
6643 int mac_audit_text(char *text, mac_policy_handle_t handle);
6644
6645 /*
6646 * Calls to assist with use of Apple XATTRs within policy modules.
6647 */
6648 int mac_vnop_setxattr(struct vnode *, const char *, char *, size_t);
6649 int mac_vnop_getxattr(struct vnode *, const char *, char *, size_t,
6650 size_t *);
6651 int mac_vnop_removexattr(struct vnode *, const char *);
6652
6653 /**
6654 @brief Set an extended attribute on a vnode-based fileglob.
6655 @param fg fileglob representing file to attach the extended attribute
6656 @param name extended attribute name
6657 @param buf buffer of data to use as the extended attribute value
6658 @param len size of buffer
6659
6660 Sets the value of an extended attribute on a file.
6661
6662 Caller must hold an iocount on the vnode represented by the fileglob.
6663 */
6664 int mac_file_setxattr(struct fileglob *fg, const char *name, char *buf, size_t len);
6665
6666 /**
6667 @brief Get an extended attribute from a vnode-based fileglob.
6668 @param fg fileglob representing file to read the extended attribute
6669 @param name extended attribute name
6670 @param buf buffer of data to hold the extended attribute value
6671 @param len size of buffer
6672 @param attrlen size of full extended attribute value
6673
6674 Gets the value of an extended attribute on a file.
6675
6676 Caller must hold an iocount on the vnode represented by the fileglob.
6677 */
6678 int mac_file_getxattr(struct fileglob *fg, const char *name, char *buf, size_t len,
6679 size_t *attrlen);
6680
6681 /**
6682 @brief Remove an extended attribute from a vnode-based fileglob.
6683 @param fg fileglob representing file to remove the extended attribute
6684 @param name extended attribute name
6685
6686 Removes the named extended attribute from the file.
6687
6688 Caller must hold an iocount on the vnode represented by the fileglob.
6689 */
6690 int mac_file_removexattr(struct fileglob *fg, const char *name);
6691
6692
6693 /*
6694 * Arbitrary limit on how much data will be logged by the audit
6695 * entry points above.
6696 */
6697 #define MAC_AUDIT_DATA_LIMIT 1024
6698
6699 /*
6700 * Values returned by mac_audit_{pre,post}select. To combine the responses
6701 * of the security policies into a single decision,
6702 * mac_audit_{pre,post}select() choose the greatest value returned.
6703 */
6704 #define MAC_AUDIT_DEFAULT 0 /* use system behavior */
6705 #define MAC_AUDIT_NO 1 /* force not auditing this event */
6706 #define MAC_AUDIT_YES 2 /* force auditing this event */
6707
6708 // \defgroup mpc_loadtime_flags Flags for the mpc_loadtime_flags field
6709
6710 /**
6711 @name Flags for the mpc_loadtime_flags field
6712 @see mac_policy_conf
6713
6714 This is the complete list of flags that are supported by the
6715 mpc_loadtime_flags field of the mac_policy_conf structure. These
6716 flags specify the load time behavior of MAC Framework policy
6717 modules.
6718 */
6719
6720 /*@{*/
6721
6722 /**
6723 @brief Flag to indicate registration preference
6724
6725 This flag indicates that the policy module must be loaded and
6726 initialized early in the boot process. If the flag is specified,
6727 attempts to register the module following boot will be rejected. The
6728 flag may be used by policies that require pervasive labeling of all
6729 system objects, and cannot handle objects that have not been
6730 properly initialized by the policy.
6731 */
6732 #define MPC_LOADTIME_FLAG_NOTLATE 0x00000001
6733
6734 /**
6735 @brief Flag to indicate unload preference
6736
6737 This flag indicates that the policy module may be unloaded. If this
6738 flag is not set, then the policy framework will reject requests to
6739 unload the module. This flag might be used by modules that allocate
6740 label state and are unable to free that state at runtime, or for
6741 modules that simply do not want to permit unload operations.
6742 */
6743 #define MPC_LOADTIME_FLAG_UNLOADOK 0x00000002
6744
6745 /**
6746 @brief Unsupported
6747
6748 XXX This flag is not yet supported.
6749 */
6750 #define MPC_LOADTIME_FLAG_LABELMBUFS 0x00000004
6751
6752 /**
6753 @brief Flag to indicate a base policy
6754
6755 This flag indicates that the policy module is a base policy. Only
6756 one module can declare itself as base, otherwise the boot process
6757 will be halted.
6758 */
6759 #define MPC_LOADTIME_BASE_POLICY 0x00000008
6760
6761 /*@}*/
6762
6763 /**
6764 @brief Policy registration flag
6765 @see mac_policy_conf
6766
6767 This flag indicates that the policy module has been successfully
6768 registered with the TrustedBSD MAC Framework. The Framework will
6769 set this flag in the mpc_runtime_flags field of the policy's
6770 mac_policy_conf structure after registering the policy.
6771 */
6772 #define MPC_RUNTIME_FLAG_REGISTERED 0x00000001
6773
6774 /*
6775 * Depends on POLICY_VER
6776 */
6777
6778 #ifndef POLICY_VER
6779 #define POLICY_VER 1.0
6780 #endif
6781
6782 #define MAC_POLICY_SET(handle, mpops, mpname, mpfullname, lnames, lcount, slot, lflags, rflags) \
6783 static struct mac_policy_conf mpname##_mac_policy_conf = { \
6784 .mpc_name = #mpname, \
6785 .mpc_fullname = mpfullname, \
6786 .mpc_labelnames = lnames, \
6787 .mpc_labelname_count = lcount, \
6788 .mpc_ops = mpops, \
6789 .mpc_loadtime_flags = lflags, \
6790 .mpc_field_off = slot, \
6791 .mpc_runtime_flags = rflags \
6792 }; \
6793 \
6794 static kern_return_t \
6795 kmod_start(kmod_info_t *ki, void *xd) \
6796 { \
6797 return mac_policy_register(&mpname##_mac_policy_conf, \
6798 &handle, xd); \
6799 } \
6800 \
6801 static kern_return_t \
6802 kmod_stop(kmod_info_t *ki, void *xd) \
6803 { \
6804 return mac_policy_unregister(handle); \
6805 } \
6806 \
6807 extern kern_return_t _start(kmod_info_t *ki, void *data); \
6808 extern kern_return_t _stop(kmod_info_t *ki, void *data); \
6809 \
6810 KMOD_EXPLICIT_DECL(security.mpname, POLICY_VER, _start, _stop) \
6811 kmod_start_func_t *_realmain = kmod_start; \
6812 kmod_stop_func_t *_antimain = kmod_stop; \
6813 int _kext_apple_cc = __APPLE_CC__
6814
6815
6816 #define LABEL_TO_SLOT(l, s) (l)->l_perpolicy[s]
6817
6818 /*
6819 * Policy interface to map a struct label pointer to per-policy data.
6820 * Typically, policies wrap this in their own accessor macro that casts an
6821 * intptr_t to a policy-specific data type.
6822 */
6823 intptr_t mac_label_get(struct label *l, int slot);
6824 void mac_label_set(struct label *l, int slot, intptr_t v);
6825
6826 #define mac_get_mpc(h) (mac_policy_list.entries[h].mpc)
6827
6828 /**
6829 @name Flags for MAC allocator interfaces
6830
6831 These flags are passed to the Darwin kernel allocator routines to
6832 indicate whether the allocation is permitted to block or not.
6833 Caution should be taken; some operations are not permitted to sleep,
6834 and some types of locks cannot be held when sleeping.
6835 */
6836
6837 /*@{*/
6838
6839 /**
6840 @brief Allocation operations may block
6841
6842 If memory is not immediately available, the allocation routine
6843 will block (typically sleeping) until memory is available.
6844
6845 @warning Inappropriate use of this flag may cause kernel panics.
6846 */
6847 #define MAC_WAITOK 0
6848
6849 /**
6850 @brief Allocation operations may not block
6851
6852 Rather than blocking, the allocator may return an error if memory
6853 is not immediately available. This type of allocation will not
6854 sleep, preserving locking semantics.
6855 */
6856 #define MAC_NOWAIT 1
6857
6858 /*@}*/
6859
6860 #endif /* !_SECURITY_MAC_POLICY_H_ */