aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c335
1 files changed, 208 insertions, 127 deletions
diff --git a/kernel/module.c b/kernel/module.c
index 9db11911e04b..c0f1826e2d9e 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -42,10 +42,13 @@
42#include <linux/string.h> 42#include <linux/string.h>
43#include <linux/mutex.h> 43#include <linux/mutex.h>
44#include <linux/unwind.h> 44#include <linux/unwind.h>
45#include <linux/rculist.h>
45#include <asm/uaccess.h> 46#include <asm/uaccess.h>
46#include <asm/cacheflush.h> 47#include <asm/cacheflush.h>
47#include <linux/license.h> 48#include <linux/license.h>
48#include <asm/sections.h> 49#include <asm/sections.h>
50#include <linux/tracepoint.h>
51#include <linux/ftrace.h>
49 52
50#if 0 53#if 0
51#define DEBUGP printk 54#define DEBUGP printk
@@ -61,7 +64,7 @@
61#define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) 64#define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
62 65
63/* List of modules, protected by module_mutex or preempt_disable 66/* List of modules, protected by module_mutex or preempt_disable
64 * (add/delete uses stop_machine). */ 67 * (delete uses stop_machine/add uses RCU list operations). */
65static DEFINE_MUTEX(module_mutex); 68static DEFINE_MUTEX(module_mutex);
66static LIST_HEAD(modules); 69static LIST_HEAD(modules);
67 70
@@ -100,7 +103,7 @@ static inline int strong_try_module_get(struct module *mod)
100static inline void add_taint_module(struct module *mod, unsigned flag) 103static inline void add_taint_module(struct module *mod, unsigned flag)
101{ 104{
102 add_taint(flag); 105 add_taint(flag);
103 mod->taints |= flag; 106 mod->taints |= (1U << flag);
104} 107}
105 108
106/* 109/*
@@ -130,6 +133,29 @@ static unsigned int find_sec(Elf_Ehdr *hdr,
130 return 0; 133 return 0;
131} 134}
132 135
136/* Find a module section, or NULL. */
137static void *section_addr(Elf_Ehdr *hdr, Elf_Shdr *shdrs,
138 const char *secstrings, const char *name)
139{
140 /* Section 0 has sh_addr 0. */
141 return (void *)shdrs[find_sec(hdr, shdrs, secstrings, name)].sh_addr;
142}
143
144/* Find a module section, or NULL. Fill in number of "objects" in section. */
145static void *section_objs(Elf_Ehdr *hdr,
146 Elf_Shdr *sechdrs,
147 const char *secstrings,
148 const char *name,
149 size_t object_size,
150 unsigned int *num)
151{
152 unsigned int sec = find_sec(hdr, sechdrs, secstrings, name);
153
154 /* Section 0 has sh_addr 0 and sh_size 0. */
155 *num = sechdrs[sec].sh_size / object_size;
156 return (void *)sechdrs[sec].sh_addr;
157}
158
133/* Provided by the linker */ 159/* Provided by the linker */
134extern const struct kernel_symbol __start___ksymtab[]; 160extern const struct kernel_symbol __start___ksymtab[];
135extern const struct kernel_symbol __stop___ksymtab[]; 161extern const struct kernel_symbol __stop___ksymtab[];
@@ -216,7 +242,7 @@ static bool each_symbol(bool (*fn)(const struct symsearch *arr,
216 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data)) 242 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data))
217 return true; 243 return true;
218 244
219 list_for_each_entry(mod, &modules, list) { 245 list_for_each_entry_rcu(mod, &modules, list) {
220 struct symsearch arr[] = { 246 struct symsearch arr[] = {
221 { mod->syms, mod->syms + mod->num_syms, mod->crcs, 247 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
222 NOT_GPL_ONLY, false }, 248 NOT_GPL_ONLY, false },
@@ -784,6 +810,7 @@ sys_delete_module(const char __user *name_user, unsigned int flags)
784 mutex_lock(&module_mutex); 810 mutex_lock(&module_mutex);
785 /* Store the name of the last unloaded module for diagnostic purposes */ 811 /* Store the name of the last unloaded module for diagnostic purposes */
786 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); 812 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module));
813 unregister_dynamic_debug_module(mod->name);
787 free_module(mod); 814 free_module(mod);
788 815
789 out: 816 out:
@@ -923,7 +950,7 @@ static const char vermagic[] = VERMAGIC_STRING;
923static int try_to_force_load(struct module *mod, const char *symname) 950static int try_to_force_load(struct module *mod, const char *symname)
924{ 951{
925#ifdef CONFIG_MODULE_FORCE_LOAD 952#ifdef CONFIG_MODULE_FORCE_LOAD
926 if (!(tainted & TAINT_FORCED_MODULE)) 953 if (!test_taint(TAINT_FORCED_MODULE))
927 printk("%s: no version for \"%s\" found: kernel tainted.\n", 954 printk("%s: no version for \"%s\" found: kernel tainted.\n",
928 mod->name, symname); 955 mod->name, symname);
929 add_taint_module(mod, TAINT_FORCED_MODULE); 956 add_taint_module(mod, TAINT_FORCED_MODULE);
@@ -1033,7 +1060,7 @@ static unsigned long resolve_symbol(Elf_Shdr *sechdrs,
1033 const unsigned long *crc; 1060 const unsigned long *crc;
1034 1061
1035 ret = find_symbol(name, &owner, &crc, 1062 ret = find_symbol(name, &owner, &crc,
1036 !(mod->taints & TAINT_PROPRIETARY_MODULE), true); 1063 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true);
1037 if (!IS_ERR_VALUE(ret)) { 1064 if (!IS_ERR_VALUE(ret)) {
1038 /* use_module can fail due to OOM, 1065 /* use_module can fail due to OOM,
1039 or module initialization or unloading */ 1066 or module initialization or unloading */
@@ -1173,7 +1200,7 @@ static void free_notes_attrs(struct module_notes_attrs *notes_attrs,
1173 while (i-- > 0) 1200 while (i-- > 0)
1174 sysfs_remove_bin_file(notes_attrs->dir, 1201 sysfs_remove_bin_file(notes_attrs->dir,
1175 &notes_attrs->attrs[i]); 1202 &notes_attrs->attrs[i]);
1176 kobject_del(notes_attrs->dir); 1203 kobject_put(notes_attrs->dir);
1177 } 1204 }
1178 kfree(notes_attrs); 1205 kfree(notes_attrs);
1179} 1206}
@@ -1391,17 +1418,6 @@ static void mod_kobject_remove(struct module *mod)
1391} 1418}
1392 1419
1393/* 1420/*
1394 * link the module with the whole machine is stopped with interrupts off
1395 * - this defends against kallsyms not taking locks
1396 */
1397static 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 1421 * unlink the module with the whole machine is stopped with interrupts off
1406 * - this defends against kallsyms not taking locks 1422 * - this defends against kallsyms not taking locks
1407 */ 1423 */
@@ -1429,6 +1445,9 @@ static void free_module(struct module *mod)
1429 /* Module unload stuff */ 1445 /* Module unload stuff */
1430 module_unload_free(mod); 1446 module_unload_free(mod);
1431 1447
1448 /* release any pointers to mcount in this module */
1449 ftrace_release(mod->module_core, mod->core_size);
1450
1432 /* This may be NULL, but that's OK */ 1451 /* This may be NULL, but that's OK */
1433 module_free(mod, mod->module_init); 1452 module_free(mod, mod->module_init);
1434 kfree(mod->args); 1453 kfree(mod->args);
@@ -1634,7 +1653,7 @@ static void set_license(struct module *mod, const char *license)
1634 license = "unspecified"; 1653 license = "unspecified";
1635 1654
1636 if (!license_is_gpl_compatible(license)) { 1655 if (!license_is_gpl_compatible(license)) {
1637 if (!(tainted & TAINT_PROPRIETARY_MODULE)) 1656 if (!test_taint(TAINT_PROPRIETARY_MODULE))
1638 printk(KERN_WARNING "%s: module license '%s' taints " 1657 printk(KERN_WARNING "%s: module license '%s' taints "
1639 "kernel.\n", mod->name, license); 1658 "kernel.\n", mod->name, license);
1640 add_taint_module(mod, TAINT_PROPRIETARY_MODULE); 1659 add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
@@ -1783,6 +1802,21 @@ static inline void add_kallsyms(struct module *mod,
1783} 1802}
1784#endif /* CONFIG_KALLSYMS */ 1803#endif /* CONFIG_KALLSYMS */
1785 1804
1805static void dynamic_printk_setup(struct mod_debug *debug, unsigned int num)
1806{
1807#ifdef CONFIG_DYNAMIC_PRINTK_DEBUG
1808 unsigned int i;
1809
1810 for (i = 0; i < num; i++) {
1811 register_dynamic_debug_module(debug[i].modname,
1812 debug[i].type,
1813 debug[i].logical_modname,
1814 debug[i].flag_names,
1815 debug[i].hash, debug[i].hash2);
1816 }
1817#endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */
1818}
1819
1786static void *module_alloc_update_bounds(unsigned long size) 1820static void *module_alloc_update_bounds(unsigned long size)
1787{ 1821{
1788 void *ret = module_alloc(size); 1822 void *ret = module_alloc(size);
@@ -1806,35 +1840,18 @@ static noinline struct module *load_module(void __user *umod,
1806 Elf_Ehdr *hdr; 1840 Elf_Ehdr *hdr;
1807 Elf_Shdr *sechdrs; 1841 Elf_Shdr *sechdrs;
1808 char *secstrings, *args, *modmagic, *strtab = NULL; 1842 char *secstrings, *args, *modmagic, *strtab = NULL;
1843 char *staging;
1809 unsigned int i; 1844 unsigned int i;
1810 unsigned int symindex = 0; 1845 unsigned int symindex = 0;
1811 unsigned int strindex = 0; 1846 unsigned int strindex = 0;
1812 unsigned int setupindex; 1847 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; 1848 unsigned int unwindex = 0;
1826#ifdef CONFIG_UNUSED_SYMBOLS 1849 unsigned int num_kp, num_mcount;
1827 unsigned int unusedindex; 1850 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; 1851 struct module *mod;
1835 long err = 0; 1852 long err = 0;
1836 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ 1853 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */
1837 struct exception_table_entry *extable; 1854 unsigned long *mseg;
1838 mm_segment_t old_fs; 1855 mm_segment_t old_fs;
1839 1856
1840 DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", 1857 DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n",
@@ -1898,6 +1915,7 @@ static noinline struct module *load_module(void __user *umod,
1898 err = -ENOEXEC; 1915 err = -ENOEXEC;
1899 goto free_hdr; 1916 goto free_hdr;
1900 } 1917 }
1918 /* This is temporary: point mod into copy of data. */
1901 mod = (void *)sechdrs[modindex].sh_addr; 1919 mod = (void *)sechdrs[modindex].sh_addr;
1902 1920
1903 if (symindex == 0) { 1921 if (symindex == 0) {
@@ -1907,22 +1925,6 @@ static noinline struct module *load_module(void __user *umod,
1907 goto free_hdr; 1925 goto free_hdr;
1908 } 1926 }
1909 1927
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"); 1928 versindex = find_sec(hdr, sechdrs, secstrings, "__versions");
1927 infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo"); 1929 infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo");
1928 pcpuindex = find_pcpusec(hdr, sechdrs, secstrings); 1930 pcpuindex = find_pcpusec(hdr, sechdrs, secstrings);
@@ -1960,6 +1962,14 @@ static noinline struct module *load_module(void __user *umod,
1960 goto free_hdr; 1962 goto free_hdr;
1961 } 1963 }
1962 1964
1965 staging = get_modinfo(sechdrs, infoindex, "staging");
1966 if (staging) {
1967 add_taint_module(mod, TAINT_CRAP);
1968 printk(KERN_WARNING "%s: module is from the staging directory,"
1969 " the quality is unknown, you have been warned.\n",
1970 mod->name);
1971 }
1972
1963 /* Now copy in args */ 1973 /* Now copy in args */
1964 args = strndup_user(uargs, ~0UL >> 1); 1974 args = strndup_user(uargs, ~0UL >> 1);
1965 if (IS_ERR(args)) { 1975 if (IS_ERR(args)) {
@@ -2070,42 +2080,57 @@ static noinline struct module *load_module(void __user *umod,
2070 if (err < 0) 2080 if (err < 0)
2071 goto cleanup; 2081 goto cleanup;
2072 2082
2073 /* Set up EXPORTed & EXPORT_GPLed symbols (section 0 is 0 length) */ 2083 /* Now we've got everything in the final locations, we can
2074 mod->num_syms = sechdrs[exportindex].sh_size / sizeof(*mod->syms); 2084 * find optional sections. */
2075 mod->syms = (void *)sechdrs[exportindex].sh_addr; 2085 kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp),
2076 if (crcindex) 2086 &num_kp);
2077 mod->crcs = (void *)sechdrs[crcindex].sh_addr; 2087 mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab",
2078 mod->num_gpl_syms = sechdrs[gplindex].sh_size / sizeof(*mod->gpl_syms); 2088 sizeof(*mod->syms), &mod->num_syms);
2079 mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr; 2089 mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab");
2080 if (gplcrcindex) 2090 mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl",
2081 mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; 2091 sizeof(*mod->gpl_syms),
2082 mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size / 2092 &mod->num_gpl_syms);
2083 sizeof(*mod->gpl_future_syms); 2093 mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl");
2084 mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr; 2094 mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings,
2085 if (gplfuturecrcindex) 2095 "__ksymtab_gpl_future",
2086 mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr; 2096 sizeof(*mod->gpl_future_syms),
2097 &mod->num_gpl_future_syms);
2098 mod->gpl_future_crcs = section_addr(hdr, sechdrs, secstrings,
2099 "__kcrctab_gpl_future");
2087 2100
2088#ifdef CONFIG_UNUSED_SYMBOLS 2101#ifdef CONFIG_UNUSED_SYMBOLS
2089 mod->num_unused_syms = sechdrs[unusedindex].sh_size / 2102 mod->unused_syms = section_objs(hdr, sechdrs, secstrings,
2090 sizeof(*mod->unused_syms); 2103 "__ksymtab_unused",
2091 mod->num_unused_gpl_syms = sechdrs[unusedgplindex].sh_size / 2104 sizeof(*mod->unused_syms),
2092 sizeof(*mod->unused_gpl_syms); 2105 &mod->num_unused_syms);
2093 mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr; 2106 mod->unused_crcs = section_addr(hdr, sechdrs, secstrings,
2094 if (unusedcrcindex) 2107 "__kcrctab_unused");
2095 mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr; 2108 mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings,
2096 mod->unused_gpl_syms = (void *)sechdrs[unusedgplindex].sh_addr; 2109 "__ksymtab_unused_gpl",
2097 if (unusedgplcrcindex) 2110 sizeof(*mod->unused_gpl_syms),
2098 mod->unused_gpl_crcs 2111 &mod->num_unused_gpl_syms);
2099 = (void *)sechdrs[unusedgplcrcindex].sh_addr; 2112 mod->unused_gpl_crcs = section_addr(hdr, sechdrs, secstrings,
2113 "__kcrctab_unused_gpl");
2114#endif
2115
2116#ifdef CONFIG_MARKERS
2117 mod->markers = section_objs(hdr, sechdrs, secstrings, "__markers",
2118 sizeof(*mod->markers), &mod->num_markers);
2119#endif
2120#ifdef CONFIG_TRACEPOINTS
2121 mod->tracepoints = section_objs(hdr, sechdrs, secstrings,
2122 "__tracepoints",
2123 sizeof(*mod->tracepoints),
2124 &mod->num_tracepoints);
2100#endif 2125#endif
2101 2126
2102#ifdef CONFIG_MODVERSIONS 2127#ifdef CONFIG_MODVERSIONS
2103 if ((mod->num_syms && !crcindex) 2128 if ((mod->num_syms && !mod->crcs)
2104 || (mod->num_gpl_syms && !gplcrcindex) 2129 || (mod->num_gpl_syms && !mod->gpl_crcs)
2105 || (mod->num_gpl_future_syms && !gplfuturecrcindex) 2130 || (mod->num_gpl_future_syms && !mod->gpl_future_crcs)
2106#ifdef CONFIG_UNUSED_SYMBOLS 2131#ifdef CONFIG_UNUSED_SYMBOLS
2107 || (mod->num_unused_syms && !unusedcrcindex) 2132 || (mod->num_unused_syms && !mod->unused_crcs)
2108 || (mod->num_unused_gpl_syms && !unusedgplcrcindex) 2133 || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs)
2109#endif 2134#endif
2110 ) { 2135 ) {
2111 printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); 2136 printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name);
@@ -2114,9 +2139,6 @@ static noinline struct module *load_module(void __user *umod,
2114 goto cleanup; 2139 goto cleanup;
2115 } 2140 }
2116#endif 2141#endif
2117 markersindex = find_sec(hdr, sechdrs, secstrings, "__markers");
2118 markersstringsindex = find_sec(hdr, sechdrs, secstrings,
2119 "__markers_strings");
2120 2142
2121 /* Now do relocations. */ 2143 /* Now do relocations. */
2122 for (i = 1; i < hdr->e_shnum; i++) { 2144 for (i = 1; i < hdr->e_shnum; i++) {
@@ -2139,22 +2161,16 @@ static noinline struct module *load_module(void __user *umod,
2139 if (err < 0) 2161 if (err < 0)
2140 goto cleanup; 2162 goto cleanup;
2141 } 2163 }
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 2164
2148 /* Find duplicate symbols */ 2165 /* Find duplicate symbols */
2149 err = verify_export_symbols(mod); 2166 err = verify_export_symbols(mod);
2150
2151 if (err < 0) 2167 if (err < 0)
2152 goto cleanup; 2168 goto cleanup;
2153 2169
2154 /* Set up and sort exception table */ 2170 /* Set up and sort exception table */
2155 mod->num_exentries = sechdrs[exindex].sh_size / sizeof(*mod->extable); 2171 mod->extable = section_objs(hdr, sechdrs, secstrings, "__ex_table",
2156 mod->extable = extable = (void *)sechdrs[exindex].sh_addr; 2172 sizeof(*mod->extable), &mod->num_exentries);
2157 sort_extable(extable, extable + mod->num_exentries); 2173 sort_extable(mod->extable, mod->extable + mod->num_exentries);
2158 2174
2159 /* Finally, copy percpu area over. */ 2175 /* Finally, copy percpu area over. */
2160 percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr, 2176 percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr,
@@ -2162,11 +2178,29 @@ static noinline struct module *load_module(void __user *umod,
2162 2178
2163 add_kallsyms(mod, sechdrs, symindex, strindex, secstrings); 2179 add_kallsyms(mod, sechdrs, symindex, strindex, secstrings);
2164 2180
2181 if (!mod->taints) {
2182 struct mod_debug *debug;
2183 unsigned int num_debug;
2184
2165#ifdef CONFIG_MARKERS 2185#ifdef CONFIG_MARKERS
2166 if (!mod->taints)
2167 marker_update_probe_range(mod->markers, 2186 marker_update_probe_range(mod->markers,
2168 mod->markers + mod->num_markers); 2187 mod->markers + mod->num_markers);
2169#endif 2188#endif
2189 debug = section_objs(hdr, sechdrs, secstrings, "__verbose",
2190 sizeof(*debug), &num_debug);
2191 dynamic_printk_setup(debug, num_debug);
2192
2193#ifdef CONFIG_TRACEPOINTS
2194 tracepoint_update_probe_range(mod->tracepoints,
2195 mod->tracepoints + mod->num_tracepoints);
2196#endif
2197 }
2198
2199 /* sechdrs[0].sh_size is always zero */
2200 mseg = section_objs(hdr, sechdrs, secstrings, "__mcount_loc",
2201 sizeof(*mseg), &num_mcount);
2202 ftrace_init_module(mseg, mseg + num_mcount);
2203
2170 err = module_finalize(hdr, sechdrs, mod); 2204 err = module_finalize(hdr, sechdrs, mod);
2171 if (err < 0) 2205 if (err < 0)
2172 goto cleanup; 2206 goto cleanup;
@@ -2190,30 +2224,24 @@ static noinline struct module *load_module(void __user *umod,
2190 set_fs(old_fs); 2224 set_fs(old_fs);
2191 2225
2192 mod->args = args; 2226 mod->args = args;
2193 if (obsparmindex) 2227 if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
2194 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", 2228 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
2195 mod->name); 2229 mod->name);
2196 2230
2197 /* Now sew it into the lists so we can get lockdep and oops 2231 /* Now sew it into the lists so we can get lockdep and oops
2198 * info during argument parsing. Noone should access us, since 2232 * info during argument parsing. Noone should access us, since
2199 * strong_try_module_get() will fail. */ 2233 * strong_try_module_get() will fail.
2200 stop_machine(__link_module, mod, NULL); 2234 * lockdep/oops can run asynchronous, so use the RCU list insertion
2201 2235 * function to insert in a way safe to concurrent readers.
2202 /* Size of section 0 is 0, so this works well if no params */ 2236 * The mutex protects against concurrent writers.
2203 err = parse_args(mod->name, mod->args, 2237 */
2204 (struct kernel_param *) 2238 list_add_rcu(&mod->list, &modules);
2205 sechdrs[setupindex].sh_addr, 2239
2206 sechdrs[setupindex].sh_size 2240 err = parse_args(mod->name, mod->args, kp, num_kp, NULL);
2207 / sizeof(struct kernel_param),
2208 NULL);
2209 if (err < 0) 2241 if (err < 0)
2210 goto unlink; 2242 goto unlink;
2211 2243
2212 err = mod_sysfs_setup(mod, 2244 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) 2245 if (err < 0)
2218 goto unlink; 2246 goto unlink;
2219 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); 2247 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
@@ -2236,6 +2264,7 @@ static noinline struct module *load_module(void __user *umod,
2236 cleanup: 2264 cleanup:
2237 kobject_del(&mod->mkobj.kobj); 2265 kobject_del(&mod->mkobj.kobj);
2238 kobject_put(&mod->mkobj.kobj); 2266 kobject_put(&mod->mkobj.kobj);
2267 ftrace_release(mod->module_core, mod->core_size);
2239 free_unload: 2268 free_unload:
2240 module_unload_free(mod); 2269 module_unload_free(mod);
2241 module_free(mod, mod->module_init); 2270 module_free(mod, mod->module_init);
@@ -2401,7 +2430,7 @@ const char *module_address_lookup(unsigned long addr,
2401 const char *ret = NULL; 2430 const char *ret = NULL;
2402 2431
2403 preempt_disable(); 2432 preempt_disable();
2404 list_for_each_entry(mod, &modules, list) { 2433 list_for_each_entry_rcu(mod, &modules, list) {
2405 if (within(addr, mod->module_init, mod->init_size) 2434 if (within(addr, mod->module_init, mod->init_size)
2406 || within(addr, mod->module_core, mod->core_size)) { 2435 || within(addr, mod->module_core, mod->core_size)) {
2407 if (modname) 2436 if (modname)
@@ -2424,7 +2453,7 @@ int lookup_module_symbol_name(unsigned long addr, char *symname)
2424 struct module *mod; 2453 struct module *mod;
2425 2454
2426 preempt_disable(); 2455 preempt_disable();
2427 list_for_each_entry(mod, &modules, list) { 2456 list_for_each_entry_rcu(mod, &modules, list) {
2428 if (within(addr, mod->module_init, mod->init_size) || 2457 if (within(addr, mod->module_init, mod->init_size) ||
2429 within(addr, mod->module_core, mod->core_size)) { 2458 within(addr, mod->module_core, mod->core_size)) {
2430 const char *sym; 2459 const char *sym;
@@ -2448,7 +2477,7 @@ int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,
2448 struct module *mod; 2477 struct module *mod;
2449 2478
2450 preempt_disable(); 2479 preempt_disable();
2451 list_for_each_entry(mod, &modules, list) { 2480 list_for_each_entry_rcu(mod, &modules, list) {
2452 if (within(addr, mod->module_init, mod->init_size) || 2481 if (within(addr, mod->module_init, mod->init_size) ||
2453 within(addr, mod->module_core, mod->core_size)) { 2482 within(addr, mod->module_core, mod->core_size)) {
2454 const char *sym; 2483 const char *sym;
@@ -2475,7 +2504,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
2475 struct module *mod; 2504 struct module *mod;
2476 2505
2477 preempt_disable(); 2506 preempt_disable();
2478 list_for_each_entry(mod, &modules, list) { 2507 list_for_each_entry_rcu(mod, &modules, list) {
2479 if (symnum < mod->num_symtab) { 2508 if (symnum < mod->num_symtab) {
2480 *value = mod->symtab[symnum].st_value; 2509 *value = mod->symtab[symnum].st_value;
2481 *type = mod->symtab[symnum].st_info; 2510 *type = mod->symtab[symnum].st_info;
@@ -2518,7 +2547,7 @@ unsigned long module_kallsyms_lookup_name(const char *name)
2518 ret = mod_find_symname(mod, colon+1); 2547 ret = mod_find_symname(mod, colon+1);
2519 *colon = ':'; 2548 *colon = ':';
2520 } else { 2549 } else {
2521 list_for_each_entry(mod, &modules, list) 2550 list_for_each_entry_rcu(mod, &modules, list)
2522 if ((ret = mod_find_symname(mod, name)) != 0) 2551 if ((ret = mod_find_symname(mod, name)) != 0)
2523 break; 2552 break;
2524 } 2553 }
@@ -2552,10 +2581,12 @@ static char *module_flags(struct module *mod, char *buf)
2552 mod->state == MODULE_STATE_GOING || 2581 mod->state == MODULE_STATE_GOING ||
2553 mod->state == MODULE_STATE_COMING) { 2582 mod->state == MODULE_STATE_COMING) {
2554 buf[bx++] = '('; 2583 buf[bx++] = '(';
2555 if (mod->taints & TAINT_PROPRIETARY_MODULE) 2584 if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE))
2556 buf[bx++] = 'P'; 2585 buf[bx++] = 'P';
2557 if (mod->taints & TAINT_FORCED_MODULE) 2586 if (mod->taints & (1 << TAINT_FORCED_MODULE))
2558 buf[bx++] = 'F'; 2587 buf[bx++] = 'F';
2588 if (mod->taints & (1 << TAINT_CRAP))
2589 buf[bx++] = 'C';
2559 /* 2590 /*
2560 * TAINT_FORCED_RMMOD: could be added. 2591 * TAINT_FORCED_RMMOD: could be added.
2561 * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't 2592 * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
@@ -2619,7 +2650,7 @@ const struct exception_table_entry *search_module_extables(unsigned long addr)
2619 struct module *mod; 2650 struct module *mod;
2620 2651
2621 preempt_disable(); 2652 preempt_disable();
2622 list_for_each_entry(mod, &modules, list) { 2653 list_for_each_entry_rcu(mod, &modules, list) {
2623 if (mod->num_exentries == 0) 2654 if (mod->num_exentries == 0)
2624 continue; 2655 continue;
2625 2656
@@ -2645,7 +2676,7 @@ int is_module_address(unsigned long addr)
2645 2676
2646 preempt_disable(); 2677 preempt_disable();
2647 2678
2648 list_for_each_entry(mod, &modules, list) { 2679 list_for_each_entry_rcu(mod, &modules, list) {
2649 if (within(addr, mod->module_core, mod->core_size)) { 2680 if (within(addr, mod->module_core, mod->core_size)) {
2650 preempt_enable(); 2681 preempt_enable();
2651 return 1; 2682 return 1;
@@ -2666,7 +2697,7 @@ struct module *__module_text_address(unsigned long addr)
2666 if (addr < module_addr_min || addr > module_addr_max) 2697 if (addr < module_addr_min || addr > module_addr_max)
2667 return NULL; 2698 return NULL;
2668 2699
2669 list_for_each_entry(mod, &modules, list) 2700 list_for_each_entry_rcu(mod, &modules, list)
2670 if (within(addr, mod->module_init, mod->init_text_size) 2701 if (within(addr, mod->module_init, mod->init_text_size)
2671 || within(addr, mod->module_core, mod->core_text_size)) 2702 || within(addr, mod->module_core, mod->core_text_size))
2672 return mod; 2703 return mod;
@@ -2691,8 +2722,11 @@ void print_modules(void)
2691 char buf[8]; 2722 char buf[8];
2692 2723
2693 printk("Modules linked in:"); 2724 printk("Modules linked in:");
2694 list_for_each_entry(mod, &modules, list) 2725 /* Most callers should already have preempt disabled, but make sure */
2726 preempt_disable();
2727 list_for_each_entry_rcu(mod, &modules, list)
2695 printk(" %s%s", mod->name, module_flags(mod, buf)); 2728 printk(" %s%s", mod->name, module_flags(mod, buf));
2729 preempt_enable();
2696 if (last_unloaded_module[0]) 2730 if (last_unloaded_module[0])
2697 printk(" [last unloaded: %s]", last_unloaded_module); 2731 printk(" [last unloaded: %s]", last_unloaded_module);
2698 printk("\n"); 2732 printk("\n");
@@ -2717,3 +2751,50 @@ void module_update_markers(void)
2717 mutex_unlock(&module_mutex); 2751 mutex_unlock(&module_mutex);
2718} 2752}
2719#endif 2753#endif
2754
2755#ifdef CONFIG_TRACEPOINTS
2756void module_update_tracepoints(void)
2757{
2758 struct module *mod;
2759
2760 mutex_lock(&module_mutex);
2761 list_for_each_entry(mod, &modules, list)
2762 if (!mod->taints)
2763 tracepoint_update_probe_range(mod->tracepoints,
2764 mod->tracepoints + mod->num_tracepoints);
2765 mutex_unlock(&module_mutex);
2766}
2767
2768/*
2769 * Returns 0 if current not found.
2770 * Returns 1 if current found.
2771 */
2772int module_get_iter_tracepoints(struct tracepoint_iter *iter)
2773{
2774 struct module *iter_mod;
2775 int found = 0;
2776
2777 mutex_lock(&module_mutex);
2778 list_for_each_entry(iter_mod, &modules, list) {
2779 if (!iter_mod->taints) {
2780 /*
2781 * Sorted module list
2782 */
2783 if (iter_mod < iter->module)
2784 continue;
2785 else if (iter_mod > iter->module)
2786 iter->tracepoint = NULL;
2787 found = tracepoint_get_iter_range(&iter->tracepoint,
2788 iter_mod->tracepoints,
2789 iter_mod->tracepoints
2790 + iter_mod->num_tracepoints);
2791 if (found) {
2792 iter->module = iter_mod;
2793 break;
2794 }
2795 }
2796 }
2797 mutex_unlock(&module_mutex);
2798 return found;
2799}
2800#endif