Skip to content

Commit

Permalink
module: set nx before marking module MODULE_STATE_COMING.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Rusty Russell committed May 14, 2014
1 parent de51098 commit 4982223
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -3023,21 +3023,6 @@ static int do_init_module(struct module *mod)
*/
current->flags &= ~PF_USED_ASYNC;

blocking_notifier_call_chain(&module_notify_list,
MODULE_STATE_COMING, mod);

/* Set RO and NX regions for core */
set_section_ro_nx(mod->module_core,
mod->core_text_size,
mod->core_ro_size,
mod->core_size);

/* Set RO and NX regions for init */
set_section_ro_nx(mod->module_init,
mod->init_text_size,
mod->init_ro_size,
mod->init_size);

do_mod_ctors(mod);
/* Start the module */
if (mod->init != NULL)
Expand Down Expand Up @@ -3168,9 +3153,26 @@ static int complete_formation(struct module *mod, struct load_info *info)
/* This relies on module_mutex for list integrity. */
module_bug_finalize(info->hdr, info->sechdrs, mod);

/* Set RO and NX regions for core */
set_section_ro_nx(mod->module_core,
mod->core_text_size,
mod->core_ro_size,
mod->core_size);

/* Set RO and NX regions for init */
set_section_ro_nx(mod->module_init,
mod->init_text_size,
mod->init_ro_size,
mod->init_size);

/* Mark state as coming so strong_try_module_get() ignores us,
* but kallsyms etc. can see us. */
mod->state = MODULE_STATE_COMING;
mutex_unlock(&module_mutex);

blocking_notifier_call_chain(&module_notify_list,
MODULE_STATE_COMING, mod);
return 0;

out:
mutex_unlock(&module_mutex);
Expand Down

0 comments on commit 4982223

Please sign in to comment.