mac_sysv_msg.c revision 165434
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 165434 2006-12-21 09:58:02Z 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 52137817Srwatson#include <sys/mac_policy.h> 53137817Srwatson 54163606Srwatson#include <security/mac/mac_framework.h> 55137817Srwatson#include <security/mac/mac_internal.h> 56137817Srwatson 57137817Srwatsonstatic struct label * 58137817Srwatsonmac_sysv_msgmsg_label_alloc(void) 59137817Srwatson{ 60137817Srwatson struct label *label; 61137817Srwatson 62137817Srwatson label = mac_labelzone_alloc(M_WAITOK); 63137817Srwatson MAC_PERFORM(init_sysv_msgmsg_label, label); 64137817Srwatson return (label); 65137817Srwatson} 66137817Srwatson 67137817Srwatsonvoid 68137817Srwatsonmac_init_sysv_msgmsg(struct msg *msgptr) 69137817Srwatson{ 70137817Srwatson 71137817Srwatson msgptr->label = mac_sysv_msgmsg_label_alloc(); 72137817Srwatson} 73137817Srwatson 74137817Srwatsonstatic struct label * 75137817Srwatsonmac_sysv_msgqueue_label_alloc(void) 76137817Srwatson{ 77137817Srwatson struct label *label; 78137817Srwatson 79137817Srwatson label = mac_labelzone_alloc(M_WAITOK); 80137817Srwatson MAC_PERFORM(init_sysv_msgqueue_label, label); 81137817Srwatson return (label); 82137817Srwatson} 83137817Srwatson 84137817Srwatsonvoid 85137817Srwatsonmac_init_sysv_msgqueue(struct msqid_kernel *msqkptr) 86137817Srwatson{ 87137817Srwatson 88137817Srwatson msqkptr->label = mac_sysv_msgqueue_label_alloc(); 89137817Srwatson} 90137817Srwatson 91137817Srwatsonstatic void 92137817Srwatsonmac_sysv_msgmsg_label_free(struct label *label) 93137817Srwatson{ 94137817Srwatson 95137817Srwatson MAC_PERFORM(destroy_sysv_msgmsg_label, label); 96137817Srwatson mac_labelzone_free(label); 97137817Srwatson} 98137817Srwatson 99137817Srwatsonvoid 100137817Srwatsonmac_destroy_sysv_msgmsg(struct msg *msgptr) 101137817Srwatson{ 102137817Srwatson 103137817Srwatson mac_sysv_msgmsg_label_free(msgptr->label); 104137817Srwatson msgptr->label = NULL; 105137817Srwatson} 106137817Srwatson 107137817Srwatsonstatic void 108137817Srwatsonmac_sysv_msgqueue_label_free(struct label *label) 109137817Srwatson{ 110137817Srwatson 111137817Srwatson MAC_PERFORM(destroy_sysv_msgqueue_label, label); 112137817Srwatson mac_labelzone_free(label); 113137817Srwatson} 114137817Srwatson 115137817Srwatsonvoid 116137817Srwatsonmac_destroy_sysv_msgqueue(struct msqid_kernel *msqkptr) 117137817Srwatson{ 118137817Srwatson 119137817Srwatson mac_sysv_msgqueue_label_free(msqkptr->label); 120137817Srwatson msqkptr->label = NULL; 121137817Srwatson} 122137817Srwatson 123137817Srwatsonvoid 124165427Srwatsonmac_create_sysv_msgmsg(struct ucred *cred, struct msqid_kernel *msqkptr, 125137817Srwatson struct msg *msgptr) 126137817Srwatson{ 127165427Srwatson 128165427Srwatson MAC_PERFORM(create_sysv_msgmsg, cred, msqkptr, msqkptr->label, 129137817Srwatson msgptr, msgptr->label); 130137817Srwatson} 131137817Srwatson 132137817Srwatsonvoid 133137817Srwatsonmac_create_sysv_msgqueue(struct ucred *cred, struct msqid_kernel *msqkptr) 134137817Srwatson{ 135165427Srwatson 136137817Srwatson MAC_PERFORM(create_sysv_msgqueue, cred, msqkptr, msqkptr->label); 137137817Srwatson} 138137817Srwatson 139137817Srwatsonvoid 140137817Srwatsonmac_cleanup_sysv_msgmsg(struct msg *msgptr) 141137817Srwatson{ 142137817Srwatson 143137817Srwatson MAC_PERFORM(cleanup_sysv_msgmsg, msgptr->label); 144137817Srwatson} 145137817Srwatson 146137817Srwatsonvoid 147137817Srwatsonmac_cleanup_sysv_msgqueue(struct msqid_kernel *msqkptr) 148137817Srwatson{ 149165427Srwatson 150137817Srwatson MAC_PERFORM(cleanup_sysv_msgqueue, msqkptr->label); 151137817Srwatson} 152137817Srwatson 153137817Srwatsonint 154137817Srwatsonmac_check_sysv_msgmsq(struct ucred *cred, struct msg *msgptr, 155137817Srwatson struct msqid_kernel *msqkptr) 156137817Srwatson{ 157137817Srwatson int error; 158137817Srwatson 159137817Srwatson MAC_CHECK(check_sysv_msgmsq, cred, msgptr, msgptr->label, msqkptr, 160137817Srwatson msqkptr->label); 161137817Srwatson 162165434Srwatson return (error); 163137817Srwatson} 164137817Srwatson 165137817Srwatsonint 166137817Srwatsonmac_check_sysv_msgrcv(struct ucred *cred, struct msg *msgptr) 167137817Srwatson{ 168137817Srwatson int error; 169137817Srwatson 170137817Srwatson MAC_CHECK(check_sysv_msgrcv, cred, msgptr, msgptr->label); 171137817Srwatson 172165434Srwatson return (error); 173137817Srwatson} 174137817Srwatson 175137817Srwatsonint 176137817Srwatsonmac_check_sysv_msgrmid(struct ucred *cred, struct msg *msgptr) 177137817Srwatson{ 178137817Srwatson int error; 179137817Srwatson 180137817Srwatson MAC_CHECK(check_sysv_msgrmid, cred, msgptr, msgptr->label); 181137817Srwatson 182165434Srwatson return (error); 183137817Srwatson} 184137817Srwatson 185137817Srwatsonint 186137817Srwatsonmac_check_sysv_msqget(struct ucred *cred, struct msqid_kernel *msqkptr) 187137817Srwatson{ 188137817Srwatson int error; 189137817Srwatson 190137817Srwatson MAC_CHECK(check_sysv_msqget, cred, msqkptr, msqkptr->label); 191137817Srwatson 192165434Srwatson return (error); 193137817Srwatson} 194137817Srwatson 195137817Srwatsonint 196137817Srwatsonmac_check_sysv_msqsnd(struct ucred *cred, struct msqid_kernel *msqkptr) 197137817Srwatson{ 198137817Srwatson int error; 199137817Srwatson 200137817Srwatson MAC_CHECK(check_sysv_msqsnd, cred, msqkptr, msqkptr->label); 201137817Srwatson 202165434Srwatson return (error); 203137817Srwatson} 204137817Srwatson 205137817Srwatsonint 206137817Srwatsonmac_check_sysv_msqrcv(struct ucred *cred, struct msqid_kernel *msqkptr) 207137817Srwatson{ 208137817Srwatson int error; 209137817Srwatson 210137817Srwatson MAC_CHECK(check_sysv_msqrcv, cred, msqkptr, msqkptr->label); 211137817Srwatson 212165434Srwatson return (error); 213137817Srwatson} 214137817Srwatson 215137817Srwatsonint 216137817Srwatsonmac_check_sysv_msqctl(struct ucred *cred, struct msqid_kernel *msqkptr, 217137817Srwatson int cmd) 218137817Srwatson{ 219137817Srwatson int error; 220137817Srwatson 221137817Srwatson MAC_CHECK(check_sysv_msqctl, cred, msqkptr, msqkptr->label, cmd); 222137817Srwatson 223165434Srwatson return (error); 224137817Srwatson} 225