From: Daniel Gomez <da.go...@samsung.com>

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 <da.go...@samsung.com>
---
 kernel/module/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/module/main.c b/kernel/module/main.c
index 35a50ded64a6..2b45a6efa0a9 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2994,10 +2994,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);

-- 
2.39.2



Reply via email to