Skip to content

Commit 0597579

Browse files
chleroymcgrof
authored andcommitted
module: Make module_enable_x() independent of CONFIG_ARCH_HAS_STRICT_MODULE_RWX
module_enable_x() has nothing to do with CONFIG_ARCH_HAS_STRICT_MODULE_RWX allthough by coincidence architectures who need module_enable_x() are selection CONFIG_ARCH_HAS_STRICT_MODULE_RWX. Enable module_enable_x() for everyone everytime. If an architecture already has module text set executable, it's a no-op. Don't check text_size alignment. When CONFIG_STRICT_MODULE_RWX is set the verification is already done in frob_rodata(). When CONFIG_STRICT_MODULE_RWX is not set it is not a big deal to have the start of data as executable. Just make sure we entirely get the last page when the boundary is not aligned. And don't BUG on misaligned base as some architectures like nios2 use kmalloc() for allocating modules. So just bail out in that case. If that's a problem, a page fault will occur later anyway. Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 4788979 commit 0597579

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

kernel/module/internal.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
/*
2424
* Modules' sections will be aligned on page boundaries
2525
* to ensure complete separation of code and data, but
26-
* only when CONFIG_ARCH_HAS_STRICT_MODULE_RWX=y
26+
* only when CONFIG_STRICT_MODULE_RWX=y
2727
*/
28-
#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX
28+
#ifdef CONFIG_STRICT_MODULE_RWX
2929
# define debug_align(X) PAGE_ALIGN(X)
3030
#else
3131
# define debug_align(X) (X)
@@ -175,10 +175,8 @@ static inline struct module *mod_find(unsigned long addr)
175175
}
176176
#endif /* CONFIG_MODULES_TREE_LOOKUP */
177177

178-
#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX
179178
void frob_text(const struct module_layout *layout, int (*set_memory)(unsigned long start,
180179
int num_pages));
181-
#endif /* CONFIG_ARCH_HAS_STRICT_MODULE_RWX */
182180

183181
#ifdef CONFIG_STRICT_MODULE_RWX
184182
void module_enable_ro(const struct module *mod, bool after_init);

kernel/module/main.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,24 +1144,22 @@ resolve_symbol_wait(struct module *mod,
11441144
* CONFIG_STRICT_MODULE_RWX block below because they are needed regardless of
11451145
* whether we are strict.
11461146
*/
1147-
#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX
11481147
void frob_text(const struct module_layout *layout,
11491148
int (*set_memory)(unsigned long start, int num_pages))
11501149
{
1151-
BUG_ON((unsigned long)layout->base & (PAGE_SIZE-1));
1152-
BUG_ON((unsigned long)layout->text_size & (PAGE_SIZE-1));
11531150
set_memory((unsigned long)layout->base,
1154-
layout->text_size >> PAGE_SHIFT);
1151+
PAGE_ALIGN(layout->text_size) >> PAGE_SHIFT);
11551152
}
11561153

11571154
static void module_enable_x(const struct module *mod)
11581155
{
1156+
if (!PAGE_ALIGNED(mod->core_layout.base) ||
1157+
!PAGE_ALIGNED(mod->init_layout.base))
1158+
return;
1159+
11591160
frob_text(&mod->core_layout, set_memory_x);
11601161
frob_text(&mod->init_layout, set_memory_x);
11611162
}
1162-
#else /* !CONFIG_ARCH_HAS_STRICT_MODULE_RWX */
1163-
static void module_enable_x(const struct module *mod) { }
1164-
#endif /* CONFIG_ARCH_HAS_STRICT_MODULE_RWX */
11651163

11661164
void __weak module_memfree(void *module_region)
11671165
{

0 commit comments

Comments
 (0)