mac_sysv_msg.c revision 172930
1/*- 2 * Copyright (c) 2003-2004 Networks Associates Technology, Inc. 3 * Copyright (c) 2006 SPARTA, Inc. 4 * All rights reserved. 5 * 6 * This software was developed for the FreeBSD Project in part by Network 7 * Associates Laboratories, the Security Research Division of Network 8 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), 9 * as part of the DARPA CHATS research program. 10 * 11 * This software was enhanced by SPARTA ISSO under SPAWAR contract 12 * N66001-04-C-6019 ("SEFOS"). 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36#include <sys/cdefs.h> 37__FBSDID("$FreeBSD: head/sys/security/mac/mac_sysv_msg.c 172930 2007-10-24 19:04:04Z rwatson $"); 38 39#include "opt_mac.h" 40 41#include <sys/param.h> 42#include <sys/kernel.h> 43#include <sys/lock.h> 44#include <sys/malloc.h> 45#include <sys/mutex.h> 46#include <sys/sbuf.h> 47#include <sys/systm.h> 48#include <sys/vnode.h> 49#include <sys/mount.h> 50#include <sys/file.h> 51#include <sys/namei.h> 52#include <sys/sysctl.h> 53#include <sys/msg.h> 54 55#include <security/mac/mac_framework.h> 56#include <security/mac/mac_internal.h> 57#include <security/mac/mac_policy.h> 58 59static struct label * 60mac_sysv_msgmsg_label_alloc(void) 61{ 62 struct label *label; 63 64 label = mac_labelzone_alloc(M_WAITOK); 65 MAC_PERFORM(sysvmsg_init_label, label); 66 return (label); 67} 68 69void 70mac_sysvmsg_init(struct msg *msgptr) 71{ 72 73 msgptr->label = mac_sysv_msgmsg_label_alloc(); 74} 75 76static struct label * 77mac_sysv_msgqueue_label_alloc(void) 78{ 79 struct label *label; 80 81 label = mac_labelzone_alloc(M_WAITOK); 82 MAC_PERFORM(sysvmsq_init_label, label); 83 return (label); 84} 85 86void 87mac_sysvmsq_init(struct msqid_kernel *msqkptr) 88{ 89 90 msqkptr->label = mac_sysv_msgqueue_label_alloc(); 91} 92 93static void 94mac_sysv_msgmsg_label_free(struct label *label) 95{ 96 97 MAC_PERFORM(sysvmsg_destroy_label, label); 98 mac_labelzone_free(label); 99} 100 101void 102mac_sysvmsg_destroy(struct msg *msgptr) 103{ 104 105 mac_sysv_msgmsg_label_free(msgptr->label); 106 msgptr->label = NULL; 107} 108 109static void 110mac_sysv_msgqueue_label_free(struct label *label) 111{ 112 113 MAC_PERFORM(sysvmsq_destroy_label, label); 114 mac_labelzone_free(label); 115} 116 117void 118mac_sysvmsq_destroy(struct msqid_kernel *msqkptr) 119{ 120 121 mac_sysv_msgqueue_label_free(msqkptr->label); 122 msqkptr->label = NULL; 123} 124 125void 126mac_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr, 127 struct msg *msgptr) 128{ 129 130 MAC_PERFORM(sysvmsg_create, cred, msqkptr, msqkptr->label, 131 msgptr, msgptr->label); 132} 133 134void 135mac_sysvmsq_create(struct ucred *cred, struct msqid_kernel *msqkptr) 136{ 137 138 MAC_PERFORM(sysvmsq_create, cred, msqkptr, msqkptr->label); 139} 140 141void 142mac_sysvmsg_cleanup(struct msg *msgptr) 143{ 144 145 MAC_PERFORM(sysvmsg_cleanup, msgptr->label); 146} 147 148void 149mac_sysvmsq_cleanup(struct msqid_kernel *msqkptr) 150{ 151 152 MAC_PERFORM(sysvmsq_cleanup, msqkptr->label); 153} 154 155int 156mac_sysvmsq_check_msgmsq(struct ucred *cred, struct msg *msgptr, 157 struct msqid_kernel *msqkptr) 158{ 159 int error; 160 161 MAC_CHECK(sysvmsq_check_msgmsq, cred, msgptr, msgptr->label, 162 msqkptr, msqkptr->label); 163 164 return (error); 165} 166 167int 168mac_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr) 169{ 170 int error; 171 172 MAC_CHECK(sysvmsq_check_msgrcv, cred, msgptr, msgptr->label); 173 174 return (error); 175} 176 177int 178mac_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr) 179{ 180 int error; 181 182 MAC_CHECK(sysvmsq_check_msgrmid, cred, msgptr, msgptr->label); 183 184 return (error); 185} 186 187int 188mac_sysvmsq_check_msqget(struct ucred *cred, struct msqid_kernel *msqkptr) 189{ 190 int error; 191 192 MAC_CHECK(sysvmsq_check_msqget, cred, msqkptr, msqkptr->label); 193 194 return (error); 195} 196 197int 198mac_sysvmsq_check_msqsnd(struct ucred *cred, struct msqid_kernel *msqkptr) 199{ 200 int error; 201 202 MAC_CHECK(sysvmsq_check_msqsnd, cred, msqkptr, msqkptr->label); 203 204 return (error); 205} 206 207int 208mac_sysvmsq_check_msqrcv(struct ucred *cred, struct msqid_kernel *msqkptr) 209{ 210 int error; 211 212 MAC_CHECK(sysvmsq_check_msqrcv, cred, msqkptr, msqkptr->label); 213 214 return (error); 215} 216 217int 218mac_sysvmsq_check_msqctl(struct ucred *cred, struct msqid_kernel *msqkptr, 219 int cmd) 220{ 221 int error; 222 223 MAC_CHECK(sysvmsq_check_msqctl, cred, msqkptr, msqkptr->label, cmd); 224 225 return (error); 226} 227