diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-04-05 13:30:21 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-04-05 13:30:21 -0400 |
commit | cab4e4c43f92582a2bfc026137b3d8a175bd0360 (patch) | |
tree | 2f0e8fbc2e7d2d0cd6f1658a5e084a53b1e83a2e | |
parent | 5412b5399e095730008a14f2107331b2123733e4 (diff) | |
parent | 49502677e11079c2e3e01867c922a894ce06a8be (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-module-and-param
* git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-module-and-param:
module: use strstarts()
strstarts: helper function for !strncmp(str, prefix, strlen(prefix))
arm: allow usage of string functions in linux/string.h
module: don't use stop_machine on module load
module: create a request_module_nowait()
module: include other structures in module version check
module: remove the SHF_ALLOC flag on the __versions section.
module: clarify the force-loading taint message.
module: Export symbols needed for Ksplice
Ksplice: Add functions for walking kallsyms symbols
module: remove module_text_address()
module: __module_address
module: Make find_symbol return a struct kernel_symbol
kernel/module.c: fix an unused goto label
param: fix charp parameters set via sysfs
Fix trivial conflicts in kernel/extable.c manually.
-rw-r--r-- | arch/arm/boot/compressed/misc.c | 5 | ||||
-rw-r--r-- | drivers/mtd/nand/nand_base.c | 4 | ||||
-rw-r--r-- | include/linux/kallsyms.h | 15 | ||||
-rw-r--r-- | include/linux/kmod.h | 11 | ||||
-rw-r--r-- | include/linux/module.h | 63 | ||||
-rw-r--r-- | include/linux/moduleparam.h | 10 | ||||
-rw-r--r-- | include/linux/string.h | 9 | ||||
-rw-r--r-- | kernel/extable.c | 6 | ||||
-rw-r--r-- | kernel/kallsyms.c | 19 | ||||
-rw-r--r-- | kernel/kmod.c | 10 | ||||
-rw-r--r-- | kernel/module.c | 274 | ||||
-rw-r--r-- | kernel/params.c | 26 | ||||
-rw-r--r-- | scripts/mod/modpost.c | 4 |
13 files changed, 319 insertions, 137 deletions
diff --git a/arch/arm/boot/compressed/misc.c b/arch/arm/boot/compressed/misc.c index 393c81641314..9e6e512f0117 100644 --- a/arch/arm/boot/compressed/misc.c +++ b/arch/arm/boot/compressed/misc.c | |||
@@ -18,7 +18,10 @@ | |||
18 | 18 | ||
19 | unsigned int __machine_arch_type; | 19 | unsigned int __machine_arch_type; |
20 | 20 | ||
21 | #include <linux/string.h> | 21 | #include <linux/compiler.h> /* for inline */ |
22 | #include <linux/types.h> /* for size_t */ | ||
23 | #include <linux/stddef.h> /* for NULL */ | ||
24 | #include <asm/string.h> | ||
22 | 25 | ||
23 | #ifdef STANDALONE_DEBUG | 26 | #ifdef STANDALONE_DEBUG |
24 | #define putstr printf | 27 | #define putstr printf |
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 0c3afccde8a2..5f71371eb1b0 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c | |||
@@ -2720,14 +2720,14 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
2720 | return chip->scan_bbt(mtd); | 2720 | return chip->scan_bbt(mtd); |
2721 | } | 2721 | } |
2722 | 2722 | ||
2723 | /* module_text_address() isn't exported, and it's mostly a pointless | 2723 | /* is_module_text_address() isn't exported, and it's mostly a pointless |
2724 | test if this is a module _anyway_ -- they'd have to try _really_ hard | 2724 | test if this is a module _anyway_ -- they'd have to try _really_ hard |
2725 | to call us from in-kernel code if the core NAND support is modular. */ | 2725 | to call us from in-kernel code if the core NAND support is modular. */ |
2726 | #ifdef MODULE | 2726 | #ifdef MODULE |
2727 | #define caller_is_module() (1) | 2727 | #define caller_is_module() (1) |
2728 | #else | 2728 | #else |
2729 | #define caller_is_module() \ | 2729 | #define caller_is_module() \ |
2730 | module_text_address((unsigned long)__builtin_return_address(0)) | 2730 | is_module_text_address((unsigned long)__builtin_return_address(0)) |
2731 | #endif | 2731 | #endif |
2732 | 2732 | ||
2733 | /** | 2733 | /** |
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h index f3fe34391d8e..792274269f2b 100644 --- a/include/linux/kallsyms.h +++ b/include/linux/kallsyms.h | |||
@@ -13,10 +13,17 @@ | |||
13 | #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \ | 13 | #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \ |
14 | 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1) | 14 | 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1) |
15 | 15 | ||
16 | struct module; | ||
17 | |||
16 | #ifdef CONFIG_KALLSYMS | 18 | #ifdef CONFIG_KALLSYMS |
17 | /* Lookup the address for a symbol. Returns 0 if not found. */ | 19 | /* Lookup the address for a symbol. Returns 0 if not found. */ |
18 | unsigned long kallsyms_lookup_name(const char *name); | 20 | unsigned long kallsyms_lookup_name(const char *name); |
19 | 21 | ||
22 | /* Call a function on each kallsyms symbol in the core kernel */ | ||
23 | int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *, | ||
24 | unsigned long), | ||
25 | void *data); | ||
26 | |||
20 | extern int kallsyms_lookup_size_offset(unsigned long addr, | 27 | extern int kallsyms_lookup_size_offset(unsigned long addr, |
21 | unsigned long *symbolsize, | 28 | unsigned long *symbolsize, |
22 | unsigned long *offset); | 29 | unsigned long *offset); |
@@ -43,6 +50,14 @@ static inline unsigned long kallsyms_lookup_name(const char *name) | |||
43 | return 0; | 50 | return 0; |
44 | } | 51 | } |
45 | 52 | ||
53 | static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *, | ||
54 | struct module *, | ||
55 | unsigned long), | ||
56 | void *data) | ||
57 | { | ||
58 | return 0; | ||
59 | } | ||
60 | |||
46 | static inline int kallsyms_lookup_size_offset(unsigned long addr, | 61 | static inline int kallsyms_lookup_size_offset(unsigned long addr, |
47 | unsigned long *symbolsize, | 62 | unsigned long *symbolsize, |
48 | unsigned long *offset) | 63 | unsigned long *offset) |
diff --git a/include/linux/kmod.h b/include/linux/kmod.h index 92213a9194e1..d5fa565086d1 100644 --- a/include/linux/kmod.h +++ b/include/linux/kmod.h | |||
@@ -29,10 +29,15 @@ | |||
29 | #ifdef CONFIG_MODULES | 29 | #ifdef CONFIG_MODULES |
30 | /* modprobe exit status on success, -ve on error. Return value | 30 | /* modprobe exit status on success, -ve on error. Return value |
31 | * usually useless though. */ | 31 | * usually useless though. */ |
32 | extern int request_module(const char * name, ...) __attribute__ ((format (printf, 1, 2))); | 32 | extern int __request_module(bool wait, const char *name, ...) \ |
33 | #define try_then_request_module(x, mod...) ((x) ?: (request_module(mod), (x))) | 33 | __attribute__((format(printf, 2, 3))); |
34 | #define request_module(mod...) __request_module(true, mod) | ||
35 | #define request_module_nowait(mod...) __request_module(false, mod) | ||
36 | #define try_then_request_module(x, mod...) \ | ||
37 | ((x) ?: (__request_module(false, mod), (x))) | ||
34 | #else | 38 | #else |
35 | static inline int request_module(const char * name, ...) { return -ENOSYS; } | 39 | static inline int request_module(const char *name, ...) { return -ENOSYS; } |
40 | static inline int request_module_nowait(const char *name, ...) { return -ENOSYS; } | ||
36 | #define try_then_request_module(x, mod...) (x) | 41 | #define try_then_request_module(x, mod...) (x) |
37 | #endif | 42 | #endif |
38 | 43 | ||
diff --git a/include/linux/module.h b/include/linux/module.h index 145a75528cc1..d246da0b0f8c 100644 --- a/include/linux/module.h +++ b/include/linux/module.h | |||
@@ -248,6 +248,10 @@ struct module | |||
248 | const unsigned long *crcs; | 248 | const unsigned long *crcs; |
249 | unsigned int num_syms; | 249 | unsigned int num_syms; |
250 | 250 | ||
251 | /* Kernel parameters. */ | ||
252 | struct kernel_param *kp; | ||
253 | unsigned int num_kp; | ||
254 | |||
251 | /* GPL-only exported symbols. */ | 255 | /* GPL-only exported symbols. */ |
252 | unsigned int num_gpl_syms; | 256 | unsigned int num_gpl_syms; |
253 | const struct kernel_symbol *gpl_syms; | 257 | const struct kernel_symbol *gpl_syms; |
@@ -350,6 +354,8 @@ struct module | |||
350 | #define MODULE_ARCH_INIT {} | 354 | #define MODULE_ARCH_INIT {} |
351 | #endif | 355 | #endif |
352 | 356 | ||
357 | extern struct mutex module_mutex; | ||
358 | |||
353 | /* FIXME: It'd be nice to isolate modules during init, too, so they | 359 | /* FIXME: It'd be nice to isolate modules during init, too, so they |
354 | aren't used before they (may) fail. But presently too much code | 360 | aren't used before they (may) fail. But presently too much code |
355 | (IDE & SCSI) require entry into the module during init.*/ | 361 | (IDE & SCSI) require entry into the module during init.*/ |
@@ -358,10 +364,10 @@ static inline int module_is_live(struct module *mod) | |||
358 | return mod->state != MODULE_STATE_GOING; | 364 | return mod->state != MODULE_STATE_GOING; |
359 | } | 365 | } |
360 | 366 | ||
361 | /* Is this address in a module? (second is with no locks, for oops) */ | ||
362 | struct module *module_text_address(unsigned long addr); | ||
363 | struct module *__module_text_address(unsigned long addr); | 367 | struct module *__module_text_address(unsigned long addr); |
364 | int is_module_address(unsigned long addr); | 368 | struct module *__module_address(unsigned long addr); |
369 | bool is_module_address(unsigned long addr); | ||
370 | bool is_module_text_address(unsigned long addr); | ||
365 | 371 | ||
366 | static inline int within_module_core(unsigned long addr, struct module *mod) | 372 | static inline int within_module_core(unsigned long addr, struct module *mod) |
367 | { | 373 | { |
@@ -375,6 +381,31 @@ static inline int within_module_init(unsigned long addr, struct module *mod) | |||
375 | addr < (unsigned long)mod->module_init + mod->init_size; | 381 | addr < (unsigned long)mod->module_init + mod->init_size; |
376 | } | 382 | } |
377 | 383 | ||
384 | /* Search for module by name: must hold module_mutex. */ | ||
385 | struct module *find_module(const char *name); | ||
386 | |||
387 | struct symsearch { | ||
388 | const struct kernel_symbol *start, *stop; | ||
389 | const unsigned long *crcs; | ||
390 | enum { | ||
391 | NOT_GPL_ONLY, | ||
392 | GPL_ONLY, | ||
393 | WILL_BE_GPL_ONLY, | ||
394 | } licence; | ||
395 | bool unused; | ||
396 | }; | ||
397 | |||
398 | /* Search for an exported symbol by name. */ | ||
399 | const struct kernel_symbol *find_symbol(const char *name, | ||
400 | struct module **owner, | ||
401 | const unsigned long **crc, | ||
402 | bool gplok, | ||
403 | bool warn); | ||
404 | |||
405 | /* Walk the exported symbol table */ | ||
406 | bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, | ||
407 | unsigned int symnum, void *data), void *data); | ||
408 | |||
378 | /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if | 409 | /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if |
379 | symnum out of range. */ | 410 | symnum out of range. */ |
380 | int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, | 411 | int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, |
@@ -383,6 +414,10 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, | |||
383 | /* Look for this name: can be of form module:name. */ | 414 | /* Look for this name: can be of form module:name. */ |
384 | unsigned long module_kallsyms_lookup_name(const char *name); | 415 | unsigned long module_kallsyms_lookup_name(const char *name); |
385 | 416 | ||
417 | int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, | ||
418 | struct module *, unsigned long), | ||
419 | void *data); | ||
420 | |||
386 | extern void __module_put_and_exit(struct module *mod, long code) | 421 | extern void __module_put_and_exit(struct module *mod, long code) |
387 | __attribute__((noreturn)); | 422 | __attribute__((noreturn)); |
388 | #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code); | 423 | #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code); |
@@ -444,6 +479,7 @@ static inline void __module_get(struct module *module) | |||
444 | #define symbol_put_addr(p) do { } while(0) | 479 | #define symbol_put_addr(p) do { } while(0) |
445 | 480 | ||
446 | #endif /* CONFIG_MODULE_UNLOAD */ | 481 | #endif /* CONFIG_MODULE_UNLOAD */ |
482 | int use_module(struct module *a, struct module *b); | ||
447 | 483 | ||
448 | /* This is a #define so the string doesn't get put in every .o file */ | 484 | /* This is a #define so the string doesn't get put in every .o file */ |
449 | #define module_name(mod) \ | 485 | #define module_name(mod) \ |
@@ -490,21 +526,24 @@ search_module_extables(unsigned long addr) | |||
490 | return NULL; | 526 | return NULL; |
491 | } | 527 | } |
492 | 528 | ||
493 | /* Is this address in a module? */ | 529 | static inline struct module *__module_address(unsigned long addr) |
494 | static inline struct module *module_text_address(unsigned long addr) | ||
495 | { | 530 | { |
496 | return NULL; | 531 | return NULL; |
497 | } | 532 | } |
498 | 533 | ||
499 | /* Is this address in a module? (don't take a lock, we're oopsing) */ | ||
500 | static inline struct module *__module_text_address(unsigned long addr) | 534 | static inline struct module *__module_text_address(unsigned long addr) |
501 | { | 535 | { |
502 | return NULL; | 536 | return NULL; |
503 | } | 537 | } |
504 | 538 | ||
505 | static inline int is_module_address(unsigned long addr) | 539 | static inline bool is_module_address(unsigned long addr) |
506 | { | 540 | { |
507 | return 0; | 541 | return false; |
542 | } | ||
543 | |||
544 | static inline bool is_module_text_address(unsigned long addr) | ||
545 | { | ||
546 | return false; | ||
508 | } | 547 | } |
509 | 548 | ||
510 | /* Get/put a kernel symbol (calls should be symmetric) */ | 549 | /* Get/put a kernel symbol (calls should be symmetric) */ |
@@ -559,6 +598,14 @@ static inline unsigned long module_kallsyms_lookup_name(const char *name) | |||
559 | return 0; | 598 | return 0; |
560 | } | 599 | } |
561 | 600 | ||
601 | static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, | ||
602 | struct module *, | ||
603 | unsigned long), | ||
604 | void *data) | ||
605 | { | ||
606 | return 0; | ||
607 | } | ||
608 | |||
562 | static inline int register_module_notifier(struct notifier_block * nb) | 609 | static inline int register_module_notifier(struct notifier_block * nb) |
563 | { | 610 | { |
564 | /* no events will happen anyway, so this can always succeed */ | 611 | /* no events will happen anyway, so this can always succeed */ |
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h index e4af3399ef48..a4f0b931846c 100644 --- a/include/linux/moduleparam.h +++ b/include/linux/moduleparam.h | |||
@@ -138,6 +138,16 @@ extern int parse_args(const char *name, | |||
138 | unsigned num, | 138 | unsigned num, |
139 | int (*unknown)(char *param, char *val)); | 139 | int (*unknown)(char *param, char *val)); |
140 | 140 | ||
141 | /* Called by module remove. */ | ||
142 | #ifdef CONFIG_SYSFS | ||
143 | extern void destroy_params(const struct kernel_param *params, unsigned num); | ||
144 | #else | ||
145 | static inline void destroy_params(const struct kernel_param *params, | ||
146 | unsigned num) | ||
147 | { | ||
148 | } | ||
149 | #endif /* !CONFIG_SYSFS */ | ||
150 | |||
141 | /* All the helper functions */ | 151 | /* All the helper functions */ |
142 | /* The macros to do compile-time type checking stolen from Jakub | 152 | /* The macros to do compile-time type checking stolen from Jakub |
143 | Jelinek, who IIRC came up with this idea for the 2.4 module init code. */ | 153 | Jelinek, who IIRC came up with this idea for the 2.4 module init code. */ |
diff --git a/include/linux/string.h b/include/linux/string.h index 3c877d686375..489019ef1694 100644 --- a/include/linux/string.h +++ b/include/linux/string.h | |||
@@ -122,5 +122,14 @@ int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) __printf(3, 4); | |||
122 | extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos, | 122 | extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos, |
123 | const void *from, size_t available); | 123 | const void *from, size_t available); |
124 | 124 | ||
125 | /** | ||
126 | * strstarts - does @str start with @prefix? | ||
127 | * @str: string to examine | ||
128 | * @prefix: prefix to look for. | ||
129 | */ | ||
130 | static inline bool strstarts(const char *str, const char *prefix) | ||
131 | { | ||
132 | return strncmp(str, prefix, strlen(prefix)) == 0; | ||
133 | } | ||
125 | #endif | 134 | #endif |
126 | #endif /* _LINUX_STRING_H_ */ | 135 | #endif /* _LINUX_STRING_H_ */ |
diff --git a/kernel/extable.c b/kernel/extable.c index c46da6a47036..81e99d1f0d5b 100644 --- a/kernel/extable.c +++ b/kernel/extable.c | |||
@@ -65,7 +65,7 @@ __notrace_funcgraph int __kernel_text_address(unsigned long addr) | |||
65 | { | 65 | { |
66 | if (core_kernel_text(addr)) | 66 | if (core_kernel_text(addr)) |
67 | return 1; | 67 | return 1; |
68 | if (__module_text_address(addr)) | 68 | if (is_module_text_address(addr)) |
69 | return 1; | 69 | return 1; |
70 | /* | 70 | /* |
71 | * There might be init symbols in saved stacktraces. | 71 | * There might be init symbols in saved stacktraces. |
@@ -84,7 +84,7 @@ int kernel_text_address(unsigned long addr) | |||
84 | { | 84 | { |
85 | if (core_kernel_text(addr)) | 85 | if (core_kernel_text(addr)) |
86 | return 1; | 86 | return 1; |
87 | return module_text_address(addr) != NULL; | 87 | return is_module_text_address(addr); |
88 | } | 88 | } |
89 | 89 | ||
90 | /* | 90 | /* |
@@ -100,5 +100,5 @@ int func_ptr_is_kernel_text(void *ptr) | |||
100 | addr = (unsigned long) dereference_function_descriptor(ptr); | 100 | addr = (unsigned long) dereference_function_descriptor(ptr); |
101 | if (core_kernel_text(addr)) | 101 | if (core_kernel_text(addr)) |
102 | return 1; | 102 | return 1; |
103 | return module_text_address(addr) != NULL; | 103 | return is_module_text_address(addr); |
104 | } | 104 | } |
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 7b8b0f21a5b1..374faf9bfdc7 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c | |||
@@ -161,6 +161,25 @@ unsigned long kallsyms_lookup_name(const char *name) | |||
161 | return module_kallsyms_lookup_name(name); | 161 | return module_kallsyms_lookup_name(name); |
162 | } | 162 | } |
163 | 163 | ||
164 | int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *, | ||
165 | unsigned long), | ||
166 | void *data) | ||
167 | { | ||
168 | char namebuf[KSYM_NAME_LEN]; | ||
169 | unsigned long i; | ||
170 | unsigned int off; | ||
171 | int ret; | ||
172 | |||
173 | for (i = 0, off = 0; i < kallsyms_num_syms; i++) { | ||
174 | off = kallsyms_expand_symbol(off, namebuf); | ||
175 | ret = fn(data, namebuf, NULL, kallsyms_addresses[i]); | ||
176 | if (ret != 0) | ||
177 | return ret; | ||
178 | } | ||
179 | return module_kallsyms_on_each_symbol(fn, data); | ||
180 | } | ||
181 | EXPORT_SYMBOL_GPL(kallsyms_on_each_symbol); | ||
182 | |||
164 | static unsigned long get_symbol_pos(unsigned long addr, | 183 | static unsigned long get_symbol_pos(unsigned long addr, |
165 | unsigned long *symbolsize, | 184 | unsigned long *symbolsize, |
166 | unsigned long *offset) | 185 | unsigned long *offset) |
diff --git a/kernel/kmod.c b/kernel/kmod.c index f0c8f545180d..b750675251e5 100644 --- a/kernel/kmod.c +++ b/kernel/kmod.c | |||
@@ -50,7 +50,8 @@ static struct workqueue_struct *khelper_wq; | |||
50 | char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe"; | 50 | char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe"; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * request_module - try to load a kernel module | 53 | * __request_module - try to load a kernel module |
54 | * @wait: wait (or not) for the operation to complete | ||
54 | * @fmt: printf style format string for the name of the module | 55 | * @fmt: printf style format string for the name of the module |
55 | * @...: arguments as specified in the format string | 56 | * @...: arguments as specified in the format string |
56 | * | 57 | * |
@@ -63,7 +64,7 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe"; | |||
63 | * If module auto-loading support is disabled then this function | 64 | * If module auto-loading support is disabled then this function |
64 | * becomes a no-operation. | 65 | * becomes a no-operation. |
65 | */ | 66 | */ |
66 | int request_module(const char *fmt, ...) | 67 | int __request_module(bool wait, const char *fmt, ...) |
67 | { | 68 | { |
68 | va_list args; | 69 | va_list args; |
69 | char module_name[MODULE_NAME_LEN]; | 70 | char module_name[MODULE_NAME_LEN]; |
@@ -108,11 +109,12 @@ int request_module(const char *fmt, ...) | |||
108 | return -ENOMEM; | 109 | return -ENOMEM; |
109 | } | 110 | } |
110 | 111 | ||
111 | ret = call_usermodehelper(modprobe_path, argv, envp, 1); | 112 | ret = call_usermodehelper(modprobe_path, argv, envp, |
113 | wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC); | ||
112 | atomic_dec(&kmod_concurrent); | 114 | atomic_dec(&kmod_concurrent); |
113 | return ret; | 115 | return ret; |
114 | } | 116 | } |
115 | EXPORT_SYMBOL(request_module); | 117 | EXPORT_SYMBOL(__request_module); |
116 | #endif /* CONFIG_MODULES */ | 118 | #endif /* CONFIG_MODULES */ |
117 | 119 | ||
118 | struct subprocess_info { | 120 | struct subprocess_info { |
diff --git a/kernel/module.c b/kernel/module.c index f77ac320d0b5..f6e08b7cff7c 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -68,7 +68,8 @@ | |||
68 | 68 | ||
69 | /* List of modules, protected by module_mutex or preempt_disable | 69 | /* List of modules, protected by module_mutex or preempt_disable |
70 | * (delete uses stop_machine/add uses RCU list operations). */ | 70 | * (delete uses stop_machine/add uses RCU list operations). */ |
71 | static DEFINE_MUTEX(module_mutex); | 71 | DEFINE_MUTEX(module_mutex); |
72 | EXPORT_SYMBOL_GPL(module_mutex); | ||
72 | static LIST_HEAD(modules); | 73 | static LIST_HEAD(modules); |
73 | 74 | ||
74 | /* Waiting for a module to finish initializing? */ | 75 | /* Waiting for a module to finish initializing? */ |
@@ -76,7 +77,7 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq); | |||
76 | 77 | ||
77 | static BLOCKING_NOTIFIER_HEAD(module_notify_list); | 78 | static BLOCKING_NOTIFIER_HEAD(module_notify_list); |
78 | 79 | ||
79 | /* Bounds of module allocation, for speeding __module_text_address */ | 80 | /* Bounds of module allocation, for speeding __module_address */ |
80 | static unsigned long module_addr_min = -1UL, module_addr_max = 0; | 81 | static unsigned long module_addr_min = -1UL, module_addr_max = 0; |
81 | 82 | ||
82 | int register_module_notifier(struct notifier_block * nb) | 83 | int register_module_notifier(struct notifier_block * nb) |
@@ -186,17 +187,6 @@ extern const unsigned long __start___kcrctab_unused_gpl[]; | |||
186 | #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) | 187 | #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) |
187 | #endif | 188 | #endif |
188 | 189 | ||
189 | struct symsearch { | ||
190 | const struct kernel_symbol *start, *stop; | ||
191 | const unsigned long *crcs; | ||
192 | enum { | ||
193 | NOT_GPL_ONLY, | ||
194 | GPL_ONLY, | ||
195 | WILL_BE_GPL_ONLY, | ||
196 | } licence; | ||
197 | bool unused; | ||
198 | }; | ||
199 | |||
200 | static bool each_symbol_in_section(const struct symsearch *arr, | 190 | static bool each_symbol_in_section(const struct symsearch *arr, |
201 | unsigned int arrsize, | 191 | unsigned int arrsize, |
202 | struct module *owner, | 192 | struct module *owner, |
@@ -217,10 +207,8 @@ static bool each_symbol_in_section(const struct symsearch *arr, | |||
217 | } | 207 | } |
218 | 208 | ||
219 | /* Returns true as soon as fn returns true, otherwise false. */ | 209 | /* Returns true as soon as fn returns true, otherwise false. */ |
220 | static bool each_symbol(bool (*fn)(const struct symsearch *arr, | 210 | bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, |
221 | struct module *owner, | 211 | unsigned int symnum, void *data), void *data) |
222 | unsigned int symnum, void *data), | ||
223 | void *data) | ||
224 | { | 212 | { |
225 | struct module *mod; | 213 | struct module *mod; |
226 | const struct symsearch arr[] = { | 214 | const struct symsearch arr[] = { |
@@ -273,6 +261,7 @@ static bool each_symbol(bool (*fn)(const struct symsearch *arr, | |||
273 | } | 261 | } |
274 | return false; | 262 | return false; |
275 | } | 263 | } |
264 | EXPORT_SYMBOL_GPL(each_symbol); | ||
276 | 265 | ||
277 | struct find_symbol_arg { | 266 | struct find_symbol_arg { |
278 | /* Input */ | 267 | /* Input */ |
@@ -283,7 +272,7 @@ struct find_symbol_arg { | |||
283 | /* Output */ | 272 | /* Output */ |
284 | struct module *owner; | 273 | struct module *owner; |
285 | const unsigned long *crc; | 274 | const unsigned long *crc; |
286 | unsigned long value; | 275 | const struct kernel_symbol *sym; |
287 | }; | 276 | }; |
288 | 277 | ||
289 | static bool find_symbol_in_section(const struct symsearch *syms, | 278 | static bool find_symbol_in_section(const struct symsearch *syms, |
@@ -324,17 +313,17 @@ static bool find_symbol_in_section(const struct symsearch *syms, | |||
324 | 313 | ||
325 | fsa->owner = owner; | 314 | fsa->owner = owner; |
326 | fsa->crc = symversion(syms->crcs, symnum); | 315 | fsa->crc = symversion(syms->crcs, symnum); |
327 | fsa->value = syms->start[symnum].value; | 316 | fsa->sym = &syms->start[symnum]; |
328 | return true; | 317 | return true; |
329 | } | 318 | } |
330 | 319 | ||
331 | /* Find a symbol, return value, (optional) crc and (optional) module | 320 | /* Find a symbol and return it, along with, (optional) crc and |
332 | * which owns it */ | 321 | * (optional) module which owns it */ |
333 | static unsigned long find_symbol(const char *name, | 322 | const struct kernel_symbol *find_symbol(const char *name, |
334 | struct module **owner, | 323 | struct module **owner, |
335 | const unsigned long **crc, | 324 | const unsigned long **crc, |
336 | bool gplok, | 325 | bool gplok, |
337 | bool warn) | 326 | bool warn) |
338 | { | 327 | { |
339 | struct find_symbol_arg fsa; | 328 | struct find_symbol_arg fsa; |
340 | 329 | ||
@@ -347,15 +336,16 @@ static unsigned long find_symbol(const char *name, | |||
347 | *owner = fsa.owner; | 336 | *owner = fsa.owner; |
348 | if (crc) | 337 | if (crc) |
349 | *crc = fsa.crc; | 338 | *crc = fsa.crc; |
350 | return fsa.value; | 339 | return fsa.sym; |
351 | } | 340 | } |
352 | 341 | ||
353 | DEBUGP("Failed to find symbol %s\n", name); | 342 | DEBUGP("Failed to find symbol %s\n", name); |
354 | return -ENOENT; | 343 | return NULL; |
355 | } | 344 | } |
345 | EXPORT_SYMBOL_GPL(find_symbol); | ||
356 | 346 | ||
357 | /* Search for module by name: must hold module_mutex. */ | 347 | /* Search for module by name: must hold module_mutex. */ |
358 | static struct module *find_module(const char *name) | 348 | struct module *find_module(const char *name) |
359 | { | 349 | { |
360 | struct module *mod; | 350 | struct module *mod; |
361 | 351 | ||
@@ -365,6 +355,7 @@ static struct module *find_module(const char *name) | |||
365 | } | 355 | } |
366 | return NULL; | 356 | return NULL; |
367 | } | 357 | } |
358 | EXPORT_SYMBOL_GPL(find_module); | ||
368 | 359 | ||
369 | #ifdef CONFIG_SMP | 360 | #ifdef CONFIG_SMP |
370 | 361 | ||
@@ -641,7 +632,7 @@ static int already_uses(struct module *a, struct module *b) | |||
641 | } | 632 | } |
642 | 633 | ||
643 | /* Module a uses b */ | 634 | /* Module a uses b */ |
644 | static int use_module(struct module *a, struct module *b) | 635 | int use_module(struct module *a, struct module *b) |
645 | { | 636 | { |
646 | struct module_use *use; | 637 | struct module_use *use; |
647 | int no_warn, err; | 638 | int no_warn, err; |
@@ -674,6 +665,7 @@ static int use_module(struct module *a, struct module *b) | |||
674 | no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); | 665 | no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); |
675 | return 1; | 666 | return 1; |
676 | } | 667 | } |
668 | EXPORT_SYMBOL_GPL(use_module); | ||
677 | 669 | ||
678 | /* Clear the unload stuff of the module. */ | 670 | /* Clear the unload stuff of the module. */ |
679 | static void module_unload_free(struct module *mod) | 671 | static void module_unload_free(struct module *mod) |
@@ -894,7 +886,7 @@ void __symbol_put(const char *symbol) | |||
894 | struct module *owner; | 886 | struct module *owner; |
895 | 887 | ||
896 | preempt_disable(); | 888 | preempt_disable(); |
897 | if (IS_ERR_VALUE(find_symbol(symbol, &owner, NULL, true, false))) | 889 | if (!find_symbol(symbol, &owner, NULL, true, false)) |
898 | BUG(); | 890 | BUG(); |
899 | module_put(owner); | 891 | module_put(owner); |
900 | preempt_enable(); | 892 | preempt_enable(); |
@@ -908,8 +900,10 @@ void symbol_put_addr(void *addr) | |||
908 | if (core_kernel_text((unsigned long)addr)) | 900 | if (core_kernel_text((unsigned long)addr)) |
909 | return; | 901 | return; |
910 | 902 | ||
911 | if (!(modaddr = module_text_address((unsigned long)addr))) | 903 | /* module_text_address is safe here: we're supposed to have reference |
912 | BUG(); | 904 | * to module from symbol_get, so it can't go away. */ |
905 | modaddr = __module_text_address((unsigned long)addr); | ||
906 | BUG_ON(!modaddr); | ||
913 | module_put(modaddr); | 907 | module_put(modaddr); |
914 | } | 908 | } |
915 | EXPORT_SYMBOL_GPL(symbol_put_addr); | 909 | EXPORT_SYMBOL_GPL(symbol_put_addr); |
@@ -949,10 +943,11 @@ static inline void module_unload_free(struct module *mod) | |||
949 | { | 943 | { |
950 | } | 944 | } |
951 | 945 | ||
952 | static inline int use_module(struct module *a, struct module *b) | 946 | int use_module(struct module *a, struct module *b) |
953 | { | 947 | { |
954 | return strong_try_module_get(b) == 0; | 948 | return strong_try_module_get(b) == 0; |
955 | } | 949 | } |
950 | EXPORT_SYMBOL_GPL(use_module); | ||
956 | 951 | ||
957 | static inline void module_unload_init(struct module *mod) | 952 | static inline void module_unload_init(struct module *mod) |
958 | { | 953 | { |
@@ -995,12 +990,12 @@ static struct module_attribute *modinfo_attrs[] = { | |||
995 | 990 | ||
996 | static const char vermagic[] = VERMAGIC_STRING; | 991 | static const char vermagic[] = VERMAGIC_STRING; |
997 | 992 | ||
998 | static int try_to_force_load(struct module *mod, const char *symname) | 993 | static int try_to_force_load(struct module *mod, const char *reason) |
999 | { | 994 | { |
1000 | #ifdef CONFIG_MODULE_FORCE_LOAD | 995 | #ifdef CONFIG_MODULE_FORCE_LOAD |
1001 | if (!test_taint(TAINT_FORCED_MODULE)) | 996 | if (!test_taint(TAINT_FORCED_MODULE)) |
1002 | printk("%s: no version for \"%s\" found: kernel tainted.\n", | 997 | printk(KERN_WARNING "%s: %s: kernel tainted.\n", |
1003 | mod->name, symname); | 998 | mod->name, reason); |
1004 | add_taint_module(mod, TAINT_FORCED_MODULE); | 999 | add_taint_module(mod, TAINT_FORCED_MODULE); |
1005 | return 0; | 1000 | return 0; |
1006 | #else | 1001 | #else |
@@ -1057,9 +1052,9 @@ static inline int check_modstruct_version(Elf_Shdr *sechdrs, | |||
1057 | { | 1052 | { |
1058 | const unsigned long *crc; | 1053 | const unsigned long *crc; |
1059 | 1054 | ||
1060 | if (IS_ERR_VALUE(find_symbol("struct_module", NULL, &crc, true, false))) | 1055 | if (!find_symbol("module_layout", NULL, &crc, true, false)) |
1061 | BUG(); | 1056 | BUG(); |
1062 | return check_version(sechdrs, versindex, "struct_module", mod, crc); | 1057 | return check_version(sechdrs, versindex, "module_layout", mod, crc); |
1063 | } | 1058 | } |
1064 | 1059 | ||
1065 | /* First part is kernel version, which we ignore if module has crcs. */ | 1060 | /* First part is kernel version, which we ignore if module has crcs. */ |
@@ -1098,25 +1093,25 @@ static inline int same_magic(const char *amagic, const char *bmagic, | |||
1098 | 1093 | ||
1099 | /* Resolve a symbol for this module. I.e. if we find one, record usage. | 1094 | /* Resolve a symbol for this module. I.e. if we find one, record usage. |
1100 | Must be holding module_mutex. */ | 1095 | Must be holding module_mutex. */ |
1101 | static unsigned long resolve_symbol(Elf_Shdr *sechdrs, | 1096 | static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs, |
1102 | unsigned int versindex, | 1097 | unsigned int versindex, |
1103 | const char *name, | 1098 | const char *name, |
1104 | struct module *mod) | 1099 | struct module *mod) |
1105 | { | 1100 | { |
1106 | struct module *owner; | 1101 | struct module *owner; |
1107 | unsigned long ret; | 1102 | const struct kernel_symbol *sym; |
1108 | const unsigned long *crc; | 1103 | const unsigned long *crc; |
1109 | 1104 | ||
1110 | ret = find_symbol(name, &owner, &crc, | 1105 | sym = find_symbol(name, &owner, &crc, |
1111 | !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); | 1106 | !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); |
1112 | if (!IS_ERR_VALUE(ret)) { | 1107 | /* use_module can fail due to OOM, |
1113 | /* use_module can fail due to OOM, | 1108 | or module initialization or unloading */ |
1114 | or module initialization or unloading */ | 1109 | if (sym) { |
1115 | if (!check_version(sechdrs, versindex, name, mod, crc) || | 1110 | if (!check_version(sechdrs, versindex, name, mod, crc) || |
1116 | !use_module(mod, owner)) | 1111 | !use_module(mod, owner)) |
1117 | ret = -EINVAL; | 1112 | sym = NULL; |
1118 | } | 1113 | } |
1119 | return ret; | 1114 | return sym; |
1120 | } | 1115 | } |
1121 | 1116 | ||
1122 | /* | 1117 | /* |
@@ -1491,6 +1486,9 @@ static void free_module(struct module *mod) | |||
1491 | /* Module unload stuff */ | 1486 | /* Module unload stuff */ |
1492 | module_unload_free(mod); | 1487 | module_unload_free(mod); |
1493 | 1488 | ||
1489 | /* Free any allocated parameters. */ | ||
1490 | destroy_params(mod->kp, mod->num_kp); | ||
1491 | |||
1494 | /* release any pointers to mcount in this module */ | 1492 | /* release any pointers to mcount in this module */ |
1495 | ftrace_release(mod->module_core, mod->core_size); | 1493 | ftrace_release(mod->module_core, mod->core_size); |
1496 | 1494 | ||
@@ -1513,17 +1511,15 @@ static void free_module(struct module *mod) | |||
1513 | void *__symbol_get(const char *symbol) | 1511 | void *__symbol_get(const char *symbol) |
1514 | { | 1512 | { |
1515 | struct module *owner; | 1513 | struct module *owner; |
1516 | unsigned long value; | 1514 | const struct kernel_symbol *sym; |
1517 | 1515 | ||
1518 | preempt_disable(); | 1516 | preempt_disable(); |
1519 | value = find_symbol(symbol, &owner, NULL, true, true); | 1517 | sym = find_symbol(symbol, &owner, NULL, true, true); |
1520 | if (IS_ERR_VALUE(value)) | 1518 | if (sym && strong_try_module_get(owner)) |
1521 | value = 0; | 1519 | sym = NULL; |
1522 | else if (strong_try_module_get(owner)) | ||
1523 | value = 0; | ||
1524 | preempt_enable(); | 1520 | preempt_enable(); |
1525 | 1521 | ||
1526 | return (void *)value; | 1522 | return sym ? (void *)sym->value : NULL; |
1527 | } | 1523 | } |
1528 | EXPORT_SYMBOL_GPL(__symbol_get); | 1524 | EXPORT_SYMBOL_GPL(__symbol_get); |
1529 | 1525 | ||
@@ -1551,8 +1547,7 @@ static int verify_export_symbols(struct module *mod) | |||
1551 | 1547 | ||
1552 | for (i = 0; i < ARRAY_SIZE(arr); i++) { | 1548 | for (i = 0; i < ARRAY_SIZE(arr); i++) { |
1553 | for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { | 1549 | for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { |
1554 | if (!IS_ERR_VALUE(find_symbol(s->name, &owner, | 1550 | if (find_symbol(s->name, &owner, NULL, true, false)) { |
1555 | NULL, true, false))) { | ||
1556 | printk(KERN_ERR | 1551 | printk(KERN_ERR |
1557 | "%s: exports duplicate symbol %s" | 1552 | "%s: exports duplicate symbol %s" |
1558 | " (owned by %s)\n", | 1553 | " (owned by %s)\n", |
@@ -1576,6 +1571,7 @@ static int simplify_symbols(Elf_Shdr *sechdrs, | |||
1576 | unsigned long secbase; | 1571 | unsigned long secbase; |
1577 | unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym); | 1572 | unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym); |
1578 | int ret = 0; | 1573 | int ret = 0; |
1574 | const struct kernel_symbol *ksym; | ||
1579 | 1575 | ||
1580 | for (i = 1; i < n; i++) { | 1576 | for (i = 1; i < n; i++) { |
1581 | switch (sym[i].st_shndx) { | 1577 | switch (sym[i].st_shndx) { |
@@ -1595,13 +1591,14 @@ static int simplify_symbols(Elf_Shdr *sechdrs, | |||
1595 | break; | 1591 | break; |
1596 | 1592 | ||
1597 | case SHN_UNDEF: | 1593 | case SHN_UNDEF: |
1598 | sym[i].st_value | 1594 | ksym = resolve_symbol(sechdrs, versindex, |
1599 | = resolve_symbol(sechdrs, versindex, | 1595 | strtab + sym[i].st_name, mod); |
1600 | strtab + sym[i].st_name, mod); | ||
1601 | |||
1602 | /* Ok if resolved. */ | 1596 | /* Ok if resolved. */ |
1603 | if (!IS_ERR_VALUE(sym[i].st_value)) | 1597 | if (ksym) { |
1598 | sym[i].st_value = ksym->value; | ||
1604 | break; | 1599 | break; |
1600 | } | ||
1601 | |||
1605 | /* Ok if weak. */ | 1602 | /* Ok if weak. */ |
1606 | if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK) | 1603 | if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK) |
1607 | break; | 1604 | break; |
@@ -1676,8 +1673,7 @@ static void layout_sections(struct module *mod, | |||
1676 | if ((s->sh_flags & masks[m][0]) != masks[m][0] | 1673 | if ((s->sh_flags & masks[m][0]) != masks[m][0] |
1677 | || (s->sh_flags & masks[m][1]) | 1674 | || (s->sh_flags & masks[m][1]) |
1678 | || s->sh_entsize != ~0UL | 1675 | || s->sh_entsize != ~0UL |
1679 | || strncmp(secstrings + s->sh_name, | 1676 | || strstarts(secstrings + s->sh_name, ".init")) |
1680 | ".init", 5) == 0) | ||
1681 | continue; | 1677 | continue; |
1682 | s->sh_entsize = get_offset(mod, &mod->core_size, s, i); | 1678 | s->sh_entsize = get_offset(mod, &mod->core_size, s, i); |
1683 | DEBUGP("\t%s\n", secstrings + s->sh_name); | 1679 | DEBUGP("\t%s\n", secstrings + s->sh_name); |
@@ -1694,8 +1690,7 @@ static void layout_sections(struct module *mod, | |||
1694 | if ((s->sh_flags & masks[m][0]) != masks[m][0] | 1690 | if ((s->sh_flags & masks[m][0]) != masks[m][0] |
1695 | || (s->sh_flags & masks[m][1]) | 1691 | || (s->sh_flags & masks[m][1]) |
1696 | || s->sh_entsize != ~0UL | 1692 | || s->sh_entsize != ~0UL |
1697 | || strncmp(secstrings + s->sh_name, | 1693 | || !strstarts(secstrings + s->sh_name, ".init")) |
1698 | ".init", 5) != 0) | ||
1699 | continue; | 1694 | continue; |
1700 | s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) | 1695 | s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) |
1701 | | INIT_OFFSET_MASK); | 1696 | | INIT_OFFSET_MASK); |
@@ -1828,8 +1823,7 @@ static char elf_type(const Elf_Sym *sym, | |||
1828 | else | 1823 | else |
1829 | return 'b'; | 1824 | return 'b'; |
1830 | } | 1825 | } |
1831 | if (strncmp(secstrings + sechdrs[sym->st_shndx].sh_name, | 1826 | if (strstarts(secstrings + sechdrs[sym->st_shndx].sh_name, ".debug")) |
1832 | ".debug", strlen(".debug")) == 0) | ||
1833 | return 'n'; | 1827 | return 'n'; |
1834 | return '?'; | 1828 | return '?'; |
1835 | } | 1829 | } |
@@ -1898,8 +1892,7 @@ static noinline struct module *load_module(void __user *umod, | |||
1898 | unsigned int symindex = 0; | 1892 | unsigned int symindex = 0; |
1899 | unsigned int strindex = 0; | 1893 | unsigned int strindex = 0; |
1900 | unsigned int modindex, versindex, infoindex, pcpuindex; | 1894 | unsigned int modindex, versindex, infoindex, pcpuindex; |
1901 | unsigned int num_kp, num_mcount; | 1895 | unsigned int num_mcount; |
1902 | struct kernel_param *kp; | ||
1903 | struct module *mod; | 1896 | struct module *mod; |
1904 | long err = 0; | 1897 | long err = 0; |
1905 | void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ | 1898 | void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ |
@@ -1916,12 +1909,6 @@ static noinline struct module *load_module(void __user *umod, | |||
1916 | if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) | 1909 | if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) |
1917 | return ERR_PTR(-ENOMEM); | 1910 | return ERR_PTR(-ENOMEM); |
1918 | 1911 | ||
1919 | /* Create stop_machine threads since the error path relies on | ||
1920 | * a non-failing stop_machine call. */ | ||
1921 | err = stop_machine_create(); | ||
1922 | if (err) | ||
1923 | goto free_hdr; | ||
1924 | |||
1925 | if (copy_from_user(hdr, umod, len) != 0) { | 1912 | if (copy_from_user(hdr, umod, len) != 0) { |
1926 | err = -EFAULT; | 1913 | err = -EFAULT; |
1927 | goto free_hdr; | 1914 | goto free_hdr; |
@@ -1962,9 +1949,12 @@ static noinline struct module *load_module(void __user *umod, | |||
1962 | } | 1949 | } |
1963 | #ifndef CONFIG_MODULE_UNLOAD | 1950 | #ifndef CONFIG_MODULE_UNLOAD |
1964 | /* Don't load .exit sections */ | 1951 | /* Don't load .exit sections */ |
1965 | if (strncmp(secstrings+sechdrs[i].sh_name, ".exit", 5) == 0) | 1952 | if (strstarts(secstrings+sechdrs[i].sh_name, ".exit")) |
1966 | sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; | 1953 | sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; |
1967 | #endif | 1954 | #endif |
1955 | /* Don't keep __versions around; it's just for loading. */ | ||
1956 | if (strcmp(secstrings + sechdrs[i].sh_name, "__versions") == 0) | ||
1957 | sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; | ||
1968 | } | 1958 | } |
1969 | 1959 | ||
1970 | modindex = find_sec(hdr, sechdrs, secstrings, | 1960 | modindex = find_sec(hdr, sechdrs, secstrings, |
@@ -2006,7 +1996,7 @@ static noinline struct module *load_module(void __user *umod, | |||
2006 | modmagic = get_modinfo(sechdrs, infoindex, "vermagic"); | 1996 | modmagic = get_modinfo(sechdrs, infoindex, "vermagic"); |
2007 | /* This is allowed: modprobe --force will invalidate it. */ | 1997 | /* This is allowed: modprobe --force will invalidate it. */ |
2008 | if (!modmagic) { | 1998 | if (!modmagic) { |
2009 | err = try_to_force_load(mod, "magic"); | 1999 | err = try_to_force_load(mod, "bad vermagic"); |
2010 | if (err) | 2000 | if (err) |
2011 | goto free_hdr; | 2001 | goto free_hdr; |
2012 | } else if (!same_magic(modmagic, vermagic, versindex)) { | 2002 | } else if (!same_magic(modmagic, vermagic, versindex)) { |
@@ -2144,8 +2134,8 @@ static noinline struct module *load_module(void __user *umod, | |||
2144 | 2134 | ||
2145 | /* Now we've got everything in the final locations, we can | 2135 | /* Now we've got everything in the final locations, we can |
2146 | * find optional sections. */ | 2136 | * find optional sections. */ |
2147 | kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp), | 2137 | mod->kp = section_objs(hdr, sechdrs, secstrings, "__param", |
2148 | &num_kp); | 2138 | sizeof(*mod->kp), &mod->num_kp); |
2149 | mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", | 2139 | mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", |
2150 | sizeof(*mod->syms), &mod->num_syms); | 2140 | sizeof(*mod->syms), &mod->num_syms); |
2151 | mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); | 2141 | mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); |
@@ -2195,8 +2185,8 @@ static noinline struct module *load_module(void __user *umod, | |||
2195 | || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) | 2185 | || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) |
2196 | #endif | 2186 | #endif |
2197 | ) { | 2187 | ) { |
2198 | printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); | 2188 | err = try_to_force_load(mod, |
2199 | err = try_to_force_load(mod, "nocrc"); | 2189 | "no versions for exported symbols"); |
2200 | if (err) | 2190 | if (err) |
2201 | goto cleanup; | 2191 | goto cleanup; |
2202 | } | 2192 | } |
@@ -2291,11 +2281,11 @@ static noinline struct module *load_module(void __user *umod, | |||
2291 | */ | 2281 | */ |
2292 | list_add_rcu(&mod->list, &modules); | 2282 | list_add_rcu(&mod->list, &modules); |
2293 | 2283 | ||
2294 | err = parse_args(mod->name, mod->args, kp, num_kp, NULL); | 2284 | err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL); |
2295 | if (err < 0) | 2285 | if (err < 0) |
2296 | goto unlink; | 2286 | goto unlink; |
2297 | 2287 | ||
2298 | err = mod_sysfs_setup(mod, kp, num_kp); | 2288 | err = mod_sysfs_setup(mod, mod->kp, mod->num_kp); |
2299 | if (err < 0) | 2289 | if (err < 0) |
2300 | goto unlink; | 2290 | goto unlink; |
2301 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); | 2291 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); |
@@ -2304,12 +2294,13 @@ static noinline struct module *load_module(void __user *umod, | |||
2304 | /* Get rid of temporary copy */ | 2294 | /* Get rid of temporary copy */ |
2305 | vfree(hdr); | 2295 | vfree(hdr); |
2306 | 2296 | ||
2307 | stop_machine_destroy(); | ||
2308 | /* Done! */ | 2297 | /* Done! */ |
2309 | return mod; | 2298 | return mod; |
2310 | 2299 | ||
2311 | unlink: | 2300 | unlink: |
2312 | stop_machine(__unlink_module, mod, NULL); | 2301 | /* Unlink carefully: kallsyms could be walking list. */ |
2302 | list_del_rcu(&mod->list); | ||
2303 | synchronize_sched(); | ||
2313 | module_arch_cleanup(mod); | 2304 | module_arch_cleanup(mod); |
2314 | cleanup: | 2305 | cleanup: |
2315 | kobject_del(&mod->mkobj.kobj); | 2306 | kobject_del(&mod->mkobj.kobj); |
@@ -2317,8 +2308,8 @@ static noinline struct module *load_module(void __user *umod, | |||
2317 | ftrace_release(mod->module_core, mod->core_size); | 2308 | ftrace_release(mod->module_core, mod->core_size); |
2318 | free_unload: | 2309 | free_unload: |
2319 | module_unload_free(mod); | 2310 | module_unload_free(mod); |
2320 | free_init: | ||
2321 | #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) | 2311 | #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP) |
2312 | free_init: | ||
2322 | percpu_modfree(mod->refptr); | 2313 | percpu_modfree(mod->refptr); |
2323 | #endif | 2314 | #endif |
2324 | module_free(mod, mod->module_init); | 2315 | module_free(mod, mod->module_init); |
@@ -2332,7 +2323,6 @@ static noinline struct module *load_module(void __user *umod, | |||
2332 | kfree(args); | 2323 | kfree(args); |
2333 | free_hdr: | 2324 | free_hdr: |
2334 | vfree(hdr); | 2325 | vfree(hdr); |
2335 | stop_machine_destroy(); | ||
2336 | return ERR_PTR(err); | 2326 | return ERR_PTR(err); |
2337 | 2327 | ||
2338 | truncated: | 2328 | truncated: |
@@ -2609,6 +2599,25 @@ unsigned long module_kallsyms_lookup_name(const char *name) | |||
2609 | preempt_enable(); | 2599 | preempt_enable(); |
2610 | return ret; | 2600 | return ret; |
2611 | } | 2601 | } |
2602 | |||
2603 | int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, | ||
2604 | struct module *, unsigned long), | ||
2605 | void *data) | ||
2606 | { | ||
2607 | struct module *mod; | ||
2608 | unsigned int i; | ||
2609 | int ret; | ||
2610 | |||
2611 | list_for_each_entry(mod, &modules, list) { | ||
2612 | for (i = 0; i < mod->num_symtab; i++) { | ||
2613 | ret = fn(data, mod->strtab + mod->symtab[i].st_name, | ||
2614 | mod, mod->symtab[i].st_value); | ||
2615 | if (ret != 0) | ||
2616 | return ret; | ||
2617 | } | ||
2618 | } | ||
2619 | return 0; | ||
2620 | } | ||
2612 | #endif /* CONFIG_KALLSYMS */ | 2621 | #endif /* CONFIG_KALLSYMS */ |
2613 | 2622 | ||
2614 | static char *module_flags(struct module *mod, char *buf) | 2623 | static char *module_flags(struct module *mod, char *buf) |
@@ -2744,29 +2753,31 @@ const struct exception_table_entry *search_module_extables(unsigned long addr) | |||
2744 | } | 2753 | } |
2745 | 2754 | ||
2746 | /* | 2755 | /* |
2747 | * Is this a valid module address? | 2756 | * is_module_address - is this address inside a module? |
2757 | * @addr: the address to check. | ||
2758 | * | ||
2759 | * See is_module_text_address() if you simply want to see if the address | ||
2760 | * is code (not data). | ||
2748 | */ | 2761 | */ |
2749 | int is_module_address(unsigned long addr) | 2762 | bool is_module_address(unsigned long addr) |
2750 | { | 2763 | { |
2751 | struct module *mod; | 2764 | bool ret; |
2752 | 2765 | ||
2753 | preempt_disable(); | 2766 | preempt_disable(); |
2754 | 2767 | ret = __module_address(addr) != NULL; | |
2755 | list_for_each_entry_rcu(mod, &modules, list) { | ||
2756 | if (within_module_core(addr, mod)) { | ||
2757 | preempt_enable(); | ||
2758 | return 1; | ||
2759 | } | ||
2760 | } | ||
2761 | |||
2762 | preempt_enable(); | 2768 | preempt_enable(); |
2763 | 2769 | ||
2764 | return 0; | 2770 | return ret; |
2765 | } | 2771 | } |
2766 | 2772 | ||
2767 | 2773 | /* | |
2768 | /* Is this a valid kernel address? */ | 2774 | * __module_address - get the module which contains an address. |
2769 | __notrace_funcgraph struct module *__module_text_address(unsigned long addr) | 2775 | * @addr: the address. |
2776 | * | ||
2777 | * Must be called with preempt disabled or module mutex held so that | ||
2778 | * module doesn't get freed during this. | ||
2779 | */ | ||
2780 | __notrace_funcgraph struct module *__module_address(unsigned long addr) | ||
2770 | { | 2781 | { |
2771 | struct module *mod; | 2782 | struct module *mod; |
2772 | 2783 | ||
@@ -2774,22 +2785,51 @@ __notrace_funcgraph struct module *__module_text_address(unsigned long addr) | |||
2774 | return NULL; | 2785 | return NULL; |
2775 | 2786 | ||
2776 | list_for_each_entry_rcu(mod, &modules, list) | 2787 | list_for_each_entry_rcu(mod, &modules, list) |
2777 | if (within(addr, mod->module_init, mod->init_text_size) | 2788 | if (within_module_core(addr, mod) |
2778 | || within(addr, mod->module_core, mod->core_text_size)) | 2789 | || within_module_init(addr, mod)) |
2779 | return mod; | 2790 | return mod; |
2780 | return NULL; | 2791 | return NULL; |
2781 | } | 2792 | } |
2793 | EXPORT_SYMBOL_GPL(__module_address); | ||
2782 | 2794 | ||
2783 | struct module *module_text_address(unsigned long addr) | 2795 | /* |
2796 | * is_module_text_address - is this address inside module code? | ||
2797 | * @addr: the address to check. | ||
2798 | * | ||
2799 | * See is_module_address() if you simply want to see if the address is | ||
2800 | * anywhere in a module. See kernel_text_address() for testing if an | ||
2801 | * address corresponds to kernel or module code. | ||
2802 | */ | ||
2803 | bool is_module_text_address(unsigned long addr) | ||
2784 | { | 2804 | { |
2785 | struct module *mod; | 2805 | bool ret; |
2786 | 2806 | ||
2787 | preempt_disable(); | 2807 | preempt_disable(); |
2788 | mod = __module_text_address(addr); | 2808 | ret = __module_text_address(addr) != NULL; |
2789 | preempt_enable(); | 2809 | preempt_enable(); |
2790 | 2810 | ||
2811 | return ret; | ||
2812 | } | ||
2813 | |||
2814 | /* | ||
2815 | * __module_text_address - get the module whose code contains an address. | ||
2816 | * @addr: the address. | ||
2817 | * | ||
2818 | * Must be called with preempt disabled or module mutex held so that | ||
2819 | * module doesn't get freed during this. | ||
2820 | */ | ||
2821 | struct module *__module_text_address(unsigned long addr) | ||
2822 | { | ||
2823 | struct module *mod = __module_address(addr); | ||
2824 | if (mod) { | ||
2825 | /* Make sure it's within the text section. */ | ||
2826 | if (!within(addr, mod->module_init, mod->init_text_size) | ||
2827 | && !within(addr, mod->module_core, mod->core_text_size)) | ||
2828 | mod = NULL; | ||
2829 | } | ||
2791 | return mod; | 2830 | return mod; |
2792 | } | 2831 | } |
2832 | EXPORT_SYMBOL_GPL(__module_text_address); | ||
2793 | 2833 | ||
2794 | /* Don't grab lock, we're oopsing. */ | 2834 | /* Don't grab lock, we're oopsing. */ |
2795 | void print_modules(void) | 2835 | void print_modules(void) |
@@ -2809,9 +2849,17 @@ void print_modules(void) | |||
2809 | } | 2849 | } |
2810 | 2850 | ||
2811 | #ifdef CONFIG_MODVERSIONS | 2851 | #ifdef CONFIG_MODVERSIONS |
2812 | /* Generate the signature for struct module here, too, for modversions. */ | 2852 | /* Generate the signature for all relevant module structures here. |
2813 | void struct_module(struct module *mod) { return; } | 2853 | * If these change, we don't want to try to parse the module. */ |
2814 | EXPORT_SYMBOL(struct_module); | 2854 | void module_layout(struct module *mod, |
2855 | struct modversion_info *ver, | ||
2856 | struct kernel_param *kp, | ||
2857 | struct kernel_symbol *ks, | ||
2858 | struct marker *marker, | ||
2859 | struct tracepoint *tp) | ||
2860 | { | ||
2861 | } | ||
2862 | EXPORT_SYMBOL(module_layout); | ||
2815 | #endif | 2863 | #endif |
2816 | 2864 | ||
2817 | #ifdef CONFIG_MARKERS | 2865 | #ifdef CONFIG_MARKERS |
diff --git a/kernel/params.c b/kernel/params.c index a1e3025b19a9..de273ec85bd2 100644 --- a/kernel/params.c +++ b/kernel/params.c | |||
@@ -24,6 +24,9 @@ | |||
24 | #include <linux/err.h> | 24 | #include <linux/err.h> |
25 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
26 | 26 | ||
27 | /* We abuse the high bits of "perm" to record whether we kmalloc'ed. */ | ||
28 | #define KPARAM_KMALLOCED 0x80000000 | ||
29 | |||
27 | #if 0 | 30 | #if 0 |
28 | #define DEBUGP printk | 31 | #define DEBUGP printk |
29 | #else | 32 | #else |
@@ -217,7 +220,19 @@ int param_set_charp(const char *val, struct kernel_param *kp) | |||
217 | return -ENOSPC; | 220 | return -ENOSPC; |
218 | } | 221 | } |
219 | 222 | ||
220 | *(char **)kp->arg = (char *)val; | 223 | if (kp->perm & KPARAM_KMALLOCED) |
224 | kfree(*(char **)kp->arg); | ||
225 | |||
226 | /* This is a hack. We can't need to strdup in early boot, and we | ||
227 | * don't need to; this mangled commandline is preserved. */ | ||
228 | if (slab_is_available()) { | ||
229 | kp->perm |= KPARAM_KMALLOCED; | ||
230 | *(char **)kp->arg = kstrdup(val, GFP_KERNEL); | ||
231 | if (!kp->arg) | ||
232 | return -ENOMEM; | ||
233 | } else | ||
234 | *(const char **)kp->arg = val; | ||
235 | |||
221 | return 0; | 236 | return 0; |
222 | } | 237 | } |
223 | 238 | ||
@@ -571,6 +586,15 @@ void module_param_sysfs_remove(struct module *mod) | |||
571 | } | 586 | } |
572 | #endif | 587 | #endif |
573 | 588 | ||
589 | void destroy_params(const struct kernel_param *params, unsigned num) | ||
590 | { | ||
591 | unsigned int i; | ||
592 | |||
593 | for (i = 0; i < num; i++) | ||
594 | if (params[i].perm & KPARAM_KMALLOCED) | ||
595 | kfree(*(char **)params[i].arg); | ||
596 | } | ||
597 | |||
574 | static void __init kernel_add_sysfs_param(const char *name, | 598 | static void __init kernel_add_sysfs_param(const char *name, |
575 | struct kernel_param *kparam, | 599 | struct kernel_param *kparam, |
576 | unsigned int name_skip) | 600 | unsigned int name_skip) |
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 7e62303133dc..8cc70612984c 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c | |||
@@ -1607,12 +1607,12 @@ static void read_symbols(char *modname) | |||
1607 | 1607 | ||
1608 | parse_elf_finish(&info); | 1608 | parse_elf_finish(&info); |
1609 | 1609 | ||
1610 | /* Our trick to get versioning for struct_module - it's | 1610 | /* Our trick to get versioning for module struct etc. - it's |
1611 | * never passed as an argument to an exported function, so | 1611 | * never passed as an argument to an exported function, so |
1612 | * the automatic versioning doesn't pick it up, but it's really | 1612 | * the automatic versioning doesn't pick it up, but it's really |
1613 | * important anyhow */ | 1613 | * important anyhow */ |
1614 | if (modversions) | 1614 | if (modversions) |
1615 | mod->unres = alloc_symbol("struct_module", 0, mod->unres); | 1615 | mod->unres = alloc_symbol("module_layout", 0, mod->unres); |
1616 | } | 1616 | } |
1617 | 1617 | ||
1618 | #define SZ 500 | 1618 | #define SZ 500 |