Commit 098c5eea authored by Andreas Gruenbacher's avatar Andreas Gruenbacher Committed by Linus Torvalds

[PATCH] null-terminate over-long /proc/kallsyms symbols

Got a customer bug report (https://bugzilla.novell.com/190296) about kernel
symbols longer than 127 characters which end up in a string buffer that is
not NULL terminated, leading to garbage in /proc/kallsyms.  Using strlcpy
prevents this from happening, even though such symbols still won't come out
right.

A better fix would be to not use a fixed-size buffer, but it's probably not
worth the trouble.  (Modversion'ed symbols even have a length limit of 60.)

[bunk@stusta.de: build fix]
Signed-off-by: default avatarAndreas Gruenbacher <agruen@suse.de>
Signed-off-by: default avatarAdrian Bunk <bunk@stusta.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 329c6e42
...@@ -362,10 +362,8 @@ int is_module_address(unsigned long addr); ...@@ -362,10 +362,8 @@ int is_module_address(unsigned long addr);
/* Returns module and fills in value, defined and namebuf, or NULL if /* Returns module and fills in value, defined and namebuf, or NULL if
symnum out of range. */ symnum out of range. */
struct module *module_get_kallsym(unsigned int symnum, struct module *module_get_kallsym(unsigned int symnum, unsigned long *value,
unsigned long *value, char *type, char *name, size_t namelen);
char *type,
char namebuf[128]);
/* Look for this name: can be of form module:name. */ /* Look for this name: can be of form module:name. */
unsigned long module_kallsyms_lookup_name(const char *name); unsigned long module_kallsyms_lookup_name(const char *name);
...@@ -535,8 +533,8 @@ static inline const char *module_address_lookup(unsigned long addr, ...@@ -535,8 +533,8 @@ static inline const char *module_address_lookup(unsigned long addr,
static inline struct module *module_get_kallsym(unsigned int symnum, static inline struct module *module_get_kallsym(unsigned int symnum,
unsigned long *value, unsigned long *value,
char *type, char *type, char *name,
char namebuf[128]) size_t namelen)
{ {
return NULL; return NULL;
} }
......
...@@ -275,8 +275,8 @@ static void upcase_if_global(struct kallsym_iter *iter) ...@@ -275,8 +275,8 @@ static void upcase_if_global(struct kallsym_iter *iter)
static int get_ksymbol_mod(struct kallsym_iter *iter) static int get_ksymbol_mod(struct kallsym_iter *iter)
{ {
iter->owner = module_get_kallsym(iter->pos - kallsyms_num_syms, iter->owner = module_get_kallsym(iter->pos - kallsyms_num_syms,
&iter->value, &iter->value, &iter->type,
&iter->type, iter->name); iter->name, sizeof(iter->name));
if (iter->owner == NULL) if (iter->owner == NULL)
return 0; return 0;
......
...@@ -2019,10 +2019,8 @@ const char *module_address_lookup(unsigned long addr, ...@@ -2019,10 +2019,8 @@ const char *module_address_lookup(unsigned long addr,
return NULL; return NULL;
} }
struct module *module_get_kallsym(unsigned int symnum, struct module *module_get_kallsym(unsigned int symnum, unsigned long *value,
unsigned long *value, char *type, char *name, size_t namelen)
char *type,
char namebuf[128])
{ {
struct module *mod; struct module *mod;
...@@ -2031,9 +2029,8 @@ struct module *module_get_kallsym(unsigned int symnum, ...@@ -2031,9 +2029,8 @@ struct module *module_get_kallsym(unsigned int symnum,
if (symnum < mod->num_symtab) { if (symnum < mod->num_symtab) {
*value = mod->symtab[symnum].st_value; *value = mod->symtab[symnum].st_value;
*type = mod->symtab[symnum].st_info; *type = mod->symtab[symnum].st_info;
strncpy(namebuf, strlcpy(name, mod->strtab + mod->symtab[symnum].st_name,
mod->strtab + mod->symtab[symnum].st_name, namelen);
127);
mutex_unlock(&module_mutex); mutex_unlock(&module_mutex);
return mod; return mod;
} }
......
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