From nobody Tue Sep 29 02:02:55 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0EB6406822; Thu, 13 Aug 2026 11:16:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786619794; cv=none; b=ecjhKxjJQdtUoCLdykA9asg8YOV0QZkpY1jnf146iSB9wKIZOSX6rMUwhanfViEpDNj2GuzDHSCO5gJsgi1ug9HQ3PP8CqZNAy93z0P+FerRTfoTtBdaBVJ2jAE6sMyo3cLQZGhQVhWuu8f2u7wtvTvq3Nis+ReQP9b8q9YJfvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786619794; c=relaxed/simple; bh=hoKGAvPa66el+QiVwMEkZGqHwBTJYUIwnX4nbuKWcK0=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=dZ4Y3Ep0uFXN19ZBdE1Zz7YqeyExeJJczm4th9s9CsuNI5zN1P+OLU0Ffyj3r3hUEmW70uqgWRFGRdsHVGdENrSh+56Q3cdwCrZGMzlvjm6r9HvJbZnj1b2tsLdrbW+pYgoNhc/sa/mQwG5NbzlqomWEiXXc452jqb+P55JA3wM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=MbTfwbrz; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=5Lxn+UIJ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MbTfwbrz"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5Lxn+UIJ" Date: Thu, 13 Aug 2026 11:16:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1786619786; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ym7aaRCGXK/92D3b03CJv4kqaaaY3t39exNOq6PA9F0=; b=MbTfwbrz4b1PFfW5EF9ar1zKAGrrjHlVzRQCgODWbrMaw/sgovjZaufDw6I9RLOTVZJRNW mMJRv+wAisItafj5a/K+uR+aCq3TKWaWXfCMjL4+NKFIEf26FWAZTOobpsXBFASJ6ssH77 jJstmmz/kbjgbxso/bQzHgEEVdLLlrZMpZY5mhZW/xzSrrrtxbgqscRycL+6/WzeXgXYii qfsnCHk3aJBfjoeXSLYYCIs3+OMxNkmFW6GvdUrrKppA+ewfw0x0EArMCKgNfYeXlkhGwW 9Yr12RdhZsoxvVtbNyYFl0SKKIE7ZOZn5fAyW39xRHVGf0fM/gn1iV2ZCVAC/A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1786619786; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ym7aaRCGXK/92D3b03CJv4kqaaaY3t39exNOq6PA9F0=; b=5Lxn+UIJ01p8v3rhOsckykE9yYBtFvbtg7SktJSetwBrDyJvsFitaclMhrXFsM5JVs/GGj XuyeLvoWHfj/0mDA== From: "tip-bot2 for Joe Lawrence" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] objtool/klp: Allow new references to module exports Cc: Joe Lawrence , Song Liu , Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178661978505.442315.10029160471506962682.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the objtool/core branch of tip: Commit-ID: 72d76d0c18ebd40f6a32df875ff40528564849c1 Gitweb: https://git.kernel.org/tip/72d76d0c18ebd40f6a32df875ff405285= 64849c1 Author: Joe Lawrence AuthorDate: Fri, 07 Aug 2026 14:37:52 -07:00 Committer: Josh Poimboeuf 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 Acked-by: Song Liu Acked-by: Joe Lawrence Link: https://patch.msgid.link/e0d725acb4774747f0e271308b4ca33daae2d5db.178= 6138493.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf --- 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) } =20 /* + * 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 =3D 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 re= loc *patched_reloc, unsigned long sympos; =20 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 undecla= red module dependency", + patched_sym->name, export->sym, export->mod); + return -1; + } } =20 /*