secmodel_overlay.c revision 1.3.4.2 1 1.3.4.2 ad /* $NetBSD: secmodel_overlay.c,v 1.3.4.2 2006/11/18 21:39:46 ad Exp $ */
2 1.3.4.2 ad /*-
3 1.3.4.2 ad * Copyright (c) 2006 Elad Efrat <elad (at) NetBSD.org>
4 1.3.4.2 ad * All rights reserved.
5 1.3.4.2 ad *
6 1.3.4.2 ad * Redistribution and use in source and binary forms, with or without
7 1.3.4.2 ad * modification, are permitted provided that the following conditions
8 1.3.4.2 ad * are met:
9 1.3.4.2 ad * 1. Redistributions of source code must retain the above copyright
10 1.3.4.2 ad * notice, this list of conditions and the following disclaimer.
11 1.3.4.2 ad * 2. Redistributions in binary form must reproduce the above copyright
12 1.3.4.2 ad * notice, this list of conditions and the following disclaimer in the
13 1.3.4.2 ad * documentation and/or other materials provided with the distribution.
14 1.3.4.2 ad * 3. All advertising materials mentioning features or use of this software
15 1.3.4.2 ad * must display the following acknowledgement:
16 1.3.4.2 ad * This product includes software developed by Elad Efrat.
17 1.3.4.2 ad * 4. The name of the author may not be used to endorse or promote products
18 1.3.4.2 ad * derived from this software without specific prior written permission.
19 1.3.4.2 ad *
20 1.3.4.2 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.3.4.2 ad * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.3.4.2 ad * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.3.4.2 ad * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.3.4.2 ad * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.3.4.2 ad * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.3.4.2 ad * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.3.4.2 ad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.3.4.2 ad * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.3.4.2 ad * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.3.4.2 ad */
31 1.3.4.2 ad
32 1.3.4.2 ad #include <sys/cdefs.h>
33 1.3.4.2 ad __KERNEL_RCSID(0, "$NetBSD: secmodel_overlay.c,v 1.3.4.2 2006/11/18 21:39:46 ad Exp $");
34 1.3.4.2 ad
35 1.3.4.2 ad #include <sys/types.h>
36 1.3.4.2 ad #include <sys/param.h>
37 1.3.4.2 ad #include <sys/kauth.h>
38 1.3.4.2 ad
39 1.3.4.2 ad #include <sys/sysctl.h>
40 1.3.4.2 ad
41 1.3.4.2 ad #include <secmodel/secmodel.h>
42 1.3.4.2 ad #include <secmodel/overlay/overlay.h>
43 1.3.4.2 ad
44 1.3.4.2 ad #include <secmodel/bsd44/bsd44.h>
45 1.3.4.2 ad #include <secmodel/bsd44/suser.h>
46 1.3.4.2 ad #include <secmodel/bsd44/securelevel.h>
47 1.3.4.2 ad
48 1.3.4.2 ad /*
49 1.3.4.2 ad * Fall-back settings.
50 1.3.4.2 ad */
51 1.3.4.2 ad #define OVERLAY_ISCOPE_GENERIC "org.netbsd.kauth.overlay.generic"
52 1.3.4.2 ad #define OVERLAY_ISCOPE_SYSTEM "org.netbsd.kauth.overlay.system"
53 1.3.4.2 ad #define OVERLAY_ISCOPE_PROCESS "org.netbsd.kauth.overlay.process"
54 1.3.4.2 ad #define OVERLAY_ISCOPE_NETWORK "org.netbsd.kauth.overlay.network"
55 1.3.4.2 ad #define OVERLAY_ISCOPE_MACHDEP "org.netbsd.kauth.overlay.machdep"
56 1.3.4.2 ad
57 1.3.4.2 ad static kauth_scope_t secmodel_overlay_iscope_generic;
58 1.3.4.2 ad static kauth_scope_t secmodel_overlay_iscope_system;
59 1.3.4.2 ad static kauth_scope_t secmodel_overlay_iscope_process;
60 1.3.4.2 ad static kauth_scope_t secmodel_overlay_iscope_network;
61 1.3.4.2 ad static kauth_scope_t secmodel_overlay_iscope_machdep;
62 1.3.4.2 ad
63 1.3.4.2 ad extern int secmodel_bsd44_curtain;
64 1.3.4.2 ad
65 1.3.4.2 ad /*
66 1.3.4.2 ad * Initialize the overlay security model.
67 1.3.4.2 ad */
68 1.3.4.2 ad void
69 1.3.4.2 ad secmodel_overlay_init(void)
70 1.3.4.2 ad {
71 1.3.4.2 ad /*
72 1.3.4.2 ad * Register internal fall-back scopes.
73 1.3.4.2 ad */
74 1.3.4.2 ad secmodel_overlay_iscope_generic = kauth_register_scope(
75 1.3.4.2 ad OVERLAY_ISCOPE_GENERIC, NULL, NULL);
76 1.3.4.2 ad secmodel_overlay_iscope_system = kauth_register_scope(
77 1.3.4.2 ad OVERLAY_ISCOPE_SYSTEM, NULL, NULL);
78 1.3.4.2 ad secmodel_overlay_iscope_process = kauth_register_scope(
79 1.3.4.2 ad OVERLAY_ISCOPE_PROCESS, NULL, NULL);
80 1.3.4.2 ad secmodel_overlay_iscope_network = kauth_register_scope(
81 1.3.4.2 ad OVERLAY_ISCOPE_NETWORK, NULL, NULL);
82 1.3.4.2 ad secmodel_overlay_iscope_machdep = kauth_register_scope(
83 1.3.4.2 ad OVERLAY_ISCOPE_MACHDEP, NULL, NULL);
84 1.3.4.2 ad
85 1.3.4.2 ad /*
86 1.3.4.2 ad * Register fall-back listeners, from bsd44, to each internal
87 1.3.4.2 ad * fall-back scope.
88 1.3.4.2 ad */
89 1.3.4.2 ad kauth_listen_scope(OVERLAY_ISCOPE_GENERIC,
90 1.3.4.2 ad secmodel_bsd44_suser_generic_cb, NULL);
91 1.3.4.2 ad
92 1.3.4.2 ad kauth_listen_scope(OVERLAY_ISCOPE_SYSTEM,
93 1.3.4.2 ad secmodel_bsd44_suser_system_cb, NULL);
94 1.3.4.2 ad kauth_listen_scope(OVERLAY_ISCOPE_SYSTEM,
95 1.3.4.2 ad secmodel_bsd44_securelevel_system_cb, NULL);
96 1.3.4.2 ad
97 1.3.4.2 ad kauth_listen_scope(OVERLAY_ISCOPE_PROCESS,
98 1.3.4.2 ad secmodel_bsd44_suser_process_cb, NULL);
99 1.3.4.2 ad kauth_listen_scope(OVERLAY_ISCOPE_PROCESS,
100 1.3.4.2 ad secmodel_bsd44_securelevel_process_cb, NULL);
101 1.3.4.2 ad
102 1.3.4.2 ad kauth_listen_scope(OVERLAY_ISCOPE_NETWORK,
103 1.3.4.2 ad secmodel_bsd44_suser_network_cb, NULL);
104 1.3.4.2 ad kauth_listen_scope(OVERLAY_ISCOPE_NETWORK,
105 1.3.4.2 ad secmodel_bsd44_securelevel_network_cb, NULL);
106 1.3.4.2 ad
107 1.3.4.2 ad kauth_listen_scope(OVERLAY_ISCOPE_MACHDEP,
108 1.3.4.2 ad secmodel_bsd44_suser_machdep_cb, NULL);
109 1.3.4.2 ad kauth_listen_scope(OVERLAY_ISCOPE_MACHDEP,
110 1.3.4.2 ad secmodel_bsd44_securelevel_machdep_cb, NULL);
111 1.3.4.2 ad
112 1.3.4.2 ad secmodel_bsd44_init();
113 1.3.4.2 ad }
114 1.3.4.2 ad
115 1.3.4.2 ad SYSCTL_SETUP(sysctl_security_overlay_setup,
116 1.3.4.2 ad "sysctl security overlay setup")
117 1.3.4.2 ad {
118 1.3.4.2 ad const struct sysctlnode *rnode;
119 1.3.4.2 ad
120 1.3.4.2 ad sysctl_createv(clog, 0, NULL, &rnode,
121 1.3.4.2 ad CTLFLAG_PERMANENT,
122 1.3.4.2 ad CTLTYPE_NODE, "security", NULL,
123 1.3.4.2 ad NULL, 0, NULL, 0,
124 1.3.4.2 ad CTL_SECURITY, CTL_EOL);
125 1.3.4.2 ad
126 1.3.4.2 ad sysctl_createv(clog, 0, &rnode, &rnode,
127 1.3.4.2 ad CTLFLAG_PERMANENT,
128 1.3.4.2 ad CTLTYPE_NODE, "models", NULL,
129 1.3.4.2 ad NULL, 0, NULL, 0,
130 1.3.4.2 ad CTL_CREATE, CTL_EOL);
131 1.3.4.2 ad
132 1.3.4.2 ad sysctl_createv(clog, 0, &rnode, &rnode,
133 1.3.4.2 ad CTLFLAG_PERMANENT,
134 1.3.4.2 ad CTLTYPE_NODE, "overlay",
135 1.3.4.2 ad SYSCTL_DESCR("Overlay security model on-top of bsd44, "),
136 1.3.4.2 ad NULL, 0, NULL, 0,
137 1.3.4.2 ad CTL_CREATE, CTL_EOL);
138 1.3.4.2 ad
139 1.3.4.2 ad sysctl_createv(clog, 0, &rnode, NULL,
140 1.3.4.2 ad CTLFLAG_PERMANENT,
141 1.3.4.2 ad CTLTYPE_STRING, "name", NULL,
142 1.3.4.2 ad NULL, 0, __UNCONST("Overlay (on-top of bsd44)"), 0,
143 1.3.4.2 ad CTL_CREATE, CTL_EOL);
144 1.3.4.2 ad
145 1.3.4.2 ad sysctl_createv(clog, 0, &rnode, NULL,
146 1.3.4.2 ad CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
147 1.3.4.2 ad CTLTYPE_INT, "securelevel",
148 1.3.4.2 ad SYSCTL_DESCR("System security level"),
149 1.3.4.2 ad secmodel_bsd44_sysctl_securelevel, 0, &securelevel, 0,
150 1.3.4.2 ad CTL_CREATE, CTL_EOL);
151 1.3.4.2 ad
152 1.3.4.2 ad sysctl_createv(clog, 0, &rnode, NULL,
153 1.3.4.2 ad CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
154 1.3.4.2 ad CTLTYPE_INT, "curtain",
155 1.3.4.2 ad SYSCTL_DESCR("Curtain information about objects to "
156 1.3.4.2 ad "users not owning them."),
157 1.3.4.2 ad NULL, 0, &secmodel_bsd44_curtain, 0,
158 1.3.4.2 ad CTL_CREATE, CTL_EOL);
159 1.3.4.2 ad }
160 1.3.4.2 ad
161 1.3.4.2 ad /*
162 1.3.4.2 ad * Start the overlay security model.
163 1.3.4.2 ad */
164 1.3.4.2 ad void
165 1.3.4.2 ad secmodel_start(void)
166 1.3.4.2 ad {
167 1.3.4.2 ad secmodel_overlay_init();
168 1.3.4.2 ad
169 1.3.4.2 ad kauth_listen_scope(KAUTH_SCOPE_GENERIC,
170 1.3.4.2 ad secmodel_overlay_generic_cb, NULL);
171 1.3.4.2 ad kauth_listen_scope(KAUTH_SCOPE_SYSTEM,
172 1.3.4.2 ad secmodel_overlay_system_cb, NULL);
173 1.3.4.2 ad kauth_listen_scope(KAUTH_SCOPE_PROCESS,
174 1.3.4.2 ad secmodel_overlay_process_cb, NULL);
175 1.3.4.2 ad kauth_listen_scope(KAUTH_SCOPE_NETWORK,
176 1.3.4.2 ad secmodel_overlay_network_cb, NULL);
177 1.3.4.2 ad kauth_listen_scope(KAUTH_SCOPE_MACHDEP,
178 1.3.4.2 ad secmodel_overlay_machdep_cb, NULL);
179 1.3.4.2 ad }
180 1.3.4.2 ad
181 1.3.4.2 ad /*
182 1.3.4.2 ad * Overlay listener for the generic scope.
183 1.3.4.2 ad */
184 1.3.4.2 ad int
185 1.3.4.2 ad secmodel_overlay_generic_cb(kauth_cred_t cred, kauth_action_t action,
186 1.3.4.2 ad void *cookie, void *arg0, void *arg1, void *arg2, void *arg3)
187 1.3.4.2 ad {
188 1.3.4.2 ad int result;
189 1.3.4.2 ad
190 1.3.4.2 ad result = KAUTH_RESULT_DEFER;
191 1.3.4.2 ad
192 1.3.4.2 ad switch (action) {
193 1.3.4.2 ad default:
194 1.3.4.2 ad result = KAUTH_RESULT_DEFER;
195 1.3.4.2 ad break;
196 1.3.4.2 ad }
197 1.3.4.2 ad
198 1.3.4.2 ad if (result == KAUTH_RESULT_DEFER) {
199 1.3.4.2 ad result = kauth_authorize_action(
200 1.3.4.2 ad secmodel_overlay_iscope_generic, cred, action,
201 1.3.4.2 ad arg0, arg1, arg2, arg3);
202 1.3.4.2 ad }
203 1.3.4.2 ad
204 1.3.4.2 ad return (result);
205 1.3.4.2 ad }
206 1.3.4.2 ad
207 1.3.4.2 ad /*
208 1.3.4.2 ad * Overlay listener for the system scope.
209 1.3.4.2 ad */
210 1.3.4.2 ad int
211 1.3.4.2 ad secmodel_overlay_system_cb(kauth_cred_t cred, kauth_action_t action,
212 1.3.4.2 ad void *cookie, void *arg0, void *arg1, void *arg2, void *arg3)
213 1.3.4.2 ad {
214 1.3.4.2 ad int result;
215 1.3.4.2 ad
216 1.3.4.2 ad result = KAUTH_RESULT_DEFER;
217 1.3.4.2 ad
218 1.3.4.2 ad switch (action) {
219 1.3.4.2 ad default:
220 1.3.4.2 ad result = KAUTH_RESULT_DEFER;
221 1.3.4.2 ad break;
222 1.3.4.2 ad }
223 1.3.4.2 ad
224 1.3.4.2 ad if (result == KAUTH_RESULT_DEFER) {
225 1.3.4.2 ad result = kauth_authorize_action(
226 1.3.4.2 ad secmodel_overlay_iscope_system, cred, action,
227 1.3.4.2 ad arg0, arg1, arg2, arg3);
228 1.3.4.2 ad }
229 1.3.4.2 ad
230 1.3.4.2 ad return (result);
231 1.3.4.2 ad }
232 1.3.4.2 ad
233 1.3.4.2 ad /*
234 1.3.4.2 ad * Overlay listener for the process scope.
235 1.3.4.2 ad */
236 1.3.4.2 ad int
237 1.3.4.2 ad secmodel_overlay_process_cb(kauth_cred_t cred, kauth_action_t action,
238 1.3.4.2 ad void *cookie, void *arg0, void *arg1, void *arg2, void *arg3)
239 1.3.4.2 ad {
240 1.3.4.2 ad int result;
241 1.3.4.2 ad
242 1.3.4.2 ad result = KAUTH_RESULT_DEFER;
243 1.3.4.2 ad
244 1.3.4.2 ad switch (action) {
245 1.3.4.2 ad default:
246 1.3.4.2 ad result = KAUTH_RESULT_DEFER;
247 1.3.4.2 ad break;
248 1.3.4.2 ad }
249 1.3.4.2 ad
250 1.3.4.2 ad if (result == KAUTH_RESULT_DEFER) {
251 1.3.4.2 ad result = kauth_authorize_action(
252 1.3.4.2 ad secmodel_overlay_iscope_process, cred, action,
253 1.3.4.2 ad arg0, arg1, arg2, arg3);
254 1.3.4.2 ad }
255 1.3.4.2 ad
256 1.3.4.2 ad return (result);
257 1.3.4.2 ad }
258 1.3.4.2 ad
259 1.3.4.2 ad /*
260 1.3.4.2 ad * Overlay listener for the network scope.
261 1.3.4.2 ad */
262 1.3.4.2 ad int
263 1.3.4.2 ad secmodel_overlay_network_cb(kauth_cred_t cred, kauth_action_t action,
264 1.3.4.2 ad void *cookie, void *arg0, void *arg1, void *arg2, void *arg3)
265 1.3.4.2 ad {
266 1.3.4.2 ad int result;
267 1.3.4.2 ad
268 1.3.4.2 ad result = KAUTH_RESULT_DEFER;
269 1.3.4.2 ad
270 1.3.4.2 ad switch (action) {
271 1.3.4.2 ad default:
272 1.3.4.2 ad result = KAUTH_RESULT_DEFER;
273 1.3.4.2 ad break;
274 1.3.4.2 ad }
275 1.3.4.2 ad
276 1.3.4.2 ad if (result == KAUTH_RESULT_DEFER) {
277 1.3.4.2 ad result = kauth_authorize_action(
278 1.3.4.2 ad secmodel_overlay_iscope_network, cred, action,
279 1.3.4.2 ad arg0, arg1, arg2, arg3);
280 1.3.4.2 ad }
281 1.3.4.2 ad
282 1.3.4.2 ad return (result);
283 1.3.4.2 ad }
284 1.3.4.2 ad
285 1.3.4.2 ad /*
286 1.3.4.2 ad * Overlay listener for the machdep scope.
287 1.3.4.2 ad */
288 1.3.4.2 ad int
289 1.3.4.2 ad secmodel_overlay_machdep_cb(kauth_cred_t cred, kauth_action_t action,
290 1.3.4.2 ad void *cookie, void *arg0, void *arg1, void *arg2, void *arg3)
291 1.3.4.2 ad {
292 1.3.4.2 ad int result;
293 1.3.4.2 ad
294 1.3.4.2 ad result = KAUTH_RESULT_DEFER;
295 1.3.4.2 ad
296 1.3.4.2 ad switch (action) {
297 1.3.4.2 ad default:
298 1.3.4.2 ad result = KAUTH_RESULT_DEFER;
299 1.3.4.2 ad break;
300 1.3.4.2 ad }
301 1.3.4.2 ad
302 1.3.4.2 ad if (result == KAUTH_RESULT_DEFER) {
303 1.3.4.2 ad result = kauth_authorize_action(
304 1.3.4.2 ad secmodel_overlay_iscope_machdep, cred, action,
305 1.3.4.2 ad arg0, arg1, arg2, arg3);
306 1.3.4.2 ad }
307 1.3.4.2 ad
308 1.3.4.2 ad return (result);
309 1.3.4.2 ad }
310