/*-1* Copyright (c) 2006 nCircle Network Security, Inc.2* Copyright (c) 2009 Robert N. M. Watson3* All rights reserved.4*5* This software was developed by Robert N. M. Watson for the TrustedBSD6* Project under contract to nCircle Network Security, Inc.7*8* This software was developed at the University of Cambridge Computer9* Laboratory with support from a grant from Google, Inc.10*11* Redistribution and use in source and binary forms, with or without12* modification, are permitted provided that the following conditions13* are met:14* 1. Redistributions of source code must retain the above copyright15* notice, this list of conditions and the following disclaimer.16* 2. Redistributions in binary form must reproduce the above copyright17* notice, this list of conditions and the following disclaimer in the18* documentation and/or other materials provided with the distribution.19*20* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, NCIRCLE NETWORK SECURITY,24* INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED26* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR27* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF28* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING29* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS30* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31*/3233/*34* MAC checks for system privileges.35*/3637#include "sys/cdefs.h"38#include "opt_mac.h"3940#include <sys/param.h>41#include <sys/kernel.h>42#include <sys/priv.h>43#include <sys/sdt.h>44#include <sys/module.h>4546#include <security/mac/mac_framework.h>47#include <security/mac/mac_internal.h>48#include <security/mac/mac_policy.h>4950/*51* The MAC Framework interacts with kernel privilege checks in two ways: it52* may restrict the granting of privilege to a subject, and it may grant53* additional privileges to the subject. Policies may implement none, one,54* or both of these entry points. Restriction of privilege by any policy55* always overrides granting of privilege by any policy or other privilege56* mechanism. See kern_priv.c:priv_check_cred() for details of the57* composition.58*/5960MAC_CHECK_PROBE_DEFINE2(priv_check, "struct ucred *", "int");6162/*63* Restrict access to a privilege for a credential. Return failure if any64* policy denies access.65*/66int67mac_priv_check_impl(struct ucred *cred, int priv)68{69int error;7071MAC_POLICY_CHECK_NOSLEEP(priv_check, cred, priv);72MAC_CHECK_PROBE2(priv_check, error, cred, priv);7374return (error);75}7677MAC_GRANT_PROBE_DEFINE2(priv_grant, "struct ucred *", "int");7879/*80* Grant access to a privilege for a credential. Return success if any81* policy grants access.82*/83int84mac_priv_grant_impl(struct ucred *cred, int priv)85{86int error;8788MAC_POLICY_GRANT_NOSLEEP(priv_grant, cred, priv);89MAC_GRANT_PROBE2(priv_grant, error, cred, priv);9091return (error);92}939495