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