[Devel] [PATCH hci-8.2 v2 14/28] objtool/klp: use the section symbol for .rodata labels

Eva Kurchatova eva.kurchatova at virtuozzo.com
Thu Nov 26 08:07:13 MSK 2026


Since "objtool/klp: Fix pointer comparisons for rodata objects", a
reference to .rodata keeps its symbol instead of the section symbol.
Asm puts global labels without a size there, such as the
uretprobe_trampoline_entry and uretprobe_trampoline_end pair. They are
not correlated, so the livepatch gets a copy of each of length 0, and
both land at one address: a patched arch_uprobe_trampoline() then works
on garbage.

Reference a non-object symbol in .rodata through the section symbol
again, as before that commit, so that the whole section is cloned.

A section copy which follows one of its objects in the output does not
start at the section symbol, and references to it, or to anonymous
.rodata data, then point into that object. Fail klp diff instead; with
the opposite reference order the object only gets a second copy.

https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support

Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
---
 tools/objtool/klp-diff.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 2f1cedf9632b..5122a3b51196 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -535,6 +535,11 @@ static struct symbol *__clone_symbol(struct elf *elf, struct symbol *patched_sym
 
 		if (!is_sec_sym(patched_sym))
 			offset = ALIGN(sec_size(out_sec), out_sec->sh.sh_addralign);
+		else if (sec_size(patched_sec) && sec_size(out_sec)) {
+			/* The copy would not start at the section symbol */
+			ERROR("can't clone section %s after one of its symbols", patched_sec->name);
+			return NULL;
+		}
 
 		if (patched_sym->len || is_sec_sym(patched_sym)) {
 			void *data = NULL;
@@ -897,6 +902,10 @@ static int convert_reloc_sym(struct elf *elf, struct reloc *reloc)
 	if (is_uncorrelated_section(sec))
 		return convert_reloc_sym_to_secsym(elf, reloc);
 
+	/* Non-object .rodata symbols, like asm labels, may have no size: clone the section */
+	if (is_rodata_sec(sec) && !is_sec_sym(reloc->sym) && !is_object_sym(reloc->sym))
+		return convert_reloc_sym_to_secsym(elf, reloc);
+
 	/* Everything else: references should use named symbols. */
 	return convert_reloc_secsym_to_sym(elf, reloc);
 }
-- 
2.56.1



More information about the Devel mailing list