Commit 6dd06c9f authored by Rusty Russell's avatar Rusty Russell

module: make module_address_lookup safe

module_address_lookup releases preemption then returns a pointer into
the module space.  The only user (kallsyms) copies the result, so just
do that under the preempt disable.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent bb9d3d56
...@@ -446,11 +446,14 @@ static inline void __module_get(struct module *module) ...@@ -446,11 +446,14 @@ static inline void __module_get(struct module *module)
__mod ? __mod->name : "kernel"; \ __mod ? __mod->name : "kernel"; \
}) })
/* For kallsyms to ask for address resolution. NULL means not found. */ /* For kallsyms to ask for address resolution. namebuf should be at
const char *module_address_lookup(unsigned long addr, * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
unsigned long *symbolsize, * found, otherwise NULL. */
unsigned long *offset, char *module_address_lookup(unsigned long addr,
char **modname); unsigned long *symbolsize,
unsigned long *offset,
char **modname,
char *namebuf);
int lookup_module_symbol_name(unsigned long addr, char *symname); int lookup_module_symbol_name(unsigned long addr, char *symname);
int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name); int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
...@@ -516,10 +519,11 @@ static inline void module_put(struct module *module) ...@@ -516,10 +519,11 @@ static inline void module_put(struct module *module)
#define module_name(mod) "kernel" #define module_name(mod) "kernel"
/* For kallsyms to ask for address resolution. NULL means not found. */ /* For kallsyms to ask for address resolution. NULL means not found. */
static inline const char *module_address_lookup(unsigned long addr, static inline char *module_address_lookup(unsigned long addr,
unsigned long *symbolsize, unsigned long *symbolsize,
unsigned long *offset, unsigned long *offset,
char **modname) char **modname,
char *namebuf)
{ {
return NULL; return NULL;
} }
......
...@@ -233,10 +233,11 @@ static unsigned long get_symbol_pos(unsigned long addr, ...@@ -233,10 +233,11 @@ static unsigned long get_symbol_pos(unsigned long addr,
int kallsyms_lookup_size_offset(unsigned long addr, unsigned long *symbolsize, int kallsyms_lookup_size_offset(unsigned long addr, unsigned long *symbolsize,
unsigned long *offset) unsigned long *offset)
{ {
char namebuf[KSYM_NAME_LEN];
if (is_ksym_addr(addr)) if (is_ksym_addr(addr))
return !!get_symbol_pos(addr, symbolsize, offset); return !!get_symbol_pos(addr, symbolsize, offset);
return !!module_address_lookup(addr, symbolsize, offset, NULL); return !!module_address_lookup(addr, symbolsize, offset, NULL, namebuf);
} }
/* /*
...@@ -251,8 +252,6 @@ const char *kallsyms_lookup(unsigned long addr, ...@@ -251,8 +252,6 @@ const char *kallsyms_lookup(unsigned long addr,
unsigned long *offset, unsigned long *offset,
char **modname, char *namebuf) char **modname, char *namebuf)
{ {
const char *msym;
namebuf[KSYM_NAME_LEN - 1] = 0; namebuf[KSYM_NAME_LEN - 1] = 0;
namebuf[0] = 0; namebuf[0] = 0;
...@@ -268,10 +267,8 @@ const char *kallsyms_lookup(unsigned long addr, ...@@ -268,10 +267,8 @@ const char *kallsyms_lookup(unsigned long addr,
} }
/* see if it's in a module */ /* see if it's in a module */
msym = module_address_lookup(addr, symbolsize, offset, modname); return module_address_lookup(addr, symbolsize, offset, modname,
if (msym) namebuf);
return strncpy(namebuf, msym, KSYM_NAME_LEN - 1);
return NULL; return NULL;
} }
......
...@@ -2230,14 +2230,13 @@ static const char *get_ksymbol(struct module *mod, ...@@ -2230,14 +2230,13 @@ static const char *get_ksymbol(struct module *mod,
return mod->strtab + mod->symtab[best].st_name; return mod->strtab + mod->symtab[best].st_name;
} }
/* For kallsyms to ask for address resolution. NULL means not found. /* For kallsyms to ask for address resolution. NULL means not found. Careful
We don't lock, as this is used for oops resolution and races are a * not to lock to avoid deadlock on oopses, simply disable preemption. */
lesser concern. */ char *module_address_lookup(unsigned long addr,
/* FIXME: Risky: returns a pointer into a module w/o lock */ unsigned long *size,
const char *module_address_lookup(unsigned long addr, unsigned long *offset,
unsigned long *size, char **modname,
unsigned long *offset, char *namebuf)
char **modname)
{ {
struct module *mod; struct module *mod;
const char *ret = NULL; const char *ret = NULL;
...@@ -2252,8 +2251,13 @@ const char *module_address_lookup(unsigned long addr, ...@@ -2252,8 +2251,13 @@ const char *module_address_lookup(unsigned long addr,
break; break;
} }
} }
/* Make a copy in here where it's safe */
if (ret) {
strncpy(namebuf, ret, KSYM_NAME_LEN - 1);
ret = namebuf;
}
preempt_enable(); preempt_enable();
return ret; return (char *)ret;
} }
int lookup_module_symbol_name(unsigned long addr, char *symname) int lookup_module_symbol_name(unsigned long addr, char *symname)
......
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