linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] init: Declare rodata_enabled and mark_rodata_ro() at all time
@ 2023-12-21  9:02 Christophe Leroy
  2023-12-21  9:02 ` [PATCH 2/3] modules: Remove #ifdef CONFIG_STRICT_MODULE_RWX around rodata_enabled Christophe Leroy
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Christophe Leroy @ 2023-12-21  9:02 UTC (permalink / raw)
  To: Michael Ellerman, Nicholas Piggin, Arnd Bergmann,
	Luis Chamberlain
  Cc: linux-modules, linuxppc-dev, linux-kernel

Declaring rodata_enabled and mark_rodata_ro() at all time
helps removing related #ifdefery in C files.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 include/linux/init.h |  4 ----
 init/main.c          | 21 +++++++--------------
 2 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/include/linux/init.h b/include/linux/init.h
index 01b52c9c7526..d2b47be38a07 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -168,12 +168,8 @@ extern initcall_entry_t __initcall_end[];
 
 extern struct file_system_type rootfs_fs_type;
 
-#if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX)
 extern bool rodata_enabled;
-#endif
-#ifdef CONFIG_STRICT_KERNEL_RWX
 void mark_rodata_ro(void);
-#endif
 
 extern void (*late_time_init)(void);
 
diff --git a/init/main.c b/init/main.c
index e24b0780fdff..807df08c501f 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1396,10 +1396,9 @@ static int __init set_debug_rodata(char *str)
 early_param("rodata", set_debug_rodata);
 #endif
 
-#ifdef CONFIG_STRICT_KERNEL_RWX
 static void mark_readonly(void)
 {
-	if (rodata_enabled) {
+	if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX) && rodata_enabled) {
 		/*
 		 * load_module() results in W+X mappings, which are cleaned
 		 * up with call_rcu().  Let's make sure that queued work is
@@ -1409,20 +1408,14 @@ static void mark_readonly(void)
 		rcu_barrier();
 		mark_rodata_ro();
 		rodata_test();
-	} else
+	} else if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)) {
 		pr_info("Kernel memory protection disabled.\n");
+	} else if (IS_ENABLED(CONFIG_ARCH_HAS_STRICT_KERNEL_RWX)) {
+		pr_warn("Kernel memory protection not selected by kernel config.\n");
+	} else {
+		pr_warn("This architecture does not have kernel memory protection.\n");
+	}
 }
-#elif defined(CONFIG_ARCH_HAS_STRICT_KERNEL_RWX)
-static inline void mark_readonly(void)
-{
-	pr_warn("Kernel memory protection not selected by kernel config.\n");
-}
-#else
-static inline void mark_readonly(void)
-{
-	pr_warn("This architecture does not have kernel memory protection.\n");
-}
-#endif
 
 void __weak free_initmem(void)
 {
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-01-31 22:17 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-21  9:02 [PATCH 1/3] init: Declare rodata_enabled and mark_rodata_ro() at all time Christophe Leroy
2023-12-21  9:02 ` [PATCH 2/3] modules: Remove #ifdef CONFIG_STRICT_MODULE_RWX around rodata_enabled Christophe Leroy
2023-12-21  9:02 ` [PATCH 3/3] powerpc: Simplify strict_kernel_rwx_enabled() Christophe Leroy
2023-12-21 12:16 ` [PATCH 1/3] init: Declare rodata_enabled and mark_rodata_ro() at all time Michael Ellerman
2023-12-22  5:35   ` Kees Cook
2023-12-22 18:23     ` Christophe Leroy
2024-01-29 20:09 ` Luis Chamberlain
2024-01-30  9:16   ` Chen-Yu Tsai
2024-01-30 11:03     ` Christophe Leroy
     [not found]       ` <CGME20240130174812eucas1p166f62549457fd188fed6ed72b6b4b9cd@eucas1p1.samsung.com>
2024-01-30 17:48         ` Marek Szyprowski
2024-01-30 20:27           ` Luis Chamberlain
2024-01-31  6:53             ` Christophe Leroy
2024-01-31 22:16               ` Luis Chamberlain
2024-01-31 11:58           ` Christophe Leroy
2024-01-31 15:17             ` Marek Szyprowski
2024-01-31 20:07               ` Christophe Leroy
2024-01-31 22:10                 ` Marek Szyprowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).