Skip to content

Commit

Permalink
module: update state and release reference under lock
Browse files Browse the repository at this point in the history
Ensure the module state change and reference drop operations are
performed within module_mutex to prevent potential race conditions in
the failure path.

Signed-off-by: Daniel Gomez <[email protected]>
  • Loading branch information
dkruces authored and mcgrof committed Nov 26, 2024
1 parent 84e5ed0 commit 08452ad
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kernel/module/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2902,10 +2902,12 @@ static noinline int do_init_module(struct module *mod)
fail_free_freeinit:
kfree(freeinit);
fail:
mutex_lock(&module_mutex);
/* Try to protect us from buggy refcounters. */
mod->state = MODULE_STATE_GOING;
synchronize_rcu();
module_put(mod);
mutex_unlock(&module_mutex);
synchronize_rcu();
blocking_notifier_call_chain(&module_notify_list,
MODULE_STATE_GOING, mod);
klp_module_going(mod);
Expand Down

0 comments on commit 08452ad

Please sign in to comment.