aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2009-03-31 15:05:29 -0400
committerRusty Russell <rusty@rustcorp.com.au>2009-03-30 22:35:30 -0400
commite180a6b7759a99a28cbcce3547c4c80822cb6c2a (patch)
treed52b950935f3192d13bdd4ad9377b39bab21325e /kernel/module.c
parent15f7176eb1cccec0a332541285ee752b935c1c85 (diff)
param: fix charp parameters set via sysfs
Impact: fix crash on reading from /sys/module/.../ieee80211_default_rc_algo The module_param type "charp" simply sets a char * pointer in the module to the parameter in the commandline string: this is why we keep the (mangled) module command line around. But when set via sysfs (as about 11 charp parameters can be) this memory is freed on the way out of the write(). Future reads hit random mem. So we kstrdup instead: we have to check we're not in early commandline parsing, and we have to note when we've used it so we can reliably kfree the parameter when it's next overwritten, and also on module unload. (Thanks to Randy Dunlap for CONFIG_SYSFS=n fixes) Reported-by: Sitsofe Wheeler <sitsofe@yahoo.com> Diagnosed-by: Frederic Weisbecker <fweisbec@gmail.com> Tested-by: Frederic Weisbecker <fweisbec@gmail.com> Tested-by: Christof Schmitt <christof.schmitt@de.ibm.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/kernel/module.c b/kernel/module.c
index f77ac320d0b5..b862fdb6a372 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1491,6 +1491,9 @@ static void free_module(struct module *mod)
1491 /* Module unload stuff */ 1491 /* Module unload stuff */
1492 module_unload_free(mod); 1492 module_unload_free(mod);
1493 1493
1494 /* Free any allocated parameters. */
1495 destroy_params(mod->kp, mod->num_kp);
1496
1494 /* release any pointers to mcount in this module */ 1497 /* release any pointers to mcount in this module */
1495 ftrace_release(mod->module_core, mod->core_size); 1498 ftrace_release(mod->module_core, mod->core_size);
1496 1499
@@ -1898,8 +1901,7 @@ static noinline struct module *load_module(void __user *umod,
1898 unsigned int symindex = 0; 1901 unsigned int symindex = 0;
1899 unsigned int strindex = 0; 1902 unsigned int strindex = 0;
1900 unsigned int modindex, versindex, infoindex, pcpuindex; 1903 unsigned int modindex, versindex, infoindex, pcpuindex;
1901 unsigned int num_kp, num_mcount; 1904 unsigned int num_mcount;
1902 struct kernel_param *kp;
1903 struct module *mod; 1905 struct module *mod;
1904 long err = 0; 1906 long err = 0;
1905 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */ 1907 void *percpu = NULL, *ptr = NULL; /* Stops spurious gcc warning */
@@ -2144,8 +2146,8 @@ static noinline struct module *load_module(void __user *umod,
2144 2146
2145 /* Now we've got everything in the final locations, we can 2147 /* Now we've got everything in the final locations, we can
2146 * find optional sections. */ 2148 * find optional sections. */
2147 kp = section_objs(hdr, sechdrs, secstrings, "__param", sizeof(*kp), 2149 mod->kp = section_objs(hdr, sechdrs, secstrings, "__param",
2148 &num_kp); 2150 sizeof(*mod->kp), &mod->num_kp);
2149 mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", 2151 mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab",
2150 sizeof(*mod->syms), &mod->num_syms); 2152 sizeof(*mod->syms), &mod->num_syms);
2151 mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); 2153 mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab");
@@ -2291,11 +2293,11 @@ static noinline struct module *load_module(void __user *umod,
2291 */ 2293 */
2292 list_add_rcu(&mod->list, &modules); 2294 list_add_rcu(&mod->list, &modules);
2293 2295
2294 err = parse_args(mod->name, mod->args, kp, num_kp, NULL); 2296 err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL);
2295 if (err < 0) 2297 if (err < 0)
2296 goto unlink; 2298 goto unlink;
2297 2299
2298 err = mod_sysfs_setup(mod, kp, num_kp); 2300 err = mod_sysfs_setup(mod, mod->kp, mod->num_kp);
2299 if (err < 0) 2301 if (err < 0)
2300 goto unlink; 2302 goto unlink;
2301 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); 2303 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs);