Skip to content

Commit

Permalink
sched, modules: Fix nested sleep in add_unformed_module()
Browse files Browse the repository at this point in the history
This is a genuine bug in add_unformed_module(), we cannot use blocking
primitives inside a wait loop.

So rewrite the wait_event_interruptible() usage to use the fresh
wait_woken() stuff.

Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: tglx@linutronix.de
Cc: ilya.dryomov@inktank.com
Cc: umgwanakikbuti@gmail.com
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: oleg@redhat.com
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: http://lkml.kernel.org/r/20140924082242.458562904@infradead.org
[ So this is probably complex to backport and the race wasn't reported AFAIK,
  so not marked for -stable. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>

Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Oct 28, 2014
1 parent 7d4d269 commit 3c9b2c3
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -3096,6 +3096,32 @@ static int may_init_module(void)
return 0;
}

/*
* Can't use wait_event_interruptible() because our condition
* 'finished_loading()' contains a blocking primitive itself (mutex_lock).
*/
static int wait_finished_loading(struct module *mod)
{
DEFINE_WAIT_FUNC(wait, woken_wake_function);
int ret = 0;

add_wait_queue(&module_wq, &wait);
for (;;) {
if (finished_loading(mod->name))
break;

if (signal_pending(current)) {
ret = -ERESTARTSYS;
break;
}

wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
}
remove_wait_queue(&module_wq, &wait);

return ret;
}

/*
* We try to place it in the list now to make sure it's unique before
* we dedicate too many resources. In particular, temporary percpu
Expand All @@ -3116,8 +3142,8 @@ static int add_unformed_module(struct module *mod)
|| old->state == MODULE_STATE_UNFORMED) {
/* Wait in case it fails to load. */
mutex_unlock(&module_mutex);
err = wait_event_interruptible(module_wq,
finished_loading(mod->name));

err = wait_finished_loading(mod);
if (err)
goto out_unlocked;
goto again;
Expand Down

0 comments on commit 3c9b2c3

Please sign in to comment.