hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8MGE6
---------------------------
In the older version of livepatch implementation without ftrace on arm, it use klp_relocs and do special relocation for klp syms. The kpatch-build front-tools use kpatch version to generate klp_relocs.
After commit 7c8e2bdd5f0d ("livepatch: Apply vmlinux-specific KLP relocations early") and commit 425595a7fc20 ("livepatch: reuse module loader code to write relocations"), the mainline klp relocation flow is always using ".klp.rela." section and kpatch-build front-tools use klp version to generate klp module.
The default klp_apply_section_relocs is only for 64bit and modules with rela support. Because CONFIG_MODULES_USE_ELF_REL is set in arm, so we modify klp relocation to support 32bit and modules using rel. Also the kpatch-build front-tools should adapter to support this.
Signed-off-by: Dong Kai dongkai11@huawei.com Signed-off-by: Zheng Yejian zhengyejian1@huawei.com --- kernel/livepatch/core.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index e8310c06751e..f06175c2dd1c 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -213,7 +213,11 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab, int i, cnt, ret; char sym_objname[MODULE_NAME_LEN]; char sym_name[KSYM_NAME_LEN]; +#ifdef CONFIG_MODULES_USE_ELF_RELA Elf_Rela *relas; +#else + Elf_Rel *relas; +#endif Elf_Sym *sym; unsigned long sympos, addr; bool sym_vmlinux; @@ -231,9 +235,13 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab, */ BUILD_BUG_ON(MODULE_NAME_LEN < 56 || KSYM_NAME_LEN != 512);
+#ifdef CONFIG_MODULES_USE_ELF_RELA relas = (Elf_Rela *) relasec->sh_addr; +#else + relas = (Elf_Rel *) relasec->sh_addr; +#endif /* For each rela in this klp relocation section */ - for (i = 0; i < relasec->sh_size / sizeof(Elf_Rela); i++) { + for (i = 0; i < relasec->sh_size / sizeof(*relas); i++) { sym = (Elf_Sym *)sechdrs[symndx].sh_addr + ELF_R_SYM(relas[i].r_info); if (sym->st_shndx != SHN_LIVEPATCH) { pr_err("symbol %s is not marked as a livepatch symbol\n", @@ -341,7 +349,11 @@ static int klp_write_section_relocs(struct module *pmod, Elf_Shdr *sechdrs, if (ret) return ret;
+#ifdef CONFIG_MODULES_USE_ELF_RELA return apply_relocate_add(sechdrs, strtab, symndx, secndx, pmod); +#else + return apply_relocate(sechdrs, strtab, symndx, secndx, pmod); +#endif }
#ifdef CONFIG_LIVEPATCH_FTRACE