diff options
author | Konstantin Khorenko <khorenko@virtuozzo.com> | 2019-11-13 12:29:50 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-12-21 10:35:38 +0100 |
commit | 575a2dbce0b2c8e489c0566527d99ebc54d35d54 (patch) | |
tree | 822220cee57af22c2e16f5d5f7ee46bf5c73d5db | |
parent | 736b632ee7470fcb9b42345df283bca28cae1a99 (diff) | |
download | linux-stable-575a2dbce0b2c8e489c0566527d99ebc54d35d54.tar.gz linux-stable-575a2dbce0b2c8e489c0566527d99ebc54d35d54.tar.bz2 linux-stable-575a2dbce0b2c8e489c0566527d99ebc54d35d54.zip |
kernel/module.c: wakeup processes in module_wq on module unload
[ Upstream commit 5d603311615f612320bb77bd2a82553ef1ced5b7 ]
Fix the race between load and unload a kernel module.
sys_delete_module()
try_stop_module()
mod->state = _GOING
add_unformed_module()
old = find_module_all()
(old->state == _GOING =>
wait_event_interruptible())
During pre-condition
finished_loading() rets 0
schedule()
(never gets waken up later)
free_module()
mod->state = _UNFORMED
list_del_rcu(&mod->list)
(dels mod from "modules" list)
return
The race above leads to modprobe hanging forever on loading
a module.
Error paths on loading module call wake_up_all(&module_wq) after
freeing module, so let's do the same on straight module unload.
Fixes: 6e6de3dee51a ("kernel/module.c: Only return -EEXIST for modules that have finished loading")
Reviewed-by: Prarit Bhargava <prarit@redhat.com>
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | kernel/module.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/kernel/module.c b/kernel/module.c index b940b2825b7b..2f695b6e1a3e 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -1014,6 +1014,8 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user, strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); free_module(mod); + /* someone could wait for the module in add_unformed_module() */ + wake_up_all(&module_wq); return 0; out: mutex_unlock(&module_mutex); |