xref: /xnu-8020.121.3/security/mac_internal.h (revision fdd8201d7b966f0c3ea610489d29bd841d358941)
1*fdd8201dSApple OSS Distributions /*
2*fdd8201dSApple OSS Distributions  * Copyright (c) 2007 Apple Inc. All rights reserved.
3*fdd8201dSApple OSS Distributions  *
4*fdd8201dSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*fdd8201dSApple OSS Distributions  *
6*fdd8201dSApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*fdd8201dSApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*fdd8201dSApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*fdd8201dSApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*fdd8201dSApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*fdd8201dSApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*fdd8201dSApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*fdd8201dSApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*fdd8201dSApple OSS Distributions  *
15*fdd8201dSApple OSS Distributions  * Please obtain a copy of the License at
16*fdd8201dSApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*fdd8201dSApple OSS Distributions  *
18*fdd8201dSApple OSS Distributions  * The Original Code and all software distributed under the License are
19*fdd8201dSApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*fdd8201dSApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*fdd8201dSApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*fdd8201dSApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*fdd8201dSApple OSS Distributions  * Please see the License for the specific language governing rights and
24*fdd8201dSApple OSS Distributions  * limitations under the License.
25*fdd8201dSApple OSS Distributions  *
26*fdd8201dSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*fdd8201dSApple OSS Distributions  */
28*fdd8201dSApple OSS Distributions 
29*fdd8201dSApple OSS Distributions /*-
30*fdd8201dSApple OSS Distributions  * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
31*fdd8201dSApple OSS Distributions  * Copyright (c) 2001 Ilmar S. Habibulin
32*fdd8201dSApple OSS Distributions  * Copyright (c) 2001, 2002, 2003, 2004 Networks Associates Technology, Inc.
33*fdd8201dSApple OSS Distributions  * Copyright (c) 2005 SPARTA, Inc.
34*fdd8201dSApple OSS Distributions  * All rights reserved.
35*fdd8201dSApple OSS Distributions  *
36*fdd8201dSApple OSS Distributions  * This software was developed by Robert Watson and Ilmar Habibulin for the
37*fdd8201dSApple OSS Distributions  * TrustedBSD Project.
38*fdd8201dSApple OSS Distributions  *
39*fdd8201dSApple OSS Distributions  * This software was developed for the FreeBSD Project in part by Network
40*fdd8201dSApple OSS Distributions  * Associates Laboratories, the Security Research Division of Network
41*fdd8201dSApple OSS Distributions  * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
42*fdd8201dSApple OSS Distributions  * as part of the DARPA CHATS research program.
43*fdd8201dSApple OSS Distributions  *
44*fdd8201dSApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
45*fdd8201dSApple OSS Distributions  * modification, are permitted provided that the following conditions
46*fdd8201dSApple OSS Distributions  * are met:
47*fdd8201dSApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
48*fdd8201dSApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
49*fdd8201dSApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
50*fdd8201dSApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
51*fdd8201dSApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
52*fdd8201dSApple OSS Distributions  *
53*fdd8201dSApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
54*fdd8201dSApple OSS Distributions  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55*fdd8201dSApple OSS Distributions  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56*fdd8201dSApple OSS Distributions  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
57*fdd8201dSApple OSS Distributions  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58*fdd8201dSApple OSS Distributions  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59*fdd8201dSApple OSS Distributions  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60*fdd8201dSApple OSS Distributions  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61*fdd8201dSApple OSS Distributions  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62*fdd8201dSApple OSS Distributions  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63*fdd8201dSApple OSS Distributions  * SUCH DAMAGE.
64*fdd8201dSApple OSS Distributions  *
65*fdd8201dSApple OSS Distributions  */
66*fdd8201dSApple OSS Distributions 
67*fdd8201dSApple OSS Distributions #ifndef _SECURITY_MAC_INTERNAL_H_
68*fdd8201dSApple OSS Distributions #define _SECURITY_MAC_INTERNAL_H_
69*fdd8201dSApple OSS Distributions 
70*fdd8201dSApple OSS Distributions #ifndef PRIVATE
71*fdd8201dSApple OSS Distributions #warning "MAC policy is not KPI, see Technical Q&A QA1574, this header will be removed in next version"
72*fdd8201dSApple OSS Distributions #endif
73*fdd8201dSApple OSS Distributions 
74*fdd8201dSApple OSS Distributions #include <string.h>
75*fdd8201dSApple OSS Distributions #include <sys/param.h>
76*fdd8201dSApple OSS Distributions #include <sys/queue.h>
77*fdd8201dSApple OSS Distributions #include <security/mac.h>
78*fdd8201dSApple OSS Distributions #include <security/mac_framework.h>
79*fdd8201dSApple OSS Distributions #include <security/mac_policy.h>
80*fdd8201dSApple OSS Distributions #include <security/mac_data.h>
81*fdd8201dSApple OSS Distributions #include <sys/sysctl.h>
82*fdd8201dSApple OSS Distributions #include <kern/locks.h>
83*fdd8201dSApple OSS Distributions #include <sys/kernel.h>
84*fdd8201dSApple OSS Distributions #include <sys/lock.h>
85*fdd8201dSApple OSS Distributions #include <sys/malloc.h>
86*fdd8201dSApple OSS Distributions #include <sys/sbuf.h>
87*fdd8201dSApple OSS Distributions #include <sys/proc.h>
88*fdd8201dSApple OSS Distributions #include <sys/systm.h>
89*fdd8201dSApple OSS Distributions #include <sys/socket.h>
90*fdd8201dSApple OSS Distributions #include <sys/socketvar.h>
91*fdd8201dSApple OSS Distributions #include <sys/vnode.h>
92*fdd8201dSApple OSS Distributions #include <mach/sdt.h>
93*fdd8201dSApple OSS Distributions 
94*fdd8201dSApple OSS Distributions /*
95*fdd8201dSApple OSS Distributions  * MAC Framework sysctl namespace.
96*fdd8201dSApple OSS Distributions  */
97*fdd8201dSApple OSS Distributions 
98*fdd8201dSApple OSS Distributions SYSCTL_DECL(_security);
99*fdd8201dSApple OSS Distributions SYSCTL_DECL(_security_mac);
100*fdd8201dSApple OSS Distributions 
101*fdd8201dSApple OSS Distributions extern int mac_late;
102*fdd8201dSApple OSS Distributions 
103*fdd8201dSApple OSS Distributions struct mac_policy_list_element {
104*fdd8201dSApple OSS Distributions 	struct mac_policy_conf *mpc;
105*fdd8201dSApple OSS Distributions };
106*fdd8201dSApple OSS Distributions 
107*fdd8201dSApple OSS Distributions struct mac_policy_list {
108*fdd8201dSApple OSS Distributions 	u_int                           numloaded;
109*fdd8201dSApple OSS Distributions 	u_int                           max;
110*fdd8201dSApple OSS Distributions 	u_int                           maxindex;
111*fdd8201dSApple OSS Distributions 	u_int                           staticmax;
112*fdd8201dSApple OSS Distributions 	u_int                           chunks;
113*fdd8201dSApple OSS Distributions 	u_int                           freehint;
114*fdd8201dSApple OSS Distributions 	struct mac_policy_list_element  *entries;
115*fdd8201dSApple OSS Distributions };
116*fdd8201dSApple OSS Distributions 
117*fdd8201dSApple OSS Distributions typedef struct mac_policy_list mac_policy_list_t;
118*fdd8201dSApple OSS Distributions 
119*fdd8201dSApple OSS Distributions 
120*fdd8201dSApple OSS Distributions /*
121*fdd8201dSApple OSS Distributions  * Policy that has registered with the framework for a specific
122*fdd8201dSApple OSS Distributions  * label namespace name.
123*fdd8201dSApple OSS Distributions  */
124*fdd8201dSApple OSS Distributions struct mac_label_listener {
125*fdd8201dSApple OSS Distributions 	mac_policy_handle_t             mll_handle;
126*fdd8201dSApple OSS Distributions 	SLIST_ENTRY(mac_label_listener) mll_list;
127*fdd8201dSApple OSS Distributions };
128*fdd8201dSApple OSS Distributions 
129*fdd8201dSApple OSS Distributions SLIST_HEAD(mac_label_listeners_t, mac_label_listener);
130*fdd8201dSApple OSS Distributions 
131*fdd8201dSApple OSS Distributions /*
132*fdd8201dSApple OSS Distributions  * Type of list used to manage label namespace names.
133*fdd8201dSApple OSS Distributions  */
134*fdd8201dSApple OSS Distributions struct mac_label_element {
135*fdd8201dSApple OSS Distributions 	char                            mle_name[MAC_MAX_LABEL_ELEMENT_NAME];
136*fdd8201dSApple OSS Distributions 	struct mac_label_listeners_t    mle_listeners;
137*fdd8201dSApple OSS Distributions 	SLIST_ENTRY(mac_label_element)  mle_list;
138*fdd8201dSApple OSS Distributions };
139*fdd8201dSApple OSS Distributions 
140*fdd8201dSApple OSS Distributions SLIST_HEAD(mac_label_element_list_t, mac_label_element);
141*fdd8201dSApple OSS Distributions 
142*fdd8201dSApple OSS Distributions /*
143*fdd8201dSApple OSS Distributions  * MAC Framework global variables.
144*fdd8201dSApple OSS Distributions  */
145*fdd8201dSApple OSS Distributions 
146*fdd8201dSApple OSS Distributions extern struct mac_label_element_list_t mac_label_element_list;
147*fdd8201dSApple OSS Distributions extern struct mac_label_element_list_t mac_static_label_element_list;
148*fdd8201dSApple OSS Distributions 
149*fdd8201dSApple OSS Distributions extern struct mac_policy_list mac_policy_list;
150*fdd8201dSApple OSS Distributions 
151*fdd8201dSApple OSS Distributions /*
152*fdd8201dSApple OSS Distributions  * global flags to control whether a MACF subsystem is configured
153*fdd8201dSApple OSS Distributions  * at all in the system.
154*fdd8201dSApple OSS Distributions  */
155*fdd8201dSApple OSS Distributions extern unsigned int mac_device_enforce;
156*fdd8201dSApple OSS Distributions extern unsigned int mac_pipe_enforce;
157*fdd8201dSApple OSS Distributions extern unsigned int mac_posixsem_enforce;
158*fdd8201dSApple OSS Distributions extern unsigned int mac_posixshm_enforce;
159*fdd8201dSApple OSS Distributions extern unsigned int mac_proc_enforce;
160*fdd8201dSApple OSS Distributions extern unsigned int mac_socket_enforce;
161*fdd8201dSApple OSS Distributions extern unsigned int mac_system_enforce;
162*fdd8201dSApple OSS Distributions extern unsigned int mac_sysvmsg_enforce;
163*fdd8201dSApple OSS Distributions extern unsigned int mac_sysvsem_enforce;
164*fdd8201dSApple OSS Distributions extern unsigned int mac_sysvshm_enforce;
165*fdd8201dSApple OSS Distributions extern unsigned int mac_vm_enforce;
166*fdd8201dSApple OSS Distributions extern unsigned int mac_vnode_enforce;
167*fdd8201dSApple OSS Distributions 
168*fdd8201dSApple OSS Distributions extern unsigned int mac_label_vnodes;
169*fdd8201dSApple OSS Distributions extern unsigned int mac_vnode_label_count;
170*fdd8201dSApple OSS Distributions 
171*fdd8201dSApple OSS Distributions static bool mac_proc_check_enforce(proc_t p);
172*fdd8201dSApple OSS Distributions 
173*fdd8201dSApple OSS Distributions static __inline__ bool
mac_proc_check_enforce(proc_t p)174*fdd8201dSApple OSS Distributions mac_proc_check_enforce(proc_t p)
175*fdd8201dSApple OSS Distributions {
176*fdd8201dSApple OSS Distributions #if CONFIG_MACF
177*fdd8201dSApple OSS Distributions 	// Don't apply policies to the kernel itself.
178*fdd8201dSApple OSS Distributions 	return p != kernproc;
179*fdd8201dSApple OSS Distributions #else
180*fdd8201dSApple OSS Distributions #pragma unused(p)
181*fdd8201dSApple OSS Distributions 	return false;
182*fdd8201dSApple OSS Distributions #endif // CONFIG_MACF
183*fdd8201dSApple OSS Distributions }
184*fdd8201dSApple OSS Distributions 
185*fdd8201dSApple OSS Distributions static bool mac_cred_check_enforce(kauth_cred_t cred);
186*fdd8201dSApple OSS Distributions 
187*fdd8201dSApple OSS Distributions static __inline__ bool
mac_cred_check_enforce(kauth_cred_t cred)188*fdd8201dSApple OSS Distributions mac_cred_check_enforce(kauth_cred_t cred)
189*fdd8201dSApple OSS Distributions {
190*fdd8201dSApple OSS Distributions #if CONFIG_MACF
191*fdd8201dSApple OSS Distributions 	return cred != proc_ucred(kernproc);
192*fdd8201dSApple OSS Distributions #else
193*fdd8201dSApple OSS Distributions #pragma unused(p)
194*fdd8201dSApple OSS Distributions 	return false;
195*fdd8201dSApple OSS Distributions #endif // CONFIG_MACF
196*fdd8201dSApple OSS Distributions }
197*fdd8201dSApple OSS Distributions 
198*fdd8201dSApple OSS Distributions /*
199*fdd8201dSApple OSS Distributions  * MAC Framework infrastructure functions.
200*fdd8201dSApple OSS Distributions  */
201*fdd8201dSApple OSS Distributions 
202*fdd8201dSApple OSS Distributions int mac_error_select(int error1, int error2);
203*fdd8201dSApple OSS Distributions 
204*fdd8201dSApple OSS Distributions void  mac_policy_list_busy(void);
205*fdd8201dSApple OSS Distributions int   mac_policy_list_conditional_busy(void);
206*fdd8201dSApple OSS Distributions void  mac_policy_list_unbusy(void);
207*fdd8201dSApple OSS Distributions 
208*fdd8201dSApple OSS Distributions #if KERNEL
209*fdd8201dSApple OSS Distributions int   mac_check_structmac_consistent(struct user_mac *mac);
210*fdd8201dSApple OSS Distributions #else
211*fdd8201dSApple OSS Distributions int   mac_check_structmac_consistent(struct mac *mac);
212*fdd8201dSApple OSS Distributions #endif
213*fdd8201dSApple OSS Distributions 
214*fdd8201dSApple OSS Distributions int mac_cred_label_externalize(struct label *, char *e, char *out, size_t olen, int flags);
215*fdd8201dSApple OSS Distributions int mac_vnode_label_externalize(struct label *, char *e, char *out, size_t olen, int flags);
216*fdd8201dSApple OSS Distributions 
217*fdd8201dSApple OSS Distributions int mac_cred_label_internalize(struct label *label, char *string);
218*fdd8201dSApple OSS Distributions int mac_vnode_label_internalize(struct label *label, char *string);
219*fdd8201dSApple OSS Distributions 
220*fdd8201dSApple OSS Distributions typedef int (^mac_getter_t)(char *, char *, size_t);
221*fdd8201dSApple OSS Distributions typedef int (^mac_setter_t)(char *, size_t);
222*fdd8201dSApple OSS Distributions 
223*fdd8201dSApple OSS Distributions int mac_do_get(struct proc *p, user_addr_t mac_p, mac_getter_t getter);
224*fdd8201dSApple OSS Distributions int mac_do_set(struct proc *p, user_addr_t mac_p, mac_setter_t setter);
225*fdd8201dSApple OSS Distributions 
226*fdd8201dSApple OSS Distributions #define MAC_POLICY_ITERATE(...) do {                                \
227*fdd8201dSApple OSS Distributions     struct mac_policy_conf *mpc;                                    \
228*fdd8201dSApple OSS Distributions     u_int i;                                                        \
229*fdd8201dSApple OSS Distributions                                                                     \
230*fdd8201dSApple OSS Distributions     for (i = 0; i < mac_policy_list.staticmax; i++) {               \
231*fdd8201dSApple OSS Distributions 	    mpc = mac_policy_list.entries[i].mpc;                       \
232*fdd8201dSApple OSS Distributions 	    if (mpc == NULL)                                            \
233*fdd8201dSApple OSS Distributions 	            continue;                                           \
234*fdd8201dSApple OSS Distributions                                                                     \
235*fdd8201dSApple OSS Distributions 	    __VA_ARGS__                                                 \
236*fdd8201dSApple OSS Distributions     }                                                               \
237*fdd8201dSApple OSS Distributions     if (mac_policy_list_conditional_busy() != 0) {                  \
238*fdd8201dSApple OSS Distributions 	    for (; i <= mac_policy_list.maxindex; i++) {                \
239*fdd8201dSApple OSS Distributions 	            mpc = mac_policy_list.entries[i].mpc;               \
240*fdd8201dSApple OSS Distributions 	            if (mpc == NULL)                                    \
241*fdd8201dSApple OSS Distributions 	                    continue;                                   \
242*fdd8201dSApple OSS Distributions                                                                     \
243*fdd8201dSApple OSS Distributions 	            __VA_ARGS__                                         \
244*fdd8201dSApple OSS Distributions 	    }                                                           \
245*fdd8201dSApple OSS Distributions 	    mac_policy_list_unbusy();                                   \
246*fdd8201dSApple OSS Distributions     }                                                               \
247*fdd8201dSApple OSS Distributions } while (0)
248*fdd8201dSApple OSS Distributions 
249*fdd8201dSApple OSS Distributions enum mac_iterate_types {
250*fdd8201dSApple OSS Distributions 	MAC_ITERATE_CHECK = 0,  // error starts at 0, callbacks can change it
251*fdd8201dSApple OSS Distributions 	MAC_ITERATE_GRANT = 1,  // error starts as EPERM, callbacks can clear it
252*fdd8201dSApple OSS Distributions 	MAC_ITERATE_PERFORM = 2, // no result
253*fdd8201dSApple OSS Distributions };
254*fdd8201dSApple OSS Distributions 
255*fdd8201dSApple OSS Distributions /*
256*fdd8201dSApple OSS Distributions  * MAC_CHECK performs the designated check by walking the policy
257*fdd8201dSApple OSS Distributions  * module list and checking with each as to how it feels about the
258*fdd8201dSApple OSS Distributions  * request.  Note that it returns its value via 'error' in the scope
259*fdd8201dSApple OSS Distributions  * of the caller.
260*fdd8201dSApple OSS Distributions  */
261*fdd8201dSApple OSS Distributions #define MAC_CHECK(check, args...) do {                              \
262*fdd8201dSApple OSS Distributions     error = 0;                                                      \
263*fdd8201dSApple OSS Distributions     MAC_POLICY_ITERATE({                                            \
264*fdd8201dSApple OSS Distributions 	    if (mpc->mpc_ops->mpo_ ## check != NULL) {              \
265*fdd8201dSApple OSS Distributions 	            DTRACE_MACF3(mac__call__ ## check, void *, mpc, int, error, int, MAC_ITERATE_CHECK); \
266*fdd8201dSApple OSS Distributions 	            int __step_err = mpc->mpc_ops->mpo_ ## check (args); \
267*fdd8201dSApple OSS Distributions 	            DTRACE_MACF2(mac__rslt__ ## check, void *, mpc, int, __step_err); \
268*fdd8201dSApple OSS Distributions 	            error = mac_error_select(__step_err, error);         \
269*fdd8201dSApple OSS Distributions 	    }                                                           \
270*fdd8201dSApple OSS Distributions     });                                                             \
271*fdd8201dSApple OSS Distributions } while (0)
272*fdd8201dSApple OSS Distributions 
273*fdd8201dSApple OSS Distributions /*
274*fdd8201dSApple OSS Distributions  * MAC_GRANT performs the designated check by walking the policy
275*fdd8201dSApple OSS Distributions  * module list and checking with each as to how it feels about the
276*fdd8201dSApple OSS Distributions  * request.  Unlike MAC_CHECK, it grants if any policies return '0',
277*fdd8201dSApple OSS Distributions  * and otherwise returns EPERM.  Note that it returns its value via
278*fdd8201dSApple OSS Distributions  * 'error' in the scope of the caller.
279*fdd8201dSApple OSS Distributions  */
280*fdd8201dSApple OSS Distributions #define MAC_GRANT(check, args...) do {                              \
281*fdd8201dSApple OSS Distributions     error = EPERM;                                                  \
282*fdd8201dSApple OSS Distributions     MAC_POLICY_ITERATE({                                            \
283*fdd8201dSApple OSS Distributions 	if (mpc->mpc_ops->mpo_ ## check != NULL) {                  \
284*fdd8201dSApple OSS Distributions 	        DTRACE_MACF3(mac__call__ ## check, void *, mpc, int, error, int, MAC_ITERATE_GRANT); \
285*fdd8201dSApple OSS Distributions 	        int __step_res = mpc->mpc_ops->mpo_ ## check (args); \
286*fdd8201dSApple OSS Distributions 	        if (__step_res == 0) {                              \
287*fdd8201dSApple OSS Distributions 	                error = 0;                                  \
288*fdd8201dSApple OSS Distributions 	        }                                                   \
289*fdd8201dSApple OSS Distributions 	        DTRACE_MACF2(mac__rslt__ ## check, void *, mpc, int, __step_res); \
290*fdd8201dSApple OSS Distributions 	    }                                                           \
291*fdd8201dSApple OSS Distributions     });                                                             \
292*fdd8201dSApple OSS Distributions } while (0)
293*fdd8201dSApple OSS Distributions 
294*fdd8201dSApple OSS Distributions #define MAC_INTERNALIZE(obj, label, instring)                       \
295*fdd8201dSApple OSS Distributions     mac_internalize(offsetof(struct mac_policy_ops, mpo_ ## obj ## _label_internalize), label, instring)
296*fdd8201dSApple OSS Distributions 
297*fdd8201dSApple OSS Distributions #define MAC_EXTERNALIZE(obj, label, elementlist, outbuf, outbuflen) \
298*fdd8201dSApple OSS Distributions     mac_externalize(offsetof(struct mac_policy_ops, mpo_ ## obj ## _label_externalize), label, elementlist, outbuf, outbuflen)
299*fdd8201dSApple OSS Distributions 
300*fdd8201dSApple OSS Distributions #define MAC_EXTERNALIZE_AUDIT(obj, label, outbuf, outbuflen)        \
301*fdd8201dSApple OSS Distributions     mac_externalize(offsetof(struct mac_policy_ops, mpo_ ## obj ## _label_externalize_audit), label, "*", outbuf, outbuflen)
302*fdd8201dSApple OSS Distributions 
303*fdd8201dSApple OSS Distributions #define MAC_PERFORM_CALL(operation, mpc) DTRACE_MACF3(mac__call__ ## operation, void *, mpc, int, 0, int, MAC_ITERATE_PERFORM)
304*fdd8201dSApple OSS Distributions #define MAC_PERFORM_RSLT(operation, mpc) DTRACE_MACF2(mac__rslt__ ## operation, void *, mpc, int, 0)
305*fdd8201dSApple OSS Distributions 
306*fdd8201dSApple OSS Distributions /*
307*fdd8201dSApple OSS Distributions  * MAC_PERFORM performs the designated operation by walking the policy
308*fdd8201dSApple OSS Distributions  * module list and invoking that operation for each policy.
309*fdd8201dSApple OSS Distributions  */
310*fdd8201dSApple OSS Distributions #define MAC_PERFORM(operation, args...) do {           \
311*fdd8201dSApple OSS Distributions     MAC_POLICY_ITERATE({                                    \
312*fdd8201dSApple OSS Distributions 	if (mpc->mpc_ops->mpo_ ## operation != NULL) {      \
313*fdd8201dSApple OSS Distributions 	        MAC_PERFORM_CALL(operation, mpc);           \
314*fdd8201dSApple OSS Distributions 	        mpc->mpc_ops->mpo_ ## operation (args);     \
315*fdd8201dSApple OSS Distributions 	        MAC_PERFORM_RSLT(operation, mpc);           \
316*fdd8201dSApple OSS Distributions 	}                                                   \
317*fdd8201dSApple OSS Distributions     });                                                     \
318*fdd8201dSApple OSS Distributions } while (0)
319*fdd8201dSApple OSS Distributions 
320*fdd8201dSApple OSS Distributions 
321*fdd8201dSApple OSS Distributions #
322*fdd8201dSApple OSS Distributions struct __mac_get_pid_args;
323*fdd8201dSApple OSS Distributions struct __mac_get_proc_args;
324*fdd8201dSApple OSS Distributions struct __mac_set_proc_args;
325*fdd8201dSApple OSS Distributions struct __mac_get_lcid_args;
326*fdd8201dSApple OSS Distributions struct __mac_get_fd_args;
327*fdd8201dSApple OSS Distributions struct __mac_get_file_args;
328*fdd8201dSApple OSS Distributions struct __mac_get_link_args;
329*fdd8201dSApple OSS Distributions struct __mac_set_fd_args;
330*fdd8201dSApple OSS Distributions struct __mac_set_file_args;
331*fdd8201dSApple OSS Distributions struct __mac_syscall_args;
332*fdd8201dSApple OSS Distributions 
333*fdd8201dSApple OSS Distributions void mac_policy_addto_labellist(const mac_policy_handle_t, int);
334*fdd8201dSApple OSS Distributions void mac_policy_removefrom_labellist(const mac_policy_handle_t);
335*fdd8201dSApple OSS Distributions 
336*fdd8201dSApple OSS Distributions int mac_externalize(size_t mpo_externalize_off, struct label *label,
337*fdd8201dSApple OSS Distributions     const char *elementlist, char *outbuf, size_t outbuflen);
338*fdd8201dSApple OSS Distributions int mac_internalize(size_t mpo_internalize_off, struct label *label,
339*fdd8201dSApple OSS Distributions     char *elementlist);
340*fdd8201dSApple OSS Distributions #endif  /* !_SECURITY_MAC_INTERNAL_H_ */
341