[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241108-modules-ro_after_init-v3-3-6dd041b588a5@samsung.com>
Date: Fri, 08 Nov 2024 17:12:15 +0100
From: Daniel Gomez via B4 Relay <devnull+da.gomez.samsung.com@...nel.org>
To: Luis Chamberlain <mcgrof@...nel.org>, Petr Pavlu <petr.pavlu@...e.com>,
Sami Tolvanen <samitolvanen@...gle.com>,
Christophe Leroy <christophe.leroy@...roup.eu>,
Thomas Gleixner <tglx@...utronix.de>, Jinjie Ruan <ruanjinjie@...wei.com>,
Jens Axboe <axboe@...nel.dk>
Cc: "Daniel Gomez (Samsung)" <d+samsung@...ces.com>,
linux-modules@...r.kernel.org, linux-kernel@...r.kernel.org,
Daniel Gomez <da.gomez@...sung.com>
Subject: [PATCH RFC v3 3/4] module: update state and release reference
under lock
From: Daniel Gomez <da.gomez@...sung.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@...sung.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
Powered by blists - more mailing lists