From mboxrd@z Thu Jan 1 00:00:00 1970 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 33E8D44C664; Thu, 13 Aug 2026 11:16:27 +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=1786619792; cv=none; b=BuZMT2ABrEgpdvmQHEM0SjHMyUIGSRCRU6TIIp2cIpOkgxbaX2F19XXO0UxIFr3jhExiCzLNww8wGbK28EJacSCmUnVBeSL5eJytZ0+yGjApMwHFBOd944kYTrCOk7AN/bbjtl3kWEY4uVnvoQJ9z61wfaorBdiwflp4EVBOxps= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786619792; c=relaxed/simple; bh=HegDOw/i0ETuE1LSf/siyL8vi2HNu/9ePN0ObwUF9xA=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=DP3C1L8T3/UIF/gkd2o0c08cqbbpC86uFPqfwk//8toD/CGCqwWqexGFf8uLT5XyIjw2+XQ+TXtOB5ZQQsQuqJOGkXUqjC70oeLhbPamr/OnYK8GzErsS8+TujL5ZaoW42NKNFmKkERxyFEdPxWXVWdgfRJZm4kZt9cWZAEXjZ0= 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=UN8NySqU; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=C3iu7Ou6; 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="UN8NySqU"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="C3iu7Ou6" Date: Thu, 13 Aug 2026 11:16:23 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1786619785; 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=MGI3ULuUTh+begUfWAvz0uPVPSYxJ3z1LnQI36hQYB8=; b=UN8NySqUSq9FYwIjQYEST+pWOHpO6MAlJOe9G4O2LdcltEBqwTX25CEPRExKSxhkNDdJ51 9LmZZAAxuTt8crcVMrJDELL7IsIVypkmyiI8LalhngTfQus8/M/TOjMCdnjWvSGOBTB8bj g4A9vPenOuLXP420xErDWrnGsdR18QZ0PZebbLdI0/o6s1YAqF2YKBqY4ri3H5E0Cej5kG CL4MJpWJe+Mws1CCt2qZHhH6mYOsCpzfCjAiqbljWOXhC6i6MI5rAfPOODge8HZNd46XKd WtxKlW/P6T3eS9unWaxTCC3185Bden434Y22MZjcm5NeOEttcRbH4fGcx+AjKA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1786619785; 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=MGI3ULuUTh+begUfWAvz0uPVPSYxJ3z1LnQI36hQYB8=; b=C3iu7Ou6rZXhhj+dnSfRZ2dcu8/CZs5CWfqhK0mNkZ3NKXcCkoVBZ87AlBkMk5yQjMUE7o 4Tun1b58cJMY9cAw== From: "tip-bot2 for Josh Poimboeuf" 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: Fix relocations for EXPORT_SYMBOL_FOR_MODULES() symbols 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: <178661978344.442315.2086828040390931045.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: 4cd3cfb8b54feca89a682720434092a87bfa4967 Gitweb: https://git.kernel.org/tip/4cd3cfb8b54feca89a682720434092a87bf= a4967 Author: Josh Poimboeuf AuthorDate: Fri, 07 Aug 2026 14:37:53 -07:00 Committer: Josh Poimboeuf CommitterDate: Tue, 11 Aug 2026 16:10:51 -07:00 objtool/klp: Fix relocations for EXPORT_SYMBOL_FOR_MODULES() symbols EXPORT_SYMBOL_FOR_MODULES() puts a symbol in a "module:" namespace, which the module loader grants access to by matching the importing module's name against that list. klp_reloc_needed() only creates a klp reloc for module-owned exports; a vmlinux export gets a normal reloc. For a vmlinux symbol exported with EXPORT_SYMBOL_FOR_MODULES(), using a normal reloc results in a modpost failure in klp-build: ERROR: modpost: module livepatch-foo uses symbol mpol_shared_policy_lookup = from namespace module:kvm, but does not import it. And the modpost error is correct: even with that error removed, the patch module would fail to load: livepatch_foo: module uses symbol (mpol_shared_policy_lookup) from namespac= e module:kvm, but does not import it. livepatch_foo: Unknown symbol mpol_shared_policy_lookup (err -22) Treat it like an unexported symbol by using a klp reloc. Note this only affects "module:" namespaces. Ordinary namespaced exports continue to work with normal relocs thanks to copy_import_ns(), which propagates the patched object's import_ns tags to the patch module. Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing = object files") Reported-by: Joe Lawrence Link: https://lore.kernel.org/6a6608f4-0a05-4d75-8b7f-edddfac9c5d4@redhat.com Acked-by: Joe Lawrence Acked-by: Song Liu Link: https://patch.msgid.link/fe5a00818e06ec613344d41d5944de054fcd8832.17861= 38493.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf --- tools/objtool/klp-diff.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 0211e5c..1f05646 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -30,7 +30,9 @@ struct elfs { =20 struct export { struct hlist_node hash; - char *mod, *sym; + char *mod; + char *sym; + bool mod_ns; }; =20 bool debug, debug_correlate, debug_clone; @@ -135,7 +137,7 @@ static int read_exports(void) } =20 while (fgets(line, 1024, file)) { - char *sym, *mod, *type; + char *sym, *mod, *type, *namespace; struct export *export; =20 sym =3D strchr(line, '\t'); @@ -162,6 +164,14 @@ static int read_exports(void) =20 *type++ =3D '\0'; =20 + namespace =3D strchr(type, '\t'); + if (!namespace) { + ERROR("malformed Module.symvers (namespace) at line %d", line_num); + return -1; + } + + *namespace++ =3D '\0'; + if (*sym =3D=3D '\0' || *mod =3D=3D '\0') { ERROR("malformed Module.symvers at line %d", line_num); return -1; @@ -188,6 +198,9 @@ static int read_exports(void) return -1; } =20 + /* EXPORT_SYMBOL_FOR_MODULES() */ + export->mod_ns =3D strstarts(namespace, "module:"); + hash_add(exports, &export->hash, str_hash(sym)); } =20 @@ -1175,11 +1188,16 @@ static bool klp_reloc_needed(struct reloc *patched_re= loc) * clusterfunk that is late module patching, the patch module is * allowed to be loaded before any modules it depends on. * - * If exported by vmlinux, a normal reloc will do. + * If exported by vmlinux to all modules, a normal reloc will do. */ export =3D find_export(patched_sym); - if (export) - return strcmp(export->mod, "vmlinux"); + if (export) { + if (strcmp(export->mod, "vmlinux")) + return true; + + /* EXPORT_SYMBOL_FOR_MODULES() gets a klp reloc */ + return export->mod_ns; + } =20 if (!patched_sym->twin) { /*