History

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.

Linus Torvalds committed 17 years ago

Commit cab4e4c2 parents 5412b53 495026713 files · +319 −137Browse files

Unified · Split

13 files
  1. arch/arm/boot/compressed/misc.c +4 −1
  2. drivers/mtd/nand/nand_base.c +2 −2
  3. include/linux/kallsyms.h +15 −0
  4. include/linux/kmod.h +8 −3
  5. include/linux/module.h +55 −8
  6. include/linux/moduleparam.h +10 −0
  7. include/linux/string.h +9 −0
  8. kernel/extable.c +3 −3
  9. kernel/kallsyms.c +19 −0
  10. kernel/kmod.c +6 −4
  11. kernel/module.c +161 −113
  12. kernel/params.c +25 −1
  13. scripts/mod/modpost.c +2 −2
arch/arm/boot/compressed/misc.c+4−1
@@ -18,7 +18,10 @@ · 17 unmodified lines
1818
1919 unsigned int __machine_arch_type;
2020
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>
2225
2326 #ifdef STANDALONE_DEBUG
2427 #define putstr printf
drivers/mtd/nand/nand_base.c+2−2
@@ -2720,14 +2720,14 @@ int nand_scan_tail(struct mtd_info *mtd) · 2719 unmodified lines
27202720 return chip->scan_bbt(mtd);
27212721 }
27222722
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
27242724 test if this is a module _anyway_ -- they'd have to try _really_ hard
27252725 to call us from in-kernel code if the core NAND support is modular. */
27262726 #ifdef MODULE
27272727 #define caller_is_module() (1)
27282728 #else
27292729 #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))
27312731 #endif
27322732
27332733 /**
include/linux/kallsyms.h+15−0
@@ -13,10 +13,17 @@ · 12 unmodified lines
1313 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
1414 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1)
1515
16+struct module;
17+
1618 #ifdef CONFIG_KALLSYMS
1719 /* Lookup the address for a symbol. Returns 0 if not found. */
1820 unsigned long kallsyms_lookup_name(const char *name);
1921
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+
2027 extern int kallsyms_lookup_size_offset(unsigned long addr,
2128 unsigned long *symbolsize,
2229 unsigned long *offset);
@@ -43,6 +50,14 @@ static inline unsigned long kallsyms_lookup_name(const char *name) · 20 unmodified lines
4350 return 0;
4451 }
4552
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+
4661 static inline int kallsyms_lookup_size_offset(unsigned long addr,
4762 unsigned long *symbolsize,
4863 unsigned long *offset)
include/linux/kmod.h+8−3
@@ -29,10 +29,15 @@ · 28 unmodified lines
2929 #ifdef CONFIG_MODULES
3030 /* modprobe exit status on success, -ve on error. Return value
3131 * usually useless though. */
32−extern int request_module(const char * name, ...) __attribute__ ((format (printf, 1, 2)));
33−#define try_then_request_module(x, mod...) ((x) ?: (request_module(mod), (x)))
32+extern int __request_module(bool wait, const char *name, ...) \
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)))
3438 #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; }
3641 #define try_then_request_module(x, mod...) (x)
3742 #endif
3843
include/linux/module.h+55−8
@@ -248,6 +248,10 @@ struct module · 247 unmodified lines
248248 const unsigned long *crcs;
249249 unsigned int num_syms;
250250
251+ /* Kernel parameters. */
252+ struct kernel_param *kp;
253+ unsigned int num_kp;
254+
251255 /* GPL-only exported symbols. */
252256 unsigned int num_gpl_syms;
253257 const struct kernel_symbol *gpl_syms;
@@ -350,6 +354,8 @@ struct module · 96 unmodified lines
350354 #define MODULE_ARCH_INIT {}
351355 #endif
352356
357+extern struct mutex module_mutex;
358+
353359 /* FIXME: It'd be nice to isolate modules during init, too, so they
354360 aren't used before they (may) fail. But presently too much code
355361 (IDE & SCSI) require entry into the module during init.*/
@@ -358,10 +364,10 @@ static inline int module_is_live(struct module *mod) · 2 unmodified lines
358364 return mod->state != MODULE_STATE_GOING;
359365 }
360366
361−/* Is this address in a module? (second is with no locks, for oops) */
362−struct module *module_text_address(unsigned long addr);
363367 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);
365371
366372 static inline int within_module_core(unsigned long addr, struct module *mod)
367373 {
@@ -375,6 +381,31 @@ static inline int within_module_init(unsigned long addr, struct module *mod) · 7 unmodified lines
375381 addr < (unsigned long)mod->module_init + mod->init_size;
376382 }
377383
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+
378409 /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
379410 symnum out of range. */
380411 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, · 2 unmodified lines
383414 /* Look for this name: can be of form module:name. */
384415 unsigned long module_kallsyms_lookup_name(const char *name);
385416
417+int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
418+ struct module *, unsigned long),
419+ void *data);
420+
386421 extern void __module_put_and_exit(struct module *mod, long code)
387422 __attribute__((noreturn));
388423 #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) · 55 unmodified lines
444479 #define symbol_put_addr(p) do { } while(0)
445480
446481 #endif /* CONFIG_MODULE_UNLOAD */
482+int use_module(struct module *a, struct module *b);
447483
448484 /* This is a #define so the string doesn't get put in every .o file */
449485 #define module_name(mod) \
@@ -490,21 +526,24 @@ search_module_extables(unsigned long addr) · 40 unmodified lines
490526 return NULL;
491527 }
492528
493−/* Is this address in a module? */
494−static inline struct module *module_text_address(unsigned long addr)
529+static inline struct module *__module_address(unsigned long addr)
495530 {
496531 return NULL;
497532 }
498533
499−/* Is this address in a module? (don't take a lock, we're oopsing) */
500534 static inline struct module *__module_text_address(unsigned long addr)
501535 {
502536 return NULL;
503537 }
504538
505−static inline int is_module_address(unsigned long addr)
539+static inline bool is_module_address(unsigned long addr)
506540 {
507− return 0;
541+ return false;
542+}
543+
544+static inline bool is_module_text_address(unsigned long addr)
545+{
546+ return false;
508547 }
509548
510549 /* Get/put a kernel symbol (calls should be symmetric) */
@@ -559,6 +598,14 @@ static inline unsigned long module_kallsyms_lookup_name(const char *name) · 48 unmodified lines
559598 return 0;
560599 }
561600
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+
562609 static inline int register_module_notifier(struct notifier_block * nb)
563610 {
564611 /* no events will happen anyway, so this can always succeed */
include/linux/moduleparam.h+10−0
@@ -138,6 +138,16 @@ extern int parse_args(const char *name, · 137 unmodified lines
138138 unsigned num,
139139 int (*unknown)(char *param, char *val));
140140
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+
141151 /* All the helper functions */
142152 /* The macros to do compile-time type checking stolen from Jakub
143153 Jelinek, who IIRC came up with this idea for the 2.4 module init code. */
include/linux/string.h+9−0
@@ -122,5 +122,14 @@ int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) __printf(3, 4); · 121 unmodified lines
122122 extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
123123 const void *from, size_t available);
124124
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+}
125134 #endif
126135 #endif /* _LINUX_STRING_H_ */
kernel/extable.c+3−3
@@ -65,7 +65,7 @@ __notrace_funcgraph int __kernel_text_address(unsigned long addr) · 64 unmodified lines
6565 {
6666 if (core_kernel_text(addr))
6767 return 1;
68− if (__module_text_address(addr))
68+ if (is_module_text_address(addr))
6969 return 1;
7070 /*
7171 * There might be init symbols in saved stacktraces.
@@ -84,7 +84,7 @@ int kernel_text_address(unsigned long addr) · 12 unmodified lines
8484 {
8585 if (core_kernel_text(addr))
8686 return 1;
87− return module_text_address(addr) != NULL;
87+ return is_module_text_address(addr);
8888 }
8989
9090 /*
@@ -100,5 +100,5 @@ int func_ptr_is_kernel_text(void *ptr) · 9 unmodified lines
100100 addr = (unsigned long) dereference_function_descriptor(ptr);
101101 if (core_kernel_text(addr))
102102 return 1;
103− return module_text_address(addr) != NULL;
103+ return is_module_text_address(addr);
104104 }
kernel/kallsyms.c+19−0
@@ -161,6 +161,25 @@ unsigned long kallsyms_lookup_name(const char *name) · 160 unmodified lines
161161 return module_kallsyms_lookup_name(name);
162162 }
163163
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+
164183 static unsigned long get_symbol_pos(unsigned long addr,
165184 unsigned long *symbolsize,
166185 unsigned long *offset)
kernel/kmod.c+6−4
@@ -50,7 +50,8 @@ static struct workqueue_struct *khelper_wq; · 49 unmodified lines
5050 char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
5151
5252 /**
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
5455 * @fmt: printf style format string for the name of the module
5556 * @...: arguments as specified in the format string
5657 *
@@ -63,7 +64,7 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe"; · 6 unmodified lines
6364 * If module auto-loading support is disabled then this function
6465 * becomes a no-operation.
6566 */
66−int request_module(const char *fmt, ...)
67+int __request_module(bool wait, const char *fmt, ...)
6768 {
6869 va_list args;
6970 char module_name[MODULE_NAME_LEN];
@@ -108,11 +109,12 @@ int request_module(const char *fmt, ...) · 38 unmodified lines
108109 return -ENOMEM;
109110 }
110111
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);
112114 atomic_dec(&kmod_concurrent);
113115 return ret;
114116 }
115−EXPORT_SYMBOL(request_module);
117+EXPORT_SYMBOL(__request_module);
116118 #endif /* CONFIG_MODULES */
117119
118120 struct subprocess_info {
kernel/module.c+161−113
@@ -68,7 +68,8 @@ · 67 unmodified lines
6868
6969 /* List of modules, protected by module_mutex or preempt_disable
7070 * (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);
7273 static LIST_HEAD(modules);
7374
7475 /* Waiting for a module to finish initializing? */
@@ -76,7 +77,7 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq); · 1 unmodified line
7677
7778 static BLOCKING_NOTIFIER_HEAD(module_notify_list);
7879
79−/* Bounds of module allocation, for speeding __module_text_address */
80+/* Bounds of module allocation, for speeding __module_address */
8081 static unsigned long module_addr_min = -1UL, module_addr_max = 0;
8182
8283 int register_module_notifier(struct notifier_block * nb)
@@ -186,17 +187,6 @@ extern const unsigned long __start___kcrctab_unused_gpl[]; · 103 unmodified lines
186187 #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL)
187188 #endif
188189
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−
200190 static bool each_symbol_in_section(const struct symsearch *arr,
201191 unsigned int arrsize,
202192 struct module *owner,
@@ -217,10 +207,8 @@ static bool each_symbol_in_section(const struct symsearch *arr, · 14 unmodified lines
217207 }
218208
219209 /* Returns true as soon as fn returns true, otherwise false. */
220−static bool each_symbol(bool (*fn)(const struct symsearch *arr,
221− struct module *owner,
222− unsigned int symnum, void *data),
223− void *data)
210+bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
211+ unsigned int symnum, void *data), void *data)
224212 {
225213 struct module *mod;
226214 const struct symsearch arr[] = {
@@ -273,6 +261,7 @@ static bool each_symbol(bool (*fn)(const struct symsearch *arr, · 46 unmodified lines
273261 }
274262 return false;
275263 }
264+EXPORT_SYMBOL_GPL(each_symbol);
276265
277266 struct find_symbol_arg {
278267 /* Input */
@@ -283,7 +272,7 @@ struct find_symbol_arg { · 4 unmodified lines
283272 /* Output */
284273 struct module *owner;
285274 const unsigned long *crc;
286− unsigned long value;
275+ const struct kernel_symbol *sym;
287276 };
288277
289278 static bool find_symbol_in_section(const struct symsearch *syms,
@@ -324,17 +313,17 @@ static bool find_symbol_in_section(const struct symsearch *syms, · 34 unmodified lines
324313
325314 fsa->owner = owner;
326315 fsa->crc = symversion(syms->crcs, symnum);
327− fsa->value = syms->start[symnum].value;
316+ fsa->sym = &syms->start[symnum];
328317 return true;
329318 }
330319
331−/* Find a symbol, return value, (optional) crc and (optional) module
332− * which owns it */
333−static unsigned long find_symbol(const char *name,
334− struct module **owner,
335− const unsigned long **crc,
336− bool gplok,
337− bool warn)
320+/* Find a symbol and return it, along with, (optional) crc and
321+ * (optional) module which owns it */
322+const struct kernel_symbol *find_symbol(const char *name,
323+ struct module **owner,
324+ const unsigned long **crc,
325+ bool gplok,
326+ bool warn)
338327 {
339328 struct find_symbol_arg fsa;
340329
@@ -347,15 +336,16 @@ static unsigned long find_symbol(const char *name, · 6 unmodified lines
347336 *owner = fsa.owner;
348337 if (crc)
349338 *crc = fsa.crc;
350− return fsa.value;
339+ return fsa.sym;
351340 }
352341
353342 DEBUGP("Failed to find symbol %s\n", name);
354− return -ENOENT;
343+ return NULL;
355344 }
345+EXPORT_SYMBOL_GPL(find_symbol);
356346
357347 /* 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)
359349 {
360350 struct module *mod;
361351
@@ -365,6 +355,7 @@ static struct module *find_module(const char *name) · 3 unmodified lines
365355 }
366356 return NULL;
367357 }
358+EXPORT_SYMBOL_GPL(find_module);
368359
369360 #ifdef CONFIG_SMP
370361
@@ -641,7 +632,7 @@ static int already_uses(struct module *a, struct module *b) · 270 unmodified lines
641632 }
642633
643634 /* 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)
645636 {
646637 struct module_use *use;
647638 int no_warn, err;
@@ -674,6 +665,7 @@ static int use_module(struct module *a, struct module *b) · 26 unmodified lines
674665 no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name);
675666 return 1;
676667 }
668+EXPORT_SYMBOL_GPL(use_module);
677669
678670 /* Clear the unload stuff of the module. */
679671 static void module_unload_free(struct module *mod)
@@ -894,7 +886,7 @@ void __symbol_put(const char *symbol) · 214 unmodified lines
894886 struct module *owner;
895887
896888 preempt_disable();
897− if (IS_ERR_VALUE(find_symbol(symbol, &owner, NULL, true, false)))
889+ if (!find_symbol(symbol, &owner, NULL, true, false))
898890 BUG();
899891 module_put(owner);
900892 preempt_enable();
@@ -908,8 +900,10 @@ void symbol_put_addr(void *addr) · 7 unmodified lines
908900 if (core_kernel_text((unsigned long)addr))
909901 return;
910902
911− if (!(modaddr = module_text_address((unsigned long)addr)))
912− BUG();
903+ /* module_text_address is safe here: we're supposed to have reference
904+ * to module from symbol_get, so it can't go away. */
905+ modaddr = __module_text_address((unsigned long)addr);
906+ BUG_ON(!modaddr);
913907 module_put(modaddr);
914908 }
915909 EXPORT_SYMBOL_GPL(symbol_put_addr);
@@ -949,10 +943,11 @@ static inline void module_unload_free(struct module *mod) · 33 unmodified lines
949943 {
950944 }
951945
952−static inline int use_module(struct module *a, struct module *b)
946+int use_module(struct module *a, struct module *b)
953947 {
954948 return strong_try_module_get(b) == 0;
955949 }
950+EXPORT_SYMBOL_GPL(use_module);
956951
957952 static inline void module_unload_init(struct module *mod)
958953 {
@@ -995,12 +990,12 @@ static struct module_attribute *modinfo_attrs[] = { · 36 unmodified lines
995990
996991 static const char vermagic[] = VERMAGIC_STRING;
997992
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)
999994 {
1000995 #ifdef CONFIG_MODULE_FORCE_LOAD
1001996 if (!test_taint(TAINT_FORCED_MODULE))
1002− printk("%s: no version for \"%s\" found: kernel tainted.\n",
1003− mod->name, symname);
997+ printk(KERN_WARNING "%s: %s: kernel tainted.\n",
998+ mod->name, reason);
1004999 add_taint_module(mod, TAINT_FORCED_MODULE);
10051000 return 0;
10061001 #else
@@ -1057,9 +1052,9 @@ static inline int check_modstruct_version(Elf_Shdr *sechdrs, · 50 unmodified lines
10571052 {
10581053 const unsigned long *crc;
10591054
1060− if (IS_ERR_VALUE(find_symbol("struct_module", NULL, &crc, true, false)))
1055+ if (!find_symbol("module_layout", NULL, &crc, true, false))
10611056 BUG();
1062− return check_version(sechdrs, versindex, "struct_module", mod, crc);
1057+ return check_version(sechdrs, versindex, "module_layout", mod, crc);
10631058 }
10641059
10651060 /* 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, · 32 unmodified lines
10981093
10991094 /* Resolve a symbol for this module. I.e. if we find one, record usage.
11001095 Must be holding module_mutex. */
1101−static unsigned long resolve_symbol(Elf_Shdr *sechdrs,
1102− unsigned int versindex,
1103− const char *name,
1104− struct module *mod)
1096+static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
1097+ unsigned int versindex,
1098+ const char *name,
1099+ struct module *mod)
11051100 {
11061101 struct module *owner;
1107− unsigned long ret;
1102+ const struct kernel_symbol *sym;
11081103 const unsigned long *crc;
11091104
1110− ret = find_symbol(name, &owner, &crc,
1105+ sym = find_symbol(name, &owner, &crc,
11111106 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true);
1112− if (!IS_ERR_VALUE(ret)) {
1113− /* use_module can fail due to OOM,
1114− or module initialization or unloading */
1107+ /* use_module can fail due to OOM,
1108+ or module initialization or unloading */
1109+ if (sym) {
11151110 if (!check_version(sechdrs, versindex, name, mod, crc) ||
11161111 !use_module(mod, owner))
1117− ret = -EINVAL;
1112+ sym = NULL;
11181113 }
1119− return ret;
1114+ return sym;
11201115 }
11211116
11221117 /*
@@ -1491,6 +1486,9 @@ static void free_module(struct module *mod) · 368 unmodified lines
14911486 /* Module unload stuff */
14921487 module_unload_free(mod);
14931488
1489+ /* Free any allocated parameters. */
1490+ destroy_params(mod->kp, mod->num_kp);
1491+
14941492 /* release any pointers to mcount in this module */
14951493 ftrace_release(mod->module_core, mod->core_size);
14961494
@@ -1513,17 +1511,15 @@ static void free_module(struct module *mod) · 16 unmodified lines
15131511 void *__symbol_get(const char *symbol)
15141512 {
15151513 struct module *owner;
1516− unsigned long value;
1514+ const struct kernel_symbol *sym;
15171515
15181516 preempt_disable();
1519− value = find_symbol(symbol, &owner, NULL, true, true);
1520− if (IS_ERR_VALUE(value))
1521− value = 0;
1522− else if (strong_try_module_get(owner))
1523− value = 0;
1517+ sym = find_symbol(symbol, &owner, NULL, true, true);
1518+ if (sym && strong_try_module_get(owner))
1519+ sym = NULL;
15241520 preempt_enable();
15251521
1526− return (void *)value;
1522+ return sym ? (void *)sym->value : NULL;
15271523 }
15281524 EXPORT_SYMBOL_GPL(__symbol_get);
15291525
@@ -1551,8 +1547,7 @@ static int verify_export_symbols(struct module *mod) · 21 unmodified lines
15511547
15521548 for (i = 0; i < ARRAY_SIZE(arr); i++) {
15531549 for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) {
1554− if (!IS_ERR_VALUE(find_symbol(s->name, &owner,
1555− NULL, true, false))) {
1550+ if (find_symbol(s->name, &owner, NULL, true, false)) {
15561551 printk(KERN_ERR
15571552 "%s: exports duplicate symbol %s"
15581553 " (owned by %s)\n",
@@ -1576,6 +1571,7 @@ static int simplify_symbols(Elf_Shdr *sechdrs, · 17 unmodified lines
15761571 unsigned long secbase;
15771572 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
15781573 int ret = 0;
1574+ const struct kernel_symbol *ksym;
15791575
15801576 for (i = 1; i < n; i++) {
15811577 switch (sym[i].st_shndx) {
@@ -1595,13 +1591,14 @@ static int simplify_symbols(Elf_Shdr *sechdrs, · 13 unmodified lines
15951591 break;
15961592
15971593 case SHN_UNDEF:
1598− sym[i].st_value
1599− = resolve_symbol(sechdrs, versindex,
1600− strtab + sym[i].st_name, mod);
1601−
1594+ ksym = resolve_symbol(sechdrs, versindex,
1595+ strtab + sym[i].st_name, mod);
16021596 /* Ok if resolved. */
1603− if (!IS_ERR_VALUE(sym[i].st_value))
1597+ if (ksym) {
1598+ sym[i].st_value = ksym->value;
16041599 break;
1600+ }
1601+
16051602 /* Ok if weak. */
16061603 if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK)
16071604 break;
@@ -1676,8 +1673,7 @@ static void layout_sections(struct module *mod, · 68 unmodified lines
16761673 if ((s->sh_flags & masks[m][0]) != masks[m][0]
16771674 || (s->sh_flags & masks[m][1])
16781675 || s->sh_entsize != ~0UL
1679− || strncmp(secstrings + s->sh_name,
1680− ".init", 5) == 0)
1676+ || strstarts(secstrings + s->sh_name, ".init"))
16811677 continue;
16821678 s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
16831679 DEBUGP("\t%s\n", secstrings + s->sh_name);
@@ -1694,8 +1690,7 @@ static void layout_sections(struct module *mod, · 10 unmodified lines
16941690 if ((s->sh_flags & masks[m][0]) != masks[m][0]
16951691 || (s->sh_flags & masks[m][1])
16961692 || s->sh_entsize != ~0UL
1697− || strncmp(secstrings + s->sh_name,
1698− ".init", 5) != 0)
1693+ || !strstarts(secstrings + s->sh_name, ".init"))
16991694 continue;
17001695 s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
17011696 | INIT_OFFSET_MASK);
@@ -1828,8 +1823,7 @@ static char elf_type(const Elf_Sym *sym, · 126 unmodified lines
18281823 else
18291824 return 'b';
18301825 }
1831− if (strncmp(secstrings + sechdrs[sym->st_shndx].sh_name,
1832− ".debug", strlen(".debug")) == 0)
1826+ if (strstarts(secstrings + sechdrs[sym->st_shndx].sh_name, ".debug"))
18331827 return 'n';
18341828 return '?';
18351829 }
@@ -1898,8 +1892,7 @@ static noinline struct module *load_module(void __user *umod, · 62 unmodified lines
18981892 unsigned int symindex = 0;
18991893 unsigned int strindex = 0;
19001894 unsigned int modindex, versindex, infoindex, pcpuindex;
1901− unsigned int num_kp, num_mcount;
1902− struct kernel_param *kp;
1895+ unsigned int num_mcount;
19031896 struct module *mod;
19041897 long err = 0;
19051898 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */
@@ -1916,12 +1909,6 @@ static noinline struct module *load_module(void __user *umod, · 10 unmodified lines
19161909 if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL)
19171910 return ERR_PTR(-ENOMEM);
19181911
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−
19251912 if (copy_from_user(hdr, umod, len) != 0) {
19261913 err = -EFAULT;
19271914 goto free_hdr;
@@ -1962,9 +1949,12 @@ static noinline struct module *load_module(void __user *umod, · 34 unmodified lines
19621949 }
19631950 #ifndef CONFIG_MODULE_UNLOAD
19641951 /* 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"))
19661953 sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC;
19671954 #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;
19681958 }
19691959
19701960 modindex = find_sec(hdr, sechdrs, secstrings,
@@ -2006,7 +1996,7 @@ static noinline struct module *load_module(void __user *umod, · 35 unmodified lines
20061996 modmagic = get_modinfo(sechdrs, infoindex, "vermagic");
20071997 /* This is allowed: modprobe --force will invalidate it. */
20081998 if (!modmagic) {
2009− err = try_to_force_load(mod, "magic");
1999+ err = try_to_force_load(mod, "bad vermagic");
20102000 if (err)
20112001 goto free_hdr;
20122002 } else if (!same_magic(modmagic, vermagic, versindex)) {
@@ -2144,8 +2134,8 @@ static noinline struct module *load_module(void __user *umod, · 131 unmodified lines
21442134
21452135 /* Now we've got everything in the final locations, we can
21462136 * find optional sections. */
2147− kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp),
2148− &num_kp);
2137+ mod->kp = section_objs(hdr, sechdrs, secstrings, "__param",
2138+ sizeof(*mod->kp), &mod->num_kp);
21492139 mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab",
21502140 sizeof(*mod->syms), &mod->num_syms);
21512141 mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab");
@@ -2195,8 +2185,8 @@ static noinline struct module *load_module(void __user *umod, · 43 unmodified lines
21952185 || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs)
21962186 #endif
21972187 ) {
2198− printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name);
2199− err = try_to_force_load(mod, "nocrc");
2188+ err = try_to_force_load(mod,
2189+ "no versions for exported symbols");
22002190 if (err)
22012191 goto cleanup;
22022192 }
@@ -2291,11 +2281,11 @@ static noinline struct module *load_module(void __user *umod, · 88 unmodified lines
22912281 */
22922282 list_add_rcu(&mod->list, &modules);
22932283
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);
22952285 if (err < 0)
22962286 goto unlink;
22972287
2298− err = mod_sysfs_setup(mod, kp, num_kp);
2288+ err = mod_sysfs_setup(mod, mod->kp, mod->num_kp);
22992289 if (err < 0)
23002290 goto unlink;
23012291 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
@@ -2304,12 +2294,13 @@ static noinline struct module *load_module(void __user *umod, · 2 unmodified lines
23042294 /* Get rid of temporary copy */
23052295 vfree(hdr);
23062296
2307− stop_machine_destroy();
23082297 /* Done! */
23092298 return mod;
23102299
23112300 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();
23132304 module_arch_cleanup(mod);
23142305 cleanup:
23152306 kobject_del(&mod->mkobj.kobj);
@@ -2317,8 +2308,8 @@ static noinline struct module *load_module(void __user *umod, · 1 unmodified line
23172308 ftrace_release(mod->module_core, mod->core_size);
23182309 free_unload:
23192310 module_unload_free(mod);
2320− free_init:
23212311 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
2312+ free_init:
23222313 percpu_modfree(mod->refptr);
23232314 #endif
23242315 module_free(mod, mod->module_init);
@@ -2332,7 +2323,6 @@ static noinline struct module *load_module(void __user *umod, · 7 unmodified lines
23322323 kfree(args);
23332324 free_hdr:
23342325 vfree(hdr);
2335− stop_machine_destroy();
23362326 return ERR_PTR(err);
23372327
23382328 truncated:
@@ -2609,6 +2599,25 @@ unsigned long module_kallsyms_lookup_name(const char *name) · 270 unmodified lines
26092599 preempt_enable();
26102600 return ret;
26112601 }
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+}
26122621 #endif /* CONFIG_KALLSYMS */
26132622
26142623 static char *module_flags(struct module *mod, char *buf)
@@ -2744,29 +2753,31 @@ const struct exception_table_entry *search_module_extables(unsigned long addr) · 129 unmodified lines
27442753 }
27452754
27462755 /*
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).
27482761 */
2749−int is_module_address(unsigned long addr)
2762+bool is_module_address(unsigned long addr)
27502763 {
2751− struct module *mod;
2764+ bool ret;
27522765
27532766 preempt_disable();
2754−
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−
2767+ ret = __module_address(addr) != NULL;
27622768 preempt_enable();
27632769
2764− return 0;
2770+ return ret;
27652771 }
27662772
2767−
2768−/* Is this a valid kernel address? */
2769−__notrace_funcgraph struct module *__module_text_address(unsigned long addr)
2773+/*
2774+ * __module_address - get the module which contains an address.
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)
27702781 {
27712782 struct module *mod;
27722783
@@ -2774,22 +2785,51 @@ __notrace_funcgraph struct module *__module_text_address(unsigned long addr) · 1 unmodified line
27742785 return NULL;
27752786
27762787 list_for_each_entry_rcu(mod, &modules, list)
2777− if (within(addr, mod->module_init, mod->init_text_size)
2778− || within(addr, mod->module_core, mod->core_text_size))
2788+ if (within_module_core(addr, mod)
2789+ || within_module_init(addr, mod))
27792790 return mod;
27802791 return NULL;
27812792 }
2793+EXPORT_SYMBOL_GPL(__module_address);
27822794
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)
27842804 {
2785− struct module *mod;
2805+ bool ret;
27862806
27872807 preempt_disable();
2788− mod = __module_text_address(addr);
2808+ ret = __module_text_address(addr) != NULL;
27892809 preempt_enable();
27902810
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+ }
27912830 return mod;
27922831 }
2832+EXPORT_SYMBOL_GPL(__module_text_address);
27932833
27942834 /* Don't grab lock, we're oopsing. */
27952835 void print_modules(void)
@@ -2809,9 +2849,17 @@ void print_modules(void) · 13 unmodified lines
28092849 }
28102850
28112851 #ifdef CONFIG_MODVERSIONS
2812−/* Generate the signature for struct module here, too, for modversions. */
2813−void struct_module(struct module *mod) { return; }
2814−EXPORT_SYMBOL(struct_module);
2852+/* Generate the signature for all relevant module structures here.
2853+ * If these change, we don't want to try to parse the 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);
28152863 #endif
28162864
28172865 #ifdef CONFIG_MARKERS
kernel/params.c+25−1
@@ -24,6 +24,9 @@ · 23 unmodified lines
2424 #include <linux/err.h>
2525 #include <linux/slab.h>
2626
27+/* We abuse the high bits of "perm" to record whether we kmalloc'ed. */
28+#define KPARAM_KMALLOCED 0x80000000
29+
2730 #if 0
2831 #define DEBUGP printk
2932 #else
@@ -217,7 +220,19 @@ int param_set_charp(const char *val, struct kernel_param *kp) · 187 unmodified lines
217220 return -ENOSPC;
218221 }
219222
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+
221236 return 0;
222237 }
223238
@@ -571,6 +586,15 @@ void module_param_sysfs_remove(struct module *mod) · 347 unmodified lines
571586 }
572587 #endif
573588
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+
574598 static void __init kernel_add_sysfs_param(const char *name,
575599 struct kernel_param *kparam,
576600 unsigned int name_skip)
scripts/mod/modpost.c+2−2
@@ -1607,12 +1607,12 @@ static void read_symbols(char *modname) · 1606 unmodified lines
16071607
16081608 parse_elf_finish(&info);
16091609
1610− /* Our trick to get versioning for struct_module - it's
1610+ /* Our trick to get versioning for module struct etc. - it's
16111611 * never passed as an argument to an exported function, so
16121612 * the automatic versioning doesn't pick it up, but it's really
16131613 * important anyhow */
16141614 if (modversions)
1615− mod->unres = alloc_symbol("struct_module", 0, mod->unres);
1615+ mod->unres = alloc_symbol("module_layout", 0, mod->unres);
16161616 }
16171617
16181618 #define SZ 500