From 08452ada76ec2af712f8c8458b1652329dbb6108 Mon Sep 17 00:00:00 2001 From: Daniel Gomez Date: Fri, 8 Nov 2024 17:12:15 +0100 Subject: [PATCH] module: update state and release reference under lock 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 --- 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 ed6c058463b224..2f0585de6bef04 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -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);