mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [tip: objtool/core] objtool/klp: Reject changed functions without an ftrace call site
       [not found] <20261022171637.3298443-3-puranjay@kernel.org>
@ 2026-11-25  8:40 ` tip-bot2 for Puranjay Mohan
  0 siblings, 0 replies; only message in thread
From: tip-bot2 for Puranjay Mohan @ 2026-11-25  8:40 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Puranjay Mohan, Joe Lawrence, Song Liu, Josh Poimboeuf, x86,
	linux-kernel

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

Commit-ID:     dee7e5a566e777ec9c5d1dfc61bc1320412cab46
Gitweb:        https://git.kernel.org/tip/dee7e5a566e777ec9c5d1dfc61bc1320412cab46
Author:        Puranjay Mohan <puranjay@kernel.org>
AuthorDate:    Thu, 22 Oct 2026 10:16:35 -07:00
Committer:     Josh Poimboeuf <jpoimboe@kernel.org>
CommitterDate: Sat, 21 Nov 2026 23:38:31 -08:00

objtool/klp: Reject changed functions without an ftrace call site

Livepatch redirects a function through its ftrace call site.  If a
changed function doesn't have one, klp-build succeeds but the patch
module fails to load:

  livepatch: failed to find location for function 'nsproxy_free'
  livepatch: failed to patch object 'vmlinux'
  livepatch: failed to enable patch 'livepatch_nsproxy'

This is easy to hit because the kernel's 'inline' implies notrace, so
any inline function which the compiler emits out of line can't be
patched.

Make klp diff fail for any changed function which has no __mcount_loc
entry in the original object.

Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
Acked-by: Song Liu <song@kernel.org>
Link: https://patch.msgid.link/20261022171637.3298443-3-puranjay@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 tools/objtool/include/objtool/elf.h |  1 +-
 tools/objtool/klp-diff.c            | 44 ++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+)

diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index a82517a..f7e6a65 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -98,6 +98,7 @@ struct symbol {
 	u8 klp		     : 1;
 	u8 dont_correlate    : 1;
 	u8 fake		     : 1;
+	u8 traceable	     : 1;
 	struct list_head pv_target;
 	struct reloc *relocs;
 	struct section *group_sec;
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 34da55e..95d0d86 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -1098,6 +1098,47 @@ static int mark_changed_functions(struct elfs *e)
 	return !changed ? 1 : 0;
 }
 
+static void mark_traceable_functions(struct elf *elf)
+{
+	struct section *sec;
+	struct reloc *reloc;
+
+	sec = find_section_by_name(elf, "__mcount_loc");
+	if (!sec || !sec->rsec)
+		return;
+
+	for_each_reloc(sec->rsec, reloc) {
+		struct symbol *func;
+
+		func = find_func_containing(reloc->sym->sec,
+					    reloc->sym->offset + reloc_addend(reloc));
+		if (func)
+			func->traceable = 1;
+	}
+}
+
+/*
+ * Livepatch redirects functions through their ftrace call sites, so a function
+ * without one can't be patched.
+ */
+static int validate_traceable_functions(struct elfs *e)
+{
+	struct symbol *patched_sym;
+	bool error = false;
+
+	mark_traceable_functions(e->orig);
+
+	for_each_sym(e->patched, patched_sym) {
+		if (!patched_sym->changed || patched_sym->twin->traceable)
+			continue;
+
+		ERROR("%s: no ftrace call site, can't patch", patched_sym->twin->name);
+		error = true;
+	}
+
+	return error ? -1 : 0;
+}
+
 static int clone_included_functions(struct elfs *e)
 {
 	struct symbol *patched_sym;
@@ -2260,6 +2301,9 @@ int cmd_klp_diff(int argc, const char **argv)
 	if (ret > 0)
 		return 0;
 
+	if (validate_traceable_functions(&e))
+		return -1;
+
 	e.out = elf_create_file(&e.orig->ehdr, argv[2]);
 	if (!e.out)
 		return -1;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-25  8:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20261022171637.3298443-3-puranjay@kernel.org>
2026-11-25  8:40 ` [tip: objtool/core] objtool/klp: Reject changed functions without an ftrace call site tip-bot2 for Puranjay Mohan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®