Skip to content

Commit 5d60331

Browse files
finist0Jessica Yu
authored andcommitted
kernel/module.c: wakeup processes in module_wq on module unload
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: 6e6de3d ("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>
1 parent e2854a1 commit 5d60331

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎kernel/module.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,8 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
10331033
strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module));
10341034

10351035
free_module(mod);
1036+
/* someone could wait for the module in add_unformed_module() */
1037+
wake_up_all(&module_wq);
10361038
return 0;
10371039
out:
10381040
mutex_unlock(&module_mutex);

0 commit comments

Comments
 (0)