lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251013143444.3999-45-david.kaplan@amd.com>
Date: Mon, 13 Oct 2025 09:34:32 -0500
From: David Kaplan <david.kaplan@....com>
To: Thomas Gleixner <tglx@...utronix.de>, Borislav Petkov <bp@...en8.de>,
	Peter Zijlstra <peterz@...radead.org>, Josh Poimboeuf <jpoimboe@...nel.org>,
	Pawan Gupta <pawan.kumar.gupta@...ux.intel.com>, Ingo Molnar
	<mingo@...hat.com>, Dave Hansen <dave.hansen@...ux.intel.com>,
	<x86@...nel.org>, "H . Peter Anvin" <hpa@...or.com>
CC: Alexander Graf <graf@...zon.com>, Boris Ostrovsky
	<boris.ostrovsky@...cle.com>, <linux-kernel@...r.kernel.org>
Subject: [RFC PATCH 44/56] x86/module: Update alternatives

Support resetting and re-configuring retpolines, returns, callthunks,
and alternatives for modules.  The ELF information is kept from when the
module was first loaded.  Static calls are non-arch specific and handled
in the generic module code.

Signed-off-by: David Kaplan <david.kaplan@....com>
---
 arch/x86/include/asm/module.h |  4 +++
 arch/x86/kernel/module.c      | 58 +++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
index 58d7f1017a14..f72359b5120d 100644
--- a/arch/x86/include/asm/module.h
+++ b/arch/x86/include/asm/module.h
@@ -27,4 +27,8 @@ struct mod_arch_specific {
 #endif
 };
 
+#ifdef CONFIG_DYNAMIC_MITIGATIONS
+void arch_module_update_alternatives(struct module *mod);
+#endif
+
 #endif /* _ASM_X86_MODULE_H */
diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
index 0765d2360a33..b6beb2b3469c 100644
--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -333,3 +333,61 @@ void module_arch_cleanup(struct module *mod)
 	alternatives_smp_module_del(mod);
 	its_free_mod(mod);
 }
+
+#ifdef CONFIG_DYNAMIC_MITIGATIONS
+void arch_module_update_alternatives(struct module *mod)
+{
+	const Elf_Ehdr *hdr;
+	const Elf_Shdr *sechdrs;
+	const Elf_Shdr *s, *alt = NULL, *retpolines = NULL, *returns = NULL, *calls = NULL;
+	char *secstrings;
+
+	if (!mod->klp_info) {
+		pr_warn("No module livepatch info, unable to update alternatives\n");
+		return;
+	}
+
+	hdr = &mod->klp_info->hdr;
+	sechdrs = mod->klp_info->sechdrs;
+	secstrings = mod->klp_info->secstrings;
+
+	for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
+		if (!strcmp(".altinstructions", secstrings + s->sh_name))
+			alt = s;
+		if (!strcmp(".retpoline_sites", secstrings + s->sh_name))
+			retpolines = s;
+		if (!strcmp(".return_sites", secstrings + s->sh_name))
+			returns = s;
+		if (!strcmp(".call_sites", secstrings + s->sh_name))
+			calls = s;
+	}
+
+	if (retpolines) {
+		void *rseg = (void *)retpolines->sh_addr;
+
+		reset_retpolines(rseg, rseg + retpolines->sh_size, mod);
+		apply_retpolines(rseg, rseg + retpolines->sh_size, mod);
+	}
+	if (returns) {
+		void *rseg = (void *)returns->sh_addr;
+
+		reset_returns(rseg, rseg + returns->sh_size, mod);
+		apply_returns(rseg, rseg + returns->sh_size, mod);
+	}
+	if (calls) {
+		struct callthunk_sites cs = {};
+
+		cs.call_start = (void *)calls->sh_addr;
+		cs.call_end = (void *)calls->sh_addr + calls->sh_size;
+
+		reset_module_callthunks(&cs, mod);
+		callthunks_patch_module_calls(&cs, mod);
+	}
+	if (alt) {
+		void *aseg = (void *)alt->sh_addr;
+
+		reset_alternatives(aseg, aseg + alt->sh_size, mod);
+		apply_alternatives(aseg, aseg + alt->sh_size, mod);
+	}
+}
+#endif
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ