linux/tools/objtool
Josh Poimboeuf d8a2860b4a 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.<patched object>, so
post-link names the section .klp.rela.<patched object>.<secname>, which the
kernel rejects for vmlinux symbols.

Commit 07f14d6af9 ("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: 07f14d6af9 ("objtool/klp: Fix cross-module klp relocation section naming")
Reported-by: Dylan Hatch <dylanbhatch@google.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Song Liu <song@kernel.org>
Link: https://patch.msgid.link/f8e3b9fae109903a6aafb2a33310e4afdcebf58e.1786761327.git.jpoimboe@kernel.org
Closes: https://lore.kernel.org/CADBMgpz7iWC0=t=_gE-tfvv0mTPq4kg0qQ2zgPH8DVPE6eQ9Kw@mail.gmail.com
2026-08-17 10:53:55 +02:00
..
arch objtool/klp: Ignore replacement offset of empty x86 alternatives 2026-08-11 15:04:57 -07:00
Documentation Revert "objtool: Warn on functions with ambiguous -ffunction-sections section names" 2025-11-21 10:04:10 +01:00
include/objtool objtool/klp: Fix vmlinux klp relocations for EXPORT_SYMBOL_FOR_MODULES() 2026-08-17 10:53:55 +02:00
.gitignore objtool: Add Function to get the name of a CPU feature 2025-11-24 20:39:47 +01:00
Build objtool/klp: Fix symbol resolution for duplicate data symbols 2026-08-03 07:12:39 +02:00
builtin-check.c objtool/klp: Add .klp.symid for sympos disambiguation 2026-08-03 07:12:39 +02:00
builtin-klp.c objtool/klp: Add "objtool klp checksum" subcommand 2026-05-04 21:16:05 -07:00
check.c objtool/klp: Add .klp.symid for sympos disambiguation 2026-08-03 07:12:39 +02:00
disas.c objtool: Add insn_sym() helper 2026-05-04 21:16:06 -07:00
elf.c objtool/klp: Fix false module dependencies caused by dead relocs 2026-08-03 07:12:38 +02:00
klp-checksum.c objtool/klp: Fix position-dependent checksums for non-relocated jumps/calls 2026-05-04 21:16:06 -07:00
klp-diff.c objtool/klp: Fix vmlinux klp relocations for EXPORT_SYMBOL_FOR_MODULES() 2026-08-17 10:53:55 +02:00
klp-post-link.c objtool/klp: Fix cross-module klp relocation section naming 2026-08-11 16:10:51 -07:00
klp-symid.c objtool/klp: Fix vmlinux .klp.symid link error for .exitcall.exit symbols 2026-08-12 13:33:32 -07:00
klp-sympos.c objtool/klp: Explicitly disallow patching or referencing init code/data 2026-08-11 16:10:38 -07:00
Makefile objtool: Include libsubcmd headers directly from source tree 2026-05-04 21:16:04 -07:00
noreturns.h x86/smpboot: Mark native_play_dead() as __noreturn 2025-10-30 08:29:41 -07:00
objtool.c objtool/klp: Add correlation debugging output 2026-05-04 21:16:06 -07:00
orc_dump.c objtool: Add annotype() helper 2025-10-14 14:46:49 -07:00
orc_gen.c objtool: Add annotype() helper 2025-10-14 14:46:49 -07:00
signal.c objtool: Add more robust signal error handling, detect and warn about stack overflows 2025-12-03 19:42:37 +01:00
special.c objtool: Provide access to feature and flags of group alternatives 2025-11-21 15:30:14 +01:00
sync-check.sh objtool/klp: Introduce klp diff subcommand for diffing object files 2025-10-14 14:50:18 -07:00
trace.c objtool: Add insn_sym() helper 2026-05-04 21:16:06 -07:00
weak.c objtool/klp: Introduce klp diff subcommand for diffing object files 2025-10-14 14:50:18 -07:00