Skip to content

Commit 9f2d1e6

Browse files
author
Jessica Yu
committed
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: Josh Poimboeuf <jpoimboe@redhat.com> Tested-by: Josh Poimboeuf <jpoimboe@redhat.com> Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Jessica Yu <jeyu@kernel.org>
1 parent ce397d2 commit 9f2d1e6

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎kernel/module.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4067,7 +4067,7 @@ static unsigned long mod_find_symname(struct module *mod, const char *name)
40674067

40684068
for (i = 0; i < kallsyms->num_symtab; i++)
40694069
if (strcmp(name, symname(kallsyms, i)) == 0 &&
4070-
kallsyms->symtab[i].st_info != 'U')
4070+
kallsyms->symtab[i].st_shndx != SHN_UNDEF)
40714071
return kallsyms->symtab[i].st_value;
40724072
return 0;
40734073
}
@@ -4113,6 +4113,10 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
41134113
if (mod->state == MODULE_STATE_UNFORMED)
41144114
continue;
41154115
for (i = 0; i < kallsyms->num_symtab; i++) {
4116+
4117+
if (kallsyms->symtab[i].st_shndx == SHN_UNDEF)
4118+
continue;
4119+
41164120
ret = fn(data, symname(kallsyms, i),
41174121
mod, kallsyms->symtab[i].st_value);
41184122
if (ret != 0)

0 commit comments

Comments
 (0)