xref: /freebsd/sys/security/mac/mac_system.c (revision 1e413cf93298b5b97441a21d9a50fdcd0ee9945e)
1 /*-
2  * Copyright (c) 2002-2003 Networks Associates Technology, Inc.
3  * Copyright (c) 2006 SPARTA, Inc.
4  * Copyright (c) 2007 Robert N. M. Watson
5  * All rights reserved.
6  *
7  * This software was developed for the FreeBSD Project in part by Network
8  * Associates Laboratories, the Security Research Division of Network
9  * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
10  * as part of the DARPA CHATS research program.
11  *
12  * Portions of this software were developed by Robert Watson for the
13  * TrustedBSD Project.
14  *
15  * This software was enhanced by SPARTA ISSO under SPAWAR contract
16  * N66001-04-C-6019 ("SEFOS").
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions
20  * are met:
21  * 1. Redistributions of source code must retain the above copyright
22  *    notice, this list of conditions and the following disclaimer.
23  * 2. Redistributions in binary form must reproduce the above copyright
24  *    notice, this list of conditions and the following disclaimer in the
25  *    documentation and/or other materials provided with the distribution.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  */
39 
40 /*
41  * MAC Framework entry points relating to overall operation of system,
42  * including global services such as the kernel environment and loadable
43  * modules.
44  *
45  * System checks often align with existing privilege checks, but provide
46  * additional security context that may be relevant to policies, such as the
47  * specific object being operated on.
48  */
49 
50 #include <sys/cdefs.h>
51 __FBSDID("$FreeBSD$");
52 
53 #include "opt_mac.h"
54 
55 #include <sys/param.h>
56 #include <sys/kernel.h>
57 #include <sys/lock.h>
58 #include <sys/malloc.h>
59 #include <sys/module.h>
60 #include <sys/mutex.h>
61 #include <sys/systm.h>
62 #include <sys/vnode.h>
63 #include <sys/sysctl.h>
64 
65 #include <security/mac/mac_framework.h>
66 #include <security/mac/mac_internal.h>
67 #include <security/mac/mac_policy.h>
68 
69 int
70 mac_kenv_check_dump(struct ucred *cred)
71 {
72 	int error;
73 
74 	MAC_CHECK(kenv_check_dump, cred);
75 
76 	return (error);
77 }
78 
79 int
80 mac_kenv_check_get(struct ucred *cred, char *name)
81 {
82 	int error;
83 
84 	MAC_CHECK(kenv_check_get, cred, name);
85 
86 	return (error);
87 }
88 
89 int
90 mac_kenv_check_set(struct ucred *cred, char *name, char *value)
91 {
92 	int error;
93 
94 	MAC_CHECK(kenv_check_set, cred, name, value);
95 
96 	return (error);
97 }
98 
99 int
100 mac_kenv_check_unset(struct ucred *cred, char *name)
101 {
102 	int error;
103 
104 	MAC_CHECK(kenv_check_unset, cred, name);
105 
106 	return (error);
107 }
108 
109 int
110 mac_kld_check_load(struct ucred *cred, struct vnode *vp)
111 {
112 	int error;
113 
114 	ASSERT_VOP_LOCKED(vp, "mac_kld_check_load");
115 
116 	MAC_CHECK(kld_check_load, cred, vp, vp->v_label);
117 
118 	return (error);
119 }
120 
121 int
122 mac_kld_check_stat(struct ucred *cred)
123 {
124 	int error;
125 
126 	MAC_CHECK(kld_check_stat, cred);
127 
128 	return (error);
129 }
130 
131 int
132 mac_system_check_acct(struct ucred *cred, struct vnode *vp)
133 {
134 	int error;
135 
136 	if (vp != NULL) {
137 		ASSERT_VOP_LOCKED(vp, "mac_system_check_acct");
138 	}
139 
140 	MAC_CHECK(system_check_acct, cred, vp,
141 	    vp != NULL ? vp->v_label : NULL);
142 
143 	return (error);
144 }
145 
146 int
147 mac_system_check_reboot(struct ucred *cred, int howto)
148 {
149 	int error;
150 
151 	MAC_CHECK(system_check_reboot, cred, howto);
152 
153 	return (error);
154 }
155 
156 int
157 mac_system_check_swapon(struct ucred *cred, struct vnode *vp)
158 {
159 	int error;
160 
161 	ASSERT_VOP_LOCKED(vp, "mac_system_check_swapon");
162 
163 	MAC_CHECK(system_check_swapon, cred, vp, vp->v_label);
164 	return (error);
165 }
166 
167 int
168 mac_system_check_swapoff(struct ucred *cred, struct vnode *vp)
169 {
170 	int error;
171 
172 	ASSERT_VOP_LOCKED(vp, "mac_system_check_swapoff");
173 
174 	MAC_CHECK(system_check_swapoff, cred, vp, vp->v_label);
175 	return (error);
176 }
177 
178 int
179 mac_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp,
180     void *arg1, int arg2, struct sysctl_req *req)
181 {
182 	int error;
183 
184 	/*
185 	 * XXXMAC: We would very much like to assert the SYSCTL_LOCK here,
186 	 * but since it's not exported from kern_sysctl.c, we can't.
187 	 */
188 	MAC_CHECK(system_check_sysctl, cred, oidp, arg1, arg2, req);
189 
190 	return (error);
191 }
192