Skip to content

Commit ac88ee7

Browse files
chleroymcgrof
authored andcommitted
module: Use set_memory_rox()
A couple of architectures seem concerned about calling set_memory_ro() and set_memory_x() too frequently and have implemented a version of set_memory_rox(), see commit 6046362 ("x86/mm: Implement native set_memory_rox()") and commit 22e99fa ("s390/mm: implement set_memory_rox()") Use set_memory_rox() in modules when STRICT_MODULES_RWX is set. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
1 parent 41bccc9 commit ac88ee7

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

kernel/module/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ static inline struct module *mod_find(unsigned long addr, struct mod_tree_root *
324324

325325
void module_enable_ro(const struct module *mod, bool after_init);
326326
void module_enable_nx(const struct module *mod);
327-
void module_enable_x(const struct module *mod);
327+
void module_enable_rox(const struct module *mod);
328328
int module_enforce_rwx_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
329329
char *secstrings, struct module *mod);
330330

kernel/module/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2738,7 +2738,7 @@ static int complete_formation(struct module *mod, struct load_info *info)
27382738

27392739
module_enable_ro(mod, false);
27402740
module_enable_nx(mod);
2741-
module_enable_x(mod);
2741+
module_enable_rox(mod);
27422742

27432743
/*
27442744
* Mark state as coming so strong_try_module_get() ignores us,

kernel/module/strict_rwx.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ static void module_set_memory(const struct module *mod, enum mod_mem_type type,
2626
* CONFIG_STRICT_MODULE_RWX because they are needed regardless of whether we
2727
* are strict.
2828
*/
29-
void module_enable_x(const struct module *mod)
29+
void module_enable_rox(const struct module *mod)
3030
{
31-
for_class_mod_mem_type(type, text)
32-
module_set_memory(mod, type, set_memory_x);
31+
for_class_mod_mem_type(type, text) {
32+
if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX))
33+
module_set_memory(mod, type, set_memory_rox);
34+
else
35+
module_set_memory(mod, type, set_memory_x);
36+
}
3337
}
3438

3539
void module_enable_ro(const struct module *mod, bool after_init)
@@ -41,8 +45,6 @@ void module_enable_ro(const struct module *mod, bool after_init)
4145
return;
4246
#endif
4347

44-
module_set_memory(mod, MOD_TEXT, set_memory_ro);
45-
module_set_memory(mod, MOD_INIT_TEXT, set_memory_ro);
4648
module_set_memory(mod, MOD_RODATA, set_memory_ro);
4749
module_set_memory(mod, MOD_INIT_RODATA, set_memory_ro);
4850

0 commit comments

Comments
 (0)