1 /* $NetBSD: secmodel_overlay.c,v 1.9 2008/02/23 23:32:30 elad Exp $ */
3 * Copyright (c) 2006 Elad Efrat <elad@NetBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: secmodel_overlay.c,v 1.9 2008/02/23 23:32:30 elad Exp $");
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/kauth.h>
35 #include <sys/module.h>
37 #include <sys/sysctl.h>
39 #include <secmodel/overlay/overlay.h>
41 #include <secmodel/bsd44/bsd44.h>
42 #include <secmodel/suser/suser.h>
43 #include <secmodel/securelevel/securelevel.h>
45 MODULE(MODULE_CLASS_SECMODEL
, secmodel_overlay
, "secmodel_bsd44");
50 #define OVERLAY_ISCOPE_GENERIC "org.netbsd.kauth.overlay.generic"
51 #define OVERLAY_ISCOPE_SYSTEM "org.netbsd.kauth.overlay.system"
52 #define OVERLAY_ISCOPE_PROCESS "org.netbsd.kauth.overlay.process"
53 #define OVERLAY_ISCOPE_NETWORK "org.netbsd.kauth.overlay.network"
54 #define OVERLAY_ISCOPE_MACHDEP "org.netbsd.kauth.overlay.machdep"
55 #define OVERLAY_ISCOPE_DEVICE "org.netbsd.kauth.overlay.device"
56 #define OVERLAY_ISCOPE_VNODE "org.netbsd.kauth.overlay.vnode"
58 static kauth_scope_t secmodel_overlay_iscope_generic
;
59 static kauth_scope_t secmodel_overlay_iscope_system
;
60 static kauth_scope_t secmodel_overlay_iscope_process
;
61 static kauth_scope_t secmodel_overlay_iscope_network
;
62 static kauth_scope_t secmodel_overlay_iscope_machdep
;
63 static kauth_scope_t secmodel_overlay_iscope_device
;
64 static kauth_scope_t secmodel_overlay_iscope_vnode
;
66 static kauth_listener_t l_generic
, l_system
, l_process
, l_network
, l_machdep
,
69 static struct sysctllog
*sysctl_overlay_log
;
72 * Initialize the overlay security model.
75 secmodel_overlay_init(void)
78 * Register internal fall-back scopes.
80 secmodel_overlay_iscope_generic
= kauth_register_scope(
81 OVERLAY_ISCOPE_GENERIC
, NULL
, NULL
);
82 secmodel_overlay_iscope_system
= kauth_register_scope(
83 OVERLAY_ISCOPE_SYSTEM
, NULL
, NULL
);
84 secmodel_overlay_iscope_process
= kauth_register_scope(
85 OVERLAY_ISCOPE_PROCESS
, NULL
, NULL
);
86 secmodel_overlay_iscope_network
= kauth_register_scope(
87 OVERLAY_ISCOPE_NETWORK
, NULL
, NULL
);
88 secmodel_overlay_iscope_machdep
= kauth_register_scope(
89 OVERLAY_ISCOPE_MACHDEP
, NULL
, NULL
);
90 secmodel_overlay_iscope_device
= kauth_register_scope(
91 OVERLAY_ISCOPE_DEVICE
, NULL
, NULL
);
92 secmodel_overlay_iscope_vnode
= kauth_register_scope(
93 OVERLAY_ISCOPE_VNODE
, NULL
, NULL
);
96 * Register fall-back listeners, from suser and securelevel, to each
99 kauth_listen_scope(OVERLAY_ISCOPE_GENERIC
,
100 secmodel_suser_generic_cb
, NULL
);
102 kauth_listen_scope(OVERLAY_ISCOPE_SYSTEM
,
103 secmodel_suser_system_cb
, NULL
);
104 kauth_listen_scope(OVERLAY_ISCOPE_SYSTEM
,
105 secmodel_securelevel_system_cb
, NULL
);
107 kauth_listen_scope(OVERLAY_ISCOPE_PROCESS
,
108 secmodel_suser_process_cb
, NULL
);
109 kauth_listen_scope(OVERLAY_ISCOPE_PROCESS
,
110 secmodel_securelevel_process_cb
, NULL
);
112 kauth_listen_scope(OVERLAY_ISCOPE_NETWORK
,
113 secmodel_suser_network_cb
, NULL
);
114 kauth_listen_scope(OVERLAY_ISCOPE_NETWORK
,
115 secmodel_securelevel_network_cb
, NULL
);
117 kauth_listen_scope(OVERLAY_ISCOPE_MACHDEP
,
118 secmodel_suser_machdep_cb
, NULL
);
119 kauth_listen_scope(OVERLAY_ISCOPE_MACHDEP
,
120 secmodel_securelevel_machdep_cb
, NULL
);
122 kauth_listen_scope(OVERLAY_ISCOPE_DEVICE
,
123 secmodel_suser_device_cb
, NULL
);
124 kauth_listen_scope(OVERLAY_ISCOPE_DEVICE
,
125 secmodel_securelevel_device_cb
, NULL
);
127 secmodel_bsd44_init();
131 sysctl_security_overlay_setup(struct sysctllog
**clog
)
133 const struct sysctlnode
*rnode
;
135 sysctl_createv(clog
, 0, NULL
, &rnode
,
137 CTLTYPE_NODE
, "security", NULL
,
139 CTL_SECURITY
, CTL_EOL
);
141 sysctl_createv(clog
, 0, &rnode
, &rnode
,
143 CTLTYPE_NODE
, "models", NULL
,
145 CTL_CREATE
, CTL_EOL
);
147 sysctl_createv(clog
, 0, &rnode
, &rnode
,
149 CTLTYPE_NODE
, "overlay",
150 SYSCTL_DESCR("Overlay security model on-top of bsd44, "),
152 CTL_CREATE
, CTL_EOL
);
154 sysctl_createv(clog
, 0, &rnode
, NULL
,
156 CTLTYPE_STRING
, "name", NULL
,
157 NULL
, 0, __UNCONST("Overlay (on-top of bsd44)"), 0,
158 CTL_CREATE
, CTL_EOL
);
162 * Start the overlay security model.
165 secmodel_overlay_start(void)
167 l_generic
= kauth_listen_scope(KAUTH_SCOPE_GENERIC
,
168 secmodel_overlay_generic_cb
, NULL
);
169 l_system
= kauth_listen_scope(KAUTH_SCOPE_SYSTEM
,
170 secmodel_overlay_system_cb
, NULL
);
171 l_process
= kauth_listen_scope(KAUTH_SCOPE_PROCESS
,
172 secmodel_overlay_process_cb
, NULL
);
173 l_network
= kauth_listen_scope(KAUTH_SCOPE_NETWORK
,
174 secmodel_overlay_network_cb
, NULL
);
175 l_machdep
= kauth_listen_scope(KAUTH_SCOPE_MACHDEP
,
176 secmodel_overlay_machdep_cb
, NULL
);
177 l_device
= kauth_listen_scope(KAUTH_SCOPE_DEVICE
,
178 secmodel_overlay_device_cb
, NULL
);
179 l_vnode
= kauth_listen_scope(KAUTH_SCOPE_VNODE
,
180 secmodel_overlay_vnode_cb
, NULL
);
182 /* secmodel_register(); */
186 * Stop the overlay security model.
189 secmodel_overlay_stop(void)
191 kauth_unlisten_scope(l_generic
);
192 kauth_unlisten_scope(l_system
);
193 kauth_unlisten_scope(l_process
);
194 kauth_unlisten_scope(l_network
);
195 kauth_unlisten_scope(l_machdep
);
196 kauth_unlisten_scope(l_device
);
197 kauth_unlisten_scope(l_vnode
);
201 secmodel_overlay_modcmd(modcmd_t cmd
, void *arg
)
206 case MODULE_CMD_INIT
:
207 secmodel_overlay_init();
208 secmodel_bsd44_stop();
209 secmodel_overlay_start();
210 sysctl_security_overlay_setup(&sysctl_overlay_log
);
213 case MODULE_CMD_FINI
:
214 sysctl_teardown(&sysctl_overlay_log
);
215 secmodel_overlay_stop();
218 case MODULE_CMD_AUTOUNLOAD
:
231 * Overlay listener for the generic scope.
234 secmodel_overlay_generic_cb(kauth_cred_t cred
, kauth_action_t action
,
235 void *cookie
, void *arg0
, void *arg1
, void *arg2
, void *arg3
)
239 result
= KAUTH_RESULT_DEFER
;
243 result
= KAUTH_RESULT_DEFER
;
247 if (result
== KAUTH_RESULT_DEFER
) {
248 result
= kauth_authorize_action(
249 secmodel_overlay_iscope_generic
, cred
, action
,
250 arg0
, arg1
, arg2
, arg3
);
257 * Overlay listener for the system scope.
260 secmodel_overlay_system_cb(kauth_cred_t cred
, kauth_action_t action
,
261 void *cookie
, void *arg0
, void *arg1
, void *arg2
, void *arg3
)
265 result
= KAUTH_RESULT_DEFER
;
269 result
= KAUTH_RESULT_DEFER
;
273 if (result
== KAUTH_RESULT_DEFER
) {
274 result
= kauth_authorize_action(
275 secmodel_overlay_iscope_system
, cred
, action
,
276 arg0
, arg1
, arg2
, arg3
);
283 * Overlay listener for the process scope.
286 secmodel_overlay_process_cb(kauth_cred_t cred
, kauth_action_t action
,
287 void *cookie
, void *arg0
, void *arg1
, void *arg2
, void *arg3
)
291 result
= KAUTH_RESULT_DEFER
;
295 result
= KAUTH_RESULT_DEFER
;
299 if (result
== KAUTH_RESULT_DEFER
) {
300 result
= kauth_authorize_action(
301 secmodel_overlay_iscope_process
, cred
, action
,
302 arg0
, arg1
, arg2
, arg3
);
309 * Overlay listener for the network scope.
312 secmodel_overlay_network_cb(kauth_cred_t cred
, kauth_action_t action
,
313 void *cookie
, void *arg0
, void *arg1
, void *arg2
, void *arg3
)
317 result
= KAUTH_RESULT_DEFER
;
321 result
= KAUTH_RESULT_DEFER
;
325 if (result
== KAUTH_RESULT_DEFER
) {
326 result
= kauth_authorize_action(
327 secmodel_overlay_iscope_network
, cred
, action
,
328 arg0
, arg1
, arg2
, arg3
);
335 * Overlay listener for the machdep scope.
338 secmodel_overlay_machdep_cb(kauth_cred_t cred
, kauth_action_t action
,
339 void *cookie
, void *arg0
, void *arg1
, void *arg2
, void *arg3
)
343 result
= KAUTH_RESULT_DEFER
;
347 result
= KAUTH_RESULT_DEFER
;
351 if (result
== KAUTH_RESULT_DEFER
) {
352 result
= kauth_authorize_action(
353 secmodel_overlay_iscope_machdep
, cred
, action
,
354 arg0
, arg1
, arg2
, arg3
);
361 * Overlay listener for the device scope.
364 secmodel_overlay_device_cb(kauth_cred_t cred
, kauth_action_t action
,
365 void *cookie
, void *arg0
, void *arg1
, void *arg2
, void *arg3
)
369 result
= KAUTH_RESULT_DEFER
;
373 result
= KAUTH_RESULT_DEFER
;
377 if (result
== KAUTH_RESULT_DEFER
) {
378 result
= kauth_authorize_action(
379 secmodel_overlay_iscope_device
, cred
, action
,
380 arg0
, arg1
, arg2
, arg3
);
387 * Overlay listener for the vnode scope.
390 secmodel_overlay_vnode_cb(kauth_cred_t cred
, kauth_action_t action
,
391 void *cookie
, void *arg0
, void *arg1
, void *arg2
, void *arg3
)
395 result
= KAUTH_RESULT_DEFER
;
399 result
= KAUTH_RESULT_DEFER
;
403 if (result
== KAUTH_RESULT_DEFER
) {
404 result
= kauth_authorize_action(
405 secmodel_overlay_iscope_vnode
, cred
, action
,
406 arg0
, arg1
, arg2
, arg3
);