aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
authorJessica Yu <jeyu@kernel.org>2018-06-05 04:22:52 -0400
committerJessica Yu <jeyu@kernel.org>2018-06-18 04:04:03 -0400
commit9f2d1e68cf4d641def734adaccfc3823d3575e6c (patch)
tree8febb7c0433318d4fb69ccbf0f5147ca766028c5 /kernel/module.c
parentce397d215ccd07b8ae3f71db689aedb85d56ab40 (diff)
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>
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/kernel/module.c b/kernel/module.c
index f475f30eed8c..4a6b9c6d5f2c 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -4067,7 +4067,7 @@ static unsigned long mod_find_symname(struct module *mod, const char *name)
4067 4067
4068 for (i = 0; i < kallsyms->num_symtab; i++) 4068 for (i = 0; i < kallsyms->num_symtab; i++)
4069 if (strcmp(name, symname(kallsyms, i)) == 0 && 4069 if (strcmp(name, symname(kallsyms, i)) == 0 &&
4070 kallsyms->symtab[i].st_info != 'U') 4070 kallsyms->symtab[i].st_shndx != SHN_UNDEF)
4071 return kallsyms->symtab[i].st_value; 4071 return kallsyms->symtab[i].st_value;
4072 return 0; 4072 return 0;
4073} 4073}
@@ -4113,6 +4113,10 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
4113 if (mod->state == MODULE_STATE_UNFORMED) 4113 if (mod->state == MODULE_STATE_UNFORMED)
4114 continue; 4114 continue;
4115 for (i = 0; i < kallsyms->num_symtab; i++) { 4115 for (i = 0; i < kallsyms->num_symtab; i++) {
4116
4117 if (kallsyms->symtab[i].st_shndx == SHN_UNDEF)
4118 continue;
4119
4116 ret = fn(data, symname(kallsyms, i), 4120 ret = fn(data, symname(kallsyms, i),
4117 mod, kallsyms->symtab[i].st_value); 4121 mod, kallsyms->symtab[i].st_value);
4118 if (ret != 0) 4122 if (ret != 0)