Commit 579adde4 authored by Martin Schwidefsky's avatar Martin Schwidefsky Committed by Adrian Bunk

kernel/kmod.c: fix a race condition in usermodehelper.

There is a race between call_usermodehelper_keys, __call_usermodehelper
and wait_for_helper. It should only happen if preemption is enabled or
on a virtualized system.

If the cpu is preempted or put to sleep by the hypervisor in
__call_usermodehelper between the creation of the wait_for_helper
thread and the second check on sub_info->wait, the whole execution
of wait_for_helper including the complete call and the continuation
after the wait_for_completion in call_usermodehelper_keys can have
happened before __call_usermodehelper checks sub_info->wait for the
second time. Since sub_info can already have been clobbered,
sub_info->wait could be zero and complete is called a second time
with an invalid argument. This has happened on s390. It took me only
three days to find out ..

Thanks to Arnd Bergmann for his help to spot this bug.

Kenneth Lee also sent the same patch independently.
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: default avatarAdrian Bunk <bunk@stusta.de>
parent ab469df3
...@@ -197,12 +197,13 @@ static int wait_for_helper(void *data) ...@@ -197,12 +197,13 @@ static int wait_for_helper(void *data)
static void __call_usermodehelper(void *data) static void __call_usermodehelper(void *data)
{ {
struct subprocess_info *sub_info = data; struct subprocess_info *sub_info = data;
int wait = sub_info->wait;
pid_t pid; pid_t pid;
/* CLONE_VFORK: wait until the usermode helper has execve'd /* CLONE_VFORK: wait until the usermode helper has execve'd
* successfully We need the data structures to stay around * successfully We need the data structures to stay around
* until that is done. */ * until that is done. */
if (sub_info->wait) if (wait)
pid = kernel_thread(wait_for_helper, sub_info, pid = kernel_thread(wait_for_helper, sub_info,
CLONE_FS | CLONE_FILES | SIGCHLD); CLONE_FS | CLONE_FILES | SIGCHLD);
else else
...@@ -212,7 +213,7 @@ static void __call_usermodehelper(void *data) ...@@ -212,7 +213,7 @@ static void __call_usermodehelper(void *data)
if (pid < 0) { if (pid < 0) {
sub_info->retval = pid; sub_info->retval = pid;
complete(sub_info->complete); complete(sub_info->complete);
} else if (!sub_info->wait) } else if (!wait)
complete(sub_info->complete); complete(sub_info->complete);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment