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