Live Patching
 help / color / mirror / Atom feed
From: "tip-bot2 for Josh Poimboeuf" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Ben Procknow <bprockno@redhat.com>,
	Joe Lawrence <joe.lawrence@redhat.com>,
	Josh Poimboeuf <jpoimboe@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	live-patching@vger.kernel.org, x86@kernel.org,
	linux-kernel@vger.kernel.org
Subject: [tip: objtool/core] objtool/klp: Fix false module dependencies caused by dead relocs
Date: Mon, 03 Aug 2026 05:49:42 -0000	[thread overview]
Message-ID: <178573618216.1210945.4485019859591624931.tip-bot2@tip-bot2> (raw)
In-Reply-To: <9548393f4d89ec3b498f4f69aa6ef6b9bb7150fe.1785727106.git.jpoimboe@kernel.org>

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     5ca8c91d1ea6534842e7e0065d15104d802506cd
Gitweb:        https://git.kernel.org/tip/5ca8c91d1ea6534842e7e0065d15104d802506cd
Author:        Josh Poimboeuf <jpoimboe@kernel.org>
AuthorDate:    Sun, 02 Aug 2026 20:24:25 -07:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 03 Aug 2026 07:12:38 +02:00

objtool/klp: Fix false module dependencies caused by dead relocs

When creating a klp reloc, klp-diff keeps the original relocation but
converts the referenced symbol to an UNDEF/WEAK placeholder tombstone
symbol, which gets fully disabled later by klp post-link.  The tombstone
symbol is only needed to avoid confusing objtool when it does the final
run on the patch module.

However, for references to exported symbols, modpost sees the reference
to the tombstone symbol as a real reference to an exported symbol,
resulting in a false module dependency getting created.

Further, for a reference to a tombstone symbol which is exported into a
module namespace, e.g. via EXPORT_SYMBOL_FOR_KVM_INTERNAL(), modpost
can't satisfy the dependency, resulting in a warning like the following:

  module ... uses symbol kvm_flush_remote_tlbs from namespace
  module:kvm-amd,kvm-intel, but does not import it.

Rename the placeholder tombstone symbols to ".klp.tombstone.<name>" so
modpost no longer recognizes them.

Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Reported-by: Ben Procknow <bprockno@redhat.com>
Reported-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: live-patching@vger.kernel.org
Link: https://lore.kernel.org/20260720145658.1103243-5-joe.lawrence@redhat.com
Link: https://patch.msgid.link/9548393f4d89ec3b498f4f69aa6ef6b9bb7150fe.1785727106.git.jpoimboe@kernel.org
---
 tools/objtool/elf.c                 | 13 +++++++++++++
 tools/objtool/include/objtool/klp.h |  2 ++
 tools/objtool/klp-diff.c            | 16 ++++++++++++----
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 33c95a7..a791f4e 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -23,6 +23,7 @@
 #include <linux/log2.h>
 #include <objtool/builtin.h>
 #include <objtool/elf.h>
+#include <objtool/klp.h>
 #include <objtool/warn.h>
 
 static ssize_t demangled_name_len(const char *name);
@@ -626,6 +627,18 @@ static int read_symbols(struct elf *elf)
 			return -1;
 		}
 
+		/*
+		 * "klp diff" renames the placeholder symbols of KLP relocs to
+		 * hide them from modpost.  Hide the prefix from the rest of
+		 * objtool so its many name-based heuristics (noreturns,
+		 * uaccess safe list, ...) still see the original symbol name.
+		 *
+		 * st_name is left alone, so the renamed symbol is preserved in
+		 * the output file.
+		 */
+		if (strstarts(sym->name, KLP_TOMBSTONE_PREFIX))
+			sym->name += strlen(KLP_TOMBSTONE_PREFIX);
+
 		if ((sym->sym.st_shndx > SHN_UNDEF &&
 		     sym->sym.st_shndx < SHN_LORESERVE) ||
 		    (shndx_data && sym->sym.st_shndx == SHN_XINDEX)) {
diff --git a/tools/objtool/include/objtool/klp.h b/tools/objtool/include/objtool/klp.h
index 6f60cf0..aab6db4 100644
--- a/tools/objtool/include/objtool/klp.h
+++ b/tools/objtool/include/objtool/klp.h
@@ -23,6 +23,8 @@
 #define KLP_RELOCS_SEC	"__klp_relocs"
 #define KLP_STRINGS_SEC	".rodata.klp.str1.1"
 
+#define KLP_TOMBSTONE_PREFIX	".klp.tombstone."
+
 struct klp_reloc {
 	void *offset;
 	void *sym;
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 15d37d9..75ba0e0 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -1362,6 +1362,7 @@ static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc,
 	s64 addend = reloc_addend(patched_reloc);
 	const char *sym_modname, *sym_orig_name;
 	static struct section *klp_relocs;
+	char tombstone_name[SYM_NAME_LEN];
 	struct symbol *sym, *klp_sym;
 	unsigned long klp_reloc_off;
 	char sym_name[SYM_NAME_LEN];
@@ -1376,15 +1377,22 @@ static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc,
 	/*
 	 * Keep the original reloc intact for now to avoid breaking objtool run
 	 * which relies on proper relocations for many of its features.  This
-	 * will be disabled later by "objtool klp post-link".
+	 * reloc now targets a functionally dead tombstone symbol and will be
+	 * disabled later by "objtool klp post-link".
 	 *
-	 * Convert it to UNDEF (and WEAK to avoid modpost warnings).
+	 * Convert the symbol to UNDEF/WEAK and rename to
+	 * .klp.tombstone.sym_name to prevent modpost from printing warnings or
+	 * creating false module dependencies.  The prefix is hidden from the
+	 * objtool run itself by read_symbols().
 	 */
 
 	sym = patched_sym->clone;
 	if (!sym) {
-		/* STB_WEAK: avoid modpost undefined symbol warnings */
-		sym = elf_create_symbol(e->out, patched_sym->name, NULL,
+		if (snprintf_check(tombstone_name, SYM_NAME_LEN,
+				   KLP_TOMBSTONE_PREFIX "%s", patched_sym->name))
+			return -1;
+
+		sym = elf_create_symbol(e->out, tombstone_name, NULL,
 					STB_WEAK, patched_sym->type, 0, 0);
 		if (!sym)
 			return -1;

  reply	other threads:[~2026-08-03  5:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03  3:24 [PATCH 00/14] objtool/klp: sympos/module/alternative/etc fixes Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 01/14] objtool/klp: Fix module name normalization for paths with dots Josh Poimboeuf
2026-08-03  5:49   ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 02/14] objtool/klp: Normalize Module.symvers paths to module names Josh Poimboeuf
2026-08-03  5:49   ` [tip: objtool/core] " tip-bot2 for Joe Lawrence
2026-08-03  3:24 ` [PATCH 03/14] objtool/klp: Fix false module dependencies caused by dead relocs Josh Poimboeuf
2026-08-03  5:49   ` tip-bot2 for Josh Poimboeuf [this message]
2026-08-03  3:24 ` [PATCH 04/14] objtool/klp: Skip hidden directories when finding objects Josh Poimboeuf
2026-08-03  5:49   ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 05/14] objtool/klp: Add .klp.symid for sympos disambiguation Josh Poimboeuf
2026-08-03  5:49   ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-03  6:12     ` sashiko-bot
2026-08-03  3:24 ` [PATCH 06/14] objtool/klp: Fix symbol resolution for duplicate data symbols Josh Poimboeuf
2026-08-03  5:49   ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 07/14] module: Add module_kallsyms_on_each_core_symbol() Josh Poimboeuf
2026-08-03  6:24   ` Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 08/14] objtool/klp,livepatch: Resolve module symbols against core kallsyms Josh Poimboeuf
2026-08-03  6:26   ` Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 09/14] objtool/klp: Fix size of empty special section entries Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 10/14] objtool/klp: Ignore replacement offset of empty x86 alternatives Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 11/14] objtool/klp: Explicitly disallow patching or referencing init code/data Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 12/14] objtool/klp: Fix cross-module klp relocation section naming Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 13/14] objtool/klp: Don't match local symbols against exports Josh Poimboeuf
2026-08-03  3:24 ` [PATCH 14/14] objtool/klp: Allow new references to module exports Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=178573618216.1210945.4485019859591624931.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=bprockno@redhat.com \
    --cc=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox