]>
git.saurik.com Git - apple/xnu.git/blob - security/mac_socket.c
2 * Copyright (c) 2007-2012 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1999-2002 Robert N. M. Watson
30 * Copyright (c) 2001 Ilmar S. Habibulin
31 * Copyright (c) 2001-2005 Networks Associates Technology, Inc.
32 * Copyright (c) 2005 SPARTA, Inc.
33 * All rights reserved.
35 * This software was developed by Robert Watson and Ilmar Habibulin for the
38 * This software was developed for the FreeBSD Project in part by McAfee
39 * Research, the Technology Research Division of Network Associates, Inc.
40 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
41 * DARPA CHATS research program.
43 * This software was enhanced by SPARTA ISSO under SPAWAR contract
44 * N66001-04-C-6019 ("SEFOS").
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
55 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 #include <sys/cdefs.h>
70 #include <sys/param.h>
71 #include <sys/kernel.h>
73 #include <sys/malloc.h>
75 #include <sys/systm.h>
76 #include <sys/mount.h>
78 #include <sys/namei.h>
79 #include <sys/protosw.h>
80 #include <sys/socket.h>
81 #include <sys/socketvar.h>
82 #include <sys/sysctl.h>
83 #include <sys/kpi_socket.h>
85 #include <security/mac_internal.h>
88 mac_socket_check_accept(kauth_cred_t cred
, struct socket
*so
)
92 #if SECURITY_MAC_CHECK_ENFORCE
93 /* 21167099 - only check if we allow write */
94 if (!mac_socket_enforce
) {
99 MAC_CHECK(socket_check_accept
, cred
,
100 (socket_t
)so
, so
->so_label
);
104 #if CONFIG_MACF_SOCKET_SUBSET
106 mac_socket_check_accepted(kauth_cred_t cred
, struct socket
*so
)
108 struct sockaddr
*sockaddr
;
111 #if SECURITY_MAC_CHECK_ENFORCE
112 /* 21167099 - only check if we allow write */
113 if (!mac_socket_enforce
) {
118 if (sock_getaddr((socket_t
)so
, &sockaddr
, 1) != 0) {
119 error
= ECONNABORTED
;
121 MAC_CHECK(socket_check_accepted
, cred
,
122 (socket_t
)so
, so
->so_label
, sockaddr
);
123 sock_freeaddr(sockaddr
);
130 mac_socket_check_bind(kauth_cred_t ucred
, struct socket
*so
,
131 struct sockaddr
*sockaddr
)
135 #if SECURITY_MAC_CHECK_ENFORCE
136 /* 21167099 - only check if we allow write */
137 if (!mac_socket_enforce
) {
142 MAC_CHECK(socket_check_bind
, ucred
,
143 (socket_t
)so
, so
->so_label
, sockaddr
);
148 mac_socket_check_connect(kauth_cred_t cred
, struct socket
*so
,
149 struct sockaddr
*sockaddr
)
153 #if SECURITY_MAC_CHECK_ENFORCE
154 /* 21167099 - only check if we allow write */
155 if (!mac_socket_enforce
) {
160 MAC_CHECK(socket_check_connect
, cred
,
161 (socket_t
)so
, so
->so_label
,
167 mac_socket_check_create(kauth_cred_t cred
, int domain
, int type
, int protocol
)
171 #if SECURITY_MAC_CHECK_ENFORCE
172 /* 21167099 - only check if we allow write */
173 if (!mac_socket_enforce
) {
178 MAC_CHECK(socket_check_create
, cred
, domain
, type
, protocol
);
183 mac_socket_check_ioctl(kauth_cred_t cred
, struct socket
*so
, u_long cmd
)
187 #if SECURITY_MAC_CHECK_ENFORCE
188 /* 21167099 - only check if we allow write */
189 if (!mac_socket_enforce
) {
194 MAC_CHECK(socket_check_ioctl
, cred
,
195 (socket_t
)so
, cmd
, so
->so_label
);
200 mac_socket_check_stat(kauth_cred_t cred
, struct socket
*so
)
204 #if SECURITY_MAC_CHECK_ENFORCE
205 /* 21167099 - only check if we allow write */
206 if (!mac_socket_enforce
) {
211 MAC_CHECK(socket_check_stat
, cred
,
212 (socket_t
)so
, so
->so_label
);
217 mac_socket_check_listen(kauth_cred_t cred
, struct socket
*so
)
221 #if SECURITY_MAC_CHECK_ENFORCE
222 /* 21167099 - only check if we allow write */
223 if (!mac_socket_enforce
) {
228 MAC_CHECK(socket_check_listen
, cred
,
229 (socket_t
)so
, so
->so_label
);
234 mac_socket_check_receive(kauth_cred_t cred
, struct socket
*so
)
238 #if SECURITY_MAC_CHECK_ENFORCE
239 /* 21167099 - only check if we allow write */
240 if (!mac_socket_enforce
) {
245 MAC_CHECK(socket_check_receive
, cred
,
246 (socket_t
)so
, so
->so_label
);
251 mac_socket_check_received(kauth_cred_t cred
, struct socket
*so
, struct sockaddr
*saddr
)
255 #if SECURITY_MAC_CHECK_ENFORCE
256 /* 21167099 - only check if we allow write */
257 if (!mac_socket_enforce
) {
262 MAC_CHECK(socket_check_received
, cred
,
263 so
, so
->so_label
, saddr
);
268 mac_socket_check_send(kauth_cred_t cred
, struct socket
*so
,
269 struct sockaddr
*sockaddr
)
273 #if SECURITY_MAC_CHECK_ENFORCE
274 /* 21167099 - only check if we allow write */
275 if (!mac_socket_enforce
) {
280 MAC_CHECK(socket_check_send
, cred
,
281 (socket_t
)so
, so
->so_label
, sockaddr
);
286 mac_socket_check_setsockopt(kauth_cred_t cred
, struct socket
*so
,
287 struct sockopt
*sopt
)
291 #if SECURITY_MAC_CHECK_ENFORCE
292 /* 21167099 - only check if we allow write */
293 if (!mac_socket_enforce
) {
298 MAC_CHECK(socket_check_setsockopt
, cred
,
299 (socket_t
)so
, so
->so_label
, sopt
);
304 mac_socket_check_getsockopt(kauth_cred_t cred
, struct socket
*so
,
305 struct sockopt
*sopt
)
309 #if SECURITY_MAC_CHECK_ENFORCE
310 /* 21167099 - only check if we allow write */
311 if (!mac_socket_enforce
) {
316 MAC_CHECK(socket_check_getsockopt
, cred
,
317 (socket_t
)so
, so
->so_label
, sopt
);