From d8a2860b4a366bfa8acb3d64da2c546ea26d2091 Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Fri, 14 Aug 2026 19:36:34 -0700 Subject: objtool/klp: Fix vmlinux klp relocations for EXPORT_SYMBOL_FOR_MODULES() When a module function references a vmlinux symbol which is exported with EXPORT_SYMBOL_FOR_MODULES(), a patch to that function needs to use a klp reloc. Currently, livepatch fails to load such a module: livepatch: invalid access to vmlinux symbol 'get_task_policy' from module-specific livepatch relocation section livepatch: failed to initialize patch 'livepatch_test' for module 'testmod' (-22) livepatch: patch 'livepatch_test' failed for module 'testmod', refusing to load module 'testmod' klp diff puts all klp relocs in __klp_relocs., so post-link names the section .klp.rela.., which the kernel rejects for vmlinux symbols. Commit 07f14d6af9d77 ("objtool/klp: Fix cross-module klp relocation section naming") changed the meaning of objname in the klp rela section name to be where the referenced symbol is referenced rather than where it lives. That premise only holds for symbols in a module: the relocs get applied when the patched module gets patched, and the module dependency guarantees the referenced module is loaded by then. A vmlinux symbol needs the opposite. It's always resolvable, and it has to be applied when the patch module loads, before the module loader initializes the patch module's special sections, which may reference it. That's why livepatch rejects vmlinux symbols in module-specific sections. Use "vmlinux" as the section objname when the referenced symbol lives in vmlinux. This moves such klp relocs from .klp.rela.kvm..text to .klp.rela.vmlinux..text. Fixes: 07f14d6af9d77 ("objtool/klp: Fix cross-module klp relocation section naming") Reported-by: Dylan Hatch Signed-off-by: Josh Poimboeuf Signed-off-by: Ingo Molnar Acked-by: Song Liu Link: https://patch.msgid.link/f8e3b9fae109903a6aafb2a33310e4afdcebf58e.1786761327.git.jpoimboe@kernel.org Closes: https://lore.kernel.org/CADBMgpz7iWC0=t=_gE-tfvv0mTPq4kg0qQ2zgPH8DVPE6eQ9Kw@mail.gmail.com --- tools/objtool/include/objtool/klp.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tools/objtool/include') diff --git a/tools/objtool/include/objtool/klp.h b/tools/objtool/include/objtool/klp.h index 646d8e1f12ef..c57775d78c71 100644 --- a/tools/objtool/include/objtool/klp.h +++ b/tools/objtool/include/objtool/klp.h @@ -20,8 +20,9 @@ * SHF_RELA_LIVEPATCH, nor does it support having two RELA sections for a * single PROGBITS section. * - * "objname" is the name of the object being patched ("vmlinux" or a module - * name). post-link uses it to name the resulting + * "objname" is the object whose loading gates the relocation: "vmlinux" for + * references to vmlinux symbols, otherwise the name of the module being + * patched. post-link uses it to name the resulting * .klp.rela.objname.section_name sections. */ #define KLP_RELOCS_SEC "__klp_relocs" -- cgit v1.2.3