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