Commit eea8b54d authored by Ashutosh Naik's avatar Ashutosh Naik Committed by Linus Torvalds

[PATCH] modules: prevent overriding of symbols

Ensure that an exported symbol does not already exist in the kernel or in
some other module's exported symbol table.  This is done by checking the
symbol tables for the exported symbol at the time of loading the module.
Currently this is done after the relocation of the symbol.
Signed-off-by: default avatarAshutosh Naik <ashutosh.naik@gmail.com>
Signed-off-by: default avatarAnand Krishnan <anandhkrishnan@yahoo.co.in>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent b368fae6
...@@ -1204,6 +1204,39 @@ void *__symbol_get(const char *symbol) ...@@ -1204,6 +1204,39 @@ void *__symbol_get(const char *symbol)
} }
EXPORT_SYMBOL_GPL(__symbol_get); EXPORT_SYMBOL_GPL(__symbol_get);
/*
* Ensure that an exported symbol [global namespace] does not already exist
* in the Kernel or in some other modules exported symbol table.
*/
static int verify_export_symbols(struct module *mod)
{
const char *name = NULL;
unsigned long i, ret = 0;
struct module *owner;
const unsigned long *crc;
for (i = 0; i < mod->num_syms; i++)
if (__find_symbol(mod->syms[i].name, &owner, &crc, 1)) {
name = mod->syms[i].name;
ret = -ENOEXEC;
goto dup;
}
for (i = 0; i < mod->num_gpl_syms; i++)
if (__find_symbol(mod->gpl_syms[i].name, &owner, &crc, 1)) {
name = mod->gpl_syms[i].name;
ret = -ENOEXEC;
goto dup;
}
dup:
if (ret)
printk(KERN_ERR "%s: exports duplicate symbol %s (owned by %s)\n",
mod->name, name, module_name(owner));
return ret;
}
/* Change all symbols so that sh_value encodes the pointer directly. */ /* Change all symbols so that sh_value encodes the pointer directly. */
static int simplify_symbols(Elf_Shdr *sechdrs, static int simplify_symbols(Elf_Shdr *sechdrs,
unsigned int symindex, unsigned int symindex,
...@@ -1772,6 +1805,12 @@ static struct module *load_module(void __user *umod, ...@@ -1772,6 +1805,12 @@ static struct module *load_module(void __user *umod,
goto cleanup; goto cleanup;
} }
/* Find duplicate symbols */
err = verify_export_symbols(mod);
if (err < 0)
goto cleanup;
/* Set up and sort exception table */ /* Set up and sort exception table */
mod->num_exentries = sechdrs[exindex].sh_size / sizeof(*mod->extable); mod->num_exentries = sechdrs[exindex].sh_size / sizeof(*mod->extable);
mod->extable = extable = (void *)sechdrs[exindex].sh_addr; mod->extable = extable = (void *)sechdrs[exindex].sh_addr;
......
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