2 * Copyright (c) 2003-2004 Networks Associates Technology, Inc.
3 * Copyright (c) 2006 SPARTA, Inc.
4 * Copyright (c) 2008 Apple Inc.
5 * Copyright (c) 2009 Robert N. M. Watson
8 * This software was developed for the FreeBSD Project in part by Network
9 * Associates Laboratories, the Security Research Division of Network
10 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
11 * as part of the DARPA CHATS research program.
13 * This software was enhanced by SPARTA ISSO under SPAWAR contract
14 * N66001-04-C-6019 ("SEFOS").
16 * This software was developed at the University of Cambridge Computer
17 * Laboratory with support from a grant from Google, Inc.
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
22 * 1. Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 * 2. Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution.
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
44 #include "opt_kdtrace.h"
47 #include <sys/param.h>
48 #include <sys/kernel.h>
50 #include <sys/malloc.h>
51 #include <sys/mutex.h>
54 #include <sys/systm.h>
55 #include <sys/vnode.h>
56 #include <sys/mount.h>
58 #include <sys/namei.h>
59 #include <sys/sysctl.h>
62 #include <security/mac/mac_framework.h>
63 #include <security/mac/mac_internal.h>
64 #include <security/mac/mac_policy.h>
67 mac_sysv_msgmsg_label_alloc(void)
71 label = mac_labelzone_alloc(M_WAITOK);
72 MAC_POLICY_PERFORM(sysvmsg_init_label, label);
77 mac_sysvmsg_init(struct msg *msgptr)
80 if (mac_labeled & MPC_OBJECT_SYSVMSG)
81 msgptr->label = mac_sysv_msgmsg_label_alloc();
87 mac_sysv_msgqueue_label_alloc(void)
91 label = mac_labelzone_alloc(M_WAITOK);
92 MAC_POLICY_PERFORM(sysvmsq_init_label, label);
97 mac_sysvmsq_init(struct msqid_kernel *msqkptr)
100 if (mac_labeled & MPC_OBJECT_SYSVMSQ)
101 msqkptr->label = mac_sysv_msgqueue_label_alloc();
103 msqkptr->label = NULL;
107 mac_sysv_msgmsg_label_free(struct label *label)
110 MAC_POLICY_PERFORM_NOSLEEP(sysvmsg_destroy_label, label);
111 mac_labelzone_free(label);
115 mac_sysvmsg_destroy(struct msg *msgptr)
118 if (msgptr->label != NULL) {
119 mac_sysv_msgmsg_label_free(msgptr->label);
120 msgptr->label = NULL;
125 mac_sysv_msgqueue_label_free(struct label *label)
128 MAC_POLICY_PERFORM_NOSLEEP(sysvmsq_destroy_label, label);
129 mac_labelzone_free(label);
133 mac_sysvmsq_destroy(struct msqid_kernel *msqkptr)
136 if (msqkptr->label != NULL) {
137 mac_sysv_msgqueue_label_free(msqkptr->label);
138 msqkptr->label = NULL;
143 mac_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr,
147 MAC_POLICY_PERFORM_NOSLEEP(sysvmsg_create, cred, msqkptr,
148 msqkptr->label, msgptr, msgptr->label);
152 mac_sysvmsq_create(struct ucred *cred, struct msqid_kernel *msqkptr)
155 MAC_POLICY_PERFORM_NOSLEEP(sysvmsq_create, cred, msqkptr,
160 mac_sysvmsg_cleanup(struct msg *msgptr)
163 MAC_POLICY_PERFORM_NOSLEEP(sysvmsg_cleanup, msgptr->label);
167 mac_sysvmsq_cleanup(struct msqid_kernel *msqkptr)
170 MAC_POLICY_PERFORM_NOSLEEP(sysvmsq_cleanup, msqkptr->label);
173 MAC_CHECK_PROBE_DEFINE3(sysvmsq_check_msgmsq, "struct ucred *",
174 "struct msg *", "struct msqid_kernel *");
177 mac_sysvmsq_check_msgmsq(struct ucred *cred, struct msg *msgptr,
178 struct msqid_kernel *msqkptr)
182 MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msgmsq, cred, msgptr,
183 msgptr->label, msqkptr, msqkptr->label);
184 MAC_CHECK_PROBE3(sysvmsq_check_msgmsq, error, cred, msgptr, msqkptr);
189 MAC_CHECK_PROBE_DEFINE2(sysvmsq_check_msgrcv, "struct ucred *",
193 mac_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr)
197 MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msgrcv, cred, msgptr,
199 MAC_CHECK_PROBE2(sysvmsq_check_msgrcv, error, cred, msgptr);
204 MAC_CHECK_PROBE_DEFINE2(sysvmsq_check_msgrmid, "struct ucred *",
208 mac_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr)
212 MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msgrmid, cred, msgptr,
214 MAC_CHECK_PROBE2(sysvmsq_check_msgrmid, error, cred, msgptr);
219 MAC_CHECK_PROBE_DEFINE2(sysvmsq_check_msqget, "struct ucred *",
220 "struct msqid_kernel *");
223 mac_sysvmsq_check_msqget(struct ucred *cred, struct msqid_kernel *msqkptr)
227 MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msqget, cred, msqkptr,
229 MAC_CHECK_PROBE2(sysvmsq_check_msqget, error, cred, msqkptr);
234 MAC_CHECK_PROBE_DEFINE2(sysvmsq_check_msqsnd, "struct ucred *",
235 "struct msqid_kernel *");
238 mac_sysvmsq_check_msqsnd(struct ucred *cred, struct msqid_kernel *msqkptr)
242 MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msqsnd, cred, msqkptr,
244 MAC_CHECK_PROBE2(sysvmsq_check_msqsnd, error, cred, msqkptr);
249 MAC_CHECK_PROBE_DEFINE2(sysvmsq_check_msqrcv, "struct ucred *",
250 "struct msqid_kernel *");
253 mac_sysvmsq_check_msqrcv(struct ucred *cred, struct msqid_kernel *msqkptr)
257 MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msqrcv, cred, msqkptr,
259 MAC_CHECK_PROBE2(sysvmsq_check_msqrcv, error, cred, msqkptr);
264 MAC_CHECK_PROBE_DEFINE3(sysvmsq_check_msqctl, "struct ucred *",
265 "struct msqid_kernel *", "int");
268 mac_sysvmsq_check_msqctl(struct ucred *cred, struct msqid_kernel *msqkptr,
273 MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msqctl, cred, msqkptr,
274 msqkptr->label, cmd);
275 MAC_CHECK_PROBE3(sysvmsq_check_msqctl, error, cred, msqkptr, cmd);