xref: /freebsd/sys/security/mac/mac_priv.c (revision 23c3d46ae871eeaf7c54d857aa73dbdf2a8f6fd9)
1800c9408SRobert Watson /*-
2800c9408SRobert Watson  * Copyright (c) 2006 nCircle Network Security, Inc.
3800c9408SRobert Watson  * All rights reserved.
4800c9408SRobert Watson  *
5800c9408SRobert Watson  * This software was developed by Robert N. M. Watson for the TrustedBSD
6800c9408SRobert Watson  * Project under contract to nCircle Network Security, Inc.
7800c9408SRobert Watson  *
8800c9408SRobert Watson  * Redistribution and use in source and binary forms, with or without
9800c9408SRobert Watson  * modification, are permitted provided that the following conditions
10800c9408SRobert Watson  * are met:
11800c9408SRobert Watson  * 1. Redistributions of source code must retain the above copyright
12800c9408SRobert Watson  *    notice, this list of conditions and the following disclaimer.
13800c9408SRobert Watson  * 2. Redistributions in binary form must reproduce the above copyright
14800c9408SRobert Watson  *    notice, this list of conditions and the following disclaimer in the
15800c9408SRobert Watson  *    documentation and/or other materials provided with the distribution.
16800c9408SRobert Watson  *
17800c9408SRobert Watson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18800c9408SRobert Watson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19800c9408SRobert Watson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20800c9408SRobert Watson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR, NCIRCLE NETWORK SECURITY,
21800c9408SRobert Watson  * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22800c9408SRobert Watson  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23800c9408SRobert Watson  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24800c9408SRobert Watson  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25800c9408SRobert Watson  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26800c9408SRobert Watson  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27800c9408SRobert Watson  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28800c9408SRobert Watson  *
29800c9408SRobert Watson  * $FreeBSD$
30800c9408SRobert Watson  */
31800c9408SRobert Watson 
32800c9408SRobert Watson /*
33800c9408SRobert Watson  * MAC checks for system privileges.
34800c9408SRobert Watson  */
35800c9408SRobert Watson 
36800c9408SRobert Watson #include "opt_mac.h"
37800c9408SRobert Watson 
38800c9408SRobert Watson #include <sys/param.h>
39800c9408SRobert Watson #include <sys/priv.h>
40800c9408SRobert Watson #include <sys/module.h>
41800c9408SRobert Watson #include <sys/mac_policy.h>
42800c9408SRobert Watson 
43800c9408SRobert Watson #include <security/mac/mac_framework.h>
44800c9408SRobert Watson #include <security/mac/mac_internal.h>
45800c9408SRobert Watson 
4623c3d46aSRobert Watson /*
4723c3d46aSRobert Watson  * The MAC Framework interacts with kernel privilege checks in two ways: it
4823c3d46aSRobert Watson  * may restrict the granting of privilege to a subject, and it may grant
4923c3d46aSRobert Watson  * additional privileges to the subject.  Policies may implement none, one,
5023c3d46aSRobert Watson  * or both of these entry points.  Restriction of privilege by any policy
5123c3d46aSRobert Watson  * always overrides granting of privilege by any policy or other privilege
5223c3d46aSRobert Watson  * mechanism.  See kern_priv.c:priv_check_cred() for details of the
5323c3d46aSRobert Watson  * composition.
5423c3d46aSRobert Watson  */
5523c3d46aSRobert Watson 
5623c3d46aSRobert Watson /*
5723c3d46aSRobert Watson  * Restrict access to a privilege for a credential.  Return failure if any
5823c3d46aSRobert Watson  * policy denies access.
5923c3d46aSRobert Watson  */
60800c9408SRobert Watson int
61800c9408SRobert Watson mac_priv_check(struct ucred *cred, int priv)
62800c9408SRobert Watson {
63800c9408SRobert Watson 	int error;
64800c9408SRobert Watson 
65800c9408SRobert Watson 	MAC_CHECK(priv_check, cred, priv);
66800c9408SRobert Watson 
67800c9408SRobert Watson 	return (error);
68800c9408SRobert Watson }
69800c9408SRobert Watson 
7023c3d46aSRobert Watson /*
7123c3d46aSRobert Watson  * Grant access to a privilege for a credential.  Return success if any
7223c3d46aSRobert Watson  * policy grants access.
7323c3d46aSRobert Watson  */
74800c9408SRobert Watson int
75800c9408SRobert Watson mac_priv_grant(struct ucred *cred, int priv)
76800c9408SRobert Watson {
77800c9408SRobert Watson 	int error;
78800c9408SRobert Watson 
79800c9408SRobert Watson 	MAC_GRANT(priv_grant, cred, priv);
80800c9408SRobert Watson 
81800c9408SRobert Watson 	return (error);
82800c9408SRobert Watson }
83