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