mac_sysv_msg.c revision 165469
1137817Srwatson/*- 2137817Srwatson * Copyright (c) 2003-2004 Networks Associates Technology, Inc. 3137817Srwatson * All rights reserved. 4137817Srwatson * 5137817Srwatson * This software was developed for the FreeBSD Project in part by Network 6137817Srwatson * Associates Laboratories, the Security Research Division of Network 7137817Srwatson * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), 8137817Srwatson * as part of the DARPA CHATS research program. 9137817Srwatson * 10137817Srwatson * Redistribution and use in source and binary forms, with or without 11137817Srwatson * modification, are permitted provided that the following conditions 12137817Srwatson * are met: 13137817Srwatson * 1. Redistributions of source code must retain the above copyright 14137817Srwatson * notice, this list of conditions and the following disclaimer. 15137817Srwatson * 2. Redistributions in binary form must reproduce the above copyright 16137817Srwatson * notice, this list of conditions and the following disclaimer in the 17137817Srwatson * documentation and/or other materials provided with the distribution. 18137817Srwatson * 19137817Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20137817Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21137817Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22137817Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23137817Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24137817Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25137817Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26137817Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27137817Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28137817Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29137817Srwatson * SUCH DAMAGE. 30137817Srwatson */ 31137817Srwatson 32137817Srwatson#include <sys/cdefs.h> 33137817Srwatson__FBSDID("$FreeBSD: head/sys/security/mac/mac_sysv_msg.c 165469 2006-12-22 23:34:47Z rwatson $"); 34137817Srwatson 35137817Srwatson#include "opt_mac.h" 36137817Srwatson 37137817Srwatson#include <sys/param.h> 38137817Srwatson#include <sys/kernel.h> 39137817Srwatson#include <sys/lock.h> 40137817Srwatson#include <sys/malloc.h> 41137817Srwatson#include <sys/mutex.h> 42137817Srwatson#include <sys/mac.h> 43137817Srwatson#include <sys/sbuf.h> 44137817Srwatson#include <sys/systm.h> 45137817Srwatson#include <sys/vnode.h> 46137817Srwatson#include <sys/mount.h> 47137817Srwatson#include <sys/file.h> 48137817Srwatson#include <sys/namei.h> 49137817Srwatson#include <sys/sysctl.h> 50137817Srwatson#include <sys/msg.h> 51137817Srwatson 52163606Srwatson#include <security/mac/mac_framework.h> 53137817Srwatson#include <security/mac/mac_internal.h> 54165469Srwatson#include <security/mac/mac_policy.h> 55137817Srwatson 56137817Srwatsonstatic struct label * 57137817Srwatsonmac_sysv_msgmsg_label_alloc(void) 58137817Srwatson{ 59137817Srwatson struct label *label; 60137817Srwatson 61137817Srwatson label = mac_labelzone_alloc(M_WAITOK); 62137817Srwatson MAC_PERFORM(init_sysv_msgmsg_label, label); 63137817Srwatson return (label); 64137817Srwatson} 65137817Srwatson 66137817Srwatsonvoid 67137817Srwatsonmac_init_sysv_msgmsg(struct msg *msgptr) 68137817Srwatson{ 69137817Srwatson 70137817Srwatson msgptr->label = mac_sysv_msgmsg_label_alloc(); 71137817Srwatson} 72137817Srwatson 73137817Srwatsonstatic struct label * 74137817Srwatsonmac_sysv_msgqueue_label_alloc(void) 75137817Srwatson{ 76137817Srwatson struct label *label; 77137817Srwatson 78137817Srwatson label = mac_labelzone_alloc(M_WAITOK); 79137817Srwatson MAC_PERFORM(init_sysv_msgqueue_label, label); 80137817Srwatson return (label); 81137817Srwatson} 82137817Srwatson 83137817Srwatsonvoid 84137817Srwatsonmac_init_sysv_msgqueue(struct msqid_kernel *msqkptr) 85137817Srwatson{ 86137817Srwatson 87137817Srwatson msqkptr->label = mac_sysv_msgqueue_label_alloc(); 88137817Srwatson} 89137817Srwatson 90137817Srwatsonstatic void 91137817Srwatsonmac_sysv_msgmsg_label_free(struct label *label) 92137817Srwatson{ 93137817Srwatson 94137817Srwatson MAC_PERFORM(destroy_sysv_msgmsg_label, label); 95137817Srwatson mac_labelzone_free(label); 96137817Srwatson} 97137817Srwatson 98137817Srwatsonvoid 99137817Srwatsonmac_destroy_sysv_msgmsg(struct msg *msgptr) 100137817Srwatson{ 101137817Srwatson 102137817Srwatson mac_sysv_msgmsg_label_free(msgptr->label); 103137817Srwatson msgptr->label = NULL; 104137817Srwatson} 105137817Srwatson 106137817Srwatsonstatic void 107137817Srwatsonmac_sysv_msgqueue_label_free(struct label *label) 108137817Srwatson{ 109137817Srwatson 110137817Srwatson MAC_PERFORM(destroy_sysv_msgqueue_label, label); 111137817Srwatson mac_labelzone_free(label); 112137817Srwatson} 113137817Srwatson 114137817Srwatsonvoid 115137817Srwatsonmac_destroy_sysv_msgqueue(struct msqid_kernel *msqkptr) 116137817Srwatson{ 117137817Srwatson 118137817Srwatson mac_sysv_msgqueue_label_free(msqkptr->label); 119137817Srwatson msqkptr->label = NULL; 120137817Srwatson} 121137817Srwatson 122137817Srwatsonvoid 123165427Srwatsonmac_create_sysv_msgmsg(struct ucred *cred, struct msqid_kernel *msqkptr, 124137817Srwatson struct msg *msgptr) 125137817Srwatson{ 126165427Srwatson 127165427Srwatson MAC_PERFORM(create_sysv_msgmsg, cred, msqkptr, msqkptr->label, 128137817Srwatson msgptr, msgptr->label); 129137817Srwatson} 130137817Srwatson 131137817Srwatsonvoid 132137817Srwatsonmac_create_sysv_msgqueue(struct ucred *cred, struct msqid_kernel *msqkptr) 133137817Srwatson{ 134165427Srwatson 135137817Srwatson MAC_PERFORM(create_sysv_msgqueue, cred, msqkptr, msqkptr->label); 136137817Srwatson} 137137817Srwatson 138137817Srwatsonvoid 139137817Srwatsonmac_cleanup_sysv_msgmsg(struct msg *msgptr) 140137817Srwatson{ 141137817Srwatson 142137817Srwatson MAC_PERFORM(cleanup_sysv_msgmsg, msgptr->label); 143137817Srwatson} 144137817Srwatson 145137817Srwatsonvoid 146137817Srwatsonmac_cleanup_sysv_msgqueue(struct msqid_kernel *msqkptr) 147137817Srwatson{ 148165427Srwatson 149137817Srwatson MAC_PERFORM(cleanup_sysv_msgqueue, msqkptr->label); 150137817Srwatson} 151137817Srwatson 152137817Srwatsonint 153137817Srwatsonmac_check_sysv_msgmsq(struct ucred *cred, struct msg *msgptr, 154137817Srwatson struct msqid_kernel *msqkptr) 155137817Srwatson{ 156137817Srwatson int error; 157137817Srwatson 158137817Srwatson MAC_CHECK(check_sysv_msgmsq, cred, msgptr, msgptr->label, msqkptr, 159137817Srwatson msqkptr->label); 160137817Srwatson 161165434Srwatson return (error); 162137817Srwatson} 163137817Srwatson 164137817Srwatsonint 165137817Srwatsonmac_check_sysv_msgrcv(struct ucred *cred, struct msg *msgptr) 166137817Srwatson{ 167137817Srwatson int error; 168137817Srwatson 169137817Srwatson MAC_CHECK(check_sysv_msgrcv, cred, msgptr, msgptr->label); 170137817Srwatson 171165434Srwatson return (error); 172137817Srwatson} 173137817Srwatson 174137817Srwatsonint 175137817Srwatsonmac_check_sysv_msgrmid(struct ucred *cred, struct msg *msgptr) 176137817Srwatson{ 177137817Srwatson int error; 178137817Srwatson 179137817Srwatson MAC_CHECK(check_sysv_msgrmid, cred, msgptr, msgptr->label); 180137817Srwatson 181165434Srwatson return (error); 182137817Srwatson} 183137817Srwatson 184137817Srwatsonint 185137817Srwatsonmac_check_sysv_msqget(struct ucred *cred, struct msqid_kernel *msqkptr) 186137817Srwatson{ 187137817Srwatson int error; 188137817Srwatson 189137817Srwatson MAC_CHECK(check_sysv_msqget, cred, msqkptr, msqkptr->label); 190137817Srwatson 191165434Srwatson return (error); 192137817Srwatson} 193137817Srwatson 194137817Srwatsonint 195137817Srwatsonmac_check_sysv_msqsnd(struct ucred *cred, struct msqid_kernel *msqkptr) 196137817Srwatson{ 197137817Srwatson int error; 198137817Srwatson 199137817Srwatson MAC_CHECK(check_sysv_msqsnd, cred, msqkptr, msqkptr->label); 200137817Srwatson 201165434Srwatson return (error); 202137817Srwatson} 203137817Srwatson 204137817Srwatsonint 205137817Srwatsonmac_check_sysv_msqrcv(struct ucred *cred, struct msqid_kernel *msqkptr) 206137817Srwatson{ 207137817Srwatson int error; 208137817Srwatson 209137817Srwatson MAC_CHECK(check_sysv_msqrcv, cred, msqkptr, msqkptr->label); 210137817Srwatson 211165434Srwatson return (error); 212137817Srwatson} 213137817Srwatson 214137817Srwatsonint 215137817Srwatsonmac_check_sysv_msqctl(struct ucred *cred, struct msqid_kernel *msqkptr, 216137817Srwatson int cmd) 217137817Srwatson{ 218137817Srwatson int error; 219137817Srwatson 220137817Srwatson MAC_CHECK(check_sysv_msqctl, cred, msqkptr, msqkptr->label, cmd); 221137817Srwatson 222165434Srwatson return (error); 223137817Srwatson} 224