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$"); 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/shm.h> 54 55 #include <security/mac/mac_framework.h> 56 #include <security/mac/mac_internal.h> 57 #include <security/mac/mac_policy.h> 58 59 static struct label * 60 mac_sysv_shm_label_alloc(void) 61 { 62 struct label *label; 63 64 label = mac_labelzone_alloc(M_WAITOK); 65 MAC_PERFORM(sysvshm_init_label, label); 66 return (label); 67 } 68 69 void 70 mac_sysvshm_init(struct shmid_kernel *shmsegptr) 71 { 72 73 if (mac_labeled & MPC_OBJECT_SYSVSHM) 74 shmsegptr->label = mac_sysv_shm_label_alloc(); 75 else 76 shmsegptr->label = NULL; 77 } 78 79 static void 80 mac_sysv_shm_label_free(struct label *label) 81 { 82 83 MAC_PERFORM(sysvshm_destroy_label, label); 84 mac_labelzone_free(label); 85 } 86 87 void 88 mac_sysvshm_destroy(struct shmid_kernel *shmsegptr) 89 { 90 91 if (shmsegptr->label != NULL) { 92 mac_sysv_shm_label_free(shmsegptr->label); 93 shmsegptr->label = NULL; 94 } 95 } 96 97 void 98 mac_sysvshm_create(struct ucred *cred, struct shmid_kernel *shmsegptr) 99 { 100 101 MAC_PERFORM(sysvshm_create, cred, shmsegptr, shmsegptr->label); 102 } 103 104 void 105 mac_sysvshm_cleanup(struct shmid_kernel *shmsegptr) 106 { 107 108 MAC_PERFORM(sysvshm_cleanup, shmsegptr->label); 109 } 110 111 int 112 mac_sysvshm_check_shmat(struct ucred *cred, struct shmid_kernel *shmsegptr, 113 int shmflg) 114 { 115 int error; 116 117 MAC_CHECK(sysvshm_check_shmat, cred, shmsegptr, shmsegptr->label, 118 shmflg); 119 120 return (error); 121 } 122 123 int 124 mac_sysvshm_check_shmctl(struct ucred *cred, struct shmid_kernel *shmsegptr, 125 int cmd) 126 { 127 int error; 128 129 MAC_CHECK(sysvshm_check_shmctl, cred, shmsegptr, shmsegptr->label, 130 cmd); 131 132 return (error); 133 } 134 135 int 136 mac_sysvshm_check_shmdt(struct ucred *cred, struct shmid_kernel *shmsegptr) 137 { 138 int error; 139 140 MAC_CHECK(sysvshm_check_shmdt, cred, shmsegptr, shmsegptr->label); 141 142 return (error); 143 } 144 145 int 146 mac_sysvshm_check_shmget(struct ucred *cred, struct shmid_kernel *shmsegptr, 147 int shmflg) 148 { 149 int error; 150 151 MAC_CHECK(sysvshm_check_shmget, cred, shmsegptr, shmsegptr->label, 152 shmflg); 153 154 return (error); 155 } 156