Skip to content

Commit db991af

Browse files
author
Jessica Yu
committed
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: Jessica Yu <[email protected]>
1 parent 8f3d9f3 commit db991af

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

kernel/module.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,6 @@ static void mod_sysfs_teardown(struct module *mod)
19431943
mod_sysfs_fini(mod);
19441944
}
19451945

1946-
#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX
19471946
/*
19481947
* LKM RO/NX protection: protect module's text/ro-data
19491948
* from modification and any data from execution.
@@ -1957,6 +1956,14 @@ static void mod_sysfs_teardown(struct module *mod)
19571956
*
19581957
* These values are always page-aligned (as is base)
19591958
*/
1959+
1960+
/*
1961+
* Since some arches are moving towards PAGE_KERNEL module allocations instead
1962+
* of PAGE_KERNEL_EXEC, keep frob_text() and module_enable_x() outside of the
1963+
* CONFIG_STRICT_MODULE_RWX block below because they are needed regardless of
1964+
* whether we are strict.
1965+
*/
1966+
#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX
19601967
static void frob_text(const struct module_layout *layout,
19611968
int (*set_memory)(unsigned long start, int num_pages))
19621969
{
@@ -1966,6 +1973,15 @@ static void frob_text(const struct module_layout *layout,
19661973
layout->text_size >> PAGE_SHIFT);
19671974
}
19681975

1976+
static void module_enable_x(const struct module *mod)
1977+
{
1978+
frob_text(&mod->core_layout, set_memory_x);
1979+
frob_text(&mod->init_layout, set_memory_x);
1980+
}
1981+
#else /* !CONFIG_ARCH_HAS_STRICT_MODULE_RWX */
1982+
static void module_enable_x(const struct module *mod) { }
1983+
#endif /* CONFIG_ARCH_HAS_STRICT_MODULE_RWX */
1984+
19691985
#ifdef CONFIG_STRICT_MODULE_RWX
19701986
static void frob_rodata(const struct module_layout *layout,
19711987
int (*set_memory)(unsigned long start, int num_pages))
@@ -2037,18 +2053,9 @@ static void module_enable_nx(const struct module *mod)
20372053
}
20382054

20392055
#else /* !CONFIG_STRICT_MODULE_RWX */
2056+
/* module_{enable,disable}_ro() stubs are in module.h */
20402057
static void module_enable_nx(const struct module *mod) { }
20412058
#endif /* CONFIG_STRICT_MODULE_RWX */
2042-
static void module_enable_x(const struct module *mod)
2043-
{
2044-
frob_text(&mod->core_layout, set_memory_x);
2045-
frob_text(&mod->init_layout, set_memory_x);
2046-
}
2047-
#else /* !CONFIG_ARCH_HAS_STRICT_MODULE_RWX */
2048-
static void module_enable_nx(const struct module *mod) { }
2049-
static void module_enable_x(const struct module *mod) { }
2050-
#endif /* CONFIG_ARCH_HAS_STRICT_MODULE_RWX */
2051-
20522059

20532060
#ifdef CONFIG_LIVEPATCH
20542061
/*

0 commit comments

Comments
 (0)