From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-cys01nam02on0126.outbound.protection.outlook.com ([104.47.37.126]:15104 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731028AbeIQIb4 (ORCPT ); Mon, 17 Sep 2018 04:31:56 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Jessica Yu , Sasha Levin Subject: [PATCH AUTOSEL 4.9 53/57] module: exclude SHN_UNDEF symbols from kallsyms api Date: Mon, 17 Sep 2018 03:04:16 +0000 Message-ID: <20180917030340.378-53-alexander.levin@microsoft.com> References: <20180917030340.378-1-alexander.levin@microsoft.com> In-Reply-To: <20180917030340.378-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Jessica Yu [ Upstream commit 9f2d1e68cf4d641def734adaccfc3823d3575e6c ] 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 Tested-by: Josh Poimboeuf Reviewed-by: Josh Poimboeuf Signed-off-by: Jessica Yu Signed-off-by: Sasha Levin --- kernel/module.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/module.c b/kernel/module.c index 0651f2d25fc9..2325c9821f2a 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -4011,7 +4011,7 @@ static unsigned long mod_find_symname(struct module *= mod, const char *name) =20 for (i =3D 0; i < kallsyms->num_symtab; i++) if (strcmp(name, symname(kallsyms, i)) =3D=3D 0 && - kallsyms->symtab[i].st_info !=3D 'U') + kallsyms->symtab[i].st_shndx !=3D SHN_UNDEF) return kallsyms->symtab[i].st_value; return 0; } @@ -4057,6 +4057,10 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *,= const char *, if (mod->state =3D=3D MODULE_STATE_UNFORMED) continue; for (i =3D 0; i < kallsyms->num_symtab; i++) { + + if (kallsyms->symtab[i].st_shndx =3D=3D SHN_UNDEF) + continue; + ret =3D fn(data, symname(kallsyms, i), mod, kallsyms->symtab[i].st_value); if (ret !=3D 0) --=20 2.17.1