xref: /xnu-8792.41.9/security/mac_socket.c (revision 5c2921b07a2480ab43ec66f5b9e41cb872bc554f)
1*5c2921b0SApple OSS Distributions /*
2*5c2921b0SApple OSS Distributions  * Copyright (c) 2007-2012 Apple Inc. All rights reserved.
3*5c2921b0SApple OSS Distributions  *
4*5c2921b0SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*5c2921b0SApple OSS Distributions  *
6*5c2921b0SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*5c2921b0SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*5c2921b0SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*5c2921b0SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*5c2921b0SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*5c2921b0SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*5c2921b0SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*5c2921b0SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*5c2921b0SApple OSS Distributions  *
15*5c2921b0SApple OSS Distributions  * Please obtain a copy of the License at
16*5c2921b0SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*5c2921b0SApple OSS Distributions  *
18*5c2921b0SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*5c2921b0SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*5c2921b0SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*5c2921b0SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*5c2921b0SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*5c2921b0SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*5c2921b0SApple OSS Distributions  * limitations under the License.
25*5c2921b0SApple OSS Distributions  *
26*5c2921b0SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*5c2921b0SApple OSS Distributions  */
28*5c2921b0SApple OSS Distributions /*-
29*5c2921b0SApple OSS Distributions  * Copyright (c) 1999-2002 Robert N. M. Watson
30*5c2921b0SApple OSS Distributions  * Copyright (c) 2001 Ilmar S. Habibulin
31*5c2921b0SApple OSS Distributions  * Copyright (c) 2001-2005 Networks Associates Technology, Inc.
32*5c2921b0SApple OSS Distributions  * Copyright (c) 2005 SPARTA, Inc.
33*5c2921b0SApple OSS Distributions  * All rights reserved.
34*5c2921b0SApple OSS Distributions  *
35*5c2921b0SApple OSS Distributions  * This software was developed by Robert Watson and Ilmar Habibulin for the
36*5c2921b0SApple OSS Distributions  * TrustedBSD Project.
37*5c2921b0SApple OSS Distributions  *
38*5c2921b0SApple OSS Distributions  * This software was developed for the FreeBSD Project in part by McAfee
39*5c2921b0SApple OSS Distributions  * Research, the Technology Research Division of Network Associates, Inc.
40*5c2921b0SApple OSS Distributions  * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
41*5c2921b0SApple OSS Distributions  * DARPA CHATS research program.
42*5c2921b0SApple OSS Distributions  *
43*5c2921b0SApple OSS Distributions  * This software was enhanced by SPARTA ISSO under SPAWAR contract
44*5c2921b0SApple OSS Distributions  * N66001-04-C-6019 ("SEFOS").
45*5c2921b0SApple OSS Distributions  *
46*5c2921b0SApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
47*5c2921b0SApple OSS Distributions  * modification, are permitted provided that the following conditions
48*5c2921b0SApple OSS Distributions  * are met:
49*5c2921b0SApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
50*5c2921b0SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
51*5c2921b0SApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
52*5c2921b0SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
53*5c2921b0SApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
54*5c2921b0SApple OSS Distributions  *
55*5c2921b0SApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
56*5c2921b0SApple OSS Distributions  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57*5c2921b0SApple OSS Distributions  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58*5c2921b0SApple OSS Distributions  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
59*5c2921b0SApple OSS Distributions  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60*5c2921b0SApple OSS Distributions  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61*5c2921b0SApple OSS Distributions  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62*5c2921b0SApple OSS Distributions  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63*5c2921b0SApple OSS Distributions  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64*5c2921b0SApple OSS Distributions  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65*5c2921b0SApple OSS Distributions  * SUCH DAMAGE.
66*5c2921b0SApple OSS Distributions  */
67*5c2921b0SApple OSS Distributions 
68*5c2921b0SApple OSS Distributions #include <sys/cdefs.h>
69*5c2921b0SApple OSS Distributions 
70*5c2921b0SApple OSS Distributions #include <sys/param.h>
71*5c2921b0SApple OSS Distributions #include <sys/kernel.h>
72*5c2921b0SApple OSS Distributions #include <sys/lock.h>
73*5c2921b0SApple OSS Distributions #include <sys/malloc.h>
74*5c2921b0SApple OSS Distributions #include <sys/sbuf.h>
75*5c2921b0SApple OSS Distributions #include <sys/systm.h>
76*5c2921b0SApple OSS Distributions #include <sys/mount.h>
77*5c2921b0SApple OSS Distributions #include <sys/file.h>
78*5c2921b0SApple OSS Distributions #include <sys/namei.h>
79*5c2921b0SApple OSS Distributions #include <sys/protosw.h>
80*5c2921b0SApple OSS Distributions #include <sys/socket.h>
81*5c2921b0SApple OSS Distributions #include <sys/socketvar.h>
82*5c2921b0SApple OSS Distributions #include <sys/sysctl.h>
83*5c2921b0SApple OSS Distributions #include <sys/kpi_socket.h>
84*5c2921b0SApple OSS Distributions 
85*5c2921b0SApple OSS Distributions #include <security/mac_internal.h>
86*5c2921b0SApple OSS Distributions 
87*5c2921b0SApple OSS Distributions int
mac_socket_check_accept(kauth_cred_t cred,struct socket * so)88*5c2921b0SApple OSS Distributions mac_socket_check_accept(kauth_cred_t cred, struct socket *so)
89*5c2921b0SApple OSS Distributions {
90*5c2921b0SApple OSS Distributions 	int error;
91*5c2921b0SApple OSS Distributions 
92*5c2921b0SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
93*5c2921b0SApple OSS Distributions 	/* 21167099 - only check if we allow write */
94*5c2921b0SApple OSS Distributions 	if (!mac_socket_enforce) {
95*5c2921b0SApple OSS Distributions 		return 0;
96*5c2921b0SApple OSS Distributions 	}
97*5c2921b0SApple OSS Distributions #endif
98*5c2921b0SApple OSS Distributions 
99*5c2921b0SApple OSS Distributions 	MAC_CHECK(socket_check_accept, cred,
100*5c2921b0SApple OSS Distributions 	    (socket_t)so, NULL);
101*5c2921b0SApple OSS Distributions 	return error;
102*5c2921b0SApple OSS Distributions }
103*5c2921b0SApple OSS Distributions 
104*5c2921b0SApple OSS Distributions #if CONFIG_MACF_SOCKET_SUBSET
105*5c2921b0SApple OSS Distributions int
mac_socket_check_accepted(kauth_cred_t cred,struct socket * so)106*5c2921b0SApple OSS Distributions mac_socket_check_accepted(kauth_cred_t cred, struct socket *so)
107*5c2921b0SApple OSS Distributions {
108*5c2921b0SApple OSS Distributions 	struct sockaddr *sockaddr;
109*5c2921b0SApple OSS Distributions 	int error;
110*5c2921b0SApple OSS Distributions 
111*5c2921b0SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
112*5c2921b0SApple OSS Distributions 	/* 21167099 - only check if we allow write */
113*5c2921b0SApple OSS Distributions 	if (!mac_socket_enforce) {
114*5c2921b0SApple OSS Distributions 		return 0;
115*5c2921b0SApple OSS Distributions 	}
116*5c2921b0SApple OSS Distributions #endif
117*5c2921b0SApple OSS Distributions 
118*5c2921b0SApple OSS Distributions 	if (sock_getaddr((socket_t)so, &sockaddr, 1) != 0) {
119*5c2921b0SApple OSS Distributions 		error = ECONNABORTED;
120*5c2921b0SApple OSS Distributions 	} else {
121*5c2921b0SApple OSS Distributions 		MAC_CHECK(socket_check_accepted, cred,
122*5c2921b0SApple OSS Distributions 		    (socket_t)so, NULL, sockaddr);
123*5c2921b0SApple OSS Distributions 		sock_freeaddr(sockaddr);
124*5c2921b0SApple OSS Distributions 	}
125*5c2921b0SApple OSS Distributions 	return error;
126*5c2921b0SApple OSS Distributions }
127*5c2921b0SApple OSS Distributions #endif
128*5c2921b0SApple OSS Distributions 
129*5c2921b0SApple OSS Distributions int
mac_socket_check_bind(kauth_cred_t ucred,struct socket * so,struct sockaddr * sockaddr)130*5c2921b0SApple OSS Distributions mac_socket_check_bind(kauth_cred_t ucred, struct socket *so,
131*5c2921b0SApple OSS Distributions     struct sockaddr *sockaddr)
132*5c2921b0SApple OSS Distributions {
133*5c2921b0SApple OSS Distributions 	int error;
134*5c2921b0SApple OSS Distributions 
135*5c2921b0SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
136*5c2921b0SApple OSS Distributions 	/* 21167099 - only check if we allow write */
137*5c2921b0SApple OSS Distributions 	if (!mac_socket_enforce) {
138*5c2921b0SApple OSS Distributions 		return 0;
139*5c2921b0SApple OSS Distributions 	}
140*5c2921b0SApple OSS Distributions #endif
141*5c2921b0SApple OSS Distributions 
142*5c2921b0SApple OSS Distributions 	MAC_CHECK(socket_check_bind, ucred,
143*5c2921b0SApple OSS Distributions 	    (socket_t)so, NULL, sockaddr);
144*5c2921b0SApple OSS Distributions 	return error;
145*5c2921b0SApple OSS Distributions }
146*5c2921b0SApple OSS Distributions 
147*5c2921b0SApple OSS Distributions int
mac_socket_check_connect(kauth_cred_t cred,struct socket * so,struct sockaddr * sockaddr)148*5c2921b0SApple OSS Distributions mac_socket_check_connect(kauth_cred_t cred, struct socket *so,
149*5c2921b0SApple OSS Distributions     struct sockaddr *sockaddr)
150*5c2921b0SApple OSS Distributions {
151*5c2921b0SApple OSS Distributions 	int error;
152*5c2921b0SApple OSS Distributions 
153*5c2921b0SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
154*5c2921b0SApple OSS Distributions 	/* 21167099 - only check if we allow write */
155*5c2921b0SApple OSS Distributions 	if (!mac_socket_enforce) {
156*5c2921b0SApple OSS Distributions 		return 0;
157*5c2921b0SApple OSS Distributions 	}
158*5c2921b0SApple OSS Distributions #endif
159*5c2921b0SApple OSS Distributions 
160*5c2921b0SApple OSS Distributions 	MAC_CHECK(socket_check_connect, cred,
161*5c2921b0SApple OSS Distributions 	    (socket_t)so, NULL,
162*5c2921b0SApple OSS Distributions 	    sockaddr);
163*5c2921b0SApple OSS Distributions 	return error;
164*5c2921b0SApple OSS Distributions }
165*5c2921b0SApple OSS Distributions 
166*5c2921b0SApple OSS Distributions int
mac_socket_check_create(kauth_cred_t cred,int domain,int type,int protocol)167*5c2921b0SApple OSS Distributions mac_socket_check_create(kauth_cred_t cred, int domain, int type, int protocol)
168*5c2921b0SApple OSS Distributions {
169*5c2921b0SApple OSS Distributions 	int error;
170*5c2921b0SApple OSS Distributions 
171*5c2921b0SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
172*5c2921b0SApple OSS Distributions 	/* 21167099 - only check if we allow write */
173*5c2921b0SApple OSS Distributions 	if (!mac_socket_enforce) {
174*5c2921b0SApple OSS Distributions 		return 0;
175*5c2921b0SApple OSS Distributions 	}
176*5c2921b0SApple OSS Distributions #endif
177*5c2921b0SApple OSS Distributions 
178*5c2921b0SApple OSS Distributions 	MAC_CHECK(socket_check_create, cred, domain, type, protocol);
179*5c2921b0SApple OSS Distributions 	return error;
180*5c2921b0SApple OSS Distributions }
181*5c2921b0SApple OSS Distributions 
182*5c2921b0SApple OSS Distributions int
mac_socket_check_ioctl(kauth_cred_t cred,struct socket * so,u_long cmd)183*5c2921b0SApple OSS Distributions mac_socket_check_ioctl(kauth_cred_t cred, struct socket *so, u_long cmd)
184*5c2921b0SApple OSS Distributions {
185*5c2921b0SApple OSS Distributions 	int error;
186*5c2921b0SApple OSS Distributions 
187*5c2921b0SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
188*5c2921b0SApple OSS Distributions 	/* 21167099 - only check if we allow write */
189*5c2921b0SApple OSS Distributions 	if (!mac_socket_enforce) {
190*5c2921b0SApple OSS Distributions 		return 0;
191*5c2921b0SApple OSS Distributions 	}
192*5c2921b0SApple OSS Distributions #endif
193*5c2921b0SApple OSS Distributions 
194*5c2921b0SApple OSS Distributions 	MAC_CHECK(socket_check_ioctl, cred,
195*5c2921b0SApple OSS Distributions 	    (socket_t)so, cmd, NULL);
196*5c2921b0SApple OSS Distributions 	return error;
197*5c2921b0SApple OSS Distributions }
198*5c2921b0SApple OSS Distributions 
199*5c2921b0SApple OSS Distributions int
mac_socket_check_stat(kauth_cred_t cred,struct socket * so)200*5c2921b0SApple OSS Distributions mac_socket_check_stat(kauth_cred_t cred, struct socket *so)
201*5c2921b0SApple OSS Distributions {
202*5c2921b0SApple OSS Distributions 	int error;
203*5c2921b0SApple OSS Distributions 
204*5c2921b0SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
205*5c2921b0SApple OSS Distributions 	/* 21167099 - only check if we allow write */
206*5c2921b0SApple OSS Distributions 	if (!mac_socket_enforce) {
207*5c2921b0SApple OSS Distributions 		return 0;
208*5c2921b0SApple OSS Distributions 	}
209*5c2921b0SApple OSS Distributions #endif
210*5c2921b0SApple OSS Distributions 
211*5c2921b0SApple OSS Distributions 	MAC_CHECK(socket_check_stat, cred,
212*5c2921b0SApple OSS Distributions 	    (socket_t)so, NULL);
213*5c2921b0SApple OSS Distributions 	return error;
214*5c2921b0SApple OSS Distributions }
215*5c2921b0SApple OSS Distributions 
216*5c2921b0SApple OSS Distributions int
mac_socket_check_listen(kauth_cred_t cred,struct socket * so)217*5c2921b0SApple OSS Distributions mac_socket_check_listen(kauth_cred_t cred, struct socket *so)
218*5c2921b0SApple OSS Distributions {
219*5c2921b0SApple OSS Distributions 	int error;
220*5c2921b0SApple OSS Distributions 
221*5c2921b0SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
222*5c2921b0SApple OSS Distributions 	/* 21167099 - only check if we allow write */
223*5c2921b0SApple OSS Distributions 	if (!mac_socket_enforce) {
224*5c2921b0SApple OSS Distributions 		return 0;
225*5c2921b0SApple OSS Distributions 	}
226*5c2921b0SApple OSS Distributions #endif
227*5c2921b0SApple OSS Distributions 
228*5c2921b0SApple OSS Distributions 	MAC_CHECK(socket_check_listen, cred,
229*5c2921b0SApple OSS Distributions 	    (socket_t)so, NULL);
230*5c2921b0SApple OSS Distributions 	return error;
231*5c2921b0SApple OSS Distributions }
232*5c2921b0SApple OSS Distributions 
233*5c2921b0SApple OSS Distributions int
mac_socket_check_receive(kauth_cred_t cred,struct socket * so)234*5c2921b0SApple OSS Distributions mac_socket_check_receive(kauth_cred_t cred, struct socket *so)
235*5c2921b0SApple OSS Distributions {
236*5c2921b0SApple OSS Distributions 	int error;
237*5c2921b0SApple OSS Distributions 
238*5c2921b0SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
239*5c2921b0SApple OSS Distributions 	/* 21167099 - only check if we allow write */
240*5c2921b0SApple OSS Distributions 	if (!mac_socket_enforce) {
241*5c2921b0SApple OSS Distributions 		return 0;
242*5c2921b0SApple OSS Distributions 	}
243*5c2921b0SApple OSS Distributions #endif
244*5c2921b0SApple OSS Distributions 
245*5c2921b0SApple OSS Distributions 	MAC_CHECK(socket_check_receive, cred,
246*5c2921b0SApple OSS Distributions 	    (socket_t)so, NULL);
247*5c2921b0SApple OSS Distributions 	return error;
248*5c2921b0SApple OSS Distributions }
249*5c2921b0SApple OSS Distributions 
250*5c2921b0SApple OSS Distributions int
mac_socket_check_received(kauth_cred_t cred,struct socket * so,struct sockaddr * saddr)251*5c2921b0SApple OSS Distributions mac_socket_check_received(kauth_cred_t cred, struct socket *so, struct sockaddr *saddr)
252*5c2921b0SApple OSS Distributions {
253*5c2921b0SApple OSS Distributions 	int error;
254*5c2921b0SApple OSS Distributions 
255*5c2921b0SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
256*5c2921b0SApple OSS Distributions 	/* 21167099 - only check if we allow write */
257*5c2921b0SApple OSS Distributions 	if (!mac_socket_enforce) {
258*5c2921b0SApple OSS Distributions 		return 0;
259*5c2921b0SApple OSS Distributions 	}
260*5c2921b0SApple OSS Distributions #endif
261*5c2921b0SApple OSS Distributions 
262*5c2921b0SApple OSS Distributions 	MAC_CHECK(socket_check_received, cred,
263*5c2921b0SApple OSS Distributions 	    so, NULL, saddr);
264*5c2921b0SApple OSS Distributions 	return error;
265*5c2921b0SApple OSS Distributions }
266*5c2921b0SApple OSS Distributions 
267*5c2921b0SApple OSS Distributions int
mac_socket_check_send(kauth_cred_t cred,struct socket * so,struct sockaddr * sockaddr)268*5c2921b0SApple OSS Distributions mac_socket_check_send(kauth_cred_t cred, struct socket *so,
269*5c2921b0SApple OSS Distributions     struct sockaddr *sockaddr)
270*5c2921b0SApple OSS Distributions {
271*5c2921b0SApple OSS Distributions 	int error;
272*5c2921b0SApple OSS Distributions 
273*5c2921b0SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
274*5c2921b0SApple OSS Distributions 	/* 21167099 - only check if we allow write */
275*5c2921b0SApple OSS Distributions 	if (!mac_socket_enforce) {
276*5c2921b0SApple OSS Distributions 		return 0;
277*5c2921b0SApple OSS Distributions 	}
278*5c2921b0SApple OSS Distributions #endif
279*5c2921b0SApple OSS Distributions 
280*5c2921b0SApple OSS Distributions 	MAC_CHECK(socket_check_send, cred,
281*5c2921b0SApple OSS Distributions 	    (socket_t)so, NULL, sockaddr);
282*5c2921b0SApple OSS Distributions 	return error;
283*5c2921b0SApple OSS Distributions }
284*5c2921b0SApple OSS Distributions 
285*5c2921b0SApple OSS Distributions int
mac_socket_check_setsockopt(kauth_cred_t cred,struct socket * so,struct sockopt * sopt)286*5c2921b0SApple OSS Distributions mac_socket_check_setsockopt(kauth_cred_t cred, struct socket *so,
287*5c2921b0SApple OSS Distributions     struct sockopt *sopt)
288*5c2921b0SApple OSS Distributions {
289*5c2921b0SApple OSS Distributions 	int error;
290*5c2921b0SApple OSS Distributions 
291*5c2921b0SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
292*5c2921b0SApple OSS Distributions 	/* 21167099 - only check if we allow write */
293*5c2921b0SApple OSS Distributions 	if (!mac_socket_enforce) {
294*5c2921b0SApple OSS Distributions 		return 0;
295*5c2921b0SApple OSS Distributions 	}
296*5c2921b0SApple OSS Distributions #endif
297*5c2921b0SApple OSS Distributions 
298*5c2921b0SApple OSS Distributions 	MAC_CHECK(socket_check_setsockopt, cred,
299*5c2921b0SApple OSS Distributions 	    (socket_t)so, NULL, sopt);
300*5c2921b0SApple OSS Distributions 	return error;
301*5c2921b0SApple OSS Distributions }
302*5c2921b0SApple OSS Distributions 
303*5c2921b0SApple OSS Distributions int
mac_socket_check_getsockopt(kauth_cred_t cred,struct socket * so,struct sockopt * sopt)304*5c2921b0SApple OSS Distributions mac_socket_check_getsockopt(kauth_cred_t cred, struct socket *so,
305*5c2921b0SApple OSS Distributions     struct sockopt *sopt)
306*5c2921b0SApple OSS Distributions {
307*5c2921b0SApple OSS Distributions 	int error;
308*5c2921b0SApple OSS Distributions 
309*5c2921b0SApple OSS Distributions #if SECURITY_MAC_CHECK_ENFORCE
310*5c2921b0SApple OSS Distributions 	/* 21167099 - only check if we allow write */
311*5c2921b0SApple OSS Distributions 	if (!mac_socket_enforce) {
312*5c2921b0SApple OSS Distributions 		return 0;
313*5c2921b0SApple OSS Distributions 	}
314*5c2921b0SApple OSS Distributions #endif
315*5c2921b0SApple OSS Distributions 
316*5c2921b0SApple OSS Distributions 	MAC_CHECK(socket_check_getsockopt, cred,
317*5c2921b0SApple OSS Distributions 	    (socket_t)so, NULL, sopt);
318*5c2921b0SApple OSS Distributions 	return error;
319*5c2921b0SApple OSS Distributions }
320