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