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