| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: kern_module.c,v 1.50 2009/10/02 18:50:14 elad Exp $ */ | | 1 | /* $NetBSD: kern_module.c,v 1.51 2009/10/03 00:06:37 elad Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software developed for The NetBSD Foundation | | 7 | * This code is derived from software developed for The NetBSD Foundation |
8 | * by Andrew Doran. | | 8 | * by Andrew Doran. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -24,27 +24,27 @@ | | | @@ -24,27 +24,27 @@ |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | /* | | 32 | /* |
33 | * Kernel module support. | | 33 | * Kernel module support. |
34 | */ | | 34 | */ |
35 | | | 35 | |
36 | #include <sys/cdefs.h> | | 36 | #include <sys/cdefs.h> |
37 | __KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.50 2009/10/02 18:50:14 elad Exp $"); | | 37 | __KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.51 2009/10/03 00:06:37 elad Exp $"); |
38 | | | 38 | |
39 | #ifdef _KERNEL_OPT | | 39 | #ifdef _KERNEL_OPT |
40 | #include "opt_ddb.h" | | 40 | #include "opt_ddb.h" |
41 | #include "opt_modular.h" | | 41 | #include "opt_modular.h" |
42 | #endif | | 42 | #endif |
43 | | | 43 | |
44 | #include <sys/param.h> | | 44 | #include <sys/param.h> |
45 | #include <sys/systm.h> | | 45 | #include <sys/systm.h> |
46 | #include <sys/kernel.h> | | 46 | #include <sys/kernel.h> |
47 | #include <sys/fcntl.h> | | 47 | #include <sys/fcntl.h> |
48 | #include <sys/proc.h> | | 48 | #include <sys/proc.h> |
49 | #include <sys/kauth.h> | | 49 | #include <sys/kauth.h> |
50 | #include <sys/kobj.h> | | 50 | #include <sys/kobj.h> |
| @@ -68,26 +68,28 @@ struct modlist module_list = TAILQ_HEAD_ | | | @@ -68,26 +68,28 @@ struct modlist module_list = TAILQ_HEAD_ |
68 | struct modlist module_bootlist = TAILQ_HEAD_INITIALIZER(module_bootlist); | | 68 | struct modlist module_bootlist = TAILQ_HEAD_INITIALIZER(module_bootlist); |
69 | static module_t *module_active; | | 69 | static module_t *module_active; |
70 | static char module_base[64]; | | 70 | static char module_base[64]; |
71 | static int module_verbose_on; | | 71 | static int module_verbose_on; |
72 | static int module_autoload_on = 1; | | 72 | static int module_autoload_on = 1; |
73 | u_int module_count; | | 73 | u_int module_count; |
74 | kmutex_t module_lock; | | 74 | kmutex_t module_lock; |
75 | u_int module_autotime = 10; | | 75 | u_int module_autotime = 10; |
76 | u_int module_gen = 1; | | 76 | u_int module_gen = 1; |
77 | static kcondvar_t module_thread_cv; | | 77 | static kcondvar_t module_thread_cv; |
78 | static kmutex_t module_thread_lock; | | 78 | static kmutex_t module_thread_lock; |
79 | static int module_thread_ticks; | | 79 | static int module_thread_ticks; |
80 | | | 80 | |
| | | 81 | static kauth_listener_t module_listener; |
| | | 82 | |
81 | /* Ensure that the kernel's link set isn't empty. */ | | 83 | /* Ensure that the kernel's link set isn't empty. */ |
82 | static modinfo_t module_dummy; | | 84 | static modinfo_t module_dummy; |
83 | __link_set_add_rodata(modules, module_dummy); | | 85 | __link_set_add_rodata(modules, module_dummy); |
84 | | | 86 | |
85 | static module_t *module_lookup(const char *); | | 87 | static module_t *module_lookup(const char *); |
86 | static int module_do_load(const char *, bool, int, prop_dictionary_t, | | 88 | static int module_do_load(const char *, bool, int, prop_dictionary_t, |
87 | module_t **, modclass_t class, bool); | | 89 | module_t **, modclass_t class, bool); |
88 | static int module_do_unload(const char *); | | 90 | static int module_do_unload(const char *); |
89 | static void module_error(const char *, ...) | | 91 | static void module_error(const char *, ...) |
90 | __attribute__((__format__(__printf__,1,2))); | | 92 | __attribute__((__format__(__printf__,1,2))); |
91 | static void module_print(const char *, ...) | | 93 | static void module_print(const char *, ...) |
92 | __attribute__((__format__(__printf__,1,2))); | | 94 | __attribute__((__format__(__printf__,1,2))); |
93 | static int module_do_builtin(const char *, module_t **); | | 95 | static int module_do_builtin(const char *, module_t **); |
| @@ -153,40 +155,60 @@ module_init(void) | | | @@ -153,40 +155,60 @@ module_init(void) |
153 | module_init_md(); | | 155 | module_init_md(); |
154 | #endif | | 156 | #endif |
155 | | | 157 | |
156 | #if __NetBSD_Version__ / 1000000 % 100 == 99 /* -current */ | | 158 | #if __NetBSD_Version__ / 1000000 % 100 == 99 /* -current */ |
157 | snprintf(module_base, sizeof(module_base), "/stand/%s/%s/modules", | | 159 | snprintf(module_base, sizeof(module_base), "/stand/%s/%s/modules", |
158 | machine, osrelease); | | 160 | machine, osrelease); |
159 | #else /* release */ | | 161 | #else /* release */ |
160 | snprintf(module_base, sizeof(module_base), "/stand/%s/%d.%d/modules", | | 162 | snprintf(module_base, sizeof(module_base), "/stand/%s/%d.%d/modules", |
161 | machine, __NetBSD_Version__ / 100000000, | | 163 | machine, __NetBSD_Version__ / 100000000, |
162 | __NetBSD_Version__ / 1000000 % 100); | | 164 | __NetBSD_Version__ / 1000000 % 100); |
163 | #endif | | 165 | #endif |
164 | } | | 166 | } |
165 | | | 167 | |
| | | 168 | static int |
| | | 169 | module_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie, |
| | | 170 | void *arg0, void *arg1, void *arg2, void *arg3) |
| | | 171 | { |
| | | 172 | int result; |
| | | 173 | |
| | | 174 | result = KAUTH_RESULT_DEFER; |
| | | 175 | |
| | | 176 | if (action != KAUTH_SYSTEM_MODULE) |
| | | 177 | return result; |
| | | 178 | |
| | | 179 | if ((uintptr_t)arg2 != 0) /* autoload */ |
| | | 180 | result = KAUTH_RESULT_ALLOW; |
| | | 181 | |
| | | 182 | return result; |
| | | 183 | } |
| | | 184 | |
166 | /* | | 185 | /* |
167 | * module_init2: | | 186 | * module_init2: |
168 | * | | 187 | * |
169 | * Start the auto unload kthread. | | 188 | * Start the auto unload kthread. |
170 | */ | | 189 | */ |
171 | void | | 190 | void |
172 | module_init2(void) | | 191 | module_init2(void) |
173 | { | | 192 | { |
174 | int error; | | 193 | int error; |
175 | | | 194 | |
176 | error = kthread_create(PRI_VM, KTHREAD_MPSAFE, NULL, module_thread, | | 195 | error = kthread_create(PRI_VM, KTHREAD_MPSAFE, NULL, module_thread, |
177 | NULL, NULL, "modunload"); | | 196 | NULL, NULL, "modunload"); |
178 | if (error != 0) | | 197 | if (error != 0) |
179 | panic("module_init: %d", error); | | 198 | panic("module_init: %d", error); |
| | | 199 | |
| | | 200 | module_listener = kauth_listen_scope(KAUTH_SCOPE_SYSTEM, |
| | | 201 | module_listener_cb, NULL); |
180 | } | | 202 | } |
181 | | | 203 | |
182 | SYSCTL_SETUP(sysctl_module_setup, "sysctl module setup") | | 204 | SYSCTL_SETUP(sysctl_module_setup, "sysctl module setup") |
183 | { | | 205 | { |
184 | const struct sysctlnode *node = NULL; | | 206 | const struct sysctlnode *node = NULL; |
185 | | | 207 | |
186 | sysctl_createv(clog, 0, NULL, NULL, | | 208 | sysctl_createv(clog, 0, NULL, NULL, |
187 | CTLFLAG_PERMANENT, | | 209 | CTLFLAG_PERMANENT, |
188 | CTLTYPE_NODE, "kern", NULL, | | 210 | CTLTYPE_NODE, "kern", NULL, |
189 | NULL, 0, NULL, 0, | | 211 | NULL, 0, NULL, 0, |
190 | CTL_KERN, CTL_EOL); | | 212 | CTL_KERN, CTL_EOL); |
191 | sysctl_createv(clog, 0, NULL, &node, | | 213 | sysctl_createv(clog, 0, NULL, &node, |
192 | CTLFLAG_PERMANENT, | | 214 | CTLFLAG_PERMANENT, |