提交 9f2d1e68 编写于 作者: J Jessica Yu

module: exclude SHN_UNDEF symbols from kallsyms api

Livepatch modules are special in that we preserve their entire symbol
tables in order to be able to apply relocations after module load. The
unwanted side effect of this is that undefined (SHN_UNDEF) symbols of
livepatch modules are accessible via the kallsyms api and this can
confuse symbol resolution in livepatch (klp_find_object_symbol()) and
cause subtle bugs in livepatch.

Have the module kallsyms api skip over SHN_UNDEF symbols. These symbols
are usually not available for normal modules anyway as we cut down their
symbol tables to just the core (non-undefined) symbols, so this should
really just affect livepatch modules. Note that this patch doesn't
affect the display of undefined symbols in /proc/kallsyms.
Reported-by: NJosh Poimboeuf <jpoimboe@redhat.com>
Tested-by: NJosh Poimboeuf <jpoimboe@redhat.com>
Reviewed-by: NJosh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: NJessica Yu <jeyu@kernel.org>
上级 ce397d21
...@@ -4067,7 +4067,7 @@ static unsigned long mod_find_symname(struct module *mod, const char *name) ...@@ -4067,7 +4067,7 @@ static unsigned long mod_find_symname(struct module *mod, const char *name)
for (i = 0; i < kallsyms->num_symtab; i++) for (i = 0; i < kallsyms->num_symtab; i++)
if (strcmp(name, symname(kallsyms, i)) == 0 && if (strcmp(name, symname(kallsyms, i)) == 0 &&
kallsyms->symtab[i].st_info != 'U') kallsyms->symtab[i].st_shndx != SHN_UNDEF)
return kallsyms->symtab[i].st_value; return kallsyms->symtab[i].st_value;
return 0; return 0;
} }
...@@ -4113,6 +4113,10 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, ...@@ -4113,6 +4113,10 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
if (mod->state == MODULE_STATE_UNFORMED) if (mod->state == MODULE_STATE_UNFORMED)
continue; continue;
for (i = 0; i < kallsyms->num_symtab; i++) { for (i = 0; i < kallsyms->num_symtab; i++) {
if (kallsyms->symtab[i].st_shndx == SHN_UNDEF)
continue;
ret = fn(data, symname(kallsyms, i), ret = fn(data, symname(kallsyms, i),
mod, kallsyms->symtab[i].st_value); mod, kallsyms->symtab[i].st_value);
if (ret != 0) if (ret != 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册