Commit db991af0 authored by Jessica Yu's avatar Jessica Yu

module: break nested ARCH_HAS_STRICT_MODULE_RWX and STRICT_MODULE_RWX #ifdefs

Various frob_* and module_{enable,disable}_* functions are defined in a
CONFIG_ARCH_HAS_STRICT_MODULE_RWX ifdef block which also has a nested
CONFIG_STRICT_MODULE_RWX ifdef block within it. This is unecessary and
makes things hard to read. Not only that, this construction requires
redundant empty stubs for module_enable_nx(). I suspect this was
originally done for cosmetic reasons - to keep all the frob_* functions
in the same place, and all the module_{enable,disable}_* functions right
after, but as a result it made the code harder to read.

Make this more readable by unnesting the ifdef blocks and getting rid of
the redundant empty stubs.
Signed-off-by: default avatarJessica Yu <jeyu@kernel.org>
parent 8f3d9f35
...@@ -1943,7 +1943,6 @@ static void mod_sysfs_teardown(struct module *mod) ...@@ -1943,7 +1943,6 @@ static void mod_sysfs_teardown(struct module *mod)
mod_sysfs_fini(mod); mod_sysfs_fini(mod);
} }
#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX
/* /*
* LKM RO/NX protection: protect module's text/ro-data * LKM RO/NX protection: protect module's text/ro-data
* from modification and any data from execution. * from modification and any data from execution.
...@@ -1957,6 +1956,14 @@ static void mod_sysfs_teardown(struct module *mod) ...@@ -1957,6 +1956,14 @@ static void mod_sysfs_teardown(struct module *mod)
* *
* These values are always page-aligned (as is base) * These values are always page-aligned (as is base)
*/ */
/*
* Since some arches are moving towards PAGE_KERNEL module allocations instead
* of PAGE_KERNEL_EXEC, keep frob_text() and module_enable_x() outside of the
* CONFIG_STRICT_MODULE_RWX block below because they are needed regardless of
* whether we are strict.
*/
#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX
static void frob_text(const struct module_layout *layout, static void frob_text(const struct module_layout *layout,
int (*set_memory)(unsigned long start, int num_pages)) int (*set_memory)(unsigned long start, int num_pages))
{ {
...@@ -1966,6 +1973,15 @@ static void frob_text(const struct module_layout *layout, ...@@ -1966,6 +1973,15 @@ static void frob_text(const struct module_layout *layout,
layout->text_size >> PAGE_SHIFT); layout->text_size >> PAGE_SHIFT);
} }
static void module_enable_x(const struct module *mod)
{
frob_text(&mod->core_layout, set_memory_x);
frob_text(&mod->init_layout, set_memory_x);
}
#else /* !CONFIG_ARCH_HAS_STRICT_MODULE_RWX */
static void module_enable_x(const struct module *mod) { }
#endif /* CONFIG_ARCH_HAS_STRICT_MODULE_RWX */
#ifdef CONFIG_STRICT_MODULE_RWX #ifdef CONFIG_STRICT_MODULE_RWX
static void frob_rodata(const struct module_layout *layout, static void frob_rodata(const struct module_layout *layout,
int (*set_memory)(unsigned long start, int num_pages)) int (*set_memory)(unsigned long start, int num_pages))
...@@ -2037,18 +2053,9 @@ static void module_enable_nx(const struct module *mod) ...@@ -2037,18 +2053,9 @@ static void module_enable_nx(const struct module *mod)
} }
#else /* !CONFIG_STRICT_MODULE_RWX */ #else /* !CONFIG_STRICT_MODULE_RWX */
/* module_{enable,disable}_ro() stubs are in module.h */
static void module_enable_nx(const struct module *mod) { } static void module_enable_nx(const struct module *mod) { }
#endif /* CONFIG_STRICT_MODULE_RWX */ #endif /* CONFIG_STRICT_MODULE_RWX */
static void module_enable_x(const struct module *mod)
{
frob_text(&mod->core_layout, set_memory_x);
frob_text(&mod->init_layout, set_memory_x);
}
#else /* !CONFIG_ARCH_HAS_STRICT_MODULE_RWX */
static void module_enable_nx(const struct module *mod) { }
static void module_enable_x(const struct module *mod) { }
#endif /* CONFIG_ARCH_HAS_STRICT_MODULE_RWX */
#ifdef CONFIG_LIVEPATCH #ifdef CONFIG_LIVEPATCH
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment