mac_label.c revision 136773
11694Sdarrenm/*- 21694Sdarrenm * Copyright (c) 2003-2004 Networks Associates Technology, Inc. 31694Sdarrenm * All rights reserved. 41694Sdarrenm * 51694Sdarrenm * This software was developed for the FreeBSD Project in part by Network 61694Sdarrenm * Associates Laboratories, the Security Research Division of Network 71694Sdarrenm * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), 81694Sdarrenm * as part of the DARPA CHATS research program. 91694Sdarrenm * 101694Sdarrenm * Redistribution and use in source and binary forms, with or without 111694Sdarrenm * modification, are permitted provided that the following conditions 121694Sdarrenm * are met: 131694Sdarrenm * 1. Redistributions of source code must retain the above copyright 141694Sdarrenm * notice, this list of conditions and the following disclaimer. 151694Sdarrenm * 2. Redistributions in binary form must reproduce the above copyright 161694Sdarrenm * notice, this list of conditions and the following disclaimer in the 171694Sdarrenm * documentation and/or other materials provided with the distribution. 181694Sdarrenm * 191694Sdarrenm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 201694Sdarrenm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2112719SRod.Evans@Sun.COM * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 221694Sdarrenm * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2312719SRod.Evans@Sun.COM * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 241694Sdarrenm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 251694Sdarrenm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2612719SRod.Evans@Sun.COM * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 271694Sdarrenm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2812719SRod.Evans@Sun.COM * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 291694Sdarrenm * SUCH DAMAGE. 3012719SRod.Evans@Sun.COM */ 311694Sdarrenm 321694Sdarrenm#include <sys/cdefs.h> 331694Sdarrenm__FBSDID("$FreeBSD: head/sys/security/mac/mac_label.c 136773 2004-10-22 11:08:52Z rwatson $"); 341694Sdarrenm 351694Sdarrenm#include "opt_mac.h" 361694Sdarrenm 371694Sdarrenm#include <sys/param.h> 381694Sdarrenm#include <sys/mac.h> 391694Sdarrenm#include <sys/sysctl.h> 401694Sdarrenm#include <sys/systm.h> 411694Sdarrenm 421694Sdarrenm#include <vm/uma.h> 4312719SRod.Evans@Sun.COM 441694Sdarrenm#include <security/mac/mac_internal.h> 4512719SRod.Evans@Sun.COM 4612719SRod.Evans@Sun.COMuma_zone_t zone_label; 471694Sdarrenm 481694Sdarrenmstatic int mac_labelzone_ctor(void *mem, int size, void *arg, int flags); 491694Sdarrenmstatic void mac_labelzone_dtor(void *mem, int size, void *arg); 501694Sdarrenm 511694Sdarrenmvoid 5212719SRod.Evans@Sun.COMmac_labelzone_init(void) 5312719SRod.Evans@Sun.COM{ 5412719SRod.Evans@Sun.COM 5512719SRod.Evans@Sun.COM zone_label = uma_zcreate("MAC labels", sizeof(struct label), 561694Sdarrenm mac_labelzone_ctor, mac_labelzone_dtor, NULL, NULL, 571694Sdarrenm UMA_ALIGN_PTR, 0); 5812719SRod.Evans@Sun.COM} 59 60static int 61mac_labelzone_ctor(void *mem, int size, void *arg, int flags) 62{ 63 struct label *label; 64 65 KASSERT(size == sizeof(*label), ("mac_labelzone_ctor: wrong size\n")); 66 label = mem; 67 bzero(label, sizeof(*label)); 68 label->l_flags = MAC_FLAG_INITIALIZED; 69 return (0); 70} 71 72static void 73mac_labelzone_dtor(void *mem, int size, void *arg) 74{ 75 struct label *label; 76 77 KASSERT(size == sizeof(*label), ("mac_labelzone_dtor: wrong size\n")); 78 label = mem; 79 KASSERT(label->l_flags & MAC_FLAG_INITIALIZED, 80 ("mac_labelzone_dtor: label not initialized")); 81#ifdef DIAGNOSTIC 82 bzero(label, sizeof(*label)); 83#else 84 label->l_flags &= ~MAC_FLAG_INITIALIZED; 85#endif 86} 87 88struct label * 89mac_labelzone_alloc(int flags) 90{ 91 92 return (uma_zalloc(zone_label, flags)); 93} 94 95void 96mac_labelzone_free(struct label *label) 97{ 98 99 uma_zfree(zone_label, label); 100} 101