[RHEL7,COMMIT] kernel/module.c: wakeup processes in module_wq on module unload

Submitted by Konstantin Khorenko on Nov. 13, 2019, 5:41 p.m.

Details

Message ID 201911131741.xADHfMpb009113@finist-ce7.sw.ru
State New
Series "kernel/module.c: don't allow modprobe to hang forever on a module load"
Headers show

Commit Message

Konstantin Khorenko Nov. 13, 2019, 5:41 p.m.
The commit is pushed to "branch-rh7-3.10.0-1062.4.2.vz7.116.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1062.4.2.vz7.116.1
------>
commit dfd0473d616ebcc701c1834ebbc7c39682760697
Author: Konstantin Khorenko <khorenko@virtuozzo.com>
Date:   Wed Nov 13 20:41:05 2019 +0300

    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: ms commit 6e6de3dee51a ("kernel/module.c: Only return
    -EEXIST for modules that have finished loading")
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1771939
    Sent to ms: https://lkml.org/lkml/2019/11/13/203
    
    https://jira.sw.ru/browse/PSBM-99356
    
    Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 kernel/module.c | 2 ++
 1 file changed, 2 insertions(+)

Patch hide | download patch | download mbox

diff --git a/kernel/module.c b/kernel/module.c
index 64ed3f94df6f..799b365aae7f 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1053,6 +1053,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);