• Tetsuo Handa's avatar
    kmod: avoid deadlock from recursive kmod call · 0f20784d
    Tetsuo Handa authored
    The system deadlocks (at least since 2.6.10) when
    call_usermodehelper(UMH_WAIT_EXEC) request triggers
    call_usermodehelper(UMH_WAIT_PROC) request.
    
    This is because "khelper thread is waiting for the worker thread at
    wait_for_completion() in do_fork() since the worker thread was created
    with CLONE_VFORK flag" and "the worker thread cannot call complete()
    because do_execve() is blocked at UMH_WAIT_PROC request" and "the khelper
    thread cannot start processing UMH_WAIT_PROC request because the khelper
    thread is waiting for the worker thread at wait_for_completion() in
    do_fork()".
    
    The easiest example to observe this deadlock is to use a corrupted
    /sbin/hotplug binary (like shown below).
    
      # : > /tmp/dummy
      # chmod 755 /tmp/dummy
      # echo /tmp/dummy > /proc/sys/kernel/hotplug
      # modprobe whatever
    
    call_usermodehelper("/tmp/dummy", UMH_WAIT_EXEC) is called from
    kobject_uevent_env() in lib/kobject_uevent.c upon loading/unloading a
    module.  do_execve("/tmp/dummy") t...
    0f20784d
kmod.c 18.8 KB