/*-1* Copyright (c) 2003-2004 Networks Associates Technology, Inc.2* Copyright (c) 2006 SPARTA, Inc.3* Copyright (c) 2009 Robert N. M. Watson4* All rights reserved.5*6* This software was developed for the FreeBSD Project in part by Network7* Associates Laboratories, the Security Research Division of Network8* 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 contract12* N66001-04-C-6019 ("SEFOS").13*14* This software was developed at the University of Cambridge Computer15* Laboratory with support from a grant from Google, Inc.16*17* Redistribution and use in source and binary forms, with or without18* modification, are permitted provided that the following conditions19* are met:20* 1. Redistributions of source code must retain the above copyright21* notice, this list of conditions and the following disclaimer.22* 2. Redistributions in binary form must reproduce the above copyright23* notice, this list of conditions and the following disclaimer in the24* documentation and/or other materials provided with the distribution.25*26* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND27* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE28* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE29* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE30* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL31* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS32* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)33* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT34* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY35* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF36* SUCH DAMAGE.37*/3839#include <sys/cdefs.h>40#include "opt_mac.h"4142#include <sys/param.h>43#include <sys/kernel.h>44#include <sys/lock.h>45#include <sys/malloc.h>46#include <sys/mutex.h>47#include <sys/sbuf.h>48#include <sys/systm.h>49#include <sys/vnode.h>50#include <sys/mount.h>51#include <sys/file.h>52#include <sys/namei.h>53#include <sys/sdt.h>54#include <sys/sysctl.h>55#include <sys/sem.h>5657#include <security/mac/mac_framework.h>58#include <security/mac/mac_internal.h>59#include <security/mac/mac_policy.h>6061static struct label *62mac_sysv_sem_label_alloc(void)63{64struct label *label;6566label = mac_labelzone_alloc(M_WAITOK);67MAC_POLICY_PERFORM(sysvsem_init_label, label);68return (label);69}7071void72mac_sysvsem_init(struct semid_kernel *semakptr)73{7475if (mac_labeled & MPC_OBJECT_SYSVSEM)76semakptr->label = mac_sysv_sem_label_alloc();77else78semakptr->label = NULL;79}8081static void82mac_sysv_sem_label_free(struct label *label)83{8485MAC_POLICY_PERFORM_NOSLEEP(sysvsem_destroy_label, label);86mac_labelzone_free(label);87}8889void90mac_sysvsem_destroy(struct semid_kernel *semakptr)91{9293if (semakptr->label != NULL) {94mac_sysv_sem_label_free(semakptr->label);95semakptr->label = NULL;96}97}9899void100mac_sysvsem_create(struct ucred *cred, struct semid_kernel *semakptr)101{102103MAC_POLICY_PERFORM_NOSLEEP(sysvsem_create, cred, semakptr,104semakptr->label);105}106107void108mac_sysvsem_cleanup(struct semid_kernel *semakptr)109{110111MAC_POLICY_PERFORM_NOSLEEP(sysvsem_cleanup, semakptr->label);112}113114MAC_CHECK_PROBE_DEFINE3(sysvsem_check_semctl, "struct ucred *",115"struct semid_kernel *", "int");116117int118mac_sysvsem_check_semctl(struct ucred *cred, struct semid_kernel *semakptr,119int cmd)120{121int error;122123MAC_POLICY_CHECK_NOSLEEP(sysvsem_check_semctl, cred, semakptr,124semakptr->label, cmd);125MAC_CHECK_PROBE3(sysvsem_check_semctl, error, cred, semakptr, cmd);126127return (error);128}129130MAC_CHECK_PROBE_DEFINE2(sysvsem_check_semget, "struct ucred *",131"struct semid_kernel *");132133int134mac_sysvsem_check_semget(struct ucred *cred, struct semid_kernel *semakptr)135{136int error;137138MAC_POLICY_CHECK_NOSLEEP(sysvsem_check_semget, cred, semakptr,139semakptr->label);140141return (error);142}143144MAC_CHECK_PROBE_DEFINE3(sysvsem_check_semop, "struct ucred *",145"struct semid_kernel *", "size_t");146147int148mac_sysvsem_check_semop(struct ucred *cred, struct semid_kernel *semakptr,149size_t accesstype)150{151int error;152153MAC_POLICY_CHECK_NOSLEEP(sysvsem_check_semop, cred, semakptr,154semakptr->label, accesstype);155MAC_CHECK_PROBE3(sysvsem_check_semop, error, cred, semakptr,156accesstype);157158return (error);159}160161162