2 Copyright (C) 2002 Richard Henderson
3 Copyright (C) 2001 Rusty Russell, 2002, 2010 Rusty Russell IBM.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <linux/export.h>
20 #include <linux/moduleloader.h>
21 #include <linux/ftrace_event.h>
22 #include <linux/init.h>
23 #include <linux/kallsyms.h>
25 #include <linux/sysfs.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/vmalloc.h>
29 #include <linux/elf.h>
30 #include <linux/proc_fs.h>
31 #include <linux/seq_file.h>
32 #include <linux/syscalls.h>
33 #include <linux/fcntl.h>
34 #include <linux/rcupdate.h>
35 #include <linux/capability.h>
36 #include <linux/cpu.h>
37 #include <linux/moduleparam.h>
38 #include <linux/errno.h>
39 #include <linux/err.h>
40 #include <linux/vermagic.h>
41 #include <linux/notifier.h>
42 #include <linux/sched.h>
43 #include <linux/stop_machine.h>
44 #include <linux/device.h>
45 #include <linux/string.h>
46 #include <linux/mutex.h>
47 #include <linux/unwind.h>
48 #include <linux/rculist.h>
49 #include <asm/uaccess.h>
50 #include <asm/cacheflush.h>
51 #include <asm/mmu_context.h>
52 #include <linux/license.h>
53 #include <asm/sections.h>
54 #include <linux/tracepoint.h>
55 #include <linux/ftrace.h>
56 #include <linux/async.h>
57 #include <linux/percpu.h>
58 #include <linux/kmemleak.h>
59 #include <linux/jump_label.h>
60 #include <linux/pfn.h>
61 #include <linux/bsearch.h>
63 #define CREATE_TRACE_POINTS
64 #include <trace/events/module.h>
66 #ifndef ARCH_SHF_SMALL
67 #define ARCH_SHF_SMALL 0
71 * Modules' sections will be aligned on page boundaries
72 * to ensure complete separation of code and data, but
73 * only when CONFIG_DEBUG_SET_MODULE_RONX=y
75 #ifdef CONFIG_DEBUG_SET_MODULE_RONX
76 # define debug_align(X) ALIGN(X, PAGE_SIZE)
78 # define debug_align(X) (X)
82 * Given BASE and SIZE this macro calculates the number of pages the
83 * memory regions occupies
85 #define MOD_NUMBER_OF_PAGES(BASE, SIZE) (((SIZE) > 0) ? \
86 (PFN_DOWN((unsigned long)(BASE) + (SIZE) - 1) - \
87 PFN_DOWN((unsigned long)BASE) + 1) \
90 /* If this is set, the section belongs in the init part of the module */
91 #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
93 #ifdef CONFIG_ENTERPRISE_SUPPORT
94 /* Allow unsupported modules switch. */
95 #ifdef UNSUPPORTED_MODULES
96 int unsupported = UNSUPPORTED_MODULES;
98 int unsupported = 2; /* don't warn when loading unsupported modules. */
101 static int __init unsupported_setup(char *str)
103 get_option(&str, &unsupported);
106 __setup("unsupported=", unsupported_setup);
111 * 1) List of modules (also safely readable with preempt_disable),
112 * 2) module_use links,
113 * 3) module_addr_min/module_addr_max.
114 * (delete uses stop_machine/add uses RCU list operations). */
115 DEFINE_MUTEX(module_mutex);
116 EXPORT_SYMBOL_GPL(module_mutex);
117 static LIST_HEAD(modules);
118 #ifdef CONFIG_KGDB_KDB
119 struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */
120 #endif /* CONFIG_KGDB_KDB */
123 /* Block module loading/unloading? */
124 int modules_disabled = 0;
126 /* Waiting for a module to finish initializing? */
127 static DECLARE_WAIT_QUEUE_HEAD(module_wq);
129 static BLOCKING_NOTIFIER_HEAD(module_notify_list);
131 /* Bounds of module allocation, for speeding __module_address.
132 * Protected by module_mutex. */
133 static unsigned long module_addr_min = -1UL, module_addr_max = 0;
135 int register_module_notifier(struct notifier_block * nb)
137 return blocking_notifier_chain_register(&module_notify_list, nb);
139 EXPORT_SYMBOL(register_module_notifier);
141 int unregister_module_notifier(struct notifier_block * nb)
143 return blocking_notifier_chain_unregister(&module_notify_list, nb);
145 EXPORT_SYMBOL(unregister_module_notifier);
151 char *secstrings, *strtab;
152 unsigned long symoffs, stroffs;
153 struct _ddebug *debug;
154 unsigned int num_debug;
156 unsigned int sym, str, mod, vers, info, pcpu, unwind;
160 /* We require a truly strong try_module_get(): 0 means failure due to
161 ongoing or failed initialization etc. */
162 static inline int strong_try_module_get(struct module *mod)
164 if (mod && mod->state == MODULE_STATE_COMING)
166 if (try_module_get(mod))
172 static inline void add_taint_module(struct module *mod, unsigned flag)
175 mod->taints |= (1U << flag);
179 * A thread that wants to hold a reference to a module only while it
180 * is running can call this to safely exit. nfsd and lockd use this.
182 void __module_put_and_exit(struct module *mod, long code)
187 EXPORT_SYMBOL(__module_put_and_exit);
189 /* Find a module section: 0 means not found. */
190 static unsigned int find_sec(const struct load_info *info, const char *name)
194 for (i = 1; i < info->hdr->e_shnum; i++) {
195 Elf_Shdr *shdr = &info->sechdrs[i];
196 /* Alloc bit cleared means "ignore it." */
197 if ((shdr->sh_flags & SHF_ALLOC)
198 && strcmp(info->secstrings + shdr->sh_name, name) == 0)
204 /* Find a module section, or NULL. */
205 static void *section_addr(const struct load_info *info, const char *name)
207 /* Section 0 has sh_addr 0. */
208 return (void *)info->sechdrs[find_sec(info, name)].sh_addr;
211 /* Find a module section, or NULL. Fill in number of "objects" in section. */
212 static void *section_objs(const struct load_info *info,
217 unsigned int sec = find_sec(info, name);
219 /* Section 0 has sh_addr 0 and sh_size 0. */
220 *num = info->sechdrs[sec].sh_size / object_size;
221 return (void *)info->sechdrs[sec].sh_addr;
224 /* Provided by the linker */
225 extern const struct kernel_symbol __start___ksymtab[];
226 extern const struct kernel_symbol __stop___ksymtab[];
227 extern const struct kernel_symbol __start___ksymtab_gpl[];
228 extern const struct kernel_symbol __stop___ksymtab_gpl[];
229 extern const struct kernel_symbol __start___ksymtab_gpl_future[];
230 extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
231 extern const unsigned long __start___kcrctab[];
232 extern const unsigned long __start___kcrctab_gpl[];
233 extern const unsigned long __start___kcrctab_gpl_future[];
234 #ifdef CONFIG_UNUSED_SYMBOLS
235 extern const struct kernel_symbol __start___ksymtab_unused[];
236 extern const struct kernel_symbol __stop___ksymtab_unused[];
237 extern const struct kernel_symbol __start___ksymtab_unused_gpl[];
238 extern const struct kernel_symbol __stop___ksymtab_unused_gpl[];
239 extern const unsigned long __start___kcrctab_unused[];
240 extern const unsigned long __start___kcrctab_unused_gpl[];
243 #ifndef CONFIG_MODVERSIONS
244 #define symversion(base, idx) NULL
246 #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL)
249 static bool each_symbol_in_section(const struct symsearch *arr,
250 unsigned int arrsize,
251 struct module *owner,
252 bool (*fn)(const struct symsearch *syms,
253 struct module *owner,
259 for (j = 0; j < arrsize; j++) {
260 if (fn(&arr[j], owner, data))
267 /* Returns true as soon as fn returns true, otherwise false. */
268 bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
269 struct module *owner,
274 static const struct symsearch arr[] = {
275 { __start___ksymtab, __stop___ksymtab, __start___kcrctab,
276 NOT_GPL_ONLY, false },
277 { __start___ksymtab_gpl, __stop___ksymtab_gpl,
278 __start___kcrctab_gpl,
280 { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future,
281 __start___kcrctab_gpl_future,
282 WILL_BE_GPL_ONLY, false },
283 #ifdef CONFIG_UNUSED_SYMBOLS
284 { __start___ksymtab_unused, __stop___ksymtab_unused,
285 __start___kcrctab_unused,
286 NOT_GPL_ONLY, true },
287 { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl,
288 __start___kcrctab_unused_gpl,
293 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data))
296 list_for_each_entry_rcu(mod, &modules, list) {
297 struct symsearch arr[] = {
298 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
299 NOT_GPL_ONLY, false },
300 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
303 { mod->gpl_future_syms,
304 mod->gpl_future_syms + mod->num_gpl_future_syms,
305 mod->gpl_future_crcs,
306 WILL_BE_GPL_ONLY, false },
307 #ifdef CONFIG_UNUSED_SYMBOLS
309 mod->unused_syms + mod->num_unused_syms,
311 NOT_GPL_ONLY, true },
312 { mod->unused_gpl_syms,
313 mod->unused_gpl_syms + mod->num_unused_gpl_syms,
314 mod->unused_gpl_crcs,
319 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
324 EXPORT_SYMBOL_GPL(each_symbol_section);
326 struct find_symbol_arg {
333 struct module *owner;
334 const unsigned long *crc;
335 const struct kernel_symbol *sym;
338 static bool check_symbol(const struct symsearch *syms,
339 struct module *owner,
340 unsigned int symnum, void *data)
342 struct find_symbol_arg *fsa = data;
345 if (syms->licence == GPL_ONLY)
347 if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) {
348 printk(KERN_WARNING "Symbol %s is being used "
349 "by a non-GPL module, which will not "
350 "be allowed in the future\n", fsa->name);
351 printk(KERN_WARNING "Please see the file "
352 "Documentation/feature-removal-schedule.txt "
353 "in the kernel source tree for more details.\n");
357 #ifdef CONFIG_UNUSED_SYMBOLS
358 if (syms->unused && fsa->warn) {
359 printk(KERN_WARNING "Symbol %s is marked as UNUSED, "
360 "however this module is using it.\n", fsa->name);
362 "This symbol will go away in the future.\n");
364 "Please evalute if this is the right api to use and if "
365 "it really is, submit a report the linux kernel "
366 "mailinglist together with submitting your code for "
372 fsa->crc = symversion(syms->crcs, symnum);
373 fsa->sym = &syms->start[symnum];
377 static int cmp_name(const void *va, const void *vb)
380 const struct kernel_symbol *b;
382 return strcmp(a, b->name);
385 static bool find_symbol_in_section(const struct symsearch *syms,
386 struct module *owner,
389 struct find_symbol_arg *fsa = data;
390 struct kernel_symbol *sym;
392 sym = bsearch(fsa->name, syms->start, syms->stop - syms->start,
393 sizeof(struct kernel_symbol), cmp_name);
395 if (sym != NULL && check_symbol(syms, owner, sym - syms->start, data))
401 /* Find a symbol and return it, along with, (optional) crc and
402 * (optional) module which owns it. Needs preempt disabled or module_mutex. */
403 const struct kernel_symbol *find_symbol(const char *name,
404 struct module **owner,
405 const unsigned long **crc,
409 struct find_symbol_arg fsa;
415 if (each_symbol_section(find_symbol_in_section, &fsa)) {
423 pr_debug("Failed to find symbol %s\n", name);
426 EXPORT_SYMBOL_GPL(find_symbol);
428 /* Search for module by name: must hold module_mutex. */
429 struct module *find_module(const char *name)
433 list_for_each_entry(mod, &modules, list) {
434 if (strcmp(mod->name, name) == 0)
439 EXPORT_SYMBOL_GPL(find_module);
443 static inline void __percpu *mod_percpu(struct module *mod)
448 static int percpu_modalloc(struct module *mod,
449 unsigned long size, unsigned long align)
451 if (align > PAGE_SIZE) {
452 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
453 mod->name, align, PAGE_SIZE);
457 mod->percpu = __alloc_reserved_percpu(size, align);
460 "%s: Could not allocate %lu bytes percpu data\n",
464 mod->percpu_size = size;
468 static void percpu_modfree(struct module *mod)
470 free_percpu(mod->percpu);
473 static unsigned int find_pcpusec(struct load_info *info)
475 return find_sec(info, ".data..percpu");
478 static void percpu_modcopy(struct module *mod,
479 const void *from, unsigned long size)
483 for_each_possible_cpu(cpu)
484 memcpy(per_cpu_ptr(mod->percpu, cpu), from, size);
488 * is_module_percpu_address - test whether address is from module static percpu
489 * @addr: address to test
491 * Test whether @addr belongs to module static percpu area.
494 * %true if @addr is from module static percpu area
496 bool is_module_percpu_address(unsigned long addr)
503 list_for_each_entry_rcu(mod, &modules, list) {
504 if (!mod->percpu_size)
506 for_each_possible_cpu(cpu) {
507 void *start = per_cpu_ptr(mod->percpu, cpu);
509 if ((void *)addr >= start &&
510 (void *)addr < start + mod->percpu_size) {
521 #else /* ... !CONFIG_SMP */
523 static inline void __percpu *mod_percpu(struct module *mod)
527 static inline int percpu_modalloc(struct module *mod,
528 unsigned long size, unsigned long align)
532 static inline void percpu_modfree(struct module *mod)
535 static unsigned int find_pcpusec(struct load_info *info)
539 static inline void percpu_modcopy(struct module *mod,
540 const void *from, unsigned long size)
542 /* pcpusec should be 0, and size of that section should be 0. */
545 bool is_module_percpu_address(unsigned long addr)
550 #endif /* CONFIG_SMP */
552 static unsigned int find_unwind(struct load_info *info)
555 #ifdef ARCH_UNWIND_SECTION_NAME
556 section = find_sec(info, ARCH_UNWIND_SECTION_NAME);
558 info->sechdrs[section].sh_flags |= SHF_ALLOC;
563 static void add_unwind_table(struct module *mod, struct load_info *info)
565 int index = info->index.unwind;
567 /* Size of section 0 is 0, so this is ok if there is no unwind info. */
568 mod->unwind_info = unwind_add_table(mod,
569 (void *)info->sechdrs[index].sh_addr,
570 info->sechdrs[index].sh_size);
573 #define MODINFO_ATTR(field) \
574 static void setup_modinfo_##field(struct module *mod, const char *s) \
576 mod->field = kstrdup(s, GFP_KERNEL); \
578 static ssize_t show_modinfo_##field(struct module_attribute *mattr, \
579 struct module_kobject *mk, char *buffer) \
581 return sprintf(buffer, "%s\n", mk->mod->field); \
583 static int modinfo_##field##_exists(struct module *mod) \
585 return mod->field != NULL; \
587 static void free_modinfo_##field(struct module *mod) \
592 static struct module_attribute modinfo_##field = { \
593 .attr = { .name = __stringify(field), .mode = 0444 }, \
594 .show = show_modinfo_##field, \
595 .setup = setup_modinfo_##field, \
596 .test = modinfo_##field##_exists, \
597 .free = free_modinfo_##field, \
600 MODINFO_ATTR(version);
601 MODINFO_ATTR(srcversion);
603 static char last_unloaded_module[MODULE_NAME_LEN+1];
605 #ifdef CONFIG_MODULE_UNLOAD
607 EXPORT_TRACEPOINT_SYMBOL(module_get);
609 /* Init the unload section of the module. */
610 static int module_unload_init(struct module *mod)
612 mod->refptr = alloc_percpu(struct module_ref);
616 INIT_LIST_HEAD(&mod->source_list);
617 INIT_LIST_HEAD(&mod->target_list);
619 /* Hold reference count during initialization. */
620 __this_cpu_write(mod->refptr->incs, 1);
621 /* Backwards compatibility macros put refcount during init. */
622 mod->waiter = current;
627 /* Does a already use b? */
628 static int already_uses(struct module *a, struct module *b)
630 struct module_use *use;
632 list_for_each_entry(use, &b->source_list, source_list) {
633 if (use->source == a) {
634 pr_debug("%s uses %s!\n", a->name, b->name);
638 pr_debug("%s does not use %s!\n", a->name, b->name);
644 * - we add 'a' as a "source", 'b' as a "target" of module use
645 * - the module_use is added to the list of 'b' sources (so
646 * 'b' can walk the list to see who sourced them), and of 'a'
647 * targets (so 'a' can see what modules it targets).
649 static int add_module_usage(struct module *a, struct module *b)
651 struct module_use *use;
653 pr_debug("Allocating new usage for %s.\n", a->name);
654 use = kmalloc(sizeof(*use), GFP_ATOMIC);
656 printk(KERN_WARNING "%s: out of memory loading\n", a->name);
662 list_add(&use->source_list, &b->source_list);
663 list_add(&use->target_list, &a->target_list);
667 /* Module a uses b: caller needs module_mutex() */
668 int ref_module(struct module *a, struct module *b)
672 if (b == NULL || already_uses(a, b))
675 /* If module isn't available, we fail. */
676 err = strong_try_module_get(b);
680 err = add_module_usage(a, b);
687 EXPORT_SYMBOL_GPL(ref_module);
689 /* Clear the unload stuff of the module. */
690 static void module_unload_free(struct module *mod)
692 struct module_use *use, *tmp;
694 mutex_lock(&module_mutex);
695 list_for_each_entry_safe(use, tmp, &mod->target_list, target_list) {
696 struct module *i = use->target;
697 pr_debug("%s unusing %s\n", mod->name, i->name);
699 list_del(&use->source_list);
700 list_del(&use->target_list);
703 mutex_unlock(&module_mutex);
705 free_percpu(mod->refptr);
708 #ifdef CONFIG_MODULE_FORCE_UNLOAD
709 static inline int try_force_unload(unsigned int flags)
711 int ret = (flags & O_TRUNC);
713 add_taint(TAINT_FORCED_RMMOD);
717 static inline int try_force_unload(unsigned int flags)
721 #endif /* CONFIG_MODULE_FORCE_UNLOAD */
730 /* Whole machine is stopped with interrupts off when this runs. */
731 static int __try_stop_module(void *_sref)
733 struct stopref *sref = _sref;
735 /* If it's not unused, quit unless we're forcing. */
736 if (module_refcount(sref->mod) != 0) {
737 if (!(*sref->forced = try_force_unload(sref->flags)))
741 /* Mark it as dying. */
742 sref->mod->state = MODULE_STATE_GOING;
746 static int try_stop_module(struct module *mod, int flags, int *forced)
748 if (flags & O_NONBLOCK) {
749 struct stopref sref = { mod, flags, forced };
751 return stop_machine(__try_stop_module, &sref, NULL);
753 /* We don't need to stop the machine for this. */
754 mod->state = MODULE_STATE_GOING;
760 unsigned long module_refcount(struct module *mod)
762 unsigned long incs = 0, decs = 0;
765 for_each_possible_cpu(cpu)
766 decs += per_cpu_ptr(mod->refptr, cpu)->decs;
768 * ensure the incs are added up after the decs.
769 * module_put ensures incs are visible before decs with smp_wmb.
771 * This 2-count scheme avoids the situation where the refcount
772 * for CPU0 is read, then CPU0 increments the module refcount,
773 * then CPU1 drops that refcount, then the refcount for CPU1 is
774 * read. We would record a decrement but not its corresponding
775 * increment so we would see a low count (disaster).
777 * Rare situation? But module_refcount can be preempted, and we
778 * might be tallying up 4096+ CPUs. So it is not impossible.
781 for_each_possible_cpu(cpu)
782 incs += per_cpu_ptr(mod->refptr, cpu)->incs;
785 EXPORT_SYMBOL(module_refcount);
787 /* This exists whether we can unload or not */
788 static void free_module(struct module *mod);
790 static void wait_for_zero_refcount(struct module *mod)
792 /* Since we might sleep for some time, release the mutex first */
793 mutex_unlock(&module_mutex);
795 pr_debug("Looking at refcount...\n");
796 set_current_state(TASK_UNINTERRUPTIBLE);
797 if (module_refcount(mod) == 0)
801 current->state = TASK_RUNNING;
802 mutex_lock(&module_mutex);
805 SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
809 char name[MODULE_NAME_LEN];
812 if (!capable(CAP_SYS_MODULE) || modules_disabled)
815 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
817 name[MODULE_NAME_LEN-1] = '\0';
819 if (mutex_lock_interruptible(&module_mutex) != 0)
822 mod = find_module(name);
828 if (!list_empty(&mod->source_list)) {
829 /* Other modules depend on us: get rid of them first. */
834 /* Doing init or already dying? */
835 if (mod->state != MODULE_STATE_LIVE) {
836 /* FIXME: if (force), slam module count and wake up
838 pr_debug("%s already dying\n", mod->name);
843 /* If it has an init func, it must have an exit func to unload */
844 if (mod->init && !mod->exit) {
845 forced = try_force_unload(flags);
847 /* This module can't be removed */
853 /* Set this up before setting mod->state */
854 mod->waiter = current;
856 /* Stop the machine so refcounts can't move and disable module. */
857 ret = try_stop_module(mod, flags, &forced);
861 /* Never wait if forced. */
862 if (!forced && module_refcount(mod) != 0)
863 wait_for_zero_refcount(mod);
865 mutex_unlock(&module_mutex);
866 /* Final destruction now no one is using it. */
867 if (mod->exit != NULL)
869 blocking_notifier_call_chain(&module_notify_list,
870 MODULE_STATE_GOING, mod);
871 async_synchronize_full();
873 /* Store the name of the last unloaded module for diagnostic purposes */
874 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module));
879 mutex_unlock(&module_mutex);
883 static inline void print_unload_info(struct seq_file *m, struct module *mod)
885 struct module_use *use;
886 int printed_something = 0;
888 seq_printf(m, " %lu ", module_refcount(mod));
890 /* Always include a trailing , so userspace can differentiate
891 between this and the old multi-field proc format. */
892 list_for_each_entry(use, &mod->source_list, source_list) {
893 printed_something = 1;
894 seq_printf(m, "%s,", use->source->name);
897 if (mod->init != NULL && mod->exit == NULL) {
898 printed_something = 1;
899 seq_printf(m, "[permanent],");
902 if (!printed_something)
906 void __symbol_put(const char *symbol)
908 struct module *owner;
911 if (!find_symbol(symbol, &owner, NULL, true, false))
916 EXPORT_SYMBOL(__symbol_put);
918 /* Note this assumes addr is a function, which it currently always is. */
919 void symbol_put_addr(void *addr)
921 struct module *modaddr;
922 unsigned long a = (unsigned long)dereference_function_descriptor(addr);
924 if (core_kernel_text(a))
927 /* module_text_address is safe here: we're supposed to have reference
928 * to module from symbol_get, so it can't go away. */
929 modaddr = __module_text_address(a);
933 EXPORT_SYMBOL_GPL(symbol_put_addr);
935 static ssize_t show_refcnt(struct module_attribute *mattr,
936 struct module_kobject *mk, char *buffer)
938 return sprintf(buffer, "%lu\n", module_refcount(mk->mod));
941 static struct module_attribute modinfo_refcnt =
942 __ATTR(refcnt, 0444, show_refcnt, NULL);
944 void module_put(struct module *module)
948 smp_wmb(); /* see comment in module_refcount */
949 __this_cpu_inc(module->refptr->decs);
951 trace_module_put(module, _RET_IP_);
952 /* Maybe they're waiting for us to drop reference? */
953 if (unlikely(!module_is_live(module)))
954 wake_up_process(module->waiter);
958 EXPORT_SYMBOL(module_put);
960 #else /* !CONFIG_MODULE_UNLOAD */
961 static inline void print_unload_info(struct seq_file *m, struct module *mod)
963 /* We don't know the usage count, or what modules are using. */
964 seq_printf(m, " - -");
967 static inline void module_unload_free(struct module *mod)
971 int ref_module(struct module *a, struct module *b)
973 return strong_try_module_get(b);
975 EXPORT_SYMBOL_GPL(ref_module);
977 static inline int module_unload_init(struct module *mod)
981 #endif /* CONFIG_MODULE_UNLOAD */
983 static size_t module_flags_taint(struct module *mod, char *buf)
987 if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE))
989 if (mod->taints & (1 << TAINT_OOT_MODULE))
991 if (mod->taints & (1 << TAINT_FORCED_MODULE))
993 if (mod->taints & (1 << TAINT_CRAP))
995 #ifdef CONFIG_ENTERPRISE_SUPPORT
996 if (mod->taints & (1 << TAINT_NO_SUPPORT))
998 if (mod->taints & (1 << TAINT_EXTERNAL_SUPPORT))
1002 * TAINT_FORCED_RMMOD: could be added.
1003 * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
1009 static ssize_t show_initstate(struct module_attribute *mattr,
1010 struct module_kobject *mk, char *buffer)
1012 const char *state = "unknown";
1014 switch (mk->mod->state) {
1015 case MODULE_STATE_LIVE:
1018 case MODULE_STATE_COMING:
1021 case MODULE_STATE_GOING:
1025 return sprintf(buffer, "%s\n", state);
1028 static struct module_attribute modinfo_initstate =
1029 __ATTR(initstate, 0444, show_initstate, NULL);
1031 static ssize_t store_uevent(struct module_attribute *mattr,
1032 struct module_kobject *mk,
1033 const char *buffer, size_t count)
1035 enum kobject_action action;
1037 if (kobject_action_type(buffer, count, &action) == 0)
1038 kobject_uevent(&mk->kobj, action);
1042 struct module_attribute module_uevent =
1043 __ATTR(uevent, 0200, NULL, store_uevent);
1045 static ssize_t show_coresize(struct module_attribute *mattr,
1046 struct module_kobject *mk, char *buffer)
1048 return sprintf(buffer, "%u\n", mk->mod->core_size);
1051 static struct module_attribute modinfo_coresize =
1052 __ATTR(coresize, 0444, show_coresize, NULL);
1054 static ssize_t show_initsize(struct module_attribute *mattr,
1055 struct module_kobject *mk, char *buffer)
1057 return sprintf(buffer, "%u\n", mk->mod->init_size);
1060 static struct module_attribute modinfo_initsize =
1061 __ATTR(initsize, 0444, show_initsize, NULL);
1063 static ssize_t show_taint(struct module_attribute *mattr,
1064 struct module_kobject *mk, char *buffer)
1068 l = module_flags_taint(mk->mod, buffer);
1073 static struct module_attribute modinfo_taint =
1074 __ATTR(taint, 0444, show_taint, NULL);
1076 #ifdef CONFIG_ENTERPRISE_SUPPORT
1077 static void setup_modinfo_supported(struct module *mod, const char *s)
1080 mod->taints |= (1 << TAINT_NO_SUPPORT);
1084 if (strcmp(s, "external") == 0)
1085 mod->taints |= (1 << TAINT_EXTERNAL_SUPPORT);
1086 else if (strcmp(s, "yes"))
1087 mod->taints |= (1 << TAINT_NO_SUPPORT);
1090 static ssize_t show_modinfo_supported(struct module_attribute *mattr,
1091 struct module_kobject *mk, char *buffer)
1093 return sprintf(buffer, "%s\n", supported_printable(mk->mod->taints));
1096 static struct module_attribute modinfo_supported = {
1097 .attr = { .name = "supported", .mode = 0444 },
1098 .show = show_modinfo_supported,
1099 .setup = setup_modinfo_supported,
1103 static struct module_attribute *modinfo_attrs[] = {
1106 &modinfo_srcversion,
1111 #ifdef CONFIG_ENTERPRISE_SUPPORT
1114 #ifdef CONFIG_MODULE_UNLOAD
1120 static const char vermagic[] = VERMAGIC_STRING;
1122 static int try_to_force_load(struct module *mod, const char *reason)
1124 #ifdef CONFIG_MODULE_FORCE_LOAD
1125 if (!test_taint(TAINT_FORCED_MODULE))
1126 printk(KERN_WARNING "%s: %s: kernel tainted.\n",
1128 add_taint_module(mod, TAINT_FORCED_MODULE);
1135 #ifdef CONFIG_MODVERSIONS
1136 /* If the arch applies (non-zero) relocations to kernel kcrctab, unapply it. */
1137 static unsigned long maybe_relocated(unsigned long crc,
1138 const struct module *crc_owner)
1140 #ifdef ARCH_RELOCATES_KCRCTAB
1141 if (crc_owner == NULL)
1142 return crc - (unsigned long)reloc_start;
1147 static int check_version(Elf_Shdr *sechdrs,
1148 unsigned int versindex,
1149 const char *symname,
1151 const unsigned long *crc,
1152 const struct module *crc_owner)
1154 unsigned int i, num_versions;
1155 struct modversion_info *versions;
1157 /* Exporting module didn't supply crcs? OK, we're already tainted. */
1161 /* No versions at all? modprobe --force does this. */
1163 return try_to_force_load(mod, symname) == 0;
1165 versions = (void *) sechdrs[versindex].sh_addr;
1166 num_versions = sechdrs[versindex].sh_size
1167 / sizeof(struct modversion_info);
1169 for (i = 0; i < num_versions; i++) {
1170 if (strcmp(versions[i].name, symname) != 0)
1173 if (versions[i].crc == maybe_relocated(*crc, crc_owner))
1175 pr_debug("Found checksum %lX vs module %lX\n",
1176 maybe_relocated(*crc, crc_owner), versions[i].crc);
1180 printk(KERN_WARNING "%s: no symbol version for %s\n",
1181 mod->name, symname);
1185 printk("%s: disagrees about version of symbol %s\n",
1186 mod->name, symname);
1190 static inline int check_modstruct_version(Elf_Shdr *sechdrs,
1191 unsigned int versindex,
1194 const unsigned long *crc;
1196 /* Since this should be found in kernel (which can't be removed),
1197 * no locking is necessary. */
1198 if (!find_symbol(MODULE_SYMBOL_PREFIX "module_layout", NULL,
1201 return check_version(sechdrs, versindex, "module_layout", mod, crc,
1205 /* First part is kernel version, which we ignore if module has crcs. */
1206 static inline int same_magic(const char *amagic, const char *bmagic,
1210 amagic += strcspn(amagic, " ");
1211 bmagic += strcspn(bmagic, " ");
1213 return strcmp(amagic, bmagic) == 0;
1216 static inline int check_version(Elf_Shdr *sechdrs,
1217 unsigned int versindex,
1218 const char *symname,
1220 const unsigned long *crc,
1221 const struct module *crc_owner)
1226 static inline int check_modstruct_version(Elf_Shdr *sechdrs,
1227 unsigned int versindex,
1233 static inline int same_magic(const char *amagic, const char *bmagic,
1236 return strcmp(amagic, bmagic) == 0;
1238 #endif /* CONFIG_MODVERSIONS */
1240 /* Resolve a symbol for this module. I.e. if we find one, record usage. */
1241 static const struct kernel_symbol *resolve_symbol(struct module *mod,
1242 const struct load_info *info,
1246 struct module *owner;
1247 const struct kernel_symbol *sym;
1248 const unsigned long *crc;
1251 mutex_lock(&module_mutex);
1252 sym = find_symbol(name, &owner, &crc,
1253 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true);
1257 if (!check_version(info->sechdrs, info->index.vers, name, mod, crc,
1259 sym = ERR_PTR(-EINVAL);
1263 err = ref_module(mod, owner);
1270 /* We must make copy under the lock if we failed to get ref. */
1271 strncpy(ownername, module_name(owner), MODULE_NAME_LEN);
1273 mutex_unlock(&module_mutex);
1277 static const struct kernel_symbol *
1278 resolve_symbol_wait(struct module *mod,
1279 const struct load_info *info,
1282 const struct kernel_symbol *ksym;
1283 char owner[MODULE_NAME_LEN];
1285 if (wait_event_interruptible_timeout(module_wq,
1286 !IS_ERR(ksym = resolve_symbol(mod, info, name, owner))
1287 || PTR_ERR(ksym) != -EBUSY,
1289 printk(KERN_WARNING "%s: gave up waiting for init of module %s.\n",
1296 * /sys/module/foo/sections stuff
1297 * J. Corbet <corbet@lwn.net>
1301 #ifdef CONFIG_KALLSYMS
1302 static inline bool sect_empty(const Elf_Shdr *sect)
1304 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
1307 struct module_sect_attr
1309 struct module_attribute mattr;
1311 unsigned long address;
1314 struct module_sect_attrs
1316 struct attribute_group grp;
1317 unsigned int nsections;
1318 struct module_sect_attr attrs[0];
1321 static ssize_t module_sect_show(struct module_attribute *mattr,
1322 struct module_kobject *mk, char *buf)
1324 struct module_sect_attr *sattr =
1325 container_of(mattr, struct module_sect_attr, mattr);
1326 return sprintf(buf, "0x%pK\n", (void *)sattr->address);
1329 static void free_sect_attrs(struct module_sect_attrs *sect_attrs)
1331 unsigned int section;
1333 for (section = 0; section < sect_attrs->nsections; section++)
1334 kfree(sect_attrs->attrs[section].name);
1338 static void add_sect_attrs(struct module *mod, const struct load_info *info)
1340 unsigned int nloaded = 0, i, size[2];
1341 struct module_sect_attrs *sect_attrs;
1342 struct module_sect_attr *sattr;
1343 struct attribute **gattr;
1345 /* Count loaded sections and allocate structures */
1346 for (i = 0; i < info->hdr->e_shnum; i++)
1347 if (!sect_empty(&info->sechdrs[i]))
1349 size[0] = ALIGN(sizeof(*sect_attrs)
1350 + nloaded * sizeof(sect_attrs->attrs[0]),
1351 sizeof(sect_attrs->grp.attrs[0]));
1352 size[1] = (nloaded + 1) * sizeof(sect_attrs->grp.attrs[0]);
1353 sect_attrs = kzalloc(size[0] + size[1], GFP_KERNEL);
1354 if (sect_attrs == NULL)
1357 /* Setup section attributes. */
1358 sect_attrs->grp.name = "sections";
1359 sect_attrs->grp.attrs = (void *)sect_attrs + size[0];
1361 sect_attrs->nsections = 0;
1362 sattr = §_attrs->attrs[0];
1363 gattr = §_attrs->grp.attrs[0];
1364 for (i = 0; i < info->hdr->e_shnum; i++) {
1365 Elf_Shdr *sec = &info->sechdrs[i];
1366 if (sect_empty(sec))
1368 sattr->address = sec->sh_addr;
1369 sattr->name = kstrdup(info->secstrings + sec->sh_name,
1371 if (sattr->name == NULL)
1373 sect_attrs->nsections++;
1374 sysfs_attr_init(&sattr->mattr.attr);
1375 sattr->mattr.show = module_sect_show;
1376 sattr->mattr.store = NULL;
1377 sattr->mattr.attr.name = sattr->name;
1378 sattr->mattr.attr.mode = S_IRUGO;
1379 *(gattr++) = &(sattr++)->mattr.attr;
1383 if (sysfs_create_group(&mod->mkobj.kobj, §_attrs->grp))
1386 mod->sect_attrs = sect_attrs;
1389 free_sect_attrs(sect_attrs);
1392 static void remove_sect_attrs(struct module *mod)
1394 if (mod->sect_attrs) {
1395 sysfs_remove_group(&mod->mkobj.kobj,
1396 &mod->sect_attrs->grp);
1397 /* We are positive that no one is using any sect attrs
1398 * at this point. Deallocate immediately. */
1399 free_sect_attrs(mod->sect_attrs);
1400 mod->sect_attrs = NULL;
1405 * /sys/module/foo/notes/.section.name gives contents of SHT_NOTE sections.
1408 struct module_notes_attrs {
1409 struct kobject *dir;
1411 struct bin_attribute attrs[0];
1414 static ssize_t module_notes_read(struct file *filp, struct kobject *kobj,
1415 struct bin_attribute *bin_attr,
1416 char *buf, loff_t pos, size_t count)
1419 * The caller checked the pos and count against our size.
1421 memcpy(buf, bin_attr->private + pos, count);
1425 static void free_notes_attrs(struct module_notes_attrs *notes_attrs,
1428 if (notes_attrs->dir) {
1430 sysfs_remove_bin_file(notes_attrs->dir,
1431 ¬es_attrs->attrs[i]);
1432 kobject_put(notes_attrs->dir);
1437 static void add_notes_attrs(struct module *mod, const struct load_info *info)
1439 unsigned int notes, loaded, i;
1440 struct module_notes_attrs *notes_attrs;
1441 struct bin_attribute *nattr;
1443 /* failed to create section attributes, so can't create notes */
1444 if (!mod->sect_attrs)
1447 /* Count notes sections and allocate structures. */
1449 for (i = 0; i < info->hdr->e_shnum; i++)
1450 if (!sect_empty(&info->sechdrs[i]) &&
1451 (info->sechdrs[i].sh_type == SHT_NOTE))
1457 notes_attrs = kzalloc(sizeof(*notes_attrs)
1458 + notes * sizeof(notes_attrs->attrs[0]),
1460 if (notes_attrs == NULL)
1463 notes_attrs->notes = notes;
1464 nattr = ¬es_attrs->attrs[0];
1465 for (loaded = i = 0; i < info->hdr->e_shnum; ++i) {
1466 if (sect_empty(&info->sechdrs[i]))
1468 if (info->sechdrs[i].sh_type == SHT_NOTE) {
1469 sysfs_bin_attr_init(nattr);
1470 nattr->attr.name = mod->sect_attrs->attrs[loaded].name;
1471 nattr->attr.mode = S_IRUGO;
1472 nattr->size = info->sechdrs[i].sh_size;
1473 nattr->private = (void *) info->sechdrs[i].sh_addr;
1474 nattr->read = module_notes_read;
1480 notes_attrs->dir = kobject_create_and_add("notes", &mod->mkobj.kobj);
1481 if (!notes_attrs->dir)
1484 for (i = 0; i < notes; ++i)
1485 if (sysfs_create_bin_file(notes_attrs->dir,
1486 ¬es_attrs->attrs[i]))
1489 mod->notes_attrs = notes_attrs;
1493 free_notes_attrs(notes_attrs, i);
1496 static void remove_notes_attrs(struct module *mod)
1498 if (mod->notes_attrs)
1499 free_notes_attrs(mod->notes_attrs, mod->notes_attrs->notes);
1504 static inline void add_sect_attrs(struct module *mod,
1505 const struct load_info *info)
1509 static inline void remove_sect_attrs(struct module *mod)
1513 static inline void add_notes_attrs(struct module *mod,
1514 const struct load_info *info)
1518 static inline void remove_notes_attrs(struct module *mod)
1521 #endif /* CONFIG_KALLSYMS */
1523 static void add_usage_links(struct module *mod)
1525 #ifdef CONFIG_MODULE_UNLOAD
1526 struct module_use *use;
1529 mutex_lock(&module_mutex);
1530 list_for_each_entry(use, &mod->target_list, target_list) {
1531 nowarn = sysfs_create_link(use->target->holders_dir,
1532 &mod->mkobj.kobj, mod->name);
1534 mutex_unlock(&module_mutex);
1538 static void del_usage_links(struct module *mod)
1540 #ifdef CONFIG_MODULE_UNLOAD
1541 struct module_use *use;
1543 mutex_lock(&module_mutex);
1544 list_for_each_entry(use, &mod->target_list, target_list)
1545 sysfs_remove_link(use->target->holders_dir, mod->name);
1546 mutex_unlock(&module_mutex);
1550 static int module_add_modinfo_attrs(struct module *mod)
1552 struct module_attribute *attr;
1553 struct module_attribute *temp_attr;
1557 mod->modinfo_attrs = kzalloc((sizeof(struct module_attribute) *
1558 (ARRAY_SIZE(modinfo_attrs) + 1)),
1560 if (!mod->modinfo_attrs)
1563 temp_attr = mod->modinfo_attrs;
1564 for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) {
1566 (attr->test && attr->test(mod))) {
1567 memcpy(temp_attr, attr, sizeof(*temp_attr));
1568 sysfs_attr_init(&temp_attr->attr);
1569 error = sysfs_create_file(&mod->mkobj.kobj,&temp_attr->attr);
1576 static void module_remove_modinfo_attrs(struct module *mod)
1578 struct module_attribute *attr;
1581 for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) {
1582 /* pick a field to test for end of list */
1583 if (!attr->attr.name)
1585 sysfs_remove_file(&mod->mkobj.kobj,&attr->attr);
1589 kfree(mod->modinfo_attrs);
1592 static int mod_sysfs_init(struct module *mod)
1595 struct kobject *kobj;
1597 if (!module_sysfs_initialized) {
1598 printk(KERN_ERR "%s: module sysfs not initialized\n",
1604 kobj = kset_find_obj(module_kset, mod->name);
1606 printk(KERN_ERR "%s: module is already loaded\n", mod->name);
1612 mod->mkobj.mod = mod;
1614 memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj));
1615 mod->mkobj.kobj.kset = module_kset;
1616 err = kobject_init_and_add(&mod->mkobj.kobj, &module_ktype, NULL,
1619 kobject_put(&mod->mkobj.kobj);
1621 /* delay uevent until full sysfs population */
1626 static int mod_sysfs_setup(struct module *mod,
1627 const struct load_info *info,
1628 struct kernel_param *kparam,
1629 unsigned int num_params)
1633 err = mod_sysfs_init(mod);
1637 mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj);
1638 if (!mod->holders_dir) {
1643 err = module_param_sysfs_setup(mod, kparam, num_params);
1645 goto out_unreg_holders;
1647 err = module_add_modinfo_attrs(mod);
1649 goto out_unreg_param;
1651 add_usage_links(mod);
1652 add_sect_attrs(mod, info);
1653 add_notes_attrs(mod, info);
1655 #ifdef CONFIG_ENTERPRISE_SUPPORT
1656 /* We don't use add_taint() here because it also disables lockdep. */
1657 if (mod->taints & (1 << TAINT_EXTERNAL_SUPPORT))
1658 add_nonfatal_taint(TAINT_EXTERNAL_SUPPORT);
1659 else if (mod->taints == (1 << TAINT_NO_SUPPORT)) {
1660 if (unsupported == 0) {
1661 printk(KERN_WARNING "%s: module not supported by "
1662 "Novell, refusing to load. To override, echo "
1663 "1 > /proc/sys/kernel/unsupported\n", mod->name);
1665 goto out_remove_attrs;
1667 add_nonfatal_taint(TAINT_NO_SUPPORT);
1668 if (unsupported == 1) {
1669 printk(KERN_WARNING "%s: module is not supported by "
1670 "Novell. Novell Technical Services may decline "
1671 "your support request if it involves a kernel "
1672 "fault.\n", mod->name);
1677 kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD);
1681 remove_notes_attrs(mod);
1682 remove_sect_attrs(mod);
1683 del_usage_links(mod);
1684 module_remove_modinfo_attrs(mod);
1686 module_param_sysfs_remove(mod);
1688 kobject_put(mod->holders_dir);
1690 kobject_put(&mod->mkobj.kobj);
1695 static void mod_sysfs_fini(struct module *mod)
1697 remove_notes_attrs(mod);
1698 remove_sect_attrs(mod);
1699 kobject_put(&mod->mkobj.kobj);
1702 #else /* !CONFIG_SYSFS */
1704 static int mod_sysfs_setup(struct module *mod,
1705 const struct load_info *info,
1706 struct kernel_param *kparam,
1707 unsigned int num_params)
1712 static void mod_sysfs_fini(struct module *mod)
1716 static void module_remove_modinfo_attrs(struct module *mod)
1720 static void del_usage_links(struct module *mod)
1724 #endif /* CONFIG_SYSFS */
1726 static void mod_sysfs_teardown(struct module *mod)
1728 del_usage_links(mod);
1729 module_remove_modinfo_attrs(mod);
1730 module_param_sysfs_remove(mod);
1731 kobject_put(mod->mkobj.drivers_dir);
1732 kobject_put(mod->holders_dir);
1733 mod_sysfs_fini(mod);
1737 * unlink the module with the whole machine is stopped with interrupts off
1738 * - this defends against kallsyms not taking locks
1740 static int __unlink_module(void *_mod)
1742 struct module *mod = _mod;
1743 list_del(&mod->list);
1744 module_bug_cleanup(mod);
1748 #ifdef CONFIG_DEBUG_SET_MODULE_RONX
1750 * LKM RO/NX protection: protect module's text/ro-data
1751 * from modification and any data from execution.
1753 void set_page_attributes(void *start, void *end, int (*set)(unsigned long start, int num_pages))
1755 unsigned long begin_pfn = PFN_DOWN((unsigned long)start);
1756 unsigned long end_pfn = PFN_DOWN((unsigned long)end);
1758 if (end_pfn > begin_pfn)
1759 set(begin_pfn << PAGE_SHIFT, end_pfn - begin_pfn);
1762 static void set_section_ro_nx(void *base,
1763 unsigned long text_size,
1764 unsigned long ro_size,
1765 unsigned long total_size)
1767 /* begin and end PFNs of the current subsection */
1768 unsigned long begin_pfn;
1769 unsigned long end_pfn;
1772 * Set RO for module text and RO-data:
1773 * - Always protect first page.
1774 * - Do not protect last partial page.
1777 set_page_attributes(base, base + ro_size, set_memory_ro);
1780 * Set NX permissions for module data:
1781 * - Do not protect first partial page.
1782 * - Always protect last page.
1784 if (total_size > text_size) {
1785 begin_pfn = PFN_UP((unsigned long)base + text_size);
1786 end_pfn = PFN_UP((unsigned long)base + total_size);
1787 if (end_pfn > begin_pfn)
1788 set_memory_nx(begin_pfn << PAGE_SHIFT, end_pfn - begin_pfn);
1792 static void unset_module_core_ro_nx(struct module *mod)
1794 set_page_attributes(mod->module_core + mod->core_text_size,
1795 mod->module_core + mod->core_size,
1797 set_page_attributes(mod->module_core,
1798 mod->module_core + mod->core_ro_size,
1802 static void unset_module_init_ro_nx(struct module *mod)
1804 set_page_attributes(mod->module_init + mod->init_text_size,
1805 mod->module_init + mod->init_size,
1807 set_page_attributes(mod->module_init,
1808 mod->module_init + mod->init_ro_size,
1812 /* Iterate through all modules and set each module's text as RW */
1813 void set_all_modules_text_rw(void)
1817 mutex_lock(&module_mutex);
1818 list_for_each_entry_rcu(mod, &modules, list) {
1819 if ((mod->module_core) && (mod->core_text_size)) {
1820 set_page_attributes(mod->module_core,
1821 mod->module_core + mod->core_text_size,
1824 if ((mod->module_init) && (mod->init_text_size)) {
1825 set_page_attributes(mod->module_init,
1826 mod->module_init + mod->init_text_size,
1830 mutex_unlock(&module_mutex);
1833 /* Iterate through all modules and set each module's text as RO */
1834 void set_all_modules_text_ro(void)
1838 mutex_lock(&module_mutex);
1839 list_for_each_entry_rcu(mod, &modules, list) {
1840 if ((mod->module_core) && (mod->core_text_size)) {
1841 set_page_attributes(mod->module_core,
1842 mod->module_core + mod->core_text_size,
1845 if ((mod->module_init) && (mod->init_text_size)) {
1846 set_page_attributes(mod->module_init,
1847 mod->module_init + mod->init_text_size,
1851 mutex_unlock(&module_mutex);
1854 static inline void set_section_ro_nx(void *base, unsigned long text_size, unsigned long ro_size, unsigned long total_size) { }
1855 static void unset_module_core_ro_nx(struct module *mod) { }
1856 static void unset_module_init_ro_nx(struct module *mod) { }
1859 void __weak module_free(struct module *mod, void *module_region)
1861 vfree(module_region);
1864 void __weak module_arch_cleanup(struct module *mod)
1868 /* Free a module, remove from lists, etc. */
1869 static void free_module(struct module *mod)
1871 trace_module_free(mod);
1873 /* Delete from various lists */
1874 mutex_lock(&module_mutex);
1875 stop_machine(__unlink_module, mod, NULL);
1876 mutex_unlock(&module_mutex);
1877 mod_sysfs_teardown(mod);
1879 /* Remove dynamic debug info */
1880 ddebug_remove_module(mod->name);
1882 unwind_remove_table(mod->unwind_info, 0);
1884 /* Arch-specific cleanup. */
1885 module_arch_cleanup(mod);
1887 /* Module unload stuff */
1888 module_unload_free(mod);
1890 /* Free any allocated parameters. */
1891 destroy_params(mod->kp, mod->num_kp);
1893 /* This may be NULL, but that's OK */
1894 unset_module_init_ro_nx(mod);
1895 module_free(mod, mod->module_init);
1897 percpu_modfree(mod);
1899 /* Free lock-classes: */
1900 lockdep_free_key_range(mod->module_core, mod->core_size);
1902 /* Finally, free the core (containing the module structure) */
1903 unset_module_core_ro_nx(mod);
1904 module_free(mod, mod->module_core);
1907 update_protections(current->mm);
1911 void *__symbol_get(const char *symbol)
1913 struct module *owner;
1914 const struct kernel_symbol *sym;
1917 sym = find_symbol(symbol, &owner, NULL, true, true);
1918 if (sym && strong_try_module_get(owner))
1922 return sym ? (void *)sym->value : NULL;
1924 EXPORT_SYMBOL_GPL(__symbol_get);
1927 * Ensure that an exported symbol [global namespace] does not already exist
1928 * in the kernel or in some other module's exported symbol table.
1930 * You must hold the module_mutex.
1932 static int verify_export_symbols(struct module *mod)
1935 struct module *owner;
1936 const struct kernel_symbol *s;
1938 const struct kernel_symbol *sym;
1941 { mod->syms, mod->num_syms },
1942 { mod->gpl_syms, mod->num_gpl_syms },
1943 { mod->gpl_future_syms, mod->num_gpl_future_syms },
1944 #ifdef CONFIG_UNUSED_SYMBOLS
1945 { mod->unused_syms, mod->num_unused_syms },
1946 { mod->unused_gpl_syms, mod->num_unused_gpl_syms },
1950 for (i = 0; i < ARRAY_SIZE(arr); i++) {
1951 for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) {
1952 if (find_symbol(s->name, &owner, NULL, true, false)) {
1954 "%s: exports duplicate symbol %s"
1956 mod->name, s->name, module_name(owner));
1964 /* Change all symbols so that st_value encodes the pointer directly. */
1965 static int simplify_symbols(struct module *mod, const struct load_info *info)
1967 Elf_Shdr *symsec = &info->sechdrs[info->index.sym];
1968 Elf_Sym *sym = (void *)symsec->sh_addr;
1969 unsigned long secbase;
1972 const struct kernel_symbol *ksym;
1974 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
1975 const char *name = info->strtab + sym[i].st_name;
1977 switch (sym[i].st_shndx) {
1979 /* We compiled with -fno-common. These are not
1980 supposed to happen. */
1981 pr_debug("Common symbol: %s\n", name);
1982 printk("%s: please compile with -fno-common\n",
1988 /* Don't need to do anything */
1989 pr_debug("Absolute symbol: 0x%08lx\n",
1990 (long)sym[i].st_value);
1994 ksym = resolve_symbol_wait(mod, info, name);
1995 /* Ok if resolved. */
1996 if (ksym && !IS_ERR(ksym)) {
1997 sym[i].st_value = ksym->value;
2002 if (!ksym && ELF_ST_BIND(sym[i].st_info) == STB_WEAK)
2005 printk(KERN_WARNING "%s: Unknown symbol %s (err %li)\n",
2006 mod->name, name, PTR_ERR(ksym));
2007 ret = PTR_ERR(ksym) ?: -ENOENT;
2011 /* Divert to percpu allocation if a percpu var. */
2012 if (sym[i].st_shndx == info->index.pcpu)
2013 secbase = (unsigned long)mod_percpu(mod);
2015 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
2016 sym[i].st_value += secbase;
2024 int __weak apply_relocate(Elf_Shdr *sechdrs,
2026 unsigned int symindex,
2027 unsigned int relsec,
2030 pr_err("module %s: REL relocation unsupported\n", me->name);
2034 int __weak apply_relocate_add(Elf_Shdr *sechdrs,
2036 unsigned int symindex,
2037 unsigned int relsec,
2040 pr_err("module %s: RELA relocation unsupported\n", me->name);
2044 static int apply_relocations(struct module *mod, const struct load_info *info)
2049 /* Now do relocations. */
2050 for (i = 1; i < info->hdr->e_shnum; i++) {
2051 unsigned int infosec = info->sechdrs[i].sh_info;
2053 /* Not a valid relocation section? */
2054 if (infosec >= info->hdr->e_shnum)
2057 /* Don't bother with non-allocated sections */
2058 if (!(info->sechdrs[infosec].sh_flags & SHF_ALLOC))
2061 if (info->sechdrs[i].sh_type == SHT_REL)
2062 err = apply_relocate(info->sechdrs, info->strtab,
2063 info->index.sym, i, mod);
2064 else if (info->sechdrs[i].sh_type == SHT_RELA)
2065 err = apply_relocate_add(info->sechdrs, info->strtab,
2066 info->index.sym, i, mod);
2073 /* Additional bytes needed by arch in front of individual sections */
2074 unsigned int __weak arch_mod_section_prepend(struct module *mod,
2075 unsigned int section)
2077 /* default implementation just returns zero */
2081 /* Update size with this section: return offset. */
2082 static long get_offset(struct module *mod, unsigned int *size,
2083 Elf_Shdr *sechdr, unsigned int section)
2087 *size += arch_mod_section_prepend(mod, section);
2088 ret = ALIGN(*size, sechdr->sh_addralign ?: 1);
2089 *size = ret + sechdr->sh_size;
2093 /* Lay out the SHF_ALLOC sections in a way not dissimilar to how ld
2094 might -- code, read-only data, read-write data, small data. Tally
2095 sizes, and place the offsets into sh_entsize fields: high bit means it
2097 static void layout_sections(struct module *mod, struct load_info *info)
2099 static unsigned long const masks[][2] = {
2100 /* NOTE: all executable code must be the first section
2101 * in this array; otherwise modify the text_size
2102 * finder in the two loops below */
2103 { SHF_EXECINSTR | SHF_ALLOC, ARCH_SHF_SMALL },
2104 { SHF_ALLOC, SHF_WRITE | ARCH_SHF_SMALL },
2105 { SHF_WRITE | SHF_ALLOC, ARCH_SHF_SMALL },
2106 { ARCH_SHF_SMALL | SHF_ALLOC, 0 }
2110 for (i = 0; i < info->hdr->e_shnum; i++)
2111 info->sechdrs[i].sh_entsize = ~0UL;
2113 pr_debug("Core section allocation order:\n");
2114 for (m = 0; m < ARRAY_SIZE(masks); ++m) {
2115 for (i = 0; i < info->hdr->e_shnum; ++i) {
2116 Elf_Shdr *s = &info->sechdrs[i];
2117 const char *sname = info->secstrings + s->sh_name;
2119 if ((s->sh_flags & masks[m][0]) != masks[m][0]
2120 || (s->sh_flags & masks[m][1])
2121 || s->sh_entsize != ~0UL
2122 || strstarts(sname, ".init"))
2124 s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
2125 pr_debug("\t%s\n", sname);
2128 case 0: /* executable */
2129 mod->core_size = debug_align(mod->core_size);
2130 mod->core_text_size = mod->core_size;
2132 case 1: /* RO: text and ro-data */
2133 mod->core_size = debug_align(mod->core_size);
2134 mod->core_ro_size = mod->core_size;
2136 case 3: /* whole core */
2137 mod->core_size = debug_align(mod->core_size);
2142 pr_debug("Init section allocation order:\n");
2143 for (m = 0; m < ARRAY_SIZE(masks); ++m) {
2144 for (i = 0; i < info->hdr->e_shnum; ++i) {
2145 Elf_Shdr *s = &info->sechdrs[i];
2146 const char *sname = info->secstrings + s->sh_name;
2148 if ((s->sh_flags & masks[m][0]) != masks[m][0]
2149 || (s->sh_flags & masks[m][1])
2150 || s->sh_entsize != ~0UL
2151 || !strstarts(sname, ".init"))
2153 s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
2154 | INIT_OFFSET_MASK);
2155 pr_debug("\t%s\n", sname);
2158 case 0: /* executable */
2159 mod->init_size = debug_align(mod->init_size);
2160 mod->init_text_size = mod->init_size;
2162 case 1: /* RO: text and ro-data */
2163 mod->init_size = debug_align(mod->init_size);
2164 mod->init_ro_size = mod->init_size;
2166 case 3: /* whole init */
2167 mod->init_size = debug_align(mod->init_size);
2173 static void set_license(struct module *mod, const char *license)
2176 license = "unspecified";
2178 if (!license_is_gpl_compatible(license)) {
2179 if (!test_taint(TAINT_PROPRIETARY_MODULE))
2180 printk(KERN_WARNING "%s: module license '%s' taints "
2181 "kernel.\n", mod->name, license);
2182 add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
2186 /* Parse tag=value strings from .modinfo section */
2187 static char *next_string(char *string, unsigned long *secsize)
2189 /* Skip non-zero chars */
2192 if ((*secsize)-- <= 1)
2196 /* Skip any zero padding. */
2197 while (!string[0]) {
2199 if ((*secsize)-- <= 1)
2205 static char *get_modinfo(struct load_info *info, const char *tag)
2208 unsigned int taglen = strlen(tag);
2209 Elf_Shdr *infosec = &info->sechdrs[info->index.info];
2210 unsigned long size = infosec->sh_size;
2212 for (p = (char *)infosec->sh_addr; p; p = next_string(p, &size)) {
2213 if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=')
2214 return p + taglen + 1;
2219 static void setup_modinfo(struct module *mod, struct load_info *info)
2221 struct module_attribute *attr;
2224 for (i = 0; (attr = modinfo_attrs[i]); i++) {
2226 attr->setup(mod, get_modinfo(info, attr->attr.name));
2230 static void free_modinfo(struct module *mod)
2232 struct module_attribute *attr;
2235 for (i = 0; (attr = modinfo_attrs[i]); i++) {
2241 #ifdef CONFIG_KALLSYMS
2243 /* lookup symbol in given range of kernel_symbols */
2244 static const struct kernel_symbol *lookup_symbol(const char *name,
2245 const struct kernel_symbol *start,
2246 const struct kernel_symbol *stop)
2248 return bsearch(name, start, stop - start,
2249 sizeof(struct kernel_symbol), cmp_name);
2252 static int is_exported(const char *name, unsigned long value,
2253 const struct module *mod)
2255 const struct kernel_symbol *ks;
2257 ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab);
2259 ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms);
2260 return ks != NULL && ks->value == value;
2264 static char elf_type(const Elf_Sym *sym, const struct load_info *info)
2266 const Elf_Shdr *sechdrs = info->sechdrs;
2268 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
2269 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
2274 if (sym->st_shndx == SHN_UNDEF)
2276 if (sym->st_shndx == SHN_ABS)
2278 if (sym->st_shndx >= SHN_LORESERVE)
2280 if (sechdrs[sym->st_shndx].sh_flags & SHF_EXECINSTR)
2282 if (sechdrs[sym->st_shndx].sh_flags & SHF_ALLOC
2283 && sechdrs[sym->st_shndx].sh_type != SHT_NOBITS) {
2284 if (!(sechdrs[sym->st_shndx].sh_flags & SHF_WRITE))
2286 else if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL)
2291 if (sechdrs[sym->st_shndx].sh_type == SHT_NOBITS) {
2292 if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL)
2297 if (strstarts(info->secstrings + sechdrs[sym->st_shndx].sh_name,
2304 static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs,
2307 const Elf_Shdr *sec;
2309 if (src->st_shndx == SHN_UNDEF
2310 || src->st_shndx >= shnum
2314 sec = sechdrs + src->st_shndx;
2315 if (!(sec->sh_flags & SHF_ALLOC)
2316 #ifndef CONFIG_KALLSYMS_ALL
2317 || !(sec->sh_flags & SHF_EXECINSTR)
2319 || (sec->sh_entsize & INIT_OFFSET_MASK))
2326 * We only allocate and copy the strings needed by the parts of symtab
2327 * we keep. This is simple, but has the effect of making multiple
2328 * copies of duplicates. We could be more sophisticated, see
2329 * linux-kernel thread starting with
2330 * <73defb5e4bca04a6431392cc341112b1@localhost>.
2332 static void layout_symtab(struct module *mod, struct load_info *info)
2334 Elf_Shdr *symsect = info->sechdrs + info->index.sym;
2335 Elf_Shdr *strsect = info->sechdrs + info->index.str;
2337 unsigned int i, nsrc, ndst, strtab_size;
2339 /* Put symbol section at end of init part of module. */
2340 symsect->sh_flags |= SHF_ALLOC;
2341 symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
2342 info->index.sym) | INIT_OFFSET_MASK;
2343 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
2345 src = (void *)info->hdr + symsect->sh_offset;
2346 nsrc = symsect->sh_size / sizeof(*src);
2348 /* Compute total space required for the core symbols' strtab. */
2349 for (ndst = i = strtab_size = 1; i < nsrc; ++i, ++src)
2350 if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) {
2351 strtab_size += strlen(&info->strtab[src->st_name]) + 1;
2355 /* Append room for core symbols at end of core part. */
2356 info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
2357 info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
2358 mod->core_size += strtab_size;
2360 /* Put string table section at end of init part of module. */
2361 strsect->sh_flags |= SHF_ALLOC;
2362 strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
2363 info->index.str) | INIT_OFFSET_MASK;
2364 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
2367 static void add_kallsyms(struct module *mod, const struct load_info *info)
2369 unsigned int i, ndst;
2373 Elf_Shdr *symsec = &info->sechdrs[info->index.sym];
2375 mod->symtab = (void *)symsec->sh_addr;
2376 mod->num_symtab = symsec->sh_size / sizeof(Elf_Sym);
2377 /* Make sure we get permanent strtab: don't use info->strtab. */
2378 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
2380 /* Set types up while we still have access to sections. */
2381 for (i = 0; i < mod->num_symtab; i++)
2382 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
2384 mod->core_symtab = dst = mod->module_core + info->symoffs;
2385 mod->core_strtab = s = mod->module_core + info->stroffs;
2389 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
2390 if (!is_core_symbol(src, info->sechdrs, info->hdr->e_shnum))
2394 dst[ndst++].st_name = s - mod->core_strtab;
2395 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
2397 mod->core_num_syms = ndst;
2400 static inline void layout_symtab(struct module *mod, struct load_info *info)
2404 static void add_kallsyms(struct module *mod, const struct load_info *info)
2407 #endif /* CONFIG_KALLSYMS */
2409 static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)
2413 #ifdef CONFIG_DYNAMIC_DEBUG
2414 if (ddebug_add_module(debug, num, debug->modname))
2415 printk(KERN_ERR "dynamic debug error adding module: %s\n",
2420 static void dynamic_debug_remove(struct _ddebug *debug)
2423 ddebug_remove_module(debug->modname);
2426 void * __weak module_alloc(unsigned long size)
2428 return size == 0 ? NULL : vmalloc_exec(size);
2431 static void *module_alloc_update_bounds(unsigned long size)
2433 void *ret = module_alloc(size);
2436 mutex_lock(&module_mutex);
2437 /* Update module bounds. */
2438 if ((unsigned long)ret < module_addr_min)
2439 module_addr_min = (unsigned long)ret;
2440 if ((unsigned long)ret + size > module_addr_max)
2441 module_addr_max = (unsigned long)ret + size;
2442 mutex_unlock(&module_mutex);
2447 #ifdef CONFIG_DEBUG_KMEMLEAK
2448 static void kmemleak_load_module(const struct module *mod,
2449 const struct load_info *info)
2453 /* only scan the sections containing data */
2454 kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL);
2456 for (i = 1; i < info->hdr->e_shnum; i++) {
2457 const char *name = info->secstrings + info->sechdrs[i].sh_name;
2458 if (!(info->sechdrs[i].sh_flags & SHF_ALLOC))
2460 if (!strstarts(name, ".data") && !strstarts(name, ".bss"))
2463 kmemleak_scan_area((void *)info->sechdrs[i].sh_addr,
2464 info->sechdrs[i].sh_size, GFP_KERNEL);
2468 static inline void kmemleak_load_module(const struct module *mod,
2469 const struct load_info *info)
2474 /* Sets info->hdr and info->len. */
2475 static int copy_and_check(struct load_info *info,
2476 const void __user *umod, unsigned long len,
2477 const char __user *uargs)
2482 if (len < sizeof(*hdr))
2485 /* Suck in entire file: we'll want most of it. */
2486 /* vmalloc barfs on "unusual" numbers. Check here */
2487 if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL)
2490 if (copy_from_user(hdr, umod, len) != 0) {
2495 /* Sanity checks against insmoding binaries or wrong arch,
2496 weird elf version */
2497 if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0
2498 || hdr->e_type != ET_REL
2499 || !elf_check_arch(hdr)
2500 || hdr->e_shentsize != sizeof(Elf_Shdr)) {
2505 if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr)) {
2519 static void free_copy(struct load_info *info)
2524 static int rewrite_section_headers(struct load_info *info)
2528 /* This should always be true, but let's be sure. */
2529 info->sechdrs[0].sh_addr = 0;
2531 for (i = 1; i < info->hdr->e_shnum; i++) {
2532 Elf_Shdr *shdr = &info->sechdrs[i];
2533 if (shdr->sh_type != SHT_NOBITS
2534 && info->len < shdr->sh_offset + shdr->sh_size) {
2535 printk(KERN_ERR "Module len %lu truncated\n",
2540 /* Mark all sections sh_addr with their address in the
2542 shdr->sh_addr = (size_t)info->hdr + shdr->sh_offset;
2544 #ifndef CONFIG_MODULE_UNLOAD
2545 /* Don't load .exit sections */
2546 if (strstarts(info->secstrings+shdr->sh_name, ".exit"))
2547 shdr->sh_flags &= ~(unsigned long)SHF_ALLOC;
2551 /* Track but don't keep modinfo and version sections. */
2552 info->index.vers = find_sec(info, "__versions");
2553 info->index.info = find_sec(info, ".modinfo");
2554 info->sechdrs[info->index.info].sh_flags &= ~(unsigned long)SHF_ALLOC;
2555 info->sechdrs[info->index.vers].sh_flags &= ~(unsigned long)SHF_ALLOC;
2560 * Set up our basic convenience variables (pointers to section headers,
2561 * search for module section index etc), and do some basic section
2564 * Return the temporary module pointer (we'll replace it with the final
2565 * one when we move the module sections around).
2567 static struct module *setup_load_info(struct load_info *info)
2573 /* Set up the convenience variables */
2574 info->sechdrs = (void *)info->hdr + info->hdr->e_shoff;
2575 info->secstrings = (void *)info->hdr
2576 + info->sechdrs[info->hdr->e_shstrndx].sh_offset;
2578 err = rewrite_section_headers(info);
2580 return ERR_PTR(err);
2582 /* Find internal symbols and strings. */
2583 for (i = 1; i < info->hdr->e_shnum; i++) {
2584 if (info->sechdrs[i].sh_type == SHT_SYMTAB) {
2585 info->index.sym = i;
2586 info->index.str = info->sechdrs[i].sh_link;
2587 info->strtab = (char *)info->hdr
2588 + info->sechdrs[info->index.str].sh_offset;
2593 info->index.mod = find_sec(info, ".gnu.linkonce.this_module");
2594 if (!info->index.mod) {
2595 printk(KERN_WARNING "No module found in object\n");
2596 return ERR_PTR(-ENOEXEC);
2598 /* This is temporary: point mod into copy of data. */
2599 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
2601 if (info->index.sym == 0) {
2602 printk(KERN_WARNING "%s: module has no symbols (stripped?)\n",
2604 return ERR_PTR(-ENOEXEC);
2607 info->index.pcpu = find_pcpusec(info);
2609 info->index.unwind = find_unwind(info);
2611 /* Check module struct version now, before we try to use module. */
2612 if (!check_modstruct_version(info->sechdrs, info->index.vers, mod))
2613 return ERR_PTR(-ENOEXEC);
2618 static int check_modinfo(struct module *mod, struct load_info *info)
2620 const char *modmagic = get_modinfo(info, "vermagic");
2623 /* This is allowed: modprobe --force will invalidate it. */
2625 err = try_to_force_load(mod, "bad vermagic");
2628 } else if (!same_magic(modmagic, vermagic, info->index.vers)) {
2629 printk(KERN_ERR "%s: version magic '%s' should be '%s'\n",
2630 mod->name, modmagic, vermagic);
2634 if (!get_modinfo(info, "intree"))
2635 add_taint_module(mod, TAINT_OOT_MODULE);
2637 if (get_modinfo(info, "staging")) {
2638 add_taint_module(mod, TAINT_CRAP);
2639 printk(KERN_WARNING "%s: module is from the staging directory,"
2640 " the quality is unknown, you have been warned.\n",
2644 /* Set up license info based on the info section */
2645 set_license(mod, get_modinfo(info, "license"));
2650 static void find_module_sections(struct module *mod, struct load_info *info)
2652 mod->kp = section_objs(info, "__param",
2653 sizeof(*mod->kp), &mod->num_kp);
2654 mod->syms = section_objs(info, "__ksymtab",
2655 sizeof(*mod->syms), &mod->num_syms);
2656 mod->crcs = section_addr(info, "__kcrctab");
2657 mod->gpl_syms = section_objs(info, "__ksymtab_gpl",
2658 sizeof(*mod->gpl_syms),
2659 &mod->num_gpl_syms);
2660 mod->gpl_crcs = section_addr(info, "__kcrctab_gpl");
2661 mod->gpl_future_syms = section_objs(info,
2662 "__ksymtab_gpl_future",
2663 sizeof(*mod->gpl_future_syms),
2664 &mod->num_gpl_future_syms);
2665 mod->gpl_future_crcs = section_addr(info, "__kcrctab_gpl_future");
2667 #ifdef CONFIG_UNUSED_SYMBOLS
2668 mod->unused_syms = section_objs(info, "__ksymtab_unused",
2669 sizeof(*mod->unused_syms),
2670 &mod->num_unused_syms);
2671 mod->unused_crcs = section_addr(info, "__kcrctab_unused");
2672 mod->unused_gpl_syms = section_objs(info, "__ksymtab_unused_gpl",
2673 sizeof(*mod->unused_gpl_syms),
2674 &mod->num_unused_gpl_syms);
2675 mod->unused_gpl_crcs = section_addr(info, "__kcrctab_unused_gpl");
2677 #ifdef CONFIG_CONSTRUCTORS
2678 mod->ctors = section_objs(info, ".ctors",
2679 sizeof(*mod->ctors), &mod->num_ctors);
2682 #ifdef CONFIG_TRACEPOINTS
2683 mod->tracepoints_ptrs = section_objs(info, "__tracepoints_ptrs",
2684 sizeof(*mod->tracepoints_ptrs),
2685 &mod->num_tracepoints);
2687 #ifdef HAVE_JUMP_LABEL
2688 mod->jump_entries = section_objs(info, "__jump_table",
2689 sizeof(*mod->jump_entries),
2690 &mod->num_jump_entries);
2692 #ifdef CONFIG_EVENT_TRACING
2693 mod->trace_events = section_objs(info, "_ftrace_events",
2694 sizeof(*mod->trace_events),
2695 &mod->num_trace_events);
2697 * This section contains pointers to allocated objects in the trace
2698 * code and not scanning it leads to false positives.
2700 kmemleak_scan_area(mod->trace_events, sizeof(*mod->trace_events) *
2701 mod->num_trace_events, GFP_KERNEL);
2703 #ifdef CONFIG_TRACING
2704 mod->trace_bprintk_fmt_start = section_objs(info, "__trace_printk_fmt",
2705 sizeof(*mod->trace_bprintk_fmt_start),
2706 &mod->num_trace_bprintk_fmt);
2708 * This section contains pointers to allocated objects in the trace
2709 * code and not scanning it leads to false positives.
2711 kmemleak_scan_area(mod->trace_bprintk_fmt_start,
2712 sizeof(*mod->trace_bprintk_fmt_start) *
2713 mod->num_trace_bprintk_fmt, GFP_KERNEL);
2715 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
2716 /* sechdrs[0].sh_size is always zero */
2717 mod->ftrace_callsites = section_objs(info, "__mcount_loc",
2718 sizeof(*mod->ftrace_callsites),
2719 &mod->num_ftrace_callsites);
2722 mod->extable = section_objs(info, "__ex_table",
2723 sizeof(*mod->extable), &mod->num_exentries);
2725 if (section_addr(info, "__obsparm"))
2726 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
2729 info->debug = section_objs(info, "__verbose",
2730 sizeof(*info->debug), &info->num_debug);
2733 static int move_module(struct module *mod, struct load_info *info)
2738 /* Do the allocs. */
2739 ptr = module_alloc_update_bounds(mod->core_size);
2741 * The pointer to this block is stored in the module structure
2742 * which is inside the block. Just mark it as not being a
2745 kmemleak_not_leak(ptr);
2749 memset(ptr, 0, mod->core_size);
2750 mod->module_core = ptr;
2752 ptr = module_alloc_update_bounds(mod->init_size);
2754 * The pointer to this block is stored in the module structure
2755 * which is inside the block. This block doesn't need to be
2756 * scanned as it contains data and code that will be freed
2757 * after the module is initialized.
2759 kmemleak_ignore(ptr);
2760 if (!ptr && mod->init_size) {
2761 module_free(mod, mod->module_core);
2764 memset(ptr, 0, mod->init_size);
2765 mod->module_init = ptr;
2767 /* Transfer each section which specifies SHF_ALLOC */
2768 pr_debug("final section addresses:\n");
2769 for (i = 0; i < info->hdr->e_shnum; i++) {
2771 Elf_Shdr *shdr = &info->sechdrs[i];
2773 if (!(shdr->sh_flags & SHF_ALLOC))
2776 if (shdr->sh_entsize & INIT_OFFSET_MASK)
2777 dest = mod->module_init
2778 + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
2780 dest = mod->module_core + shdr->sh_entsize;
2782 if (shdr->sh_type != SHT_NOBITS)
2783 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
2784 /* Update sh_addr to point to copy in image. */
2785 shdr->sh_addr = (unsigned long)dest;
2786 pr_debug("\t0x%lx %s\n",
2787 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
2793 static int check_module_license_and_versions(struct module *mod)
2796 * ndiswrapper is under GPL by itself, but loads proprietary modules.
2797 * Don't use add_taint_module(), as it would prevent ndiswrapper from
2798 * using GPL-only symbols it needs.
2800 if (strcmp(mod->name, "ndiswrapper") == 0)
2801 add_taint(TAINT_PROPRIETARY_MODULE);
2803 /* driverloader was caught wrongly pretending to be under GPL */
2804 if (strcmp(mod->name, "driverloader") == 0)
2805 add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
2807 #ifdef CONFIG_MODVERSIONS
2808 if ((mod->num_syms && !mod->crcs)
2809 || (mod->num_gpl_syms && !mod->gpl_crcs)
2810 || (mod->num_gpl_future_syms && !mod->gpl_future_crcs)
2811 #ifdef CONFIG_UNUSED_SYMBOLS
2812 || (mod->num_unused_syms && !mod->unused_crcs)
2813 || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs)
2816 return try_to_force_load(mod,
2817 "no versions for exported symbols");
2823 static void flush_module_icache(const struct module *mod)
2825 mm_segment_t old_fs;
2827 /* flush the icache in correct context */
2832 * Flush the instruction cache, since we've played with text.
2833 * Do it before processing of module parameters, so the module
2834 * can provide parameter accessor functions of its own.
2836 if (mod->module_init)
2837 flush_icache_range((unsigned long)mod->module_init,
2838 (unsigned long)mod->module_init
2840 flush_icache_range((unsigned long)mod->module_core,
2841 (unsigned long)mod->module_core + mod->core_size);
2846 int __weak module_frob_arch_sections(Elf_Ehdr *hdr,
2854 static struct module *layout_and_allocate(struct load_info *info)
2856 /* Module within temporary copy. */
2861 mod = setup_load_info(info);
2865 err = check_modinfo(mod, info);
2867 return ERR_PTR(err);
2869 /* Allow arches to frob section contents and sizes. */
2870 err = module_frob_arch_sections(info->hdr, info->sechdrs,
2871 info->secstrings, mod);
2875 pcpusec = &info->sechdrs[info->index.pcpu];
2876 if (pcpusec->sh_size) {
2877 /* We have a special allocation for this section. */
2878 err = percpu_modalloc(mod,
2879 pcpusec->sh_size, pcpusec->sh_addralign);
2882 pcpusec->sh_flags &= ~(unsigned long)SHF_ALLOC;
2885 /* Determine total sizes, and put offsets in sh_entsize. For now
2886 this is done generically; there doesn't appear to be any
2887 special cases for the architectures. */
2888 layout_sections(mod, info);
2889 layout_symtab(mod, info);
2891 /* Allocate and move to the final place */
2892 err = move_module(mod, info);
2896 /* Module has been copied to its final place now: return it. */
2897 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
2898 kmemleak_load_module(mod, info);
2902 percpu_modfree(mod);
2904 return ERR_PTR(err);
2907 /* mod is no longer valid after this! */
2908 static void module_deallocate(struct module *mod, struct load_info *info)
2910 percpu_modfree(mod);
2911 module_free(mod, mod->module_init);
2912 module_free(mod, mod->module_core);
2915 int __weak module_finalize(const Elf_Ehdr *hdr,
2916 const Elf_Shdr *sechdrs,
2922 static int post_relocation(struct module *mod, const struct load_info *info)
2924 /* Sort exception table now relocations are done. */
2925 sort_extable(mod->extable, mod->extable + mod->num_exentries);
2927 /* Copy relocated percpu area over. */
2928 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
2929 info->sechdrs[info->index.pcpu].sh_size);
2931 /* Setup kallsyms-specific fields. */
2932 add_kallsyms(mod, info);
2934 /* Arch-specific module finalizing. */
2935 return module_finalize(info->hdr, info->sechdrs, mod);
2938 /* Allocate and load the module: note that size of section 0 is always
2939 zero, and we rely on this for optional sections. */
2940 static struct module *load_module(void __user *umod,
2942 const char __user *uargs)
2944 struct load_info info = { NULL, };
2948 pr_debug("load_module: umod=%p, len=%lu, uargs=%p\n",
2951 /* Copy in the blobs from userspace, check they are vaguely sane. */
2952 err = copy_and_check(&info, umod, len, uargs);
2954 return ERR_PTR(err);
2956 /* Figure out module layout, and allocate all the memory. */
2957 mod = layout_and_allocate(&info);
2963 /* Now module is in final location, initialize linked lists, etc. */
2964 err = module_unload_init(mod);
2968 /* Now we've got everything in the final locations, we can
2969 * find optional sections. */
2970 find_module_sections(mod, &info);
2972 err = check_module_license_and_versions(mod);
2976 /* Set up MODINFO_ATTR fields */
2977 setup_modinfo(mod, &info);
2979 /* Fix up syms, so that st_value is a pointer to location. */
2980 err = simplify_symbols(mod, &info);
2984 err = apply_relocations(mod, &info);
2988 err = post_relocation(mod, &info);
2992 flush_module_icache(mod);
2994 /* Now copy in args */
2995 mod->args = strndup_user(uargs, ~0UL >> 1);
2996 if (IS_ERR(mod->args)) {
2997 err = PTR_ERR(mod->args);
2998 goto free_arch_cleanup;
3001 /* Mark state as coming so strong_try_module_get() ignores us. */
3002 mod->state = MODULE_STATE_COMING;
3004 /* Now sew it into the lists so we can get lockdep and oops
3005 * info during argument parsing. No one should access us, since
3006 * strong_try_module_get() will fail.
3007 * lockdep/oops can run asynchronous, so use the RCU list insertion
3008 * function to insert in a way safe to concurrent readers.
3009 * The mutex protects against concurrent writers.
3011 mutex_lock(&module_mutex);
3012 if (find_module(mod->name)) {
3017 /* This has to be done once we're sure module name is unique. */
3018 dynamic_debug_setup(info.debug, info.num_debug);
3020 /* Find duplicate symbols */
3021 err = verify_export_symbols(mod);
3025 module_bug_finalize(info.hdr, info.sechdrs, mod);
3026 list_add_rcu(&mod->list, &modules);
3027 mutex_unlock(&module_mutex);
3029 /* Module is ready to execute: parsing args may do that. */
3030 err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL);
3034 /* Link in to syfs. */
3035 err = mod_sysfs_setup(mod, &info, mod->kp, mod->num_kp);
3039 /* Initialize unwind table */
3040 add_unwind_table(mod, &info);
3042 /* Get rid of temporary copy. */
3046 trace_module_load(mod);
3050 mutex_lock(&module_mutex);
3051 /* Unlink carefully: kallsyms could be walking list. */
3052 list_del_rcu(&mod->list);
3053 module_bug_cleanup(mod);
3056 dynamic_debug_remove(info.debug);
3058 mutex_unlock(&module_mutex);
3059 synchronize_sched();
3062 module_arch_cleanup(mod);
3066 module_unload_free(mod);
3068 module_deallocate(mod, &info);
3071 return ERR_PTR(err);
3074 /* Call module constructors. */
3075 static void do_mod_ctors(struct module *mod)
3077 #ifdef CONFIG_CONSTRUCTORS
3080 for (i = 0; i < mod->num_ctors; i++)
3085 /* This is where the real work happens */
3086 SYSCALL_DEFINE3(init_module, void __user *, umod,
3087 unsigned long, len, const char __user *, uargs)
3092 /* Must have permission */
3093 if (!capable(CAP_SYS_MODULE) || modules_disabled)
3096 /* Do all the hard work */
3097 mod = load_module(umod, len, uargs);
3099 return PTR_ERR(mod);
3101 blocking_notifier_call_chain(&module_notify_list,
3102 MODULE_STATE_COMING, mod);
3104 /* Set RO and NX regions for core */
3105 set_section_ro_nx(mod->module_core,
3106 mod->core_text_size,
3110 /* Set RO and NX regions for init */
3111 set_section_ro_nx(mod->module_init,
3112 mod->init_text_size,
3117 /* Start the module */
3118 if (mod->init != NULL)
3119 ret = do_one_initcall(mod->init);
3121 /* Init routine failed: abort. Try to protect us from
3122 buggy refcounters. */
3123 mod->state = MODULE_STATE_GOING;
3124 synchronize_sched();
3126 blocking_notifier_call_chain(&module_notify_list,
3127 MODULE_STATE_GOING, mod);
3129 wake_up(&module_wq);
3134 "%s: '%s'->init suspiciously returned %d, it should follow 0/-E convention\n"
3135 "%s: loading module anyway...\n",
3136 __func__, mod->name, ret,
3141 /* Now it's a first class citizen! Wake up anyone waiting for it. */
3142 mod->state = MODULE_STATE_LIVE;
3143 wake_up(&module_wq);
3144 blocking_notifier_call_chain(&module_notify_list,
3145 MODULE_STATE_LIVE, mod);
3147 /* We need to finish all async code before the module init sequence is done */
3148 async_synchronize_full();
3150 mutex_lock(&module_mutex);
3151 /* Drop initial reference. */
3153 trim_init_extable(mod);
3154 unwind_remove_table(mod->unwind_info, 1);
3155 #ifdef CONFIG_KALLSYMS
3156 mod->num_symtab = mod->core_num_syms;
3157 mod->symtab = mod->core_symtab;
3158 mod->strtab = mod->core_strtab;
3160 unset_module_init_ro_nx(mod);
3161 module_free(mod, mod->module_init);
3162 mod->module_init = NULL;
3164 mod->init_ro_size = 0;
3165 mod->init_text_size = 0;
3166 mutex_unlock(&module_mutex);
3171 static inline int within(unsigned long addr, void *start, unsigned long size)
3173 return ((void *)addr >= start && (void *)addr < start + size);
3176 #ifdef CONFIG_KALLSYMS
3178 * This ignores the intensely annoying "mapping symbols" found
3179 * in ARM ELF files: $a, $t and $d.
3181 static inline int is_arm_mapping_symbol(const char *str)
3183 return str[0] == '$' && strchr("atd", str[1])
3184 && (str[2] == '\0' || str[2] == '.');
3187 static const char *get_ksymbol(struct module *mod,
3189 unsigned long *size,
3190 unsigned long *offset)
3192 unsigned int i, best = 0;
3193 unsigned long nextval;
3195 /* At worse, next value is at end of module */
3196 if (within_module_init(addr, mod))
3197 nextval = (unsigned long)mod->module_init+mod->init_text_size;
3199 nextval = (unsigned long)mod->module_core+mod->core_text_size;
3201 /* Scan for closest preceding symbol, and next symbol. (ELF
3202 starts real symbols at 1). */
3203 for (i = 1; i < mod->num_symtab; i++) {
3204 if (mod->symtab[i].st_shndx == SHN_UNDEF)
3207 /* We ignore unnamed symbols: they're uninformative
3208 * and inserted at a whim. */
3209 if (mod->symtab[i].st_value <= addr
3210 && mod->symtab[i].st_value > mod->symtab[best].st_value
3211 && *(mod->strtab + mod->symtab[i].st_name) != '\0'
3212 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
3214 if (mod->symtab[i].st_value > addr
3215 && mod->symtab[i].st_value < nextval
3216 && *(mod->strtab + mod->symtab[i].st_name) != '\0'
3217 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
3218 nextval = mod->symtab[i].st_value;
3225 *size = nextval - mod->symtab[best].st_value;
3227 *offset = addr - mod->symtab[best].st_value;
3228 return mod->strtab + mod->symtab[best].st_name;
3231 /* For kallsyms to ask for address resolution. NULL means not found. Careful
3232 * not to lock to avoid deadlock on oopses, simply disable preemption. */
3233 const char *module_address_lookup(unsigned long addr,
3234 unsigned long *size,
3235 unsigned long *offset,
3240 const char *ret = NULL;
3243 list_for_each_entry_rcu(mod, &modules, list) {
3244 if (within_module_init(addr, mod) ||
3245 within_module_core(addr, mod)) {
3247 *modname = mod->name;
3248 ret = get_ksymbol(mod, addr, size, offset);
3252 /* Make a copy in here where it's safe */
3254 strncpy(namebuf, ret, KSYM_NAME_LEN - 1);
3261 int lookup_module_symbol_name(unsigned long addr, char *symname)
3266 list_for_each_entry_rcu(mod, &modules, list) {
3267 if (within_module_init(addr, mod) ||
3268 within_module_core(addr, mod)) {
3271 sym = get_ksymbol(mod, addr, NULL, NULL);
3274 strlcpy(symname, sym, KSYM_NAME_LEN);
3284 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,
3285 unsigned long *offset, char *modname, char *name)
3290 list_for_each_entry_rcu(mod, &modules, list) {
3291 if (within_module_init(addr, mod) ||
3292 within_module_core(addr, mod)) {
3295 sym = get_ksymbol(mod, addr, size, offset);
3299 strlcpy(modname, mod->name, MODULE_NAME_LEN);
3301 strlcpy(name, sym, KSYM_NAME_LEN);
3311 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
3312 char *name, char *module_name, int *exported)
3317 list_for_each_entry_rcu(mod, &modules, list) {
3318 if (symnum < mod->num_symtab) {
3319 *value = mod->symtab[symnum].st_value;
3320 *type = mod->symtab[symnum].st_info;
3321 strlcpy(name, mod->strtab + mod->symtab[symnum].st_name,
3323 strlcpy(module_name, mod->name, MODULE_NAME_LEN);
3324 *exported = is_exported(name, *value, mod);
3328 symnum -= mod->num_symtab;
3334 static unsigned long mod_find_symname(struct module *mod, const char *name)
3338 for (i = 0; i < mod->num_symtab; i++)
3339 if (strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0 &&
3340 mod->symtab[i].st_info != 'U')
3341 return mod->symtab[i].st_value;
3345 /* Look for this name: can be of form module:name. */
3346 unsigned long module_kallsyms_lookup_name(const char *name)
3350 unsigned long ret = 0;
3352 /* Don't lock: we're in enough trouble already. */
3354 if ((colon = strchr(name, ':')) != NULL) {
3356 if ((mod = find_module(name)) != NULL)
3357 ret = mod_find_symname(mod, colon+1);
3360 list_for_each_entry_rcu(mod, &modules, list)
3361 if ((ret = mod_find_symname(mod, name)) != 0)
3368 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
3369 struct module *, unsigned long),
3376 list_for_each_entry(mod, &modules, list) {
3377 for (i = 0; i < mod->num_symtab; i++) {
3378 ret = fn(data, mod->strtab + mod->symtab[i].st_name,
3379 mod, mod->symtab[i].st_value);
3386 #endif /* CONFIG_KALLSYMS */
3388 static char *module_flags(struct module *mod, char *buf)
3393 mod->state == MODULE_STATE_GOING ||
3394 mod->state == MODULE_STATE_COMING) {
3396 bx += module_flags_taint(mod, buf + bx);
3397 /* Show a - for module-is-being-unloaded */
3398 if (mod->state == MODULE_STATE_GOING)
3400 /* Show a + for module-is-being-loaded */
3401 if (mod->state == MODULE_STATE_COMING)
3410 #ifdef CONFIG_PROC_FS
3411 /* Called by the /proc file system to return a list of modules. */
3412 static void *m_start(struct seq_file *m, loff_t *pos)
3414 mutex_lock(&module_mutex);
3415 return seq_list_start(&modules, *pos);
3418 static void *m_next(struct seq_file *m, void *p, loff_t *pos)
3420 return seq_list_next(p, &modules, pos);
3423 static void m_stop(struct seq_file *m, void *p)
3425 mutex_unlock(&module_mutex);
3428 static int m_show(struct seq_file *m, void *p)
3430 struct module *mod = list_entry(p, struct module, list);
3433 seq_printf(m, "%s %u",
3434 mod->name, mod->init_size + mod->core_size);
3435 print_unload_info(m, mod);
3437 /* Informative for users. */
3438 seq_printf(m, " %s",
3439 mod->state == MODULE_STATE_GOING ? "Unloading":
3440 mod->state == MODULE_STATE_COMING ? "Loading":
3442 /* Used by oprofile and other similar tools. */
3443 seq_printf(m, " 0x%pK", mod->module_core);
3447 seq_printf(m, " %s", module_flags(mod, buf));
3449 seq_printf(m, "\n");
3453 /* Format: modulename size refcount deps address
3455 Where refcount is a number or -, and deps is a comma-separated list
3458 static const struct seq_operations modules_op = {
3465 static int modules_open(struct inode *inode, struct file *file)
3467 return seq_open(file, &modules_op);
3470 static const struct file_operations proc_modules_operations = {
3471 .open = modules_open,
3473 .llseek = seq_lseek,
3474 .release = seq_release,
3477 static int __init proc_modules_init(void)
3479 proc_create("modules", 0, NULL, &proc_modules_operations);
3482 module_init(proc_modules_init);
3485 /* Given an address, look for it in the module exception tables. */
3486 const struct exception_table_entry *search_module_extables(unsigned long addr)
3488 const struct exception_table_entry *e = NULL;
3492 list_for_each_entry_rcu(mod, &modules, list) {
3493 if (mod->num_exentries == 0)
3496 e = search_extable(mod->extable,
3497 mod->extable + mod->num_exentries - 1,
3504 /* Now, if we found one, we are running inside it now, hence
3505 we cannot unload the module, hence no refcnt needed. */
3510 * is_module_address - is this address inside a module?
3511 * @addr: the address to check.
3513 * See is_module_text_address() if you simply want to see if the address
3514 * is code (not data).
3516 bool is_module_address(unsigned long addr)
3521 ret = __module_address(addr) != NULL;
3528 * __module_address - get the module which contains an address.
3529 * @addr: the address.
3531 * Must be called with preempt disabled or module mutex held so that
3532 * module doesn't get freed during this.
3534 struct module *__module_address(unsigned long addr)
3538 if (addr < module_addr_min || addr > module_addr_max)
3541 list_for_each_entry_rcu(mod, &modules, list)
3542 if (within_module_core(addr, mod)
3543 || within_module_init(addr, mod))
3547 EXPORT_SYMBOL_GPL(__module_address);
3550 * is_module_text_address - is this address inside module code?
3551 * @addr: the address to check.
3553 * See is_module_address() if you simply want to see if the address is
3554 * anywhere in a module. See kernel_text_address() for testing if an
3555 * address corresponds to kernel or module code.
3557 bool is_module_text_address(unsigned long addr)
3562 ret = __module_text_address(addr) != NULL;
3569 * __module_text_address - get the module whose code contains an address.
3570 * @addr: the address.
3572 * Must be called with preempt disabled or module mutex held so that
3573 * module doesn't get freed during this.
3575 struct module *__module_text_address(unsigned long addr)
3577 struct module *mod = __module_address(addr);
3579 /* Make sure it's within the text section. */
3580 if (!within(addr, mod->module_init, mod->init_text_size)
3581 && !within(addr, mod->module_core, mod->core_text_size))
3586 EXPORT_SYMBOL_GPL(__module_text_address);
3588 /* Don't grab lock, we're oopsing. */
3589 void print_modules(void)
3594 printk(KERN_DEFAULT "Modules linked in:");
3595 /* Most callers should already have preempt disabled, but make sure */
3597 list_for_each_entry_rcu(mod, &modules, list)
3598 printk(" %s%s", mod->name, module_flags(mod, buf));
3600 if (last_unloaded_module[0])
3601 printk(" [last unloaded: %s]", last_unloaded_module);
3603 #ifdef CONFIG_ENTERPRISE_SUPPORT
3604 printk("Supported: %s\n", supported_printable(get_taint()));
3608 #ifdef CONFIG_MODVERSIONS
3609 /* Generate the signature for all relevant module structures here.
3610 * If these change, we don't want to try to parse the module. */
3611 void module_layout(struct module *mod,
3612 struct modversion_info *ver,
3613 struct kernel_param *kp,
3614 struct kernel_symbol *ks,
3615 struct tracepoint * const *tp)
3618 EXPORT_SYMBOL(module_layout);