aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
authorAlexey Dobriyan <adobriyan@sw.ru>2007-05-08 03:28:43 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-08 14:15:08 -0400
commit9d65cb4a1718a072898c7a57a3bc61b2dc4bcd4d (patch)
tree9e3fd1c9e61e8ed16959d115a9a3f6f7eb0bbf21 /kernel/module.c
parentffb45122766db220d0bf3d01848d575fbbcb6430 (diff)
Fix race between cat /proc/*/wchan and rmmod et al
kallsyms_lookup() can go iterating over modules list unprotected which is OK for emergency situations (oops), but not OK for regular stuff like /proc/*/wchan. Introduce lookup_symbol_name()/lookup_module_symbol_name() which copy symbol name into caller-supplied buffer or return -ERANGE. All copying is done with module_mutex held, so... Signed-off-by: Alexey Dobriyan <adobriyan@sw.ru> Cc: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/kernel/module.c b/kernel/module.c
index bf4dccadf7b..3da76ad32d7 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2126,6 +2126,29 @@ const char *module_address_lookup(unsigned long addr,
2126 return NULL; 2126 return NULL;
2127} 2127}
2128 2128
2129int lookup_module_symbol_name(unsigned long addr, char *symname)
2130{
2131 struct module *mod;
2132
2133 mutex_lock(&module_mutex);
2134 list_for_each_entry(mod, &modules, list) {
2135 if (within(addr, mod->module_init, mod->init_size) ||
2136 within(addr, mod->module_core, mod->core_size)) {
2137 const char *sym;
2138
2139 sym = get_ksymbol(mod, addr, NULL, NULL);
2140 if (!sym)
2141 goto out;
2142 strlcpy(symname, sym, KSYM_NAME_LEN + 1);
2143 mutex_unlock(&module_mutex);
2144 return 0;
2145 }
2146 }
2147out:
2148 mutex_unlock(&module_mutex);
2149 return -ERANGE;
2150}
2151
2129int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, 2152int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
2130 char *name, char *module_name, int *exported) 2153 char *name, char *module_name, int *exported)
2131{ 2154{