diff mbox series

[RFC,v3,3/4] module: update state and release reference under lock

Message ID 20241108-modules-ro_after_init-v3-3-6dd041b588a5@samsung.com (mailing list archive)
State New
Headers show
Series module: refactor ro_after_init failure path | expand

Checks

Context Check Description
mcgrof/vmtest-modules-next-PR success PR summary
mcgrof/vmtest-modules-next-VM_Test-5 success Logs for setup / Setup kdevops environment
mcgrof/vmtest-modules-next-VM_Test-4 success Logs for setup / Setup kdevops environment
mcgrof/vmtest-modules-next-VM_Test-3 fail Logs for cleanup / Archive results and cleanup
mcgrof/vmtest-modules-next-VM_Test-0 success Logs for Run CI tests
mcgrof/vmtest-modules-next-VM_Test-1 success Logs for cleanup / Archive results and cleanup
mcgrof/vmtest-modules-next-VM_Test-2 success Logs for setup / Setup kdevops environment

Commit Message

Daniel Gomez via B4 Relay Nov. 8, 2024, 4:12 p.m. UTC
From: Daniel Gomez <da.gomez@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.gomez@samsung.com>
---
 kernel/module/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

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);