Skip to content

Commit

Permalink
init: Declare rodata_enabled and mark_rodata_ro() at all time
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
  • Loading branch information
Christophe Leroy authored and Luis Chamberlain committed Feb 2, 2024
1 parent 3559ad3 commit 398ec3e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
4 changes: 0 additions & 4 deletions include/linux/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
21 changes: 7 additions & 14 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand Down

0 comments on commit 398ec3e

Please sign in to comment.