|
@@ -45,6 +45,13 @@ extern int max_threads;
|
|
|
|
|
|
static struct workqueue_struct *khelper_wq;
|
|
|
|
|
|
+/*
|
|
|
+ * kmod_thread_locker is used for deadlock avoidance. There is no explicit
|
|
|
+ * locking to protect this global - it is private to the singleton khelper
|
|
|
+ * thread and should only ever be modified by that thread.
|
|
|
+ */
|
|
|
+static const struct task_struct *kmod_thread_locker;
|
|
|
+
|
|
|
#define CAP_BSET (void *)1
|
|
|
#define CAP_PI (void *)2
|
|
|
|
|
@@ -221,6 +228,13 @@ fail:
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+static int call_helper(void *data)
|
|
|
+{
|
|
|
+ /* Worker thread started blocking khelper thread. */
|
|
|
+ kmod_thread_locker = current;
|
|
|
+ return ____call_usermodehelper(data);
|
|
|
+}
|
|
|
+
|
|
|
static void call_usermodehelper_freeinfo(struct subprocess_info *info)
|
|
|
{
|
|
|
if (info->cleanup)
|
|
@@ -295,9 +309,12 @@ static void __call_usermodehelper(struct work_struct *work)
|
|
|
if (wait == UMH_WAIT_PROC)
|
|
|
pid = kernel_thread(wait_for_helper, sub_info,
|
|
|
CLONE_FS | CLONE_FILES | SIGCHLD);
|
|
|
- else
|
|
|
- pid = kernel_thread(____call_usermodehelper, sub_info,
|
|
|
+ else {
|
|
|
+ pid = kernel_thread(call_helper, sub_info,
|
|
|
CLONE_VFORK | SIGCHLD);
|
|
|
+ /* Worker thread stopped blocking khelper thread. */
|
|
|
+ kmod_thread_locker = NULL;
|
|
|
+ }
|
|
|
|
|
|
switch (wait) {
|
|
|
case UMH_NO_WAIT:
|
|
@@ -548,6 +565,16 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
|
|
|
retval = -EBUSY;
|
|
|
goto out;
|
|
|
}
|
|
|
+ /*
|
|
|
+ * Worker thread must not wait for khelper thread at below
|
|
|
+ * wait_for_completion() if the thread was created with CLONE_VFORK
|
|
|
+ * flag, for khelper thread is already waiting for the thread at
|
|
|
+ * wait_for_completion() in do_fork().
|
|
|
+ */
|
|
|
+ if (wait != UMH_NO_WAIT && current == kmod_thread_locker) {
|
|
|
+ retval = -EBUSY;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
|
|
|
sub_info->complete = &done;
|
|
|
sub_info->wait = wait;
|