aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c388
1 files changed, 225 insertions, 163 deletions
diff --git a/kernel/module.c b/kernel/module.c
index 25bc9ac9e226..1f4cc00e0c20 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). */
65static DEFINE_MUTEX(module_mutex); 70static DEFINE_MUTEX(module_mutex);
66static LIST_HEAD(modules); 71static LIST_HEAD(modules);
67 72
@@ -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. */
139static 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. */
147static 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 */
134extern const struct kernel_symbol __start___ksymtab[]; 162extern const struct kernel_symbol __start___ksymtab[];
135extern const struct kernel_symbol __stop___ksymtab[]; 163extern 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 },
@@ -1392,17 +1420,6 @@ static void mod_kobject_remove(struct module *mod)
1392} 1420}
1393 1421
1394/* 1422/*
1395 * link the module with the whole machine is stopped with interrupts off
1396 * - this defends against kallsyms not taking locks
1397 */
1398static int __link_module(void *_mod)
1399{
1400 struct module *mod = _mod;
1401 list_add(&mod->list, &modules);
1402 return 0;
1403}
1404
1405/*
1406 * 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
1407 * - this defends against kallsyms not taking locks 1424 * - this defends against kallsyms not taking locks
1408 */ 1425 */
@@ -1430,6 +1447,9 @@ static void free_module(struct module *mod)
1430 /* Module unload stuff */ 1447 /* Module unload stuff */
1431 module_unload_free(mod); 1448 module_unload_free(mod);
1432 1449
1450 /* release any pointers to mcount in this module */
1451 ftrace_release(mod->module_core, mod->core_size);
1452
1433 /* This may be NULL, but that's OK */ 1453 /* This may be NULL, but that's OK */
1434 module_free(mod, mod->module_init); 1454 module_free(mod, mod->module_init);
1435 kfree(mod->args); 1455 kfree(mod->args);
@@ -1784,32 +1804,20 @@ static inline void add_kallsyms(struct module *mod,
1784} 1804}
1785#endif /* CONFIG_KALLSYMS */ 1805#endif /* CONFIG_KALLSYMS */
1786 1806
1787#ifdef CONFIG_DYNAMIC_PRINTK_DEBUG 1807static void dynamic_printk_setup(struct mod_debug *debug, unsigned int num)
1788static void dynamic_printk_setup(Elf_Shdr *sechdrs, unsigned int verboseindex)
1789{ 1808{
1790 struct mod_debug *debug_info; 1809#ifdef CONFIG_DYNAMIC_PRINTK_DEBUG
1791 unsigned long pos, end; 1810 unsigned int i;
1792 unsigned int num_verbose;
1793
1794 pos = sechdrs[verboseindex].sh_addr;
1795 num_verbose = sechdrs[verboseindex].sh_size /
1796 sizeof(struct mod_debug);
1797 end = pos + (num_verbose * sizeof(struct mod_debug));
1798 1811
1799 for (; pos < end; pos += sizeof(struct mod_debug)) { 1812 for (i = 0; i < num; i++) {
1800 debug_info = (struct mod_debug *)pos; 1813 register_dynamic_debug_module(debug[i].modname,
1801 register_dynamic_debug_module(debug_info->modname, 1814 debug[i].type,
1802 debug_info->type, debug_info->logical_modname, 1815 debug[i].logical_modname,
1803 debug_info->flag_names, debug_info->hash, 1816 debug[i].flag_names,
1804 debug_info->hash2); 1817 debug[i].hash, debug[i].hash2);
1805 } 1818 }
1806}
1807#else
1808static inline void dynamic_printk_setup(Elf_Shdr *sechdrs,
1809 unsigned int verboseindex)
1810{
1811}
1812#endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */ 1819#endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */
1820}
1813 1821
1814static void *module_alloc_update_bounds(unsigned long size) 1822static void *module_alloc_update_bounds(unsigned long size)
1815{ 1823{
@@ -1838,33 +1846,14 @@ static noinline struct module *load_module(void __user *umod,
1838 unsigned int i; 1846 unsigned int i;
1839 unsigned int symindex = 0; 1847 unsigned int symindex = 0;
1840 unsigned int strindex = 0; 1848 unsigned int strindex = 0;
1841 unsigned int setupindex; 1849 unsigned int modindex, versindex, infoindex, pcpuindex;
1842 unsigned int exindex;
1843 unsigned int exportindex;
1844 unsigned int modindex;
1845 unsigned int obsparmindex;
1846 unsigned int infoindex;
1847 unsigned int gplindex;
1848 unsigned int crcindex;
1849 unsigned int gplcrcindex;
1850 unsigned int versindex;
1851 unsigned int pcpuindex;
1852 unsigned int gplfutureindex;
1853 unsigned int gplfuturecrcindex;
1854 unsigned int unwindex = 0; 1850 unsigned int unwindex = 0;
1855#ifdef CONFIG_UNUSED_SYMBOLS 1851 unsigned int num_kp, num_mcount;
1856 unsigned int unusedindex; 1852 struct kernel_param *kp;
1857 unsigned int unusedcrcindex;
1858 unsigned int unusedgplindex;
1859 unsigned int unusedgplcrcindex;
1860#endif
1861 unsigned int markersindex;
1862 unsigned int markersstringsindex;
1863 unsigned int verboseindex;
1864 struct module *mod; 1853 struct module *mod;
1865 long err = 0; 1854 long err = 0;
1866 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ 1855 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */
1867 struct exception_table_entry *extable; 1856 unsigned long *mseg;
1868 mm_segment_t old_fs; 1857 mm_segment_t old_fs;
1869 1858
1870 DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", 1859 DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n",
@@ -1928,6 +1917,7 @@ static noinline struct module *load_module(void __user *umod,
1928 err = -ENOEXEC; 1917 err = -ENOEXEC;
1929 goto free_hdr; 1918 goto free_hdr;
1930 } 1919 }
1920 /* This is temporary: point mod into copy of data. */
1931 mod = (void *)sechdrs[modindex].sh_addr; 1921 mod = (void *)sechdrs[modindex].sh_addr;
1932 1922
1933 if (symindex == 0) { 1923 if (symindex == 0) {
@@ -1937,22 +1927,6 @@ static noinline struct module *load_module(void __user *umod,
1937 goto free_hdr; 1927 goto free_hdr;
1938 } 1928 }
1939 1929
1940 /* Optional sections */
1941 exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab");
1942 gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl");
1943 gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future");
1944 crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab");
1945 gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl");
1946 gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future");
1947#ifdef CONFIG_UNUSED_SYMBOLS
1948 unusedindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused");
1949 unusedgplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused_gpl");
1950 unusedcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused");
1951 unusedgplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused_gpl");
1952#endif
1953 setupindex = find_sec(hdr, sechdrs, secstrings, "__param");
1954 exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table");
1955 obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm");
1956 versindex = find_sec(hdr, sechdrs, secstrings, "__versions"); 1930 versindex = find_sec(hdr, sechdrs, secstrings, "__versions");
1957 infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo"); 1931 infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo");
1958 pcpuindex = find_pcpusec(hdr, sechdrs, secstrings); 1932 pcpuindex = find_pcpusec(hdr, sechdrs, secstrings);
@@ -2108,42 +2082,57 @@ static noinline struct module *load_module(void __user *umod,
2108 if (err < 0) 2082 if (err < 0)
2109 goto cleanup; 2083 goto cleanup;
2110 2084
2111 /* Set up EXPORTed & EXPORT_GPLed symbols (section 0 is 0 length) */ 2085 /* Now we've got everything in the final locations, we can
2112 mod->num_syms = sechdrs[exportindex].sh_size / sizeof(*mod->syms); 2086 * find optional sections. */
2113 mod->syms = (void *)sechdrs[exportindex].sh_addr; 2087 kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp),
2114 if (crcindex) 2088 &num_kp);
2115 mod->crcs = (void *)sechdrs[crcindex].sh_addr; 2089 mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab",
2116 mod->num_gpl_syms = sechdrs[gplindex].sh_size / sizeof(*mod->gpl_syms); 2090 sizeof(*mod->syms), &mod->num_syms);
2117 mod->gpl_syms = (void *)sechdrs[gplindex].sh_addr; 2091 mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab");
2118 if (gplcrcindex) 2092 mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl",
2119 mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; 2093 sizeof(*mod->gpl_syms),
2120 mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size / 2094 &mod->num_gpl_syms);
2121 sizeof(*mod->gpl_future_syms); 2095 mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl");
2122 mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr; 2096 mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings,
2123 if (gplfuturecrcindex) 2097 "__ksymtab_gpl_future",
2124 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");
2125 2102
2126#ifdef CONFIG_UNUSED_SYMBOLS 2103#ifdef CONFIG_UNUSED_SYMBOLS
2127 mod->num_unused_syms = sechdrs[unusedindex].sh_size / 2104 mod->unused_syms = section_objs(hdr, sechdrs, secstrings,
2128 sizeof(*mod->unused_syms); 2105 "__ksymtab_unused",
2129 mod->num_unused_gpl_syms = sechdrs[unusedgplindex].sh_size / 2106 sizeof(*mod->unused_syms),
2130 sizeof(*mod->unused_gpl_syms); 2107 &mod->num_unused_syms);
2131 mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr; 2108 mod->unused_crcs = section_addr(hdr, sechdrs, secstrings,
2132 if (unusedcrcindex) 2109 "__kcrctab_unused");
2133 mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr; 2110 mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings,
2134 mod->unused_gpl_syms = (void *)sechdrs[unusedgplindex].sh_addr; 2111 "__ksymtab_unused_gpl",
2135 if (unusedgplcrcindex) 2112 sizeof(*mod->unused_gpl_syms),
2136 mod->unused_gpl_crcs 2113 &mod->num_unused_gpl_syms);
2137 = (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);
2138#endif 2127#endif
2139 2128
2140#ifdef CONFIG_MODVERSIONS 2129#ifdef CONFIG_MODVERSIONS
2141 if ((mod->num_syms && !crcindex) 2130 if ((mod->num_syms && !mod->crcs)
2142 || (mod->num_gpl_syms && !gplcrcindex) 2131 || (mod->num_gpl_syms && !mod->gpl_crcs)
2143 || (mod->num_gpl_future_syms && !gplfuturecrcindex) 2132 || (mod->num_gpl_future_syms && !mod->gpl_future_crcs)
2144#ifdef CONFIG_UNUSED_SYMBOLS 2133#ifdef CONFIG_UNUSED_SYMBOLS
2145 || (mod->num_unused_syms && !unusedcrcindex) 2134 || (mod->num_unused_syms && !mod->unused_crcs)
2146 || (mod->num_unused_gpl_syms && !unusedgplcrcindex) 2135 || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs)
2147#endif 2136#endif
2148 ) { 2137 ) {
2149 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);
@@ -2152,10 +2141,6 @@ static noinline struct module *load_module(void __user *umod,
2152 goto cleanup; 2141 goto cleanup;
2153 } 2142 }
2154#endif 2143#endif
2155 markersindex = find_sec(hdr, sechdrs, secstrings, "__markers");
2156 markersstringsindex = find_sec(hdr, sechdrs, secstrings,
2157 "__markers_strings");
2158 verboseindex = find_sec(hdr, sechdrs, secstrings, "__verbose");
2159 2144
2160 /* Now do relocations. */ 2145 /* Now do relocations. */
2161 for (i = 1; i < hdr->e_shnum; i++) { 2146 for (i = 1; i < hdr->e_shnum; i++) {
@@ -2178,22 +2163,16 @@ static noinline struct module *load_module(void __user *umod,
2178 if (err < 0) 2163 if (err < 0)
2179 goto cleanup; 2164 goto cleanup;
2180 } 2165 }
2181#ifdef CONFIG_MARKERS
2182 mod->markers = (void *)sechdrs[markersindex].sh_addr;
2183 mod->num_markers =
2184 sechdrs[markersindex].sh_size / sizeof(*mod->markers);
2185#endif
2186 2166
2187 /* Find duplicate symbols */ 2167 /* Find duplicate symbols */
2188 err = verify_export_symbols(mod); 2168 err = verify_export_symbols(mod);
2189
2190 if (err < 0) 2169 if (err < 0)
2191 goto cleanup; 2170 goto cleanup;
2192 2171
2193 /* Set up and sort exception table */ 2172 /* Set up and sort exception table */
2194 mod->num_exentries = sechdrs[exindex].sh_size / sizeof(*mod->extable); 2173 mod->extable = section_objs(hdr, sechdrs, secstrings, "__ex_table",
2195 mod->extable = extable = (void *)sechdrs[exindex].sh_addr; 2174 sizeof(*mod->extable), &mod->num_exentries);
2196 sort_extable(extable, extable + mod->num_exentries); 2175 sort_extable(mod->extable, mod->extable + mod->num_exentries);
2197 2176
2198 /* Finally, copy percpu area over. */ 2177 /* Finally, copy percpu area over. */
2199 percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr, 2178 percpu_modcopy(mod->percpu, (void *)sechdrs[pcpuindex].sh_addr,
@@ -2201,12 +2180,29 @@ static noinline struct module *load_module(void __user *umod,
2201 2180
2202 add_kallsyms(mod, sechdrs, symindex, strindex, secstrings); 2181 add_kallsyms(mod, sechdrs, symindex, strindex, secstrings);
2203 2182
2183 if (!mod->taints) {
2184 struct mod_debug *debug;
2185 unsigned int num_debug;
2186
2204#ifdef CONFIG_MARKERS 2187#ifdef CONFIG_MARKERS
2205 if (!mod->taints)
2206 marker_update_probe_range(mod->markers, 2188 marker_update_probe_range(mod->markers,
2207 mod->markers + mod->num_markers); 2189 mod->markers + mod->num_markers);
2208#endif 2190#endif
2209 dynamic_printk_setup(sechdrs, verboseindex); 2191 debug = section_objs(hdr, sechdrs, secstrings, "__verbose",
2192 sizeof(*debug), &num_debug);
2193 dynamic_printk_setup(debug, num_debug);
2194
2195#ifdef CONFIG_TRACEPOINTS
2196 tracepoint_update_probe_range(mod->tracepoints,
2197 mod->tracepoints + mod->num_tracepoints);
2198#endif
2199 }
2200
2201 /* sechdrs[0].sh_size is always zero */
2202 mseg = section_objs(hdr, sechdrs, secstrings, "__mcount_loc",
2203 sizeof(*mseg), &num_mcount);
2204 ftrace_init_module(mseg, mseg + num_mcount);
2205
2210 err = module_finalize(hdr, sechdrs, mod); 2206 err = module_finalize(hdr, sechdrs, mod);
2211 if (err < 0) 2207 if (err < 0)
2212 goto cleanup; 2208 goto cleanup;
@@ -2230,30 +2226,24 @@ static noinline struct module *load_module(void __user *umod,
2230 set_fs(old_fs); 2226 set_fs(old_fs);
2231 2227
2232 mod->args = args; 2228 mod->args = args;
2233 if (obsparmindex) 2229 if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
2234 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", 2230 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
2235 mod->name); 2231 mod->name);
2236 2232
2237 /* Now sew it into the lists so we can get lockdep and oops 2233 /* Now sew it into the lists so we can get lockdep and oops
2238 * info during argument parsing. Noone should access us, since 2234 * info during argument parsing. Noone should access us, since
2239 * strong_try_module_get() will fail. */ 2235 * strong_try_module_get() will fail.
2240 stop_machine(__link_module, mod, NULL); 2236 * lockdep/oops can run asynchronous, so use the RCU list insertion
2241 2237 * function to insert in a way safe to concurrent readers.
2242 /* Size of section 0 is 0, so this works well if no params */ 2238 * The mutex protects against concurrent writers.
2243 err = parse_args(mod->name, mod->args, 2239 */
2244 (struct kernel_param *) 2240 list_add_rcu(&mod->list, &modules);
2245 sechdrs[setupindex].sh_addr, 2241
2246 sechdrs[setupindex].sh_size 2242 err = parse_args(mod->name, mod->args, kp, num_kp, NULL);
2247 / sizeof(struct kernel_param),
2248 NULL);
2249 if (err < 0) 2243 if (err < 0)
2250 goto unlink; 2244 goto unlink;
2251 2245
2252 err = mod_sysfs_setup(mod, 2246 err = mod_sysfs_setup(mod, kp, num_kp);
2253 (struct kernel_param *)
2254 sechdrs[setupindex].sh_addr,
2255 sechdrs[setupindex].sh_size
2256 / sizeof(struct kernel_param));
2257 if (err < 0) 2247 if (err < 0)
2258 goto unlink; 2248 goto unlink;
2259 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); 2249 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
@@ -2276,6 +2266,7 @@ static noinline struct module *load_module(void __user *umod,
2276 cleanup: 2266 cleanup:
2277 kobject_del(&mod->mkobj.kobj); 2267 kobject_del(&mod->mkobj.kobj);
2278 kobject_put(&mod->mkobj.kobj); 2268 kobject_put(&mod->mkobj.kobj);
2269 ftrace_release(mod->module_core, mod->core_size);
2279 free_unload: 2270 free_unload:
2280 module_unload_free(mod); 2271 module_unload_free(mod);
2281 module_free(mod, mod->module_init); 2272 module_free(mod, mod->module_init);
@@ -2441,7 +2432,7 @@ const char *module_address_lookup(unsigned long addr,
2441 const char *ret = NULL; 2432 const char *ret = NULL;
2442 2433
2443 preempt_disable(); 2434 preempt_disable();
2444 list_for_each_entry(mod, &modules, list) { 2435 list_for_each_entry_rcu(mod, &modules, list) {
2445 if (within(addr, mod->module_init, mod->init_size) 2436 if (within(addr, mod->module_init, mod->init_size)
2446 || within(addr, mod->module_core, mod->core_size)) { 2437 || within(addr, mod->module_core, mod->core_size)) {
2447 if (modname) 2438 if (modname)
@@ -2464,7 +2455,7 @@ int lookup_module_symbol_name(unsigned long addr, char *symname)
2464 struct module *mod; 2455 struct module *mod;
2465 2456
2466 preempt_disable(); 2457 preempt_disable();
2467 list_for_each_entry(mod, &modules, list) { 2458 list_for_each_entry_rcu(mod, &modules, list) {
2468 if (within(addr, mod->module_init, mod->init_size) || 2459 if (within(addr, mod->module_init, mod->init_size) ||
2469 within(addr, mod->module_core, mod->core_size)) { 2460 within(addr, mod->module_core, mod->core_size)) {
2470 const char *sym; 2461 const char *sym;
@@ -2488,7 +2479,7 @@ int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,
2488 struct module *mod; 2479 struct module *mod;
2489 2480
2490 preempt_disable(); 2481 preempt_disable();
2491 list_for_each_entry(mod, &modules, list) { 2482 list_for_each_entry_rcu(mod, &modules, list) {
2492 if (within(addr, mod->module_init, mod->init_size) || 2483 if (within(addr, mod->module_init, mod->init_size) ||
2493 within(addr, mod->module_core, mod->core_size)) { 2484 within(addr, mod->module_core, mod->core_size)) {
2494 const char *sym; 2485 const char *sym;
@@ -2515,7 +2506,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
2515 struct module *mod; 2506 struct module *mod;
2516 2507
2517 preempt_disable(); 2508 preempt_disable();
2518 list_for_each_entry(mod, &modules, list) { 2509 list_for_each_entry_rcu(mod, &modules, list) {
2519 if (symnum < mod->num_symtab) { 2510 if (symnum < mod->num_symtab) {
2520 *value = mod->symtab[symnum].st_value; 2511 *value = mod->symtab[symnum].st_value;
2521 *type = mod->symtab[symnum].st_info; 2512 *type = mod->symtab[symnum].st_info;
@@ -2558,7 +2549,7 @@ unsigned long module_kallsyms_lookup_name(const char *name)
2558 ret = mod_find_symname(mod, colon+1); 2549 ret = mod_find_symname(mod, colon+1);
2559 *colon = ':'; 2550 *colon = ':';
2560 } else { 2551 } else {
2561 list_for_each_entry(mod, &modules, list) 2552 list_for_each_entry_rcu(mod, &modules, list)
2562 if ((ret = mod_find_symname(mod, name)) != 0) 2553 if ((ret = mod_find_symname(mod, name)) != 0)
2563 break; 2554 break;
2564 } 2555 }
@@ -2567,23 +2558,6 @@ unsigned long module_kallsyms_lookup_name(const char *name)
2567} 2558}
2568#endif /* CONFIG_KALLSYMS */ 2559#endif /* CONFIG_KALLSYMS */
2569 2560
2570/* Called by the /proc file system to return a list of modules. */
2571static void *m_start(struct seq_file *m, loff_t *pos)
2572{
2573 mutex_lock(&module_mutex);
2574 return seq_list_start(&modules, *pos);
2575}
2576
2577static void *m_next(struct seq_file *m, void *p, loff_t *pos)
2578{
2579 return seq_list_next(p, &modules, pos);
2580}
2581
2582static void m_stop(struct seq_file *m, void *p)
2583{
2584 mutex_unlock(&module_mutex);
2585}
2586
2587static char *module_flags(struct module *mod, char *buf) 2561static char *module_flags(struct module *mod, char *buf)
2588{ 2562{
2589 int bx = 0; 2563 int bx = 0;
@@ -2617,6 +2591,24 @@ static char *module_flags(struct module *mod, char *buf)
2617 return buf; 2591 return buf;
2618} 2592}
2619 2593
2594#ifdef CONFIG_PROC_FS
2595/* Called by the /proc file system to return a list of modules. */
2596static void *m_start(struct seq_file *m, loff_t *pos)
2597{
2598 mutex_lock(&module_mutex);
2599 return seq_list_start(&modules, *pos);
2600}
2601
2602static void *m_next(struct seq_file *m, void *p, loff_t *pos)
2603{
2604 return seq_list_next(p, &modules, pos);
2605}
2606
2607static void m_stop(struct seq_file *m, void *p)
2608{
2609 mutex_unlock(&module_mutex);
2610}
2611
2620static int m_show(struct seq_file *m, void *p) 2612static int m_show(struct seq_file *m, void *p)
2621{ 2613{
2622 struct module *mod = list_entry(p, struct module, list); 2614 struct module *mod = list_entry(p, struct module, list);
@@ -2647,13 +2639,33 @@ static int m_show(struct seq_file *m, void *p)
2647 Where refcount is a number or -, and deps is a comma-separated list 2639 Where refcount is a number or -, and deps is a comma-separated list
2648 of depends or -. 2640 of depends or -.
2649*/ 2641*/
2650const struct seq_operations modules_op = { 2642static const struct seq_operations modules_op = {
2651 .start = m_start, 2643 .start = m_start,
2652 .next = m_next, 2644 .next = m_next,
2653 .stop = m_stop, 2645 .stop = m_stop,
2654 .show = m_show 2646 .show = m_show
2655}; 2647};
2656 2648
2649static int modules_open(struct inode *inode, struct file *file)
2650{
2651 return seq_open(file, &modules_op);
2652}
2653
2654static const struct file_operations proc_modules_operations = {
2655 .open = modules_open,
2656 .read = seq_read,
2657 .llseek = seq_lseek,
2658 .release = seq_release,
2659};
2660
2661static int __init proc_modules_init(void)
2662{
2663 proc_create("modules", 0, NULL, &proc_modules_operations);
2664 return 0;
2665}
2666module_init(proc_modules_init);
2667#endif
2668
2657/* Given an address, look for it in the module exception tables. */ 2669/* Given an address, look for it in the module exception tables. */
2658const struct exception_table_entry *search_module_extables(unsigned long addr) 2670const struct exception_table_entry *search_module_extables(unsigned long addr)
2659{ 2671{
@@ -2661,7 +2673,7 @@ const struct exception_table_entry *search_module_extables(unsigned long addr)
2661 struct module *mod; 2673 struct module *mod;
2662 2674
2663 preempt_disable(); 2675 preempt_disable();
2664 list_for_each_entry(mod, &modules, list) { 2676 list_for_each_entry_rcu(mod, &modules, list) {
2665 if (mod->num_exentries == 0) 2677 if (mod->num_exentries == 0)
2666 continue; 2678 continue;
2667 2679
@@ -2687,7 +2699,7 @@ int is_module_address(unsigned long addr)
2687 2699
2688 preempt_disable(); 2700 preempt_disable();
2689 2701
2690 list_for_each_entry(mod, &modules, list) { 2702 list_for_each_entry_rcu(mod, &modules, list) {
2691 if (within(addr, mod->module_core, mod->core_size)) { 2703 if (within(addr, mod->module_core, mod->core_size)) {
2692 preempt_enable(); 2704 preempt_enable();
2693 return 1; 2705 return 1;
@@ -2708,7 +2720,7 @@ struct module *__module_text_address(unsigned long addr)
2708 if (addr < module_addr_min || addr > module_addr_max) 2720 if (addr < module_addr_min || addr > module_addr_max)
2709 return NULL; 2721 return NULL;
2710 2722
2711 list_for_each_entry(mod, &modules, list) 2723 list_for_each_entry_rcu(mod, &modules, list)
2712 if (within(addr, mod->module_init, mod->init_text_size) 2724 if (within(addr, mod->module_init, mod->init_text_size)
2713 || within(addr, mod->module_core, mod->core_text_size)) 2725 || within(addr, mod->module_core, mod->core_text_size))
2714 return mod; 2726 return mod;
@@ -2733,8 +2745,11 @@ void print_modules(void)
2733 char buf[8]; 2745 char buf[8];
2734 2746
2735 printk("Modules linked in:"); 2747 printk("Modules linked in:");
2736 list_for_each_entry(mod, &modules, list) 2748 /* Most callers should already have preempt disabled, but make sure */
2749 preempt_disable();
2750 list_for_each_entry_rcu(mod, &modules, list)
2737 printk(" %s%s", mod->name, module_flags(mod, buf)); 2751 printk(" %s%s", mod->name, module_flags(mod, buf));
2752 preempt_enable();
2738 if (last_unloaded_module[0]) 2753 if (last_unloaded_module[0])
2739 printk(" [last unloaded: %s]", last_unloaded_module); 2754 printk(" [last unloaded: %s]", last_unloaded_module);
2740 printk("\n"); 2755 printk("\n");
@@ -2759,3 +2774,50 @@ void module_update_markers(void)
2759 mutex_unlock(&module_mutex); 2774 mutex_unlock(&module_mutex);
2760} 2775}
2761#endif 2776#endif
2777
2778#ifdef CONFIG_TRACEPOINTS
2779void module_update_tracepoints(void)
2780{
2781 struct module *mod;
2782
2783 mutex_lock(&module_mutex);
2784 list_for_each_entry(mod, &modules, list)
2785 if (!mod->taints)
2786 tracepoint_update_probe_range(mod->tracepoints,
2787 mod->tracepoints + mod->num_tracepoints);
2788 mutex_unlock(&module_mutex);
2789}
2790
2791/*
2792 * Returns 0 if current not found.
2793 * Returns 1 if current found.
2794 */
2795int module_get_iter_tracepoints(struct tracepoint_iter *iter)
2796{
2797 struct module *iter_mod;
2798 int found = 0;
2799
2800 mutex_lock(&module_mutex);
2801 list_for_each_entry(iter_mod, &modules, list) {
2802 if (!iter_mod->taints) {
2803 /*
2804 * Sorted module list
2805 */
2806 if (iter_mod < iter->module)
2807 continue;
2808 else if (iter_mod > iter->module)
2809 iter->tracepoint = NULL;
2810 found = tracepoint_get_iter_range(&iter->tracepoint,
2811 iter_mod->tracepoints,
2812 iter_mod->tracepoints
2813 + iter_mod->num_tracepoints);
2814 if (found) {
2815 iter->module = iter_mod;
2816 break;
2817 }
2818 }
2819 }
2820 mutex_unlock(&module_mutex);
2821 return found;
2822}
2823#endif