Skip to content

Commit 4982223

Browse files
committed
module: set nx before marking module MODULE_STATE_COMING.
We currently set RO & NX on modules very late: after we move them from MODULE_STATE_UNFORMED to MODULE_STATE_COMING, and after we call parse_args() (which can exec code in the module). Much better is to do it in complete_formation() and then call the notifier. This means that the notifiers will be called on a module which is already RO & NX, so that may cause problems (ftrace already changed so they're unaffected). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent de51098 commit 4982223

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

kernel/module.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,21 +3023,6 @@ static int do_init_module(struct module *mod)
30233023
*/
30243024
current->flags &= ~PF_USED_ASYNC;
30253025

3026-
blocking_notifier_call_chain(&module_notify_list,
3027-
MODULE_STATE_COMING, mod);
3028-
3029-
/* Set RO and NX regions for core */
3030-
set_section_ro_nx(mod->module_core,
3031-
mod->core_text_size,
3032-
mod->core_ro_size,
3033-
mod->core_size);
3034-
3035-
/* Set RO and NX regions for init */
3036-
set_section_ro_nx(mod->module_init,
3037-
mod->init_text_size,
3038-
mod->init_ro_size,
3039-
mod->init_size);
3040-
30413026
do_mod_ctors(mod);
30423027
/* Start the module */
30433028
if (mod->init != NULL)
@@ -3168,9 +3153,26 @@ static int complete_formation(struct module *mod, struct load_info *info)
31683153
/* This relies on module_mutex for list integrity. */
31693154
module_bug_finalize(info->hdr, info->sechdrs, mod);
31703155

3156+
/* Set RO and NX regions for core */
3157+
set_section_ro_nx(mod->module_core,
3158+
mod->core_text_size,
3159+
mod->core_ro_size,
3160+
mod->core_size);
3161+
3162+
/* Set RO and NX regions for init */
3163+
set_section_ro_nx(mod->module_init,
3164+
mod->init_text_size,
3165+
mod->init_ro_size,
3166+
mod->init_size);
3167+
31713168
/* Mark state as coming so strong_try_module_get() ignores us,
31723169
* but kallsyms etc. can see us. */
31733170
mod->state = MODULE_STATE_COMING;
3171+
mutex_unlock(&module_mutex);
3172+
3173+
blocking_notifier_call_chain(&module_notify_list,
3174+
MODULE_STATE_COMING, mod);
3175+
return 0;
31743176

31753177
out:
31763178
mutex_unlock(&module_mutex);

0 commit comments

Comments
 (0)