From: "tip-bot2 for Joe Lawrence" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Joe Lawrence <joe.lawrence@redhat.com>,
Song Liu <song@kernel.org>, Josh Poimboeuf <jpoimboe@kernel.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: objtool/core] objtool/klp: Allow new references to module exports
Date: Thu, 13 Aug 2026 11:16:25 -0000 [thread overview]
Message-ID: <178661978505.442315.10029160471506962682.tip-bot2@tip-bot2> (raw)
In-Reply-To: <e0d725acb4774747f0e271308b4ca33daae2d5db.1786138493.git.jpoimboe@kernel.org>
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 72d76d0c18ebd40f6a32df875ff40528564849c1
Gitweb: https://git.kernel.org/tip/72d76d0c18ebd40f6a32df875ff40528564849c1
Author: Joe Lawrence <joe.lawrence@redhat.com>
AuthorDate: Fri, 07 Aug 2026 14:37:52 -07:00
Committer: Josh Poimboeuf <jpoimboe@kernel.org>
CommitterDate: Tue, 11 Aug 2026 16:10:51 -07:00
objtool/klp: Allow new references to module exports
klp_reloc_needed() returns true for module exports to support
late-module patching. However, clone_reloc_klp() unconditionally
rejects symbols without a twin (i.e., new references added by the
patch), even when the symbol is a known export from Module.symvers.
Relax the check: allow new references to exported symbols by only
erroring on !twin when there is no export. The export metadata from
Module.symvers provides sufficient context to emit the klp-relocation
without a twin.
For a module export that isn't sufficient on its own though, as the
resulting klp relocation will only be resolved at patch-enable time if
the exporting module is loaded.
If the original (unpatched) module already depends on the exporting
module, the dependency is safe: the module loader ensures the dependency
is satisfied before the patched module can be loaded, so the
klp relocation target will exist.
However, if the patch introduces a reference to a module that the
original doesn't depend on, there is no such guarantee. The exporting
module could be absent or could be unloaded at any time, leading to a
relocation failure or use-after-free.
So also add a build-time check: when a new symbol reference (no twin)
targets a module export, verify that the original module already has at
least one UNDEF symbol resolving to that same exporting module. If not,
error out with a diagnostic message.
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Acked-by: Song Liu <song@kernel.org>
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
Link: https://patch.msgid.link/e0d725acb4774747f0e271308b4ca33daae2d5db.1786138493.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
tools/objtool/klp-diff.c | 35 +++++++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index a7cdba0..0211e5c 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -1296,6 +1296,28 @@ static int convert_reloc_sym(struct elf *elf, struct reloc *reloc)
}
/*
+ * Check if the original module already has a dependency on dep_mod, i.e. it
+ * already references at least one export from that module.
+ */
+static bool has_module_dep(struct elfs *e, const char *dep_mod)
+{
+ struct symbol *sym;
+
+ for_each_sym(e->orig, sym) {
+ struct export *exp;
+
+ if (!is_undef_sym(sym) || is_weak_sym(sym))
+ continue;
+
+ exp = find_export(sym);
+ if (exp && !strcmp(exp->mod, dep_mod))
+ return true;
+ }
+
+ return false;
+}
+
+/*
* Convert a regular relocation to a klp relocation (sort of).
*/
static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc,
@@ -1314,8 +1336,17 @@ static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc,
unsigned long sympos;
if (!patched_sym->twin) {
- ERROR("unexpected klp reloc for new symbol %s", patched_sym->name);
- return -1;
+ if (!export) {
+ ERROR("unexpected klp reloc for new symbol %s", patched_sym->name);
+ return -1;
+ }
+
+ if (strcmp(export->mod, "vmlinux") &&
+ !has_module_dep(e, export->mod)) {
+ ERROR("%s: new reference to %s (exported by %s) would create an undeclared module dependency",
+ patched_sym->name, export->sym, export->mod);
+ return -1;
+ }
}
/*
next prev parent reply other threads:[~2026-08-13 11:16 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 21:37 [PATCH v3 0/9] objtool/klp: sympos/module/alternative/etc fixes Josh Poimboeuf
2026-08-07 21:37 ` [PATCH v3 1/9] objtool/klp: Fix vmlinux .klp.symid link error for .no_trim_symbol symbols Josh Poimboeuf
2026-08-13 11:16 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-07 21:37 ` [PATCH v3 2/9] objtool/klp: Fix size of empty special section entries Josh Poimboeuf
2026-08-13 11:16 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-07 21:37 ` [PATCH v3 3/9] objtool/klp: Ignore replacement offset of empty x86 alternatives Josh Poimboeuf
2026-08-13 11:16 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-07 21:37 ` [PATCH v3 4/9] objtool/klp: Explicitly disallow patching or referencing init code/data Josh Poimboeuf
2026-08-11 22:32 ` Song Liu
2026-08-13 11:16 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-07 21:37 ` [PATCH v3 5/9] objtool/klp: Fix cross-module klp relocation section naming Josh Poimboeuf
2026-08-13 11:16 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-07 21:37 ` [PATCH v3 6/9] objtool/klp: Don't match local symbols against exports Josh Poimboeuf
2026-08-07 21:46 ` sashiko-bot
2026-08-08 22:27 ` Josh Poimboeuf
2026-08-13 11:16 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-07 21:37 ` [PATCH v3 7/9] objtool/klp: Allow new references to module exports Josh Poimboeuf
2026-08-13 11:16 ` tip-bot2 for Joe Lawrence [this message]
2026-08-07 21:37 ` [PATCH v3 8/9] objtool/klp: Fix relocations for EXPORT_SYMBOL_FOR_MODULES() symbols Josh Poimboeuf
2026-08-11 22:36 ` Song Liu
2026-08-13 11:16 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-14 21:05 ` [PATCH v3 8/9] " Dylan Hatch
2026-08-15 0:18 ` Josh Poimboeuf
2026-08-15 1:25 ` Josh Poimboeuf
2026-08-07 21:37 ` [PATCH v3 9/9] objtool/klp: Fix line numbers in Module.symvers parse errors Josh Poimboeuf
2026-08-11 22:36 ` Song Liu
2026-08-13 11:16 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2026-08-11 20:36 ` [PATCH v3 0/9] objtool/klp: sympos/module/alternative/etc fixes Joe Lawrence
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=178661978505.442315.10029160471506962682.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=song@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
all inboxes | Powered by JetHome®