From b17ff311f3cc2c812901ca85260e533474f14271 Mon Sep 17 00:00:00 2001 From: Will Deacon Date: Thu, 5 Jan 2023 23:24:26 +0000 Subject: [PATCH] ANDROID: KVM: arm64: Ignore modules with empty .hyp.text section Modules with an empty '.hyp.text' section do not contain any EL2 code and should therefore be ignored for the purposes of hypervisor module loading. Failing to ignore such modules will likely result in a later loading failure due to the absence of '.hyp.reloc', which is not present for non-hypervisor modules. Don't bother parsing the other '.hyp.*' sections for modules with an empty '.hyp.text' section and return early success to allow the module to load as a normal kernel module. Fixes: 3dc729d157a7 ("ANDROID: KVM: arm64: Resolve hyp module addresses using ELF sections") Signed-off-by: Will Deacon Signed-off-by: Will Deacon Bug: 261855285 Change-Id: Idc24f95881c520b40038f77cd5af5ccc1d23624f --- arch/arm64/kernel/module.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index 1f10cd529b48..e727c51a53eb 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -511,9 +511,13 @@ static int module_init_hyp(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, #ifdef CONFIG_KVM const Elf_Shdr *s; + /* + * If the .hyp.text is missing or empty, this is not a hypervisor + * module so ignore the rest of it. + */ s = find_section(hdr, sechdrs, ".hyp.text"); - if (!s) - return -ENOEXEC; + if (!s || !s->sh_size) + return 0; mod->arch.hyp.text = (struct pkvm_module_section) { .start = (void *)s->sh_addr,