aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c711
1 files changed, 443 insertions, 268 deletions
diff --git a/kernel/module.c b/kernel/module.c
index 5f80478b746d..1f4cc00e0c20 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -20,11 +20,13 @@
20#include <linux/moduleloader.h> 20#include <linux/moduleloader.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/kallsyms.h> 22#include <linux/kallsyms.h>
23#include <linux/fs.h>
23#include <linux/sysfs.h> 24#include <linux/sysfs.h>
24#include <linux/kernel.h> 25#include <linux/kernel.h>
25#include <linux/slab.h> 26#include <linux/slab.h>
26#include <linux/vmalloc.h> 27#include <linux/vmalloc.h>
27#include <linux/elf.h> 28#include <linux/elf.h>
29#include <linux/proc_fs.h>
28#include <linux/seq_file.h> 30#include <linux/seq_file.h>
29#include <linux/syscalls.h> 31#include <linux/syscalls.h>
30#include <linux/fcntl.h> 32#include <linux/fcntl.h>
@@ -42,10 +44,13 @@
42#include <linux/string.h> 44#include <linux/string.h>
43#include <linux/mutex.h> 45#include <linux/mutex.h>
44#include <linux/unwind.h> 46#include <linux/unwind.h>
47#include <linux/rculist.h>
45#include <asm/uaccess.h> 48#include <asm/uaccess.h>
46#include <asm/cacheflush.h> 49#include <asm/cacheflush.h>
47#include <linux/license.h> 50#include <linux/license.h>
48#include <asm/sections.h> 51#include <asm/sections.h>
52#include <linux/tracepoint.h>
53#include <linux/ftrace.h>
49 54
50#if 0 55#if 0
51#define DEBUGP printk 56#define DEBUGP printk
@@ -61,7 +66,7 @@
61#define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) 66#define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
62 67
63/* List of modules, protected by module_mutex or preempt_disable 68/* List of modules, protected by module_mutex or preempt_disable
64 * (add/delete uses stop_machine). */ 69 * (delete uses stop_machine/add uses RCU list operations). */
65static DEFINE_MUTEX(module_mutex); 70static DEFINE_MUTEX(module_mutex);
66static LIST_HEAD(modules); 71static LIST_HEAD(modules);
67 72
@@ -70,6 +75,9 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq);
70 75
71static BLOCKING_NOTIFIER_HEAD(module_notify_list); 76static BLOCKING_NOTIFIER_HEAD(module_notify_list);
72 77
78/* Bounds of module allocation, for speeding __module_text_address */
79static unsigned long module_addr_min = -1UL, module_addr_max = 0;
80
73int register_module_notifier(struct notifier_block * nb) 81int register_module_notifier(struct notifier_block * nb)
74{ 82{
75 return blocking_notifier_chain_register(&module_notify_list, nb); 83 return blocking_notifier_chain_register(&module_notify_list, nb);
@@ -97,7 +105,7 @@ static inline int strong_try_module_get(struct module *mod)
97static inline void add_taint_module(struct module *mod, unsigned flag) 105static inline void add_taint_module(struct module *mod, unsigned flag)
98{ 106{
99 add_taint(flag); 107 add_taint(flag);
100 mod->taints |= flag; 108 mod->taints |= (1U << flag);
101} 109}
102 110
103/* 111/*
@@ -127,6 +135,29 @@ static unsigned int find_sec(Elf_Ehdr *hdr,
127 return 0; 135 return 0;
128} 136}
129 137
138/* Find a module section, or NULL. */
139static void *section_addr(Elf_Ehdr *hdr, Elf_Shdr *shdrs,
140 const char *secstrings, const char *name)
141{
142 /* Section 0 has sh_addr 0. */
143 return (void *)shdrs[find_sec(hdr, shdrs, secstrings, name)].sh_addr;
144}
145
146/* Find a module section, or NULL. Fill in number of "objects" in section. */
147static void *section_objs(Elf_Ehdr *hdr,
148 Elf_Shdr *sechdrs,
149 const char *secstrings,
150 const char *name,
151 size_t object_size,
152 unsigned int *num)
153{
154 unsigned int sec = find_sec(hdr, sechdrs, secstrings, name);
155
156 /* Section 0 has sh_addr 0 and sh_size 0. */
157 *num = sechdrs[sec].sh_size / object_size;
158 return (void *)sechdrs[sec].sh_addr;
159}
160
130/* Provided by the linker */ 161/* Provided by the linker */
131extern const struct kernel_symbol __start___ksymtab[]; 162extern const struct kernel_symbol __start___ksymtab[];
132extern const struct kernel_symbol __stop___ksymtab[]; 163extern const struct kernel_symbol __stop___ksymtab[];
@@ -134,17 +165,19 @@ extern const struct kernel_symbol __start___ksymtab_gpl[];
134extern const struct kernel_symbol __stop___ksymtab_gpl[]; 165extern const struct kernel_symbol __stop___ksymtab_gpl[];
135extern const struct kernel_symbol __start___ksymtab_gpl_future[]; 166extern const struct kernel_symbol __start___ksymtab_gpl_future[];
136extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; 167extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
137extern const struct kernel_symbol __start___ksymtab_unused[];
138extern const struct kernel_symbol __stop___ksymtab_unused[];
139extern const struct kernel_symbol __start___ksymtab_unused_gpl[];
140extern const struct kernel_symbol __stop___ksymtab_unused_gpl[];
141extern const struct kernel_symbol __start___ksymtab_gpl_future[]; 168extern const struct kernel_symbol __start___ksymtab_gpl_future[];
142extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; 169extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
143extern const unsigned long __start___kcrctab[]; 170extern const unsigned long __start___kcrctab[];
144extern const unsigned long __start___kcrctab_gpl[]; 171extern const unsigned long __start___kcrctab_gpl[];
145extern const unsigned long __start___kcrctab_gpl_future[]; 172extern const unsigned long __start___kcrctab_gpl_future[];
173#ifdef CONFIG_UNUSED_SYMBOLS
174extern const struct kernel_symbol __start___ksymtab_unused[];
175extern const struct kernel_symbol __stop___ksymtab_unused[];
176extern const struct kernel_symbol __start___ksymtab_unused_gpl[];
177extern const struct kernel_symbol __stop___ksymtab_unused_gpl[];
146extern const unsigned long __start___kcrctab_unused[]; 178extern const unsigned long __start___kcrctab_unused[];
147extern const unsigned long __start___kcrctab_unused_gpl[]; 179extern const unsigned long __start___kcrctab_unused_gpl[];
180#endif
148 181
149#ifndef CONFIG_MODVERSIONS 182#ifndef CONFIG_MODVERSIONS
150#define symversion(base, idx) NULL 183#define symversion(base, idx) NULL
@@ -152,152 +185,170 @@ extern const unsigned long __start___kcrctab_unused_gpl[];
152#define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) 185#define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL)
153#endif 186#endif
154 187
155/* lookup symbol in given range of kernel_symbols */
156static const struct kernel_symbol *lookup_symbol(const char *name,
157 const struct kernel_symbol *start,
158 const struct kernel_symbol *stop)
159{
160 const struct kernel_symbol *ks = start;
161 for (; ks < stop; ks++)
162 if (strcmp(ks->name, name) == 0)
163 return ks;
164 return NULL;
165}
166
167static bool always_ok(bool gplok, bool warn, const char *name)
168{
169 return true;
170}
171
172static bool printk_unused_warning(bool gplok, bool warn, const char *name)
173{
174 if (warn) {
175 printk(KERN_WARNING "Symbol %s is marked as UNUSED, "
176 "however this module is using it.\n", name);
177 printk(KERN_WARNING
178 "This symbol will go away in the future.\n");
179 printk(KERN_WARNING
180 "Please evalute if this is the right api to use and if "
181 "it really is, submit a report the linux kernel "
182 "mailinglist together with submitting your code for "
183 "inclusion.\n");
184 }
185 return true;
186}
187
188static bool gpl_only_unused_warning(bool gplok, bool warn, const char *name)
189{
190 if (!gplok)
191 return false;
192 return printk_unused_warning(gplok, warn, name);
193}
194
195static bool gpl_only(bool gplok, bool warn, const char *name)
196{
197 return gplok;
198}
199
200static bool warn_if_not_gpl(bool gplok, bool warn, const char *name)
201{
202 if (!gplok && warn) {
203 printk(KERN_WARNING "Symbol %s is being used "
204 "by a non-GPL module, which will not "
205 "be allowed in the future\n", name);
206 printk(KERN_WARNING "Please see the file "
207 "Documentation/feature-removal-schedule.txt "
208 "in the kernel source tree for more details.\n");
209 }
210 return true;
211}
212
213struct symsearch { 188struct symsearch {
214 const struct kernel_symbol *start, *stop; 189 const struct kernel_symbol *start, *stop;
215 const unsigned long *crcs; 190 const unsigned long *crcs;
216 bool (*check)(bool gplok, bool warn, const char *name); 191 enum {
192 NOT_GPL_ONLY,
193 GPL_ONLY,
194 WILL_BE_GPL_ONLY,
195 } licence;
196 bool unused;
217}; 197};
218 198
219/* Look through this array of symbol tables for a symbol match which 199static bool each_symbol_in_section(const struct symsearch *arr,
220 * passes the check function. */ 200 unsigned int arrsize,
221static const struct kernel_symbol *search_symarrays(const struct symsearch *arr, 201 struct module *owner,
222 unsigned int num, 202 bool (*fn)(const struct symsearch *syms,
223 const char *name, 203 struct module *owner,
224 bool gplok, 204 unsigned int symnum, void *data),
225 bool warn, 205 void *data)
226 const unsigned long **crc)
227{ 206{
228 unsigned int i; 207 unsigned int i, j;
229 const struct kernel_symbol *ks;
230
231 for (i = 0; i < num; i++) {
232 ks = lookup_symbol(name, arr[i].start, arr[i].stop);
233 if (!ks || !arr[i].check(gplok, warn, name))
234 continue;
235 208
236 if (crc) 209 for (j = 0; j < arrsize; j++) {
237 *crc = symversion(arr[i].crcs, ks - arr[i].start); 210 for (i = 0; i < arr[j].stop - arr[j].start; i++)
238 return ks; 211 if (fn(&arr[j], owner, i, data))
212 return true;
239 } 213 }
240 return NULL; 214
215 return false;
241} 216}
242 217
243/* Find a symbol, return value, (optional) crc and (optional) module 218/* Returns true as soon as fn returns true, otherwise false. */
244 * which owns it */ 219static bool each_symbol(bool (*fn)(const struct symsearch *arr,
245static unsigned long find_symbol(const char *name, 220 struct module *owner,
246 struct module **owner, 221 unsigned int symnum, void *data),
247 const unsigned long **crc, 222 void *data)
248 bool gplok,
249 bool warn)
250{ 223{
251 struct module *mod; 224 struct module *mod;
252 const struct kernel_symbol *ks;
253 const struct symsearch arr[] = { 225 const struct symsearch arr[] = {
254 { __start___ksymtab, __stop___ksymtab, __start___kcrctab, 226 { __start___ksymtab, __stop___ksymtab, __start___kcrctab,
255 always_ok }, 227 NOT_GPL_ONLY, false },
256 { __start___ksymtab_gpl, __stop___ksymtab_gpl, 228 { __start___ksymtab_gpl, __stop___ksymtab_gpl,
257 __start___kcrctab_gpl, gpl_only }, 229 __start___kcrctab_gpl,
230 GPL_ONLY, false },
258 { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future, 231 { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future,
259 __start___kcrctab_gpl_future, warn_if_not_gpl }, 232 __start___kcrctab_gpl_future,
233 WILL_BE_GPL_ONLY, false },
234#ifdef CONFIG_UNUSED_SYMBOLS
260 { __start___ksymtab_unused, __stop___ksymtab_unused, 235 { __start___ksymtab_unused, __stop___ksymtab_unused,
261 __start___kcrctab_unused, printk_unused_warning }, 236 __start___kcrctab_unused,
237 NOT_GPL_ONLY, true },
262 { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl, 238 { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl,
263 __start___kcrctab_unused_gpl, gpl_only_unused_warning }, 239 __start___kcrctab_unused_gpl,
240 GPL_ONLY, true },
241#endif
264 }; 242 };
265 243
266 /* Core kernel first. */ 244 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data))
267 ks = search_symarrays(arr, ARRAY_SIZE(arr), name, gplok, warn, crc); 245 return true;
268 if (ks) {
269 if (owner)
270 *owner = NULL;
271 return ks->value;
272 }
273 246
274 /* Now try modules. */ 247 list_for_each_entry_rcu(mod, &modules, list) {
275 list_for_each_entry(mod, &modules, list) {
276 struct symsearch arr[] = { 248 struct symsearch arr[] = {
277 { mod->syms, mod->syms + mod->num_syms, mod->crcs, 249 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
278 always_ok }, 250 NOT_GPL_ONLY, false },
279 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms, 251 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
280 mod->gpl_crcs, gpl_only }, 252 mod->gpl_crcs,
253 GPL_ONLY, false },
281 { mod->gpl_future_syms, 254 { mod->gpl_future_syms,
282 mod->gpl_future_syms + mod->num_gpl_future_syms, 255 mod->gpl_future_syms + mod->num_gpl_future_syms,
283 mod->gpl_future_crcs, warn_if_not_gpl }, 256 mod->gpl_future_crcs,
257 WILL_BE_GPL_ONLY, false },
258#ifdef CONFIG_UNUSED_SYMBOLS
284 { mod->unused_syms, 259 { mod->unused_syms,
285 mod->unused_syms + mod->num_unused_syms, 260 mod->unused_syms + mod->num_unused_syms,
286 mod->unused_crcs, printk_unused_warning }, 261 mod->unused_crcs,
262 NOT_GPL_ONLY, true },
287 { mod->unused_gpl_syms, 263 { mod->unused_gpl_syms,
288 mod->unused_gpl_syms + mod->num_unused_gpl_syms, 264 mod->unused_gpl_syms + mod->num_unused_gpl_syms,
289 mod->unused_gpl_crcs, gpl_only_unused_warning }, 265 mod->unused_gpl_crcs,
266 GPL_ONLY, true },
267#endif
290 }; 268 };
291 269
292 ks = search_symarrays(arr, ARRAY_SIZE(arr), 270 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
293 name, gplok, warn, crc); 271 return true;
294 if (ks) { 272 }
295 if (owner) 273 return false;
296 *owner = mod; 274}
297 return ks->value; 275
276struct find_symbol_arg {
277 /* Input */
278 const char *name;
279 bool gplok;
280 bool warn;
281
282 /* Output */
283 struct module *owner;
284 const unsigned long *crc;
285 unsigned long value;
286};
287
288static bool find_symbol_in_section(const struct symsearch *syms,
289 struct module *owner,
290 unsigned int symnum, void *data)
291{
292 struct find_symbol_arg *fsa = data;
293
294 if (strcmp(syms->start[symnum].name, fsa->name) != 0)
295 return false;
296
297 if (!fsa->gplok) {
298 if (syms->licence == GPL_ONLY)
299 return false;
300 if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) {
301 printk(KERN_WARNING "Symbol %s is being used "
302 "by a non-GPL module, which will not "
303 "be allowed in the future\n", fsa->name);
304 printk(KERN_WARNING "Please see the file "
305 "Documentation/feature-removal-schedule.txt "
306 "in the kernel source tree for more details.\n");
298 } 307 }
299 } 308 }
300 309
310#ifdef CONFIG_UNUSED_SYMBOLS
311 if (syms->unused && fsa->warn) {
312 printk(KERN_WARNING "Symbol %s is marked as UNUSED, "
313 "however this module is using it.\n", fsa->name);
314 printk(KERN_WARNING
315 "This symbol will go away in the future.\n");
316 printk(KERN_WARNING
317 "Please evalute if this is the right api to use and if "
318 "it really is, submit a report the linux kernel "
319 "mailinglist together with submitting your code for "
320 "inclusion.\n");
321 }
322#endif
323
324 fsa->owner = owner;
325 fsa->crc = symversion(syms->crcs, symnum);
326 fsa->value = syms->start[symnum].value;
327 return true;
328}
329
330/* Find a symbol, return value, (optional) crc and (optional) module
331 * which owns it */
332static unsigned long find_symbol(const char *name,
333 struct module **owner,
334 const unsigned long **crc,
335 bool gplok,
336 bool warn)
337{
338 struct find_symbol_arg fsa;
339
340 fsa.name = name;
341 fsa.gplok = gplok;
342 fsa.warn = warn;
343
344 if (each_symbol(find_symbol_in_section, &fsa)) {
345 if (owner)
346 *owner = fsa.owner;
347 if (crc)
348 *crc = fsa.crc;
349 return fsa.value;
350 }
351
301 DEBUGP("Failed to find symbol %s\n", name); 352 DEBUGP("Failed to find symbol %s\n", name);
302 return -ENOENT; 353 return -ENOENT;
303} 354}
@@ -639,8 +690,8 @@ static int __try_stop_module(void *_sref)
639{ 690{
640 struct stopref *sref = _sref; 691 struct stopref *sref = _sref;
641 692
642 /* If it's not unused, quit unless we are told to block. */ 693 /* If it's not unused, quit unless we're forcing. */
643 if ((sref->flags & O_NONBLOCK) && module_refcount(sref->mod) != 0) { 694 if (module_refcount(sref->mod) != 0) {
644 if (!(*sref->forced = try_force_unload(sref->flags))) 695 if (!(*sref->forced = try_force_unload(sref->flags)))
645 return -EWOULDBLOCK; 696 return -EWOULDBLOCK;
646 } 697 }
@@ -652,9 +703,16 @@ static int __try_stop_module(void *_sref)
652 703
653static int try_stop_module(struct module *mod, int flags, int *forced) 704static int try_stop_module(struct module *mod, int flags, int *forced)
654{ 705{
655 struct stopref sref = { mod, flags, forced }; 706 if (flags & O_NONBLOCK) {
707 struct stopref sref = { mod, flags, forced };
656 708
657 return stop_machine_run(__try_stop_module, &sref, NR_CPUS); 709 return stop_machine(__try_stop_module, &sref, NULL);
710 } else {
711 /* We don't need to stop the machine for this. */
712 mod->state = MODULE_STATE_GOING;
713 synchronize_sched();
714 return 0;
715 }
658} 716}
659 717
660unsigned int module_refcount(struct module *mod) 718unsigned int module_refcount(struct module *mod)
@@ -754,6 +812,7 @@ sys_delete_module(const char __user *name_user, unsigned int flags)
754 mutex_lock(&module_mutex); 812 mutex_lock(&module_mutex);
755 /* Store the name of the last unloaded module for diagnostic purposes */ 813 /* Store the name of the last unloaded module for diagnostic purposes */
756 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); 814 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module));
815 unregister_dynamic_debug_module(mod->name);
757 free_module(mod); 816 free_module(mod);
758 817
759 out: 818 out:
@@ -893,7 +952,7 @@ static const char vermagic[] = VERMAGIC_STRING;
893static int try_to_force_load(struct module *mod, const char *symname) 952static int try_to_force_load(struct module *mod, const char *symname)
894{ 953{
895#ifdef CONFIG_MODULE_FORCE_LOAD 954#ifdef CONFIG_MODULE_FORCE_LOAD
896 if (!(tainted & TAINT_FORCED_MODULE)) 955 if (!test_taint(TAINT_FORCED_MODULE))
897 printk("%s: no version for \"%s\" found: kernel tainted.\n", 956 printk("%s: no version for \"%s\" found: kernel tainted.\n",
898 mod->name, symname); 957 mod->name, symname);
899 add_taint_module(mod, TAINT_FORCED_MODULE); 958 add_taint_module(mod, TAINT_FORCED_MODULE);
@@ -1003,7 +1062,7 @@ static unsigned long resolve_symbol(Elf_Shdr *sechdrs,
1003 const unsigned long *crc; 1062 const unsigned long *crc;
1004 1063
1005 ret = find_symbol(name, &owner, &crc, 1064 ret = find_symbol(name, &owner, &crc,
1006 !(mod->taints & TAINT_PROPRIETARY_MODULE), true); 1065 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true);
1007 if (!IS_ERR_VALUE(ret)) { 1066 if (!IS_ERR_VALUE(ret)) {
1008 /* use_module can fail due to OOM, 1067 /* use_module can fail due to OOM,
1009 or module initialization or unloading */ 1068 or module initialization or unloading */
@@ -1143,7 +1202,7 @@ static void free_notes_attrs(struct module_notes_attrs *notes_attrs,
1143 while (i-- > 0) 1202 while (i-- > 0)
1144 sysfs_remove_bin_file(notes_attrs->dir, 1203 sysfs_remove_bin_file(notes_attrs->dir,
1145 &notes_attrs->attrs[i]); 1204 &notes_attrs->attrs[i]);
1146 kobject_del(notes_attrs->dir); 1205 kobject_put(notes_attrs->dir);
1147 } 1206 }
1148 kfree(notes_attrs); 1207 kfree(notes_attrs);
1149} 1208}
@@ -1361,17 +1420,6 @@ static void mod_kobject_remove(struct module *mod)
1361} 1420}
1362 1421
1363/* 1422/*
1364 * link the module with the whole machine is stopped with interrupts off
1365 * - this defends against kallsyms not taking locks
1366 */
1367static int __link_module(void *_mod)
1368{
1369 struct module *mod = _mod;
1370 list_add(&mod->list, &modules);
1371 return 0;
1372}
1373
1374/*
1375 * unlink the module with the whole machine is stopped with interrupts off 1423 * unlink the module with the whole machine is stopped with interrupts off
1376 * - this defends against kallsyms not taking locks 1424 * - this defends against kallsyms not taking locks
1377 */ 1425 */
@@ -1386,7 +1434,7 @@ static int __unlink_module(void *_mod)
1386static void free_module(struct module *mod) 1434static void free_module(struct module *mod)
1387{ 1435{
1388 /* Delete from various lists */ 1436 /* Delete from various lists */
1389 stop_machine_run(__unlink_module, mod, NR_CPUS); 1437 stop_machine(__unlink_module, mod, NULL);
1390 remove_notes_attrs(mod); 1438 remove_notes_attrs(mod);
1391 remove_sect_attrs(mod); 1439 remove_sect_attrs(mod);
1392 mod_kobject_remove(mod); 1440 mod_kobject_remove(mod);
@@ -1399,6 +1447,9 @@ static void free_module(struct module *mod)
1399 /* Module unload stuff */ 1447 /* Module unload stuff */
1400 module_unload_free(mod); 1448 module_unload_free(mod);
1401 1449
1450 /* release any pointers to mcount in this module */
1451 ftrace_release(mod->module_core, mod->core_size);
1452
1402 /* This may be NULL, but that's OK */ 1453 /* This may be NULL, but that's OK */
1403 module_free(mod, mod->module_init); 1454 module_free(mod, mod->module_init);
1404 kfree(mod->args); 1455 kfree(mod->args);
@@ -1445,8 +1496,10 @@ static int verify_export_symbols(struct module *mod)
1445 { mod->syms, mod->num_syms }, 1496 { mod->syms, mod->num_syms },
1446 { mod->gpl_syms, mod->num_gpl_syms }, 1497 { mod->gpl_syms, mod->num_gpl_syms },
1447 { mod->gpl_future_syms, mod->num_gpl_future_syms }, 1498 { mod->gpl_future_syms, mod->num_gpl_future_syms },
1499#ifdef CONFIG_UNUSED_SYMBOLS
1448 { mod->unused_syms, mod->num_unused_syms }, 1500 { mod->unused_syms, mod->num_unused_syms },
1449 { mod->unused_gpl_syms, mod->num_unused_gpl_syms }, 1501 { mod->unused_gpl_syms, mod->num_unused_gpl_syms },
1502#endif
1450 }; 1503 };
1451 1504
1452 for (i = 0; i < ARRAY_SIZE(arr); i++) { 1505 for (i = 0; i < ARRAY_SIZE(arr); i++) {
@@ -1526,7 +1579,7 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
1526} 1579}
1527 1580
1528/* Update size with this section: return offset. */ 1581/* Update size with this section: return offset. */
1529static long get_offset(unsigned long *size, Elf_Shdr *sechdr) 1582static long get_offset(unsigned int *size, Elf_Shdr *sechdr)
1530{ 1583{
1531 long ret; 1584 long ret;
1532 1585
@@ -1602,7 +1655,7 @@ static void set_license(struct module *mod, const char *license)
1602 license = "unspecified"; 1655 license = "unspecified";
1603 1656
1604 if (!license_is_gpl_compatible(license)) { 1657 if (!license_is_gpl_compatible(license)) {
1605 if (!(tainted & TAINT_PROPRIETARY_MODULE)) 1658 if (!test_taint(TAINT_PROPRIETARY_MODULE))
1606 printk(KERN_WARNING "%s: module license '%s' taints " 1659 printk(KERN_WARNING "%s: module license '%s' taints "
1607 "kernel.\n", mod->name, license); 1660 "kernel.\n", mod->name, license);
1608 add_taint_module(mod, TAINT_PROPRIETARY_MODULE); 1661 add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
@@ -1659,6 +1712,19 @@ static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs,
1659} 1712}
1660 1713
1661#ifdef CONFIG_KALLSYMS 1714#ifdef CONFIG_KALLSYMS
1715
1716/* lookup symbol in given range of kernel_symbols */
1717static const struct kernel_symbol *lookup_symbol(const char *name,
1718 const struct kernel_symbol *start,
1719 const struct kernel_symbol *stop)
1720{
1721 const struct kernel_symbol *ks = start;
1722 for (; ks < stop; ks++)
1723 if (strcmp(ks->name, name) == 0)
1724 return ks;
1725 return NULL;
1726}
1727
1662static int is_exported(const char *name, const struct module *mod) 1728static int is_exported(const char *name, const struct module *mod)
1663{ 1729{
1664 if (!mod && lookup_symbol(name, __start___ksymtab, __stop___ksymtab)) 1730 if (!mod && lookup_symbol(name, __start___ksymtab, __stop___ksymtab))
@@ -1738,42 +1804,56 @@ static inline void add_kallsyms(struct module *mod,
1738} 1804}
1739#endif /* CONFIG_KALLSYMS */ 1805#endif /* CONFIG_KALLSYMS */
1740 1806
1807static void dynamic_printk_setup(struct mod_debug *debug, unsigned int num)
1808{
1809#ifdef CONFIG_DYNAMIC_PRINTK_DEBUG
1810 unsigned int i;
1811
1812 for (i = 0; i < num; i++) {
1813 register_dynamic_debug_module(debug[i].modname,
1814 debug[i].type,
1815 debug[i].logical_modname,
1816 debug[i].flag_names,
1817 debug[i].hash, debug[i].hash2);
1818 }
1819#endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */
1820}
1821
1822static void *module_alloc_update_bounds(unsigned long size)
1823{
1824 void *ret = module_alloc(size);
1825
1826 if (ret) {
1827 /* Update module bounds. */
1828 if ((unsigned long)ret < module_addr_min)
1829 module_addr_min = (unsigned long)ret;
1830 if ((unsigned long)ret + size > module_addr_max)
1831 module_addr_max = (unsigned long)ret + size;
1832 }
1833 return ret;
1834}
1835
1741/* Allocate and load the module: note that size of section 0 is always 1836/* Allocate and load the module: note that size of section 0 is always
1742 zero, and we rely on this for optional sections. */ 1837 zero, and we rely on this for optional sections. */
1743static struct module *load_module(void __user *umod, 1838static noinline struct module *load_module(void __user *umod,
1744 unsigned long len, 1839 unsigned long len,
1745 const char __user *uargs) 1840 const char __user *uargs)
1746{ 1841{
1747 Elf_Ehdr *hdr; 1842 Elf_Ehdr *hdr;
1748 Elf_Shdr *sechdrs; 1843 Elf_Shdr *sechdrs;
1749 char *secstrings, *args, *modmagic, *strtab = NULL; 1844 char *secstrings, *args, *modmagic, *strtab = NULL;
1845 char *staging;
1750 unsigned int i; 1846 unsigned int i;
1751 unsigned int symindex = 0; 1847 unsigned int symindex = 0;
1752 unsigned int strindex = 0; 1848 unsigned int strindex = 0;
1753 unsigned int setupindex; 1849 unsigned int modindex, versindex, infoindex, pcpuindex;
1754 unsigned int exindex;
1755 unsigned int exportindex;
1756 unsigned int modindex;
1757 unsigned int obsparmindex;
1758 unsigned int infoindex;
1759 unsigned int gplindex;
1760 unsigned int crcindex;
1761 unsigned int gplcrcindex;
1762 unsigned int versindex;
1763 unsigned int pcpuindex;
1764 unsigned int gplfutureindex;
1765 unsigned int gplfuturecrcindex;
1766 unsigned int unwindex = 0; 1850 unsigned int unwindex = 0;
1767 unsigned int unusedindex; 1851 unsigned int num_kp, num_mcount;
1768 unsigned int unusedcrcindex; 1852 struct kernel_param *kp;
1769 unsigned int unusedgplindex;
1770 unsigned int unusedgplcrcindex;
1771 unsigned int markersindex;
1772 unsigned int markersstringsindex;
1773 struct module *mod; 1853 struct module *mod;
1774 long err = 0; 1854 long err = 0;
1775 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ 1855 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */
1776 struct exception_table_entry *extable; 1856 unsigned long *mseg;
1777 mm_segment_t old_fs; 1857 mm_segment_t old_fs;
1778 1858
1779 DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", 1859 DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n",
@@ -1837,6 +1917,7 @@ static struct module *load_module(void __user *umod,
1837 err = -ENOEXEC; 1917 err = -ENOEXEC;
1838 goto free_hdr; 1918 goto free_hdr;
1839 } 1919 }
1920 /* This is temporary: point mod into copy of data. */
1840 mod = (void *)sechdrs[modindex].sh_addr; 1921 mod = (void *)sechdrs[modindex].sh_addr;
1841 1922
1842 if (symindex == 0) { 1923 if (symindex == 0) {
@@ -1846,20 +1927,6 @@ static struct module *load_module(void __user *umod,
1846 goto free_hdr; 1927 goto free_hdr;
1847 } 1928 }
1848 1929
1849 /* Optional sections */
1850 exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab");
1851 gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl");
1852 gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future");
1853 unusedindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused");
1854 unusedgplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused_gpl");
1855 crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab");
1856 gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl");
1857 gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future");
1858 unusedcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused");
1859 unusedgplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused_gpl");
1860 setupindex = find_sec(hdr, sechdrs, secstrings, "__param");
1861 exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table");
1862 obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm");
1863 versindex = find_sec(hdr, sechdrs, secstrings, "__versions"); 1930 versindex = find_sec(hdr, sechdrs, secstrings, "__versions");
1864 infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo"); 1931 infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo");
1865 pcpuindex = find_pcpusec(hdr, sechdrs, secstrings); 1932 pcpuindex = find_pcpusec(hdr, sechdrs, secstrings);
@@ -1897,6 +1964,14 @@ static struct module *load_module(void __user *umod,
1897 goto free_hdr; 1964 goto free_hdr;
1898 } 1965 }
1899 1966
1967 staging = get_modinfo(sechdrs, infoindex, "staging");
1968 if (staging) {
1969 add_taint_module(mod, TAINT_CRAP);
1970 printk(KERN_WARNING "%s: module is from the staging directory,"
1971 " the quality is unknown, you have been warned.\n",
1972 mod->name);
1973 }
1974
1900 /* Now copy in args */ 1975 /* Now copy in args */
1901 args = strndup_user(uargs, ~0UL >> 1); 1976 args = strndup_user(uargs, ~0UL >> 1);
1902 if (IS_ERR(args)) { 1977 if (IS_ERR(args)) {
@@ -1935,7 +2010,7 @@ static struct module *load_module(void __user *umod,
1935 layout_sections(mod, hdr, sechdrs, secstrings); 2010 layout_sections(mod, hdr, sechdrs, secstrings);
1936 2011
1937 /* Do the allocs. */ 2012 /* Do the allocs. */
1938 ptr = module_alloc(mod->core_size); 2013 ptr = module_alloc_update_bounds(mod->core_size);
1939 if (!ptr) { 2014 if (!ptr) {
1940 err = -ENOMEM; 2015 err = -ENOMEM;
1941 goto free_percpu; 2016 goto free_percpu;
@@ -1943,7 +2018,7 @@ static struct module *load_module(void __user *umod,
1943 memset(ptr, 0, mod->core_size); 2018 memset(ptr, 0, mod->core_size);
1944 mod->module_core = ptr; 2019 mod->module_core = ptr;
1945 2020
1946 ptr = module_alloc(mod->init_size); 2021 ptr = module_alloc_update_bounds(mod->init_size);
1947 if (!ptr && mod->init_size) { 2022 if (!ptr && mod->init_size) {
1948 err = -ENOMEM; 2023 err = -ENOMEM;
1949 goto free_core; 2024 goto free_core;
@@ -2007,48 +2082,65 @@ static struct module *load_module(void __user *umod,
2007 if (err < 0) 2082 if (err < 0)
2008 goto cleanup; 2083 goto cleanup;
2009 2084
2010 /* Set up EXPORTed & EXPORT_GPLed symbols (section 0 is 0 length) */ 2085 /* Now we've got everything in the final locations, we can
2011 mod->num_syms = sechdrs[exportindex].sh_size / sizeof(*mod->syms); 2086 * find optional sections. */
2012 mod->syms = (void *)sechdrs[exportindex].sh_addr; 2087 kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp),
2013 if (crcindex) 2088 &num_kp);
2014 mod->crcs = (void *)sechdrs[crcindex].sh_addr; 2089 mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab",
2015 mod->num_gpl_syms = sechdrs[gplindex].sh_size / sizeof(*mod->gpl_syms); 2090 sizeof(*mod->syms), &mod->num_syms);
2016 mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr; 2091 mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab");
2017 if (gplcrcindex) 2092 mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl",
2018 mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; 2093 sizeof(*mod->gpl_syms),
2019 mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size / 2094 &mod->num_gpl_syms);
2020 sizeof(*mod->gpl_future_syms); 2095 mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl");
2021 mod->num_unused_syms = sechdrs[unusedindex].sh_size / 2096 mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings,
2022 sizeof(*mod->unused_syms); 2097 "__ksymtab_gpl_future",
2023 mod->num_unused_gpl_syms = sechdrs[unusedgplindex].sh_size / 2098 sizeof(*mod->gpl_future_syms),
2024 sizeof(*mod->unused_gpl_syms); 2099 &mod->num_gpl_future_syms);
2025 mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr; 2100 mod->gpl_future_crcs = section_addr(hdr, sechdrs, secstrings,
2026 if (gplfuturecrcindex) 2101 "__kcrctab_gpl_future");
2027 mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr; 2102
2028 2103#ifdef CONFIG_UNUSED_SYMBOLS
2029 mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr; 2104 mod->unused_syms = section_objs(hdr, sechdrs, secstrings,
2030 if (unusedcrcindex) 2105 "__ksymtab_unused",
2031 mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr; 2106 sizeof(*mod->unused_syms),
2032 mod->unused_gpl_syms = (void *)sechdrs[unusedgplindex].sh_addr; 2107 &mod->num_unused_syms);
2033 if (unusedgplcrcindex) 2108 mod->unused_crcs = section_addr(hdr, sechdrs, secstrings,
2034 mod->unused_gpl_crcs 2109 "__kcrctab_unused");
2035 = (void *)sechdrs[unusedgplcrcindex].sh_addr; 2110 mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings,
2111 "__ksymtab_unused_gpl",
2112 sizeof(*mod->unused_gpl_syms),
2113 &mod->num_unused_gpl_syms);
2114 mod->unused_gpl_crcs = section_addr(hdr, sechdrs, secstrings,
2115 "__kcrctab_unused_gpl");
2116#endif
2117
2118#ifdef CONFIG_MARKERS
2119 mod->markers = section_objs(hdr, sechdrs, secstrings, "__markers",
2120 sizeof(*mod->markers), &mod->num_markers);
2121#endif
2122#ifdef CONFIG_TRACEPOINTS
2123 mod->tracepoints = section_objs(hdr, sechdrs, secstrings,
2124 "__tracepoints",
2125 sizeof(*mod->tracepoints),
2126 &mod->num_tracepoints);
2127#endif
2036 2128
2037#ifdef CONFIG_MODVERSIONS 2129#ifdef CONFIG_MODVERSIONS
2038 if ((mod->num_syms && !crcindex) || 2130 if ((mod->num_syms && !mod->crcs)
2039 (mod->num_gpl_syms && !gplcrcindex) || 2131 || (mod->num_gpl_syms && !mod->gpl_crcs)
2040 (mod->num_gpl_future_syms && !gplfuturecrcindex) || 2132 || (mod->num_gpl_future_syms && !mod->gpl_future_crcs)
2041 (mod->num_unused_syms && !unusedcrcindex) || 2133#ifdef CONFIG_UNUSED_SYMBOLS
2042 (mod->num_unused_gpl_syms && !unusedgplcrcindex)) { 2134 || (mod->num_unused_syms && !mod->unused_crcs)
2135 || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs)
2136#endif
2137 ) {
2043 printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); 2138 printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name);
2044 err = try_to_force_load(mod, "nocrc"); 2139 err = try_to_force_load(mod, "nocrc");
2045 if (err) 2140 if (err)
2046 goto cleanup; 2141 goto cleanup;
2047 } 2142 }
2048#endif 2143#endif
2049 markersindex = find_sec(hdr, sechdrs, secstrings, "__markers");
2050 markersstringsindex = find_sec(hdr, sechdrs, secstrings,
2051 "__markers_strings");
2052 2144
2053 /* Now do relocations. */ 2145 /* Now do relocations. */
2054 for (i = 1; i < hdr->e_shnum; i++) { 2146 for (i = 1; i < hdr->e_shnum; i++) {
@@ -2071,22 +2163,16 @@ static struct module *load_module(void __user *umod,
2071 if (err < 0) 2163 if (err < 0)
2072 goto cleanup; 2164 goto cleanup;
2073 } 2165 }
2074#ifdef CONFIG_MARKERS
2075 mod->markers = (void *)sechdrs[markersindex].sh_addr;
2076 mod->num_markers =
2077 sechdrs[markersindex].sh_size / sizeof(*mod->markers);
2078#endif
2079 2166
2080 /* Find duplicate symbols */ 2167 /* Find duplicate symbols */
2081 err = verify_export_symbols(mod); 2168 err = verify_export_symbols(mod);
2082
2083 if (err < 0) 2169 if (err < 0)
2084 goto cleanup; 2170 goto cleanup;
2085 2171
2086 /* Set up and sort exception table */ 2172 /* Set up and sort exception table */
2087 mod->num_exentries = sechdrs[exindex].sh_size / sizeof(*mod->extable); 2173 mod->extable = section_objs(hdr, sechdrs, secstrings, "__ex_table",
2088 mod->extable = extable = (void *)sechdrs[exindex].sh_addr; 2174 sizeof(*mod->extable), &mod->num_exentries);
2089 sort_extable(extable, extable + mod->num_exentries); 2175 sort_extable(mod->extable, mod->extable + mod->num_exentries);
2090 2176
2091 /* Finally, copy percpu area over. */ 2177 /* Finally, copy percpu area over. */
2092 percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr, 2178 percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr,
@@ -2094,11 +2180,29 @@ static struct module *load_module(void __user *umod,
2094 2180
2095 add_kallsyms(mod, sechdrs, symindex, strindex, secstrings); 2181 add_kallsyms(mod, sechdrs, symindex, strindex, secstrings);
2096 2182
2183 if (!mod->taints) {
2184 struct mod_debug *debug;
2185 unsigned int num_debug;
2186
2097#ifdef CONFIG_MARKERS 2187#ifdef CONFIG_MARKERS
2098 if (!mod->taints)
2099 marker_update_probe_range(mod->markers, 2188 marker_update_probe_range(mod->markers,
2100 mod->markers + mod->num_markers); 2189 mod->markers + mod->num_markers);
2101#endif 2190#endif
2191 debug = section_objs(hdr, sechdrs, secstrings, "__verbose",
2192 sizeof(*debug), &num_debug);
2193 dynamic_printk_setup(debug, num_debug);
2194
2195#ifdef CONFIG_TRACEPOINTS
2196 tracepoint_update_probe_range(mod->tracepoints,
2197 mod->tracepoints + mod->num_tracepoints);
2198#endif
2199 }
2200
2201 /* sechdrs[0].sh_size is always zero */
2202 mseg = section_objs(hdr, sechdrs, secstrings, "__mcount_loc",
2203 sizeof(*mseg), &num_mcount);
2204 ftrace_init_module(mseg, mseg + num_mcount);
2205
2102 err = module_finalize(hdr, sechdrs, mod); 2206 err = module_finalize(hdr, sechdrs, mod);
2103 if (err < 0) 2207 if (err < 0)
2104 goto cleanup; 2208 goto cleanup;
@@ -2122,30 +2226,24 @@ static struct module *load_module(void __user *umod,
2122 set_fs(old_fs); 2226 set_fs(old_fs);
2123 2227
2124 mod->args = args; 2228 mod->args = args;
2125 if (obsparmindex) 2229 if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
2126 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", 2230 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
2127 mod->name); 2231 mod->name);
2128 2232
2129 /* Now sew it into the lists so we can get lockdep and oops 2233 /* Now sew it into the lists so we can get lockdep and oops
2130 * info during argument parsing. Noone should access us, since 2234 * info during argument parsing. Noone should access us, since
2131 * strong_try_module_get() will fail. */ 2235 * strong_try_module_get() will fail.
2132 stop_machine_run(__link_module, mod, NR_CPUS); 2236 * lockdep/oops can run asynchronous, so use the RCU list insertion
2133 2237 * function to insert in a way safe to concurrent readers.
2134 /* Size of section 0 is 0, so this works well if no params */ 2238 * The mutex protects against concurrent writers.
2135 err = parse_args(mod->name, mod->args, 2239 */
2136 (struct kernel_param *) 2240 list_add_rcu(&mod->list, &modules);
2137 sechdrs[setupindex].sh_addr, 2241
2138 sechdrs[setupindex].sh_size 2242 err = parse_args(mod->name, mod->args, kp, num_kp, NULL);
2139 / sizeof(struct kernel_param),
2140 NULL);
2141 if (err < 0) 2243 if (err < 0)
2142 goto unlink; 2244 goto unlink;
2143 2245
2144 err = mod_sysfs_setup(mod, 2246 err = mod_sysfs_setup(mod, kp, num_kp);
2145 (struct kernel_param *)
2146 sechdrs[setupindex].sh_addr,
2147 sechdrs[setupindex].sh_size
2148 / sizeof(struct kernel_param));
2149 if (err < 0) 2247 if (err < 0)
2150 goto unlink; 2248 goto unlink;
2151 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); 2249 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
@@ -2163,11 +2261,12 @@ static struct module *load_module(void __user *umod,
2163 return mod; 2261 return mod;
2164 2262
2165 unlink: 2263 unlink:
2166 stop_machine_run(__unlink_module, mod, NR_CPUS); 2264 stop_machine(__unlink_module, mod, NULL);
2167 module_arch_cleanup(mod); 2265 module_arch_cleanup(mod);
2168 cleanup: 2266 cleanup:
2169 kobject_del(&mod->mkobj.kobj); 2267 kobject_del(&mod->mkobj.kobj);
2170 kobject_put(&mod->mkobj.kobj); 2268 kobject_put(&mod->mkobj.kobj);
2269 ftrace_release(mod->module_core, mod->core_size);
2171 free_unload: 2270 free_unload:
2172 module_unload_free(mod); 2271 module_unload_free(mod);
2173 module_free(mod, mod->module_init); 2272 module_free(mod, mod->module_init);
@@ -2220,7 +2319,7 @@ sys_init_module(void __user *umod,
2220 2319
2221 /* Start the module */ 2320 /* Start the module */
2222 if (mod->init != NULL) 2321 if (mod->init != NULL)
2223 ret = mod->init(); 2322 ret = do_one_initcall(mod->init);
2224 if (ret < 0) { 2323 if (ret < 0) {
2225 /* Init routine failed: abort. Try to protect us from 2324 /* Init routine failed: abort. Try to protect us from
2226 buggy refcounters. */ 2325 buggy refcounters. */
@@ -2333,7 +2432,7 @@ const char *module_address_lookup(unsigned long addr,
2333 const char *ret = NULL; 2432 const char *ret = NULL;
2334 2433
2335 preempt_disable(); 2434 preempt_disable();
2336 list_for_each_entry(mod, &modules, list) { 2435 list_for_each_entry_rcu(mod, &modules, list) {
2337 if (within(addr, mod->module_init, mod->init_size) 2436 if (within(addr, mod->module_init, mod->init_size)
2338 || within(addr, mod->module_core, mod->core_size)) { 2437 || within(addr, mod->module_core, mod->core_size)) {
2339 if (modname) 2438 if (modname)
@@ -2356,7 +2455,7 @@ int lookup_module_symbol_name(unsigned long addr, char *symname)
2356 struct module *mod; 2455 struct module *mod;
2357 2456
2358 preempt_disable(); 2457 preempt_disable();
2359 list_for_each_entry(mod, &modules, list) { 2458 list_for_each_entry_rcu(mod, &modules, list) {
2360 if (within(addr, mod->module_init, mod->init_size) || 2459 if (within(addr, mod->module_init, mod->init_size) ||
2361 within(addr, mod->module_core, mod->core_size)) { 2460 within(addr, mod->module_core, mod->core_size)) {
2362 const char *sym; 2461 const char *sym;
@@ -2380,7 +2479,7 @@ int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,
2380 struct module *mod; 2479 struct module *mod;
2381 2480
2382 preempt_disable(); 2481 preempt_disable();
2383 list_for_each_entry(mod, &modules, list) { 2482 list_for_each_entry_rcu(mod, &modules, list) {
2384 if (within(addr, mod->module_init, mod->init_size) || 2483 if (within(addr, mod->module_init, mod->init_size) ||
2385 within(addr, mod->module_core, mod->core_size)) { 2484 within(addr, mod->module_core, mod->core_size)) {
2386 const char *sym; 2485 const char *sym;
@@ -2407,7 +2506,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
2407 struct module *mod; 2506 struct module *mod;
2408 2507
2409 preempt_disable(); 2508 preempt_disable();
2410 list_for_each_entry(mod, &modules, list) { 2509 list_for_each_entry_rcu(mod, &modules, list) {
2411 if (symnum < mod->num_symtab) { 2510 if (symnum < mod->num_symtab) {
2412 *value = mod->symtab[symnum].st_value; 2511 *value = mod->symtab[symnum].st_value;
2413 *type = mod->symtab[symnum].st_info; 2512 *type = mod->symtab[symnum].st_info;
@@ -2450,7 +2549,7 @@ unsigned long module_kallsyms_lookup_name(const char *name)
2450 ret = mod_find_symname(mod, colon+1); 2549 ret = mod_find_symname(mod, colon+1);
2451 *colon = ':'; 2550 *colon = ':';
2452 } else { 2551 } else {
2453 list_for_each_entry(mod, &modules, list) 2552 list_for_each_entry_rcu(mod, &modules, list)
2454 if ((ret = mod_find_symname(mod, name)) != 0) 2553 if ((ret = mod_find_symname(mod, name)) != 0)
2455 break; 2554 break;
2456 } 2555 }
@@ -2459,23 +2558,6 @@ unsigned long module_kallsyms_lookup_name(const char *name)
2459} 2558}
2460#endif /* CONFIG_KALLSYMS */ 2559#endif /* CONFIG_KALLSYMS */
2461 2560
2462/* Called by the /proc file system to return a list of modules. */
2463static void *m_start(struct seq_file *m, loff_t *pos)
2464{
2465 mutex_lock(&module_mutex);
2466 return seq_list_start(&modules, *pos);
2467}
2468
2469static void *m_next(struct seq_file *m, void *p, loff_t *pos)
2470{
2471 return seq_list_next(p, &modules, pos);
2472}
2473
2474static void m_stop(struct seq_file *m, void *p)
2475{
2476 mutex_unlock(&module_mutex);
2477}
2478
2479static char *module_flags(struct module *mod, char *buf) 2561static char *module_flags(struct module *mod, char *buf)
2480{ 2562{
2481 int bx = 0; 2563 int bx = 0;
@@ -2484,10 +2566,12 @@ static char *module_flags(struct module *mod, char *buf)
2484 mod->state == MODULE_STATE_GOING || 2566 mod->state == MODULE_STATE_GOING ||
2485 mod->state == MODULE_STATE_COMING) { 2567 mod->state == MODULE_STATE_COMING) {
2486 buf[bx++] = '('; 2568 buf[bx++] = '(';
2487 if (mod->taints & TAINT_PROPRIETARY_MODULE) 2569 if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE))
2488 buf[bx++] = 'P'; 2570 buf[bx++] = 'P';
2489 if (mod->taints & TAINT_FORCED_MODULE) 2571 if (mod->taints & (1 << TAINT_FORCED_MODULE))
2490 buf[bx++] = 'F'; 2572 buf[bx++] = 'F';
2573 if (mod->taints & (1 << TAINT_CRAP))
2574 buf[bx++] = 'C';
2491 /* 2575 /*
2492 * TAINT_FORCED_RMMOD: could be added. 2576 * TAINT_FORCED_RMMOD: could be added.
2493 * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't 2577 * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
@@ -2507,12 +2591,30 @@ static char *module_flags(struct module *mod, char *buf)
2507 return buf; 2591 return buf;
2508} 2592}
2509 2593
2594#ifdef CONFIG_PROC_FS
2595/* Called by the /proc file system to return a list of modules. */
2596static void *m_start(struct seq_file *m, loff_t *pos)
2597{
2598 mutex_lock(&module_mutex);
2599 return seq_list_start(&modules, *pos);
2600}
2601
2602static void *m_next(struct seq_file *m, void *p, loff_t *pos)
2603{
2604 return seq_list_next(p, &modules, pos);
2605}
2606
2607static void m_stop(struct seq_file *m, void *p)
2608{
2609 mutex_unlock(&module_mutex);
2610}
2611
2510static int m_show(struct seq_file *m, void *p) 2612static int m_show(struct seq_file *m, void *p)
2511{ 2613{
2512 struct module *mod = list_entry(p, struct module, list); 2614 struct module *mod = list_entry(p, struct module, list);
2513 char buf[8]; 2615 char buf[8];
2514 2616
2515 seq_printf(m, "%s %lu", 2617 seq_printf(m, "%s %u",
2516 mod->name, mod->init_size + mod->core_size); 2618 mod->name, mod->init_size + mod->core_size);
2517 print_unload_info(m, mod); 2619 print_unload_info(m, mod);
2518 2620
@@ -2537,13 +2639,33 @@ static int m_show(struct seq_file *m, void *p)
2537 Where refcount is a number or -, and deps is a comma-separated list 2639 Where refcount is a number or -, and deps is a comma-separated list
2538 of depends or -. 2640 of depends or -.
2539*/ 2641*/
2540const struct seq_operations modules_op = { 2642static const struct seq_operations modules_op = {
2541 .start = m_start, 2643 .start = m_start,
2542 .next = m_next, 2644 .next = m_next,
2543 .stop = m_stop, 2645 .stop = m_stop,
2544 .show = m_show 2646 .show = m_show
2545}; 2647};
2546 2648
2649static int modules_open(struct inode *inode, struct file *file)
2650{
2651 return seq_open(file, &modules_op);
2652}
2653
2654static const struct file_operations proc_modules_operations = {
2655 .open = modules_open,
2656 .read = seq_read,
2657 .llseek = seq_lseek,
2658 .release = seq_release,
2659};
2660
2661static int __init proc_modules_init(void)
2662{
2663 proc_create("modules", 0, NULL, &proc_modules_operations);
2664 return 0;
2665}
2666module_init(proc_modules_init);
2667#endif
2668
2547/* Given an address, look for it in the module exception tables. */ 2669/* Given an address, look for it in the module exception tables. */
2548const struct exception_table_entry *search_module_extables(unsigned long addr) 2670const struct exception_table_entry *search_module_extables(unsigned long addr)
2549{ 2671{
@@ -2551,7 +2673,7 @@ const struct exception_table_entry *search_module_extables(unsigned long addr)
2551 struct module *mod; 2673 struct module *mod;
2552 2674
2553 preempt_disable(); 2675 preempt_disable();
2554 list_for_each_entry(mod, &modules, list) { 2676 list_for_each_entry_rcu(mod, &modules, list) {
2555 if (mod->num_exentries == 0) 2677 if (mod->num_exentries == 0)
2556 continue; 2678 continue;
2557 2679
@@ -2577,7 +2699,7 @@ int is_module_address(unsigned long addr)
2577 2699
2578 preempt_disable(); 2700 preempt_disable();
2579 2701
2580 list_for_each_entry(mod, &modules, list) { 2702 list_for_each_entry_rcu(mod, &modules, list) {
2581 if (within(addr, mod->module_core, mod->core_size)) { 2703 if (within(addr, mod->module_core, mod->core_size)) {
2582 preempt_enable(); 2704 preempt_enable();
2583 return 1; 2705 return 1;
@@ -2595,7 +2717,10 @@ struct module *__module_text_address(unsigned long addr)
2595{ 2717{
2596 struct module *mod; 2718 struct module *mod;
2597 2719
2598 list_for_each_entry(mod, &modules, list) 2720 if (addr < module_addr_min || addr > module_addr_max)
2721 return NULL;
2722
2723 list_for_each_entry_rcu(mod, &modules, list)
2599 if (within(addr, mod->module_init, mod->init_text_size) 2724 if (within(addr, mod->module_init, mod->init_text_size)
2600 || within(addr, mod->module_core, mod->core_text_size)) 2725 || within(addr, mod->module_core, mod->core_text_size))
2601 return mod; 2726 return mod;
@@ -2620,8 +2745,11 @@ void print_modules(void)
2620 char buf[8]; 2745 char buf[8];
2621 2746
2622 printk("Modules linked in:"); 2747 printk("Modules linked in:");
2623 list_for_each_entry(mod, &modules, list) 2748 /* Most callers should already have preempt disabled, but make sure */
2749 preempt_disable();
2750 list_for_each_entry_rcu(mod, &modules, list)
2624 printk(" %s%s", mod->name, module_flags(mod, buf)); 2751 printk(" %s%s", mod->name, module_flags(mod, buf));
2752 preempt_enable();
2625 if (last_unloaded_module[0]) 2753 if (last_unloaded_module[0])
2626 printk(" [last unloaded: %s]", last_unloaded_module); 2754 printk(" [last unloaded: %s]", last_unloaded_module);
2627 printk("\n"); 2755 printk("\n");
@@ -2646,3 +2774,50 @@ void module_update_markers(void)
2646 mutex_unlock(&module_mutex); 2774 mutex_unlock(&module_mutex);
2647} 2775}
2648#endif 2776#endif
2777
2778#ifdef CONFIG_TRACEPOINTS
2779void module_update_tracepoints(void)
2780{
2781 struct module *mod;
2782
2783 mutex_lock(&module_mutex);
2784 list_for_each_entry(mod, &modules, list)
2785 if (!mod->taints)
2786 tracepoint_update_probe_range(mod->tracepoints,
2787 mod->tracepoints + mod->num_tracepoints);
2788 mutex_unlock(&module_mutex);
2789}
2790
2791/*
2792 * Returns 0 if current not found.
2793 * Returns 1 if current found.
2794 */
2795int module_get_iter_tracepoints(struct tracepoint_iter *iter)
2796{
2797 struct module *iter_mod;
2798 int found = 0;
2799
2800 mutex_lock(&module_mutex);
2801 list_for_each_entry(iter_mod, &modules, list) {
2802 if (!iter_mod->taints) {
2803 /*
2804 * Sorted module list
2805 */
2806 if (iter_mod < iter->module)
2807 continue;
2808 else if (iter_mod > iter->module)
2809 iter->tracepoint = NULL;
2810 found = tracepoint_get_iter_range(&iter->tracepoint,
2811 iter_mod->tracepoints,
2812 iter_mod->tracepoints
2813 + iter_mod->num_tracepoints);
2814 if (found) {
2815 iter->module = iter_mod;
2816 break;
2817 }
2818 }
2819 }
2820 mutex_unlock(&module_mutex);
2821 return found;
2822}
2823#endif