diff options
Diffstat (limited to 'kernel/module.c')
-rw-r--r-- | kernel/module.c | 395 |
1 files changed, 245 insertions, 150 deletions
diff --git a/kernel/module.c b/kernel/module.c index 9db11911e04b..dd2a54155b54 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -20,11 +20,13 @@ | |||
20 | #include <linux/moduleloader.h> | 20 | #include <linux/moduleloader.h> |
21 | #include <linux/init.h> | 21 | #include <linux/init.h> |
22 | #include <linux/kallsyms.h> | 22 | #include <linux/kallsyms.h> |
23 | #include <linux/fs.h> | ||
23 | #include <linux/sysfs.h> | 24 | #include <linux/sysfs.h> |
24 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
25 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
26 | #include <linux/vmalloc.h> | 27 | #include <linux/vmalloc.h> |
27 | #include <linux/elf.h> | 28 | #include <linux/elf.h> |
29 | #include <linux/proc_fs.h> | ||
28 | #include <linux/seq_file.h> | 30 | #include <linux/seq_file.h> |
29 | #include <linux/syscalls.h> | 31 | #include <linux/syscalls.h> |
30 | #include <linux/fcntl.h> | 32 | #include <linux/fcntl.h> |
@@ -42,10 +44,13 @@ | |||
42 | #include <linux/string.h> | 44 | #include <linux/string.h> |
43 | #include <linux/mutex.h> | 45 | #include <linux/mutex.h> |
44 | #include <linux/unwind.h> | 46 | #include <linux/unwind.h> |
47 | #include <linux/rculist.h> | ||
45 | #include <asm/uaccess.h> | 48 | #include <asm/uaccess.h> |
46 | #include <asm/cacheflush.h> | 49 | #include <asm/cacheflush.h> |
47 | #include <linux/license.h> | 50 | #include <linux/license.h> |
48 | #include <asm/sections.h> | 51 | #include <asm/sections.h> |
52 | #include <linux/tracepoint.h> | ||
53 | #include <linux/ftrace.h> | ||
49 | 54 | ||
50 | #if 0 | 55 | #if 0 |
51 | #define DEBUGP printk | 56 | #define DEBUGP printk |
@@ -61,7 +66,7 @@ | |||
61 | #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) | 66 | #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) |
62 | 67 | ||
63 | /* List of modules, protected by module_mutex or preempt_disable | 68 | /* List of modules, protected by module_mutex or preempt_disable |
64 | * (add/delete uses stop_machine). */ | 69 | * (delete uses stop_machine/add uses RCU list operations). */ |
65 | static DEFINE_MUTEX(module_mutex); | 70 | static DEFINE_MUTEX(module_mutex); |
66 | static LIST_HEAD(modules); | 71 | static LIST_HEAD(modules); |
67 | 72 | ||
@@ -100,7 +105,7 @@ static inline int strong_try_module_get(struct module *mod) | |||
100 | static inline void add_taint_module(struct module *mod, unsigned flag) | 105 | static inline void add_taint_module(struct module *mod, unsigned flag) |
101 | { | 106 | { |
102 | add_taint(flag); | 107 | add_taint(flag); |
103 | mod->taints |= flag; | 108 | mod->taints |= (1U << flag); |
104 | } | 109 | } |
105 | 110 | ||
106 | /* | 111 | /* |
@@ -130,6 +135,29 @@ static unsigned int find_sec(Elf_Ehdr *hdr, | |||
130 | return 0; | 135 | return 0; |
131 | } | 136 | } |
132 | 137 | ||
138 | /* Find a module section, or NULL. */ | ||
139 | static void *section_addr(Elf_Ehdr *hdr, Elf_Shdr *shdrs, | ||
140 | const char *secstrings, const char *name) | ||
141 | { | ||
142 | /* Section 0 has sh_addr 0. */ | ||
143 | return (void *)shdrs[find_sec(hdr, shdrs, secstrings, name)].sh_addr; | ||
144 | } | ||
145 | |||
146 | /* Find a module section, or NULL. Fill in number of "objects" in section. */ | ||
147 | static void *section_objs(Elf_Ehdr *hdr, | ||
148 | Elf_Shdr *sechdrs, | ||
149 | const char *secstrings, | ||
150 | const char *name, | ||
151 | size_t object_size, | ||
152 | unsigned int *num) | ||
153 | { | ||
154 | unsigned int sec = find_sec(hdr, sechdrs, secstrings, name); | ||
155 | |||
156 | /* Section 0 has sh_addr 0 and sh_size 0. */ | ||
157 | *num = sechdrs[sec].sh_size / object_size; | ||
158 | return (void *)sechdrs[sec].sh_addr; | ||
159 | } | ||
160 | |||
133 | /* Provided by the linker */ | 161 | /* Provided by the linker */ |
134 | extern const struct kernel_symbol __start___ksymtab[]; | 162 | extern const struct kernel_symbol __start___ksymtab[]; |
135 | extern const struct kernel_symbol __stop___ksymtab[]; | 163 | extern const struct kernel_symbol __stop___ksymtab[]; |
@@ -216,7 +244,7 @@ static bool each_symbol(bool (*fn)(const struct symsearch *arr, | |||
216 | if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data)) | 244 | if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data)) |
217 | return true; | 245 | return true; |
218 | 246 | ||
219 | list_for_each_entry(mod, &modules, list) { | 247 | list_for_each_entry_rcu(mod, &modules, list) { |
220 | struct symsearch arr[] = { | 248 | struct symsearch arr[] = { |
221 | { mod->syms, mod->syms + mod->num_syms, mod->crcs, | 249 | { mod->syms, mod->syms + mod->num_syms, mod->crcs, |
222 | NOT_GPL_ONLY, false }, | 250 | NOT_GPL_ONLY, false }, |
@@ -784,6 +812,7 @@ sys_delete_module(const char __user *name_user, unsigned int flags) | |||
784 | mutex_lock(&module_mutex); | 812 | mutex_lock(&module_mutex); |
785 | /* Store the name of the last unloaded module for diagnostic purposes */ | 813 | /* Store the name of the last unloaded module for diagnostic purposes */ |
786 | strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); | 814 | strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); |
815 | unregister_dynamic_debug_module(mod->name); | ||
787 | free_module(mod); | 816 | free_module(mod); |
788 | 817 | ||
789 | out: | 818 | out: |
@@ -923,7 +952,7 @@ static const char vermagic[] = VERMAGIC_STRING; | |||
923 | static int try_to_force_load(struct module *mod, const char *symname) | 952 | static int try_to_force_load(struct module *mod, const char *symname) |
924 | { | 953 | { |
925 | #ifdef CONFIG_MODULE_FORCE_LOAD | 954 | #ifdef CONFIG_MODULE_FORCE_LOAD |
926 | if (!(tainted & TAINT_FORCED_MODULE)) | 955 | if (!test_taint(TAINT_FORCED_MODULE)) |
927 | printk("%s: no version for \"%s\" found: kernel tainted.\n", | 956 | printk("%s: no version for \"%s\" found: kernel tainted.\n", |
928 | mod->name, symname); | 957 | mod->name, symname); |
929 | add_taint_module(mod, TAINT_FORCED_MODULE); | 958 | add_taint_module(mod, TAINT_FORCED_MODULE); |
@@ -1033,7 +1062,7 @@ static unsigned long resolve_symbol(Elf_Shdr *sechdrs, | |||
1033 | const unsigned long *crc; | 1062 | const unsigned long *crc; |
1034 | 1063 | ||
1035 | ret = find_symbol(name, &owner, &crc, | 1064 | ret = find_symbol(name, &owner, &crc, |
1036 | !(mod->taints & TAINT_PROPRIETARY_MODULE), true); | 1065 | !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); |
1037 | if (!IS_ERR_VALUE(ret)) { | 1066 | if (!IS_ERR_VALUE(ret)) { |
1038 | /* use_module can fail due to OOM, | 1067 | /* use_module can fail due to OOM, |
1039 | or module initialization or unloading */ | 1068 | or module initialization or unloading */ |
@@ -1173,7 +1202,7 @@ static void free_notes_attrs(struct module_notes_attrs *notes_attrs, | |||
1173 | while (i-- > 0) | 1202 | while (i-- > 0) |
1174 | sysfs_remove_bin_file(notes_attrs->dir, | 1203 | sysfs_remove_bin_file(notes_attrs->dir, |
1175 | ¬es_attrs->attrs[i]); | 1204 | ¬es_attrs->attrs[i]); |
1176 | kobject_del(notes_attrs->dir); | 1205 | kobject_put(notes_attrs->dir); |
1177 | } | 1206 | } |
1178 | kfree(notes_attrs); | 1207 | kfree(notes_attrs); |
1179 | } | 1208 | } |
@@ -1391,17 +1420,6 @@ static void mod_kobject_remove(struct module *mod) | |||
1391 | } | 1420 | } |
1392 | 1421 | ||
1393 | /* | 1422 | /* |
1394 | * link the module with the whole machine is stopped with interrupts off | ||
1395 | * - this defends against kallsyms not taking locks | ||
1396 | */ | ||
1397 | static int __link_module(void *_mod) | ||
1398 | { | ||
1399 | struct module *mod = _mod; | ||
1400 | list_add(&mod->list, &modules); | ||
1401 | return 0; | ||
1402 | } | ||
1403 | |||
1404 | /* | ||
1405 | * unlink the module with the whole machine is stopped with interrupts off | 1423 | * unlink the module with the whole machine is stopped with interrupts off |
1406 | * - this defends against kallsyms not taking locks | 1424 | * - this defends against kallsyms not taking locks |
1407 | */ | 1425 | */ |
@@ -1429,6 +1447,9 @@ static void free_module(struct module *mod) | |||
1429 | /* Module unload stuff */ | 1447 | /* Module unload stuff */ |
1430 | module_unload_free(mod); | 1448 | module_unload_free(mod); |
1431 | 1449 | ||
1450 | /* release any pointers to mcount in this module */ | ||
1451 | ftrace_release(mod->module_core, mod->core_size); | ||
1452 | |||
1432 | /* This may be NULL, but that's OK */ | 1453 | /* This may be NULL, but that's OK */ |
1433 | module_free(mod, mod->module_init); | 1454 | module_free(mod, mod->module_init); |
1434 | kfree(mod->args); | 1455 | kfree(mod->args); |
@@ -1634,7 +1655,7 @@ static void set_license(struct module *mod, const char *license) | |||
1634 | license = "unspecified"; | 1655 | license = "unspecified"; |
1635 | 1656 | ||
1636 | if (!license_is_gpl_compatible(license)) { | 1657 | if (!license_is_gpl_compatible(license)) { |
1637 | if (!(tainted & TAINT_PROPRIETARY_MODULE)) | 1658 | if (!test_taint(TAINT_PROPRIETARY_MODULE)) |
1638 | printk(KERN_WARNING "%s: module license '%s' taints " | 1659 | printk(KERN_WARNING "%s: module license '%s' taints " |
1639 | "kernel.\n", mod->name, license); | 1660 | "kernel.\n", mod->name, license); |
1640 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); | 1661 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); |
@@ -1783,6 +1804,21 @@ static inline void add_kallsyms(struct module *mod, | |||
1783 | } | 1804 | } |
1784 | #endif /* CONFIG_KALLSYMS */ | 1805 | #endif /* CONFIG_KALLSYMS */ |
1785 | 1806 | ||
1807 | static void dynamic_printk_setup(struct mod_debug *debug, unsigned int num) | ||
1808 | { | ||
1809 | #ifdef CONFIG_DYNAMIC_PRINTK_DEBUG | ||
1810 | unsigned int i; | ||
1811 | |||
1812 | for (i = 0; i < num; i++) { | ||
1813 | register_dynamic_debug_module(debug[i].modname, | ||
1814 | debug[i].type, | ||
1815 | debug[i].logical_modname, | ||
1816 | debug[i].flag_names, | ||
1817 | debug[i].hash, debug[i].hash2); | ||
1818 | } | ||
1819 | #endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */ | ||
1820 | } | ||
1821 | |||
1786 | static void *module_alloc_update_bounds(unsigned long size) | 1822 | static void *module_alloc_update_bounds(unsigned long size) |
1787 | { | 1823 | { |
1788 | void *ret = module_alloc(size); | 1824 | void *ret = module_alloc(size); |
@@ -1806,35 +1842,18 @@ static noinline struct module *load_module(void __user *umod, | |||
1806 | Elf_Ehdr *hdr; | 1842 | Elf_Ehdr *hdr; |
1807 | Elf_Shdr *sechdrs; | 1843 | Elf_Shdr *sechdrs; |
1808 | char *secstrings, *args, *modmagic, *strtab = NULL; | 1844 | char *secstrings, *args, *modmagic, *strtab = NULL; |
1845 | char *staging; | ||
1809 | unsigned int i; | 1846 | unsigned int i; |
1810 | unsigned int symindex = 0; | 1847 | unsigned int symindex = 0; |
1811 | unsigned int strindex = 0; | 1848 | unsigned int strindex = 0; |
1812 | unsigned int setupindex; | 1849 | unsigned int modindex, versindex, infoindex, pcpuindex; |
1813 | unsigned int exindex; | ||
1814 | unsigned int exportindex; | ||
1815 | unsigned int modindex; | ||
1816 | unsigned int obsparmindex; | ||
1817 | unsigned int infoindex; | ||
1818 | unsigned int gplindex; | ||
1819 | unsigned int crcindex; | ||
1820 | unsigned int gplcrcindex; | ||
1821 | unsigned int versindex; | ||
1822 | unsigned int pcpuindex; | ||
1823 | unsigned int gplfutureindex; | ||
1824 | unsigned int gplfuturecrcindex; | ||
1825 | unsigned int unwindex = 0; | 1850 | unsigned int unwindex = 0; |
1826 | #ifdef CONFIG_UNUSED_SYMBOLS | 1851 | unsigned int num_kp, num_mcount; |
1827 | unsigned int unusedindex; | 1852 | struct kernel_param *kp; |
1828 | unsigned int unusedcrcindex; | ||
1829 | unsigned int unusedgplindex; | ||
1830 | unsigned int unusedgplcrcindex; | ||
1831 | #endif | ||
1832 | unsigned int markersindex; | ||
1833 | unsigned int markersstringsindex; | ||
1834 | struct module *mod; | 1853 | struct module *mod; |
1835 | long err = 0; | 1854 | long err = 0; |
1836 | void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ | 1855 | void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ |
1837 | struct exception_table_entry *extable; | 1856 | unsigned long *mseg; |
1838 | mm_segment_t old_fs; | 1857 | mm_segment_t old_fs; |
1839 | 1858 | ||
1840 | DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", | 1859 | DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", |
@@ -1898,6 +1917,7 @@ static noinline struct module *load_module(void __user *umod, | |||
1898 | err = -ENOEXEC; | 1917 | err = -ENOEXEC; |
1899 | goto free_hdr; | 1918 | goto free_hdr; |
1900 | } | 1919 | } |
1920 | /* This is temporary: point mod into copy of data. */ | ||
1901 | mod = (void *)sechdrs[modindex].sh_addr; | 1921 | mod = (void *)sechdrs[modindex].sh_addr; |
1902 | 1922 | ||
1903 | if (symindex == 0) { | 1923 | if (symindex == 0) { |
@@ -1907,22 +1927,6 @@ static noinline struct module *load_module(void __user *umod, | |||
1907 | goto free_hdr; | 1927 | goto free_hdr; |
1908 | } | 1928 | } |
1909 | 1929 | ||
1910 | /* Optional sections */ | ||
1911 | exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab"); | ||
1912 | gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl"); | ||
1913 | gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future"); | ||
1914 | crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab"); | ||
1915 | gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl"); | ||
1916 | gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future"); | ||
1917 | #ifdef CONFIG_UNUSED_SYMBOLS | ||
1918 | unusedindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused"); | ||
1919 | unusedgplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused_gpl"); | ||
1920 | unusedcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused"); | ||
1921 | unusedgplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused_gpl"); | ||
1922 | #endif | ||
1923 | setupindex = find_sec(hdr, sechdrs, secstrings, "__param"); | ||
1924 | exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table"); | ||
1925 | obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm"); | ||
1926 | versindex = find_sec(hdr, sechdrs, secstrings, "__versions"); | 1930 | versindex = find_sec(hdr, sechdrs, secstrings, "__versions"); |
1927 | infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo"); | 1931 | infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo"); |
1928 | pcpuindex = find_pcpusec(hdr, sechdrs, secstrings); | 1932 | pcpuindex = find_pcpusec(hdr, sechdrs, secstrings); |
@@ -1960,6 +1964,14 @@ static noinline struct module *load_module(void __user *umod, | |||
1960 | goto free_hdr; | 1964 | goto free_hdr; |
1961 | } | 1965 | } |
1962 | 1966 | ||
1967 | staging = get_modinfo(sechdrs, infoindex, "staging"); | ||
1968 | if (staging) { | ||
1969 | add_taint_module(mod, TAINT_CRAP); | ||
1970 | printk(KERN_WARNING "%s: module is from the staging directory," | ||
1971 | " the quality is unknown, you have been warned.\n", | ||
1972 | mod->name); | ||
1973 | } | ||
1974 | |||
1963 | /* Now copy in args */ | 1975 | /* Now copy in args */ |
1964 | args = strndup_user(uargs, ~0UL >> 1); | 1976 | args = strndup_user(uargs, ~0UL >> 1); |
1965 | if (IS_ERR(args)) { | 1977 | if (IS_ERR(args)) { |
@@ -2070,42 +2082,57 @@ static noinline struct module *load_module(void __user *umod, | |||
2070 | if (err < 0) | 2082 | if (err < 0) |
2071 | goto cleanup; | 2083 | goto cleanup; |
2072 | 2084 | ||
2073 | /* Set up EXPORTed & EXPORT_GPLed symbols (section 0 is 0 length) */ | 2085 | /* Now we've got everything in the final locations, we can |
2074 | mod->num_syms = sechdrs[exportindex].sh_size / sizeof(*mod->syms); | 2086 | * find optional sections. */ |
2075 | mod->syms = (void *)sechdrs[exportindex].sh_addr; | 2087 | kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp), |
2076 | if (crcindex) | 2088 | &num_kp); |
2077 | mod->crcs = (void *)sechdrs[crcindex].sh_addr; | 2089 | mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", |
2078 | mod->num_gpl_syms = sechdrs[gplindex].sh_size / sizeof(*mod->gpl_syms); | 2090 | sizeof(*mod->syms), &mod->num_syms); |
2079 | mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr; | 2091 | mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); |
2080 | if (gplcrcindex) | 2092 | mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl", |
2081 | mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; | 2093 | sizeof(*mod->gpl_syms), |
2082 | mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size / | 2094 | &mod->num_gpl_syms); |
2083 | sizeof(*mod->gpl_future_syms); | 2095 | mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl"); |
2084 | mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr; | 2096 | mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings, |
2085 | if (gplfuturecrcindex) | 2097 | "__ksymtab_gpl_future", |
2086 | mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr; | 2098 | sizeof(*mod->gpl_future_syms), |
2099 | &mod->num_gpl_future_syms); | ||
2100 | mod->gpl_future_crcs = section_addr(hdr, sechdrs, secstrings, | ||
2101 | "__kcrctab_gpl_future"); | ||
2087 | 2102 | ||
2088 | #ifdef CONFIG_UNUSED_SYMBOLS | 2103 | #ifdef CONFIG_UNUSED_SYMBOLS |
2089 | mod->num_unused_syms = sechdrs[unusedindex].sh_size / | 2104 | mod->unused_syms = section_objs(hdr, sechdrs, secstrings, |
2090 | sizeof(*mod->unused_syms); | 2105 | "__ksymtab_unused", |
2091 | mod->num_unused_gpl_syms = sechdrs[unusedgplindex].sh_size / | 2106 | sizeof(*mod->unused_syms), |
2092 | sizeof(*mod->unused_gpl_syms); | 2107 | &mod->num_unused_syms); |
2093 | mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr; | 2108 | mod->unused_crcs = section_addr(hdr, sechdrs, secstrings, |
2094 | if (unusedcrcindex) | 2109 | "__kcrctab_unused"); |
2095 | mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr; | 2110 | mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings, |
2096 | mod->unused_gpl_syms = (void *)sechdrs[unusedgplindex].sh_addr; | 2111 | "__ksymtab_unused_gpl", |
2097 | if (unusedgplcrcindex) | 2112 | sizeof(*mod->unused_gpl_syms), |
2098 | mod->unused_gpl_crcs | 2113 | &mod->num_unused_gpl_syms); |
2099 | = (void *)sechdrs[unusedgplcrcindex].sh_addr; | 2114 | mod->unused_gpl_crcs = section_addr(hdr, sechdrs, secstrings, |
2115 | "__kcrctab_unused_gpl"); | ||
2116 | #endif | ||
2117 | |||
2118 | #ifdef CONFIG_MARKERS | ||
2119 | mod->markers = section_objs(hdr, sechdrs, secstrings, "__markers", | ||
2120 | sizeof(*mod->markers), &mod->num_markers); | ||
2121 | #endif | ||
2122 | #ifdef CONFIG_TRACEPOINTS | ||
2123 | mod->tracepoints = section_objs(hdr, sechdrs, secstrings, | ||
2124 | "__tracepoints", | ||
2125 | sizeof(*mod->tracepoints), | ||
2126 | &mod->num_tracepoints); | ||
2100 | #endif | 2127 | #endif |
2101 | 2128 | ||
2102 | #ifdef CONFIG_MODVERSIONS | 2129 | #ifdef CONFIG_MODVERSIONS |
2103 | if ((mod->num_syms && !crcindex) | 2130 | if ((mod->num_syms && !mod->crcs) |
2104 | || (mod->num_gpl_syms && !gplcrcindex) | 2131 | || (mod->num_gpl_syms && !mod->gpl_crcs) |
2105 | || (mod->num_gpl_future_syms && !gplfuturecrcindex) | 2132 | || (mod->num_gpl_future_syms && !mod->gpl_future_crcs) |
2106 | #ifdef CONFIG_UNUSED_SYMBOLS | 2133 | #ifdef CONFIG_UNUSED_SYMBOLS |
2107 | || (mod->num_unused_syms && !unusedcrcindex) | 2134 | || (mod->num_unused_syms && !mod->unused_crcs) |
2108 | || (mod->num_unused_gpl_syms && !unusedgplcrcindex) | 2135 | || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) |
2109 | #endif | 2136 | #endif |
2110 | ) { | 2137 | ) { |
2111 | printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); | 2138 | printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); |
@@ -2114,9 +2141,6 @@ static noinline struct module *load_module(void __user *umod, | |||
2114 | goto cleanup; | 2141 | goto cleanup; |
2115 | } | 2142 | } |
2116 | #endif | 2143 | #endif |
2117 | markersindex = find_sec(hdr, sechdrs, secstrings, "__markers"); | ||
2118 | markersstringsindex = find_sec(hdr, sechdrs, secstrings, | ||
2119 | "__markers_strings"); | ||
2120 | 2144 | ||
2121 | /* Now do relocations. */ | 2145 | /* Now do relocations. */ |
2122 | for (i = 1; i < hdr->e_shnum; i++) { | 2146 | for (i = 1; i < hdr->e_shnum; i++) { |
@@ -2139,22 +2163,16 @@ static noinline struct module *load_module(void __user *umod, | |||
2139 | if (err < 0) | 2163 | if (err < 0) |
2140 | goto cleanup; | 2164 | goto cleanup; |
2141 | } | 2165 | } |
2142 | #ifdef CONFIG_MARKERS | ||
2143 | mod->markers = (void *)sechdrs[markersindex].sh_addr; | ||
2144 | mod->num_markers = | ||
2145 | sechdrs[markersindex].sh_size / sizeof(*mod->markers); | ||
2146 | #endif | ||
2147 | 2166 | ||
2148 | /* Find duplicate symbols */ | 2167 | /* Find duplicate symbols */ |
2149 | err = verify_export_symbols(mod); | 2168 | err = verify_export_symbols(mod); |
2150 | |||
2151 | if (err < 0) | 2169 | if (err < 0) |
2152 | goto cleanup; | 2170 | goto cleanup; |
2153 | 2171 | ||
2154 | /* Set up and sort exception table */ | 2172 | /* Set up and sort exception table */ |
2155 | mod->num_exentries = sechdrs[exindex].sh_size / sizeof(*mod->extable); | 2173 | mod->extable = section_objs(hdr, sechdrs, secstrings, "__ex_table", |
2156 | mod->extable = extable = (void *)sechdrs[exindex].sh_addr; | 2174 | sizeof(*mod->extable), &mod->num_exentries); |
2157 | sort_extable(extable, extable + mod->num_exentries); | 2175 | sort_extable(mod->extable, mod->extable + mod->num_exentries); |
2158 | 2176 | ||
2159 | /* Finally, copy percpu area over. */ | 2177 | /* Finally, copy percpu area over. */ |
2160 | percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr, | 2178 | percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr, |
@@ -2162,11 +2180,20 @@ static noinline struct module *load_module(void __user *umod, | |||
2162 | 2180 | ||
2163 | add_kallsyms(mod, sechdrs, symindex, strindex, secstrings); | 2181 | add_kallsyms(mod, sechdrs, symindex, strindex, secstrings); |
2164 | 2182 | ||
2165 | #ifdef CONFIG_MARKERS | 2183 | if (!mod->taints) { |
2166 | if (!mod->taints) | 2184 | struct mod_debug *debug; |
2167 | marker_update_probe_range(mod->markers, | 2185 | unsigned int num_debug; |
2168 | mod->markers + mod->num_markers); | 2186 | |
2169 | #endif | 2187 | debug = section_objs(hdr, sechdrs, secstrings, "__verbose", |
2188 | sizeof(*debug), &num_debug); | ||
2189 | dynamic_printk_setup(debug, num_debug); | ||
2190 | } | ||
2191 | |||
2192 | /* sechdrs[0].sh_size is always zero */ | ||
2193 | mseg = section_objs(hdr, sechdrs, secstrings, "__mcount_loc", | ||
2194 | sizeof(*mseg), &num_mcount); | ||
2195 | ftrace_init_module(mod, mseg, mseg + num_mcount); | ||
2196 | |||
2170 | err = module_finalize(hdr, sechdrs, mod); | 2197 | err = module_finalize(hdr, sechdrs, mod); |
2171 | if (err < 0) | 2198 | if (err < 0) |
2172 | goto cleanup; | 2199 | goto cleanup; |
@@ -2190,30 +2217,24 @@ static noinline struct module *load_module(void __user *umod, | |||
2190 | set_fs(old_fs); | 2217 | set_fs(old_fs); |
2191 | 2218 | ||
2192 | mod->args = args; | 2219 | mod->args = args; |
2193 | if (obsparmindex) | 2220 | if (section_addr(hdr, sechdrs, secstrings, "__obsparm")) |
2194 | printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", | 2221 | printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", |
2195 | mod->name); | 2222 | mod->name); |
2196 | 2223 | ||
2197 | /* Now sew it into the lists so we can get lockdep and oops | 2224 | /* Now sew it into the lists so we can get lockdep and oops |
2198 | * info during argument parsing. Noone should access us, since | 2225 | * info during argument parsing. Noone should access us, since |
2199 | * strong_try_module_get() will fail. */ | 2226 | * strong_try_module_get() will fail. |
2200 | stop_machine(__link_module, mod, NULL); | 2227 | * lockdep/oops can run asynchronous, so use the RCU list insertion |
2201 | 2228 | * function to insert in a way safe to concurrent readers. | |
2202 | /* Size of section 0 is 0, so this works well if no params */ | 2229 | * The mutex protects against concurrent writers. |
2203 | err = parse_args(mod->name, mod->args, | 2230 | */ |
2204 | (struct kernel_param *) | 2231 | list_add_rcu(&mod->list, &modules); |
2205 | sechdrs[setupindex].sh_addr, | 2232 | |
2206 | sechdrs[setupindex].sh_size | 2233 | err = parse_args(mod->name, mod->args, kp, num_kp, NULL); |
2207 | / sizeof(struct kernel_param), | ||
2208 | NULL); | ||
2209 | if (err < 0) | 2234 | if (err < 0) |
2210 | goto unlink; | 2235 | goto unlink; |
2211 | 2236 | ||
2212 | err = mod_sysfs_setup(mod, | 2237 | err = mod_sysfs_setup(mod, kp, num_kp); |
2213 | (struct kernel_param *) | ||
2214 | sechdrs[setupindex].sh_addr, | ||
2215 | sechdrs[setupindex].sh_size | ||
2216 | / sizeof(struct kernel_param)); | ||
2217 | if (err < 0) | 2238 | if (err < 0) |
2218 | goto unlink; | 2239 | goto unlink; |
2219 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); | 2240 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); |
@@ -2236,6 +2257,7 @@ static noinline struct module *load_module(void __user *umod, | |||
2236 | cleanup: | 2257 | cleanup: |
2237 | kobject_del(&mod->mkobj.kobj); | 2258 | kobject_del(&mod->mkobj.kobj); |
2238 | kobject_put(&mod->mkobj.kobj); | 2259 | kobject_put(&mod->mkobj.kobj); |
2260 | ftrace_release(mod->module_core, mod->core_size); | ||
2239 | free_unload: | 2261 | free_unload: |
2240 | module_unload_free(mod); | 2262 | module_unload_free(mod); |
2241 | module_free(mod, mod->module_init); | 2263 | module_free(mod, mod->module_init); |
@@ -2401,7 +2423,7 @@ const char *module_address_lookup(unsigned long addr, | |||
2401 | const char *ret = NULL; | 2423 | const char *ret = NULL; |
2402 | 2424 | ||
2403 | preempt_disable(); | 2425 | preempt_disable(); |
2404 | list_for_each_entry(mod, &modules, list) { | 2426 | list_for_each_entry_rcu(mod, &modules, list) { |
2405 | if (within(addr, mod->module_init, mod->init_size) | 2427 | if (within(addr, mod->module_init, mod->init_size) |
2406 | || within(addr, mod->module_core, mod->core_size)) { | 2428 | || within(addr, mod->module_core, mod->core_size)) { |
2407 | if (modname) | 2429 | if (modname) |
@@ -2424,7 +2446,7 @@ int lookup_module_symbol_name(unsigned long addr, char *symname) | |||
2424 | struct module *mod; | 2446 | struct module *mod; |
2425 | 2447 | ||
2426 | preempt_disable(); | 2448 | preempt_disable(); |
2427 | list_for_each_entry(mod, &modules, list) { | 2449 | list_for_each_entry_rcu(mod, &modules, list) { |
2428 | if (within(addr, mod->module_init, mod->init_size) || | 2450 | if (within(addr, mod->module_init, mod->init_size) || |
2429 | within(addr, mod->module_core, mod->core_size)) { | 2451 | within(addr, mod->module_core, mod->core_size)) { |
2430 | const char *sym; | 2452 | const char *sym; |
@@ -2448,7 +2470,7 @@ int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, | |||
2448 | struct module *mod; | 2470 | struct module *mod; |
2449 | 2471 | ||
2450 | preempt_disable(); | 2472 | preempt_disable(); |
2451 | list_for_each_entry(mod, &modules, list) { | 2473 | list_for_each_entry_rcu(mod, &modules, list) { |
2452 | if (within(addr, mod->module_init, mod->init_size) || | 2474 | if (within(addr, mod->module_init, mod->init_size) || |
2453 | within(addr, mod->module_core, mod->core_size)) { | 2475 | within(addr, mod->module_core, mod->core_size)) { |
2454 | const char *sym; | 2476 | const char *sym; |
@@ -2475,7 +2497,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, | |||
2475 | struct module *mod; | 2497 | struct module *mod; |
2476 | 2498 | ||
2477 | preempt_disable(); | 2499 | preempt_disable(); |
2478 | list_for_each_entry(mod, &modules, list) { | 2500 | list_for_each_entry_rcu(mod, &modules, list) { |
2479 | if (symnum < mod->num_symtab) { | 2501 | if (symnum < mod->num_symtab) { |
2480 | *value = mod->symtab[symnum].st_value; | 2502 | *value = mod->symtab[symnum].st_value; |
2481 | *type = mod->symtab[symnum].st_info; | 2503 | *type = mod->symtab[symnum].st_info; |
@@ -2518,7 +2540,7 @@ unsigned long module_kallsyms_lookup_name(const char *name) | |||
2518 | ret = mod_find_symname(mod, colon+1); | 2540 | ret = mod_find_symname(mod, colon+1); |
2519 | *colon = ':'; | 2541 | *colon = ':'; |
2520 | } else { | 2542 | } else { |
2521 | list_for_each_entry(mod, &modules, list) | 2543 | list_for_each_entry_rcu(mod, &modules, list) |
2522 | if ((ret = mod_find_symname(mod, name)) != 0) | 2544 | if ((ret = mod_find_symname(mod, name)) != 0) |
2523 | break; | 2545 | break; |
2524 | } | 2546 | } |
@@ -2527,23 +2549,6 @@ unsigned long module_kallsyms_lookup_name(const char *name) | |||
2527 | } | 2549 | } |
2528 | #endif /* CONFIG_KALLSYMS */ | 2550 | #endif /* CONFIG_KALLSYMS */ |
2529 | 2551 | ||
2530 | /* Called by the /proc file system to return a list of modules. */ | ||
2531 | static void *m_start(struct seq_file *m, loff_t *pos) | ||
2532 | { | ||
2533 | mutex_lock(&module_mutex); | ||
2534 | return seq_list_start(&modules, *pos); | ||
2535 | } | ||
2536 | |||
2537 | static void *m_next(struct seq_file *m, void *p, loff_t *pos) | ||
2538 | { | ||
2539 | return seq_list_next(p, &modules, pos); | ||
2540 | } | ||
2541 | |||
2542 | static void m_stop(struct seq_file *m, void *p) | ||
2543 | { | ||
2544 | mutex_unlock(&module_mutex); | ||
2545 | } | ||
2546 | |||
2547 | static char *module_flags(struct module *mod, char *buf) | 2552 | static char *module_flags(struct module *mod, char *buf) |
2548 | { | 2553 | { |
2549 | int bx = 0; | 2554 | int bx = 0; |
@@ -2552,10 +2557,12 @@ static char *module_flags(struct module *mod, char *buf) | |||
2552 | mod->state == MODULE_STATE_GOING || | 2557 | mod->state == MODULE_STATE_GOING || |
2553 | mod->state == MODULE_STATE_COMING) { | 2558 | mod->state == MODULE_STATE_COMING) { |
2554 | buf[bx++] = '('; | 2559 | buf[bx++] = '('; |
2555 | if (mod->taints & TAINT_PROPRIETARY_MODULE) | 2560 | if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE)) |
2556 | buf[bx++] = 'P'; | 2561 | buf[bx++] = 'P'; |
2557 | if (mod->taints & TAINT_FORCED_MODULE) | 2562 | if (mod->taints & (1 << TAINT_FORCED_MODULE)) |
2558 | buf[bx++] = 'F'; | 2563 | buf[bx++] = 'F'; |
2564 | if (mod->taints & (1 << TAINT_CRAP)) | ||
2565 | buf[bx++] = 'C'; | ||
2559 | /* | 2566 | /* |
2560 | * TAINT_FORCED_RMMOD: could be added. | 2567 | * TAINT_FORCED_RMMOD: could be added. |
2561 | * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't | 2568 | * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't |
@@ -2575,6 +2582,24 @@ static char *module_flags(struct module *mod, char *buf) | |||
2575 | return buf; | 2582 | return buf; |
2576 | } | 2583 | } |
2577 | 2584 | ||
2585 | #ifdef CONFIG_PROC_FS | ||
2586 | /* Called by the /proc file system to return a list of modules. */ | ||
2587 | static void *m_start(struct seq_file *m, loff_t *pos) | ||
2588 | { | ||
2589 | mutex_lock(&module_mutex); | ||
2590 | return seq_list_start(&modules, *pos); | ||
2591 | } | ||
2592 | |||
2593 | static void *m_next(struct seq_file *m, void *p, loff_t *pos) | ||
2594 | { | ||
2595 | return seq_list_next(p, &modules, pos); | ||
2596 | } | ||
2597 | |||
2598 | static void m_stop(struct seq_file *m, void *p) | ||
2599 | { | ||
2600 | mutex_unlock(&module_mutex); | ||
2601 | } | ||
2602 | |||
2578 | static int m_show(struct seq_file *m, void *p) | 2603 | static int m_show(struct seq_file *m, void *p) |
2579 | { | 2604 | { |
2580 | struct module *mod = list_entry(p, struct module, list); | 2605 | struct module *mod = list_entry(p, struct module, list); |
@@ -2605,13 +2630,33 @@ static int m_show(struct seq_file *m, void *p) | |||
2605 | Where refcount is a number or -, and deps is a comma-separated list | 2630 | Where refcount is a number or -, and deps is a comma-separated list |
2606 | of depends or -. | 2631 | of depends or -. |
2607 | */ | 2632 | */ |
2608 | const struct seq_operations modules_op = { | 2633 | static const struct seq_operations modules_op = { |
2609 | .start = m_start, | 2634 | .start = m_start, |
2610 | .next = m_next, | 2635 | .next = m_next, |
2611 | .stop = m_stop, | 2636 | .stop = m_stop, |
2612 | .show = m_show | 2637 | .show = m_show |
2613 | }; | 2638 | }; |
2614 | 2639 | ||
2640 | static int modules_open(struct inode *inode, struct file *file) | ||
2641 | { | ||
2642 | return seq_open(file, &modules_op); | ||
2643 | } | ||
2644 | |||
2645 | static const struct file_operations proc_modules_operations = { | ||
2646 | .open = modules_open, | ||
2647 | .read = seq_read, | ||
2648 | .llseek = seq_lseek, | ||
2649 | .release = seq_release, | ||
2650 | }; | ||
2651 | |||
2652 | static int __init proc_modules_init(void) | ||
2653 | { | ||
2654 | proc_create("modules", 0, NULL, &proc_modules_operations); | ||
2655 | return 0; | ||
2656 | } | ||
2657 | module_init(proc_modules_init); | ||
2658 | #endif | ||
2659 | |||
2615 | /* Given an address, look for it in the module exception tables. */ | 2660 | /* Given an address, look for it in the module exception tables. */ |
2616 | const struct exception_table_entry *search_module_extables(unsigned long addr) | 2661 | const struct exception_table_entry *search_module_extables(unsigned long addr) |
2617 | { | 2662 | { |
@@ -2619,7 +2664,7 @@ const struct exception_table_entry *search_module_extables(unsigned long addr) | |||
2619 | struct module *mod; | 2664 | struct module *mod; |
2620 | 2665 | ||
2621 | preempt_disable(); | 2666 | preempt_disable(); |
2622 | list_for_each_entry(mod, &modules, list) { | 2667 | list_for_each_entry_rcu(mod, &modules, list) { |
2623 | if (mod->num_exentries == 0) | 2668 | if (mod->num_exentries == 0) |
2624 | continue; | 2669 | continue; |
2625 | 2670 | ||
@@ -2645,7 +2690,7 @@ int is_module_address(unsigned long addr) | |||
2645 | 2690 | ||
2646 | preempt_disable(); | 2691 | preempt_disable(); |
2647 | 2692 | ||
2648 | list_for_each_entry(mod, &modules, list) { | 2693 | list_for_each_entry_rcu(mod, &modules, list) { |
2649 | if (within(addr, mod->module_core, mod->core_size)) { | 2694 | if (within(addr, mod->module_core, mod->core_size)) { |
2650 | preempt_enable(); | 2695 | preempt_enable(); |
2651 | return 1; | 2696 | return 1; |
@@ -2659,14 +2704,14 @@ int is_module_address(unsigned long addr) | |||
2659 | 2704 | ||
2660 | 2705 | ||
2661 | /* Is this a valid kernel address? */ | 2706 | /* Is this a valid kernel address? */ |
2662 | struct module *__module_text_address(unsigned long addr) | 2707 | __notrace_funcgraph struct module *__module_text_address(unsigned long addr) |
2663 | { | 2708 | { |
2664 | struct module *mod; | 2709 | struct module *mod; |
2665 | 2710 | ||
2666 | if (addr < module_addr_min || addr > module_addr_max) | 2711 | if (addr < module_addr_min || addr > module_addr_max) |
2667 | return NULL; | 2712 | return NULL; |
2668 | 2713 | ||
2669 | list_for_each_entry(mod, &modules, list) | 2714 | list_for_each_entry_rcu(mod, &modules, list) |
2670 | if (within(addr, mod->module_init, mod->init_text_size) | 2715 | if (within(addr, mod->module_init, mod->init_text_size) |
2671 | || within(addr, mod->module_core, mod->core_text_size)) | 2716 | || within(addr, mod->module_core, mod->core_text_size)) |
2672 | return mod; | 2717 | return mod; |
@@ -2691,8 +2736,11 @@ void print_modules(void) | |||
2691 | char buf[8]; | 2736 | char buf[8]; |
2692 | 2737 | ||
2693 | printk("Modules linked in:"); | 2738 | printk("Modules linked in:"); |
2694 | list_for_each_entry(mod, &modules, list) | 2739 | /* Most callers should already have preempt disabled, but make sure */ |
2740 | preempt_disable(); | ||
2741 | list_for_each_entry_rcu(mod, &modules, list) | ||
2695 | printk(" %s%s", mod->name, module_flags(mod, buf)); | 2742 | printk(" %s%s", mod->name, module_flags(mod, buf)); |
2743 | preempt_enable(); | ||
2696 | if (last_unloaded_module[0]) | 2744 | if (last_unloaded_module[0]) |
2697 | printk(" [last unloaded: %s]", last_unloaded_module); | 2745 | printk(" [last unloaded: %s]", last_unloaded_module); |
2698 | printk("\n"); | 2746 | printk("\n"); |
@@ -2717,3 +2765,50 @@ void module_update_markers(void) | |||
2717 | mutex_unlock(&module_mutex); | 2765 | mutex_unlock(&module_mutex); |
2718 | } | 2766 | } |
2719 | #endif | 2767 | #endif |
2768 | |||
2769 | #ifdef CONFIG_TRACEPOINTS | ||
2770 | void module_update_tracepoints(void) | ||
2771 | { | ||
2772 | struct module *mod; | ||
2773 | |||
2774 | mutex_lock(&module_mutex); | ||
2775 | list_for_each_entry(mod, &modules, list) | ||
2776 | if (!mod->taints) | ||
2777 | tracepoint_update_probe_range(mod->tracepoints, | ||
2778 | mod->tracepoints + mod->num_tracepoints); | ||
2779 | mutex_unlock(&module_mutex); | ||
2780 | } | ||
2781 | |||
2782 | /* | ||
2783 | * Returns 0 if current not found. | ||
2784 | * Returns 1 if current found. | ||
2785 | */ | ||
2786 | int module_get_iter_tracepoints(struct tracepoint_iter *iter) | ||
2787 | { | ||
2788 | struct module *iter_mod; | ||
2789 | int found = 0; | ||
2790 | |||
2791 | mutex_lock(&module_mutex); | ||
2792 | list_for_each_entry(iter_mod, &modules, list) { | ||
2793 | if (!iter_mod->taints) { | ||
2794 | /* | ||
2795 | * Sorted module list | ||
2796 | */ | ||
2797 | if (iter_mod < iter->module) | ||
2798 | continue; | ||
2799 | else if (iter_mod > iter->module) | ||
2800 | iter->tracepoint = NULL; | ||
2801 | found = tracepoint_get_iter_range(&iter->tracepoint, | ||
2802 | iter_mod->tracepoints, | ||
2803 | iter_mod->tracepoints | ||
2804 | + iter_mod->num_tracepoints); | ||
2805 | if (found) { | ||
2806 | iter->module = iter_mod; | ||
2807 | break; | ||
2808 | } | ||
2809 | } | ||
2810 | } | ||
2811 | mutex_unlock(&module_mutex); | ||
2812 | return found; | ||
2813 | } | ||
2814 | #endif | ||