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>
This commit is contained in:
Alexey Dobriyan
2007-05-08 00:28:43 -07:00
committed by Linus Torvalds
parent ffb4512276
commit 9d65cb4a17
7 changed files with 66 additions and 19 deletions

View File

@ -2126,6 +2126,29 @@ const char *module_address_lookup(unsigned long addr,
return NULL;
}
int lookup_module_symbol_name(unsigned long addr, char *symname)
{
struct module *mod;
mutex_lock(&module_mutex);
list_for_each_entry(mod, &modules, list) {
if (within(addr, mod->module_init, mod->init_size) ||
within(addr, mod->module_core, mod->core_size)) {
const char *sym;
sym = get_ksymbol(mod, addr, NULL, NULL);
if (!sym)
goto out;
strlcpy(symname, sym, KSYM_NAME_LEN + 1);
mutex_unlock(&module_mutex);
return 0;
}
}
out:
mutex_unlock(&module_mutex);
return -ERANGE;
}
int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
char *name, char *module_name, int *exported)
{