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 <will@kernel.org>
Signed-off-by: Will Deacon <willdeacon@google.com>
Bug: 261855285
Change-Id: Idc24f95881c520b40038f77cd5af5ccc1d23624f
This commit is contained in:
Will Deacon
2023-01-05 23:24:26 +00:00
committed by Treehugger Robot
parent 0ead19c440
commit b17ff311f3

View File

@@ -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,