Skip to content

Commit 398ec3e

Browse files
chleroymcgrof
authored andcommitted
init: Declare rodata_enabled and mark_rodata_ro() at all time
Declaring rodata_enabled and mark_rodata_ro() at all time helps removing related #ifdefery in C files. Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 3559ad3 commit 398ec3e

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

include/linux/init.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,8 @@ extern initcall_entry_t __initcall_end[];
168168

169169
extern struct file_system_type rootfs_fs_type;
170170

171-
#if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX)
172171
extern bool rodata_enabled;
173-
#endif
174-
#ifdef CONFIG_STRICT_KERNEL_RWX
175172
void mark_rodata_ro(void);
176-
#endif
177173

178174
extern void (*late_time_init)(void);
179175

init/main.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,10 +1396,9 @@ static int __init set_debug_rodata(char *str)
13961396
early_param("rodata", set_debug_rodata);
13971397
#endif
13981398

1399-
#ifdef CONFIG_STRICT_KERNEL_RWX
14001399
static void mark_readonly(void)
14011400
{
1402-
if (rodata_enabled) {
1401+
if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX) && rodata_enabled) {
14031402
/*
14041403
* load_module() results in W+X mappings, which are cleaned
14051404
* up with call_rcu(). Let's make sure that queued work is
@@ -1409,20 +1408,14 @@ static void mark_readonly(void)
14091408
rcu_barrier();
14101409
mark_rodata_ro();
14111410
rodata_test();
1412-
} else
1411+
} else if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)) {
14131412
pr_info("Kernel memory protection disabled.\n");
1413+
} else if (IS_ENABLED(CONFIG_ARCH_HAS_STRICT_KERNEL_RWX)) {
1414+
pr_warn("Kernel memory protection not selected by kernel config.\n");
1415+
} else {
1416+
pr_warn("This architecture does not have kernel memory protection.\n");
1417+
}
14141418
}
1415-
#elif defined(CONFIG_ARCH_HAS_STRICT_KERNEL_RWX)
1416-
static inline void mark_readonly(void)
1417-
{
1418-
pr_warn("Kernel memory protection not selected by kernel config.\n");
1419-
}
1420-
#else
1421-
static inline void mark_readonly(void)
1422-
{
1423-
pr_warn("This architecture does not have kernel memory protection.\n");
1424-
}
1425-
#endif
14261419

14271420
void __weak free_initmem(void)
14281421
{

0 commit comments

Comments
 (0)