Commit 7fdaa121 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] fix modversions now __this_module is created only in .ko

From: Rusty Russell <rusty@rustcorp.com.au>

Brian Gerst's patch which moved __this_module out from module.h into the
module post-processing had a side effect.  genksyms didn't see the
undefined symbols for modules without a module_init (or module_exit), and
hence didn't generate a version for them, causing the kernel to be tainted.

The simple solution is to always include the versions for these functions. 
Also includes two cleanups:

1) alloc_symbol is easier to use if it populates ->next for us.

2) add_exported_symbol should set owner to module, not head of module
   list (we don't use this field in entries in that list, fortunately).
parent 7ee168c0
...@@ -113,12 +113,13 @@ static inline unsigned int tdb_hash(const char *name) ...@@ -113,12 +113,13 @@ static inline unsigned int tdb_hash(const char *name)
* the list of unresolved symbols per module */ * the list of unresolved symbols per module */
struct symbol * struct symbol *
alloc_symbol(const char *name) alloc_symbol(const char *name, struct symbol *next)
{ {
struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1)); struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1));
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
strcpy(s->name, name); strcpy(s->name, name);
s->next = next;
return s; return s;
} }
...@@ -128,17 +129,15 @@ void ...@@ -128,17 +129,15 @@ void
new_symbol(const char *name, struct module *module, unsigned int *crc) new_symbol(const char *name, struct module *module, unsigned int *crc)
{ {
unsigned int hash; unsigned int hash;
struct symbol *new = alloc_symbol(name); struct symbol *new;
hash = tdb_hash(name) % SYMBOL_HASH_SIZE;
new = symbolhash[hash] = alloc_symbol(name, symbolhash[hash]);
new->module = module; new->module = module;
if (crc) { if (crc) {
new->crc = *crc; new->crc = *crc;
new->crc_valid = 1; new->crc_valid = 1;
} }
hash = tdb_hash(name) % SYMBOL_HASH_SIZE;
new->next = symbolhash[hash];
symbolhash[hash] = new;
} }
struct symbol * struct symbol *
...@@ -165,7 +164,7 @@ add_exported_symbol(const char *name, struct module *module, unsigned int *crc) ...@@ -165,7 +164,7 @@ add_exported_symbol(const char *name, struct module *module, unsigned int *crc)
struct symbol *s = find_symbol(name); struct symbol *s = find_symbol(name);
if (!s) { if (!s) {
new_symbol(name, modules, crc); new_symbol(name, module, crc);
return; return;
} }
if (crc) { if (crc) {
...@@ -319,7 +318,6 @@ void ...@@ -319,7 +318,6 @@ void
handle_modversions(struct module *mod, struct elf_info *info, handle_modversions(struct module *mod, struct elf_info *info,
Elf_Sym *sym, const char *symname) Elf_Sym *sym, const char *symname)
{ {
struct symbol *s;
unsigned int crc; unsigned int crc;
switch (sym->st_shndx) { switch (sym->st_shndx) {
...@@ -356,13 +354,10 @@ handle_modversions(struct module *mod, struct elf_info *info, ...@@ -356,13 +354,10 @@ handle_modversions(struct module *mod, struct elf_info *info,
#endif #endif
if (memcmp(symname, MODULE_SYMBOL_PREFIX, if (memcmp(symname, MODULE_SYMBOL_PREFIX,
strlen(MODULE_SYMBOL_PREFIX)) == 0) { strlen(MODULE_SYMBOL_PREFIX)) == 0)
s = alloc_symbol(symname + mod->unres = alloc_symbol(symname +
strlen(MODULE_SYMBOL_PREFIX)); strlen(MODULE_SYMBOL_PREFIX),
/* add to list */ mod->unres);
s->next = mod->unres;
mod->unres = s;
}
break; break;
default: default:
/* All exported symbols */ /* All exported symbols */
...@@ -393,7 +388,6 @@ read_symbols(char *modname) ...@@ -393,7 +388,6 @@ read_symbols(char *modname)
const char *symname; const char *symname;
struct module *mod; struct module *mod;
struct elf_info info = { }; struct elf_info info = { };
struct symbol *s;
Elf_Sym *sym; Elf_Sym *sym;
/* When there's no vmlinux, don't print warnings about /* When there's no vmlinux, don't print warnings about
...@@ -419,10 +413,12 @@ read_symbols(char *modname) ...@@ -419,10 +413,12 @@ read_symbols(char *modname)
* the automatic versioning doesn't pick it up, but it's really * the automatic versioning doesn't pick it up, but it's really
* important anyhow */ * important anyhow */
if (modversions) { if (modversions) {
s = alloc_symbol("struct_module"); mod->unres = alloc_symbol("struct_module", mod->unres);
/* add to list */
s->next = mod->unres; /* Always version init_module and cleanup_module, in
mod->unres = s; * case module doesn't have its own. */
mod->unres = alloc_symbol("init_module", mod->unres);
mod->unres = alloc_symbol("cleanup_module", mod->unres);
} }
} }
......
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