[Devel] [PATCH hci-8.2 6/6] ms/objtool/klp: Fix checksums for constant pool references

Konstantin Khorenko khorenko at virtuozzo.com
Fri Nov 27 00:51:21 MSK 2026


From: Josh Poimboeuf <jpoimboe at kernel.org>

Adding a line of code to __link_shadow_page() with a literal string
causes a false positive changed function with GCC:

  arch/x86/kvm/kvm.ko.o: changed function: kvm_tdp_mmu_map_private_pfn

While the patch only touched __link_shadow_page(), the string addition
triggered a rename of .LC64 -> .LC65 in kvm_tdp_mmu_map_private_pfn()
even though the underlying referenced constant data didn't change.

So for .LC* symbols, the suffix is arbitrary but the data isn't.  Add
the underlying data to the checksum calculation rather than the symbol
name.

Clang also uses .LC* symbols, but also uses anonymous data.  Both
compilers put this data in .rodata.cst<num> sections.

Fixes: 0d83da43b1e1 ("objtool/klp: Add --checksum option to generate per-function checksums")
Link: https://patch.msgid.link/f3a9e74ceebc6475ce94bcfe985401140857814a.1787939301.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe at kernel.org>
[khorenko@:
 - 26.x has no klp-checksum.c yet, ported into check.c
 - checksum_update() instead of __checksum_update_insn() and "return"
   instead of "goto alts": 26.x has neither]
(cherry picked from commit ac323c9467092479dc1e5bc138c9abbe015b0069)

https://virtuozzo.atlassian.net/browse/VSTOR-157128
Feature: klp-build support
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 tools/objtool/check.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 403da0d3739a6..17d6735032408 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -3633,6 +3633,19 @@ static int checksum_debug_init(struct objtool_file *file)
 	return 0;
 }
 
+/*
+ * Detect a reference to anonymous constant pool data which the compiler places
+ * in .rodata.cst<num> and which either has an .LC<num> symbol associated with
+ * it or (with Clang) no symbol at all.  These are typically initializers for
+ * local function stack data, so they're considered part of the function rather
+ * than data per se.
+ */
+static bool is_anonymous_const_data(struct symbol *sym)
+{
+	return strstarts(sym->sec->name, ".rodata.cst") &&
+	       (is_sec_sym(sym) || strstarts(sym->name, ".LC"));
+}
+
 static void checksum_update_insn(struct objtool_file *file, struct symbol *func,
 				 struct instruction *insn)
 {
@@ -3665,6 +3678,14 @@ static void checksum_update_insn(struct objtool_file *file, struct symbol *func,
 		return;
 	}
 
+	if (is_anonymous_const_data(sym)) {
+		void *cst;
+
+		cst = sym->sec->data->d_buf + sym->offset + offset;
+		checksum_update(func, insn, cst, sym->sec->sh.sh_entsize);
+		return;
+	}
+
 	if (is_sec_sym(sym)) {
 		sym = find_symbol_containing(reloc->sym->sec, offset);
 		if (!sym)

-- 
2.43.0



More information about the Devel mailing list