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-43-david.kaplan@amd.com>
Date: Mon, 13 Oct 2025 09:34:30 -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 42/56] module: Make memory writeable for re-patching

The text code for a module must be made writeable to support
re-patching, and can then be marked read-only again after patching is
complete.

Signed-off-by: David Kaplan <david.kaplan@....com>
---
 include/linux/module.h |  5 +++++
 kernel/module/main.c   | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/include/linux/module.h b/include/linux/module.h
index e135cc79acee..2d8c34cb961f 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -1020,4 +1020,9 @@ static inline unsigned long find_kallsyms_symbol_value(struct module *mod,
 /* Define __free(module_put) macro for struct module *. */
 DEFINE_FREE(module_put, struct module *, if (_T) module_put(_T))
 
+#ifdef CONFIG_DYNAMIC_MITIGATIONS
+void modules_prepare_repatch(void);
+void modules_post_repatch(void);
+#endif
+
 #endif /* _LINUX_MODULE_H */
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 088f9399af11..0525b1c6d5b9 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -3910,3 +3910,37 @@ static int module_debugfs_init(void)
 }
 module_init(module_debugfs_init);
 #endif
+
+#ifdef CONFIG_DYNAMIC_MITIGATIONS
+static void change_mod_mem_perm(struct module *mod, enum mod_mem_type type,
+		bool writeable)
+{
+	unsigned long base, size;
+
+	base = (unsigned long) mod->mem[type].base;
+	size = mod->mem[type].size;
+
+	if (writeable)
+		set_memory_rw(base, PFN_UP(size));
+	else
+		set_memory_ro(base, PFN_UP(size));
+}
+
+void modules_prepare_repatch(void)
+{
+	struct module *mod;
+
+	list_for_each_entry(mod, &modules, list) {
+		change_mod_mem_perm(mod, MOD_TEXT, true);
+	}
+}
+
+void modules_post_repatch(void)
+{
+	struct module *mod;
+
+	list_for_each_entry(mod, &modules, list) {
+		change_mod_mem_perm(mod, MOD_TEXT, false);
+	}
+}
+#endif
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ