Commit 4f6de4d5 authored by Mathias Krause's avatar Mathias Krause Committed by Rusty Russell

module: don't modify argument of module_kallsyms_lookup_name()

If we pass a pointer to a const string in the form "module:symbol"
module_kallsyms_lookup_name() will try to split the string at the colon,
i.e., will try to modify r/o data. That will, in fact, fail on a kernel
with enabled CONFIG_DEBUG_RODATA.

Avoid modifying the passed string in module_kallsyms_lookup_name(),
modify find_module_all() instead to pass it the module name length.
Signed-off-by: default avatarMathias Krause <minipli@googlemail.com>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 06df44ee
...@@ -455,7 +455,7 @@ const struct kernel_symbol *find_symbol(const char *name, ...@@ -455,7 +455,7 @@ const struct kernel_symbol *find_symbol(const char *name,
EXPORT_SYMBOL_GPL(find_symbol); EXPORT_SYMBOL_GPL(find_symbol);
/* Search for module by name: must hold module_mutex. */ /* Search for module by name: must hold module_mutex. */
static struct module *find_module_all(const char *name, static struct module *find_module_all(const char *name, size_t len,
bool even_unformed) bool even_unformed)
{ {
struct module *mod; struct module *mod;
...@@ -463,7 +463,7 @@ static struct module *find_module_all(const char *name, ...@@ -463,7 +463,7 @@ static struct module *find_module_all(const char *name,
list_for_each_entry(mod, &modules, list) { list_for_each_entry(mod, &modules, list) {
if (!even_unformed && mod->state == MODULE_STATE_UNFORMED) if (!even_unformed && mod->state == MODULE_STATE_UNFORMED)
continue; continue;
if (strcmp(mod->name, name) == 0) if (strlen(mod->name) == len && !memcmp(mod->name, name, len))
return mod; return mod;
} }
return NULL; return NULL;
...@@ -471,7 +471,7 @@ static struct module *find_module_all(const char *name, ...@@ -471,7 +471,7 @@ static struct module *find_module_all(const char *name,
struct module *find_module(const char *name) struct module *find_module(const char *name)
{ {
return find_module_all(name, false); return find_module_all(name, strlen(name), false);
} }
EXPORT_SYMBOL_GPL(find_module); EXPORT_SYMBOL_GPL(find_module);
...@@ -3027,7 +3027,7 @@ static bool finished_loading(const char *name) ...@@ -3027,7 +3027,7 @@ static bool finished_loading(const char *name)
bool ret; bool ret;
mutex_lock(&module_mutex); mutex_lock(&module_mutex);
mod = find_module_all(name, true); mod = find_module_all(name, strlen(name), true);
ret = !mod || mod->state == MODULE_STATE_LIVE ret = !mod || mod->state == MODULE_STATE_LIVE
|| mod->state == MODULE_STATE_GOING; || mod->state == MODULE_STATE_GOING;
mutex_unlock(&module_mutex); mutex_unlock(&module_mutex);
...@@ -3165,7 +3165,8 @@ static int add_unformed_module(struct module *mod) ...@@ -3165,7 +3165,8 @@ static int add_unformed_module(struct module *mod)
again: again:
mutex_lock(&module_mutex); mutex_lock(&module_mutex);
if ((old = find_module_all(mod->name, true)) != NULL) { old = find_module_all(mod->name, strlen(mod->name), true);
if (old != NULL) {
if (old->state == MODULE_STATE_COMING if (old->state == MODULE_STATE_COMING
|| old->state == MODULE_STATE_UNFORMED) { || old->state == MODULE_STATE_UNFORMED) {
/* Wait in case it fails to load. */ /* Wait in case it fails to load. */
...@@ -3576,10 +3577,8 @@ unsigned long module_kallsyms_lookup_name(const char *name) ...@@ -3576,10 +3577,8 @@ unsigned long module_kallsyms_lookup_name(const char *name)
/* Don't lock: we're in enough trouble already. */ /* Don't lock: we're in enough trouble already. */
preempt_disable(); preempt_disable();
if ((colon = strchr(name, ':')) != NULL) { if ((colon = strchr(name, ':')) != NULL) {
*colon = '\0'; if ((mod = find_module_all(name, colon - name, false)) != NULL)
if ((mod = find_module(name)) != NULL)
ret = mod_find_symname(mod, colon+1); ret = mod_find_symname(mod, colon+1);
*colon = ':';
} else { } else {
list_for_each_entry_rcu(mod, &modules, list) { list_for_each_entry_rcu(mod, &modules, list) {
if (mod->state == MODULE_STATE_UNFORMED) if (mod->state == MODULE_STATE_UNFORMED)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment