mac_label.c revision 122524
1122524Srwatson/*- 2122524Srwatson * Copyright (c) 2003 Networks Associates Technology, Inc. 3122524Srwatson * All rights reserved. 4122524Srwatson * 5122524Srwatson * This software was developed for the FreeBSD Project in part by Network 6122524Srwatson * Associates Laboratories, the Security Research Division of Network 7122524Srwatson * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), 8122524Srwatson * as part of the DARPA CHATS research program. 9122524Srwatson * 10122524Srwatson * Redistribution and use in source and binary forms, with or without 11122524Srwatson * modification, are permitted provided that the following conditions 12122524Srwatson * are met: 13122524Srwatson * 1. Redistributions of source code must retain the above copyright 14122524Srwatson * notice, this list of conditions and the following disclaimer. 15122524Srwatson * 2. Redistributions in binary form must reproduce the above copyright 16122524Srwatson * notice, this list of conditions and the following disclaimer in the 17122524Srwatson * documentation and/or other materials provided with the distribution. 18122524Srwatson * 19122524Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20122524Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21122524Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22122524Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23122524Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24122524Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25122524Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26122524Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27122524Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28122524Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29122524Srwatson * SUCH DAMAGE. 30122524Srwatson */ 31122524Srwatson 32122524Srwatson#include <sys/cdefs.h> 33122524Srwatson__FBSDID("$FreeBSD: head/sys/security/mac/mac_label.c 122524 2003-11-12 03:14:31Z rwatson $"); 34122524Srwatson 35122524Srwatson#include "opt_mac.h" 36122524Srwatson 37122524Srwatson#include <sys/param.h> 38122524Srwatson#include <sys/mac.h> 39122524Srwatson#include <sys/sysctl.h> 40122524Srwatson#include <sys/systm.h> 41122524Srwatson 42122524Srwatson#include <vm/uma.h> 43122524Srwatson 44122524Srwatson#include <security/mac/mac_internal.h> 45122524Srwatson 46122524Srwatsonuma_zone_t zone_label; 47122524Srwatson 48122524Srwatsonstatic void mac_labelzone_ctor(void *mem, int size, void *arg); 49122524Srwatsonstatic void mac_labelzone_dtor(void *mem, int size, void *arg); 50122524Srwatson 51122524Srwatsonvoid 52122524Srwatsonmac_labelzone_init(void) 53122524Srwatson{ 54122524Srwatson 55122524Srwatson zone_label = uma_zcreate("MAC labels", sizeof(struct label), 56122524Srwatson mac_labelzone_ctor, mac_labelzone_dtor, NULL, NULL, 57122524Srwatson UMA_ALIGN_PTR, 0); 58122524Srwatson} 59122524Srwatson 60122524Srwatsonstatic void 61122524Srwatsonmac_labelzone_ctor(void *mem, int size, void *arg) 62122524Srwatson{ 63122524Srwatson struct label *label; 64122524Srwatson 65122524Srwatson KASSERT(size == sizeof(*label), ("mac_labelzone_ctor: wrong size\n")); 66122524Srwatson label = mem; 67122524Srwatson bzero(label, sizeof(*label)); 68122524Srwatson label->l_flags = MAC_FLAG_INITIALIZED; 69122524Srwatson} 70122524Srwatson 71122524Srwatsonstatic void 72122524Srwatsonmac_labelzone_dtor(void *mem, int size, void *arg) 73122524Srwatson{ 74122524Srwatson struct label *label; 75122524Srwatson 76122524Srwatson KASSERT(size == sizeof(*label), ("mac_labelzone_dtor: wrong size\n")); 77122524Srwatson label = mem; 78122524Srwatson#ifdef DIAGNOSTIC 79122524Srwatson bzero(label, sizeof(*label)); 80122524Srwatson#else 81122524Srwatson label->l_flags &= ~MAC_FLAG_INITIALIZED; 82122524Srwatson#endif 83122524Srwatson} 84122524Srwatson 85122524Srwatsonstruct label * 86122524Srwatsonmac_labelzone_alloc(int flags) 87122524Srwatson{ 88122524Srwatson 89122524Srwatson return (uma_zalloc(zone_label, flags)); 90122524Srwatson} 91122524Srwatson 92122524Srwatsonvoid 93122524Srwatsonmac_labelzone_free(struct label *label) 94122524Srwatson{ 95122524Srwatson 96122524Srwatson uma_zfree(zone_label, label); 97122524Srwatson} 98