From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] kmod: Avoid deadlock by recursive kmod call.
Date: Wed, 4 Jan 2012 22:08:09 +0900 [thread overview]
Message-ID: <201201042208.JHG52695.OLStHFQOFFMVJO@I-love.SAKURA.ne.jp> (raw)
In-Reply-To: <201201040743.q047h9OD055670@www262.sakura.ne.jp>
Tetsuo Handa wrote:
> I noticed that the system deadlocks if do_execve() request by kmod() triggered
> recursive do_execve() request.
>
> An example operation for triggering this deadlock:
>
> # : > /tmp/dummy
> # chmod 755 /tmp/dummy
> # echo /tmp/dummy > /proc/sys/kernel/hotplug
> # modprobe whatever
>
> Although this patch works for me, I'm not sure that this is a correct fix.
> Also, my analysis in the patch description may be wrong. Please check.
Well, we should not unconditionally prevent all vfork()ed threads from using
request_module() at search_binary_handler(). We should prevent only kernel
threads created by __call_usermodehelper(). Updated to filter only kmod threads.
--------------------
[PATCH v2] kmod: Avoid deadlock by recursive kmod call.
call_usermodehelper(UMH_WAIT_EXEC or UMH_WAIT_PROC) request depends on an
assumption that do_execve() will not trigger recursive
call_usermodehelper(UMH_WAIT_EXEC or UMH_WAIT_PROC) request, for
"khelper cannot start processing recursive call_usermodehelper() request until
do_execve() of original call_usermodehelper() request completes" but
"do_execve() of original call_usermodehelper() cannot be completed until
recursive call_usermodehelper() request completes".
There are several callers that break this assumption and lead to deadlock.
We need to make sure that do_execve() request by kmod thread does not trigger
recursive call_usermodehelper(UMH_WAIT_PROC or UMH_WAIT_EXEC).
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
include/linux/sched.h | 3 +++
kernel/kmod.c | 18 +++++++++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)
--- linux-3.1.7.orig/include/linux/sched.h
+++ linux-3.1.7/include/linux/sched.h
@@ -1305,6 +1305,9 @@ struct task_struct {
unsigned sched_reset_on_fork:1;
unsigned sched_contributes_to_load:1;
+ /* Prevent recursive kmod request. */
+ unsigned kmod_thread:1;
+
pid_t pid;
pid_t tgid;
--- linux-3.1.7.orig/kernel/kmod.c
+++ linux-3.1.7/kernel/kmod.c
@@ -189,6 +189,13 @@ fail:
do_exit(0);
}
+static int call_helper(void *data)
+{
+ /* Do not trigger recursive kmod call. */
+ current->kmod_thread = 1;
+ return ____call_usermodehelper(data);
+}
+
void call_usermodehelper_freeinfo(struct subprocess_info *info)
{
if (info->cleanup)
@@ -252,7 +259,7 @@ static void __call_usermodehelper(struct
pid = kernel_thread(wait_for_helper, sub_info,
CLONE_FS | CLONE_FILES | SIGCHLD);
else
- pid = kernel_thread(____call_usermodehelper, sub_info,
+ pid = kernel_thread(call_helper, sub_info,
CLONE_VFORK | SIGCHLD);
switch (wait) {
@@ -428,6 +435,15 @@ int call_usermodehelper_exec(struct subp
retval = -EBUSY;
goto out;
}
+ /*
+ * We can't call wait_for_completion() if current thread was created by
+ * call_helper(), or we will deadlock when current thread calls
+ * request_module() from search_binary_handler().
+ */
+ if (wait != UMH_NO_WAIT && current->kmod_thread) {
+ retval = -EBUSY;
+ goto out;
+ }
sub_info->complete = &done;
sub_info->wait = wait;
next prev parent reply other threads:[~2012-01-04 13:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-27 7:01 [3.1.6] Deadlock upon recursive call_usermodehelper_exec() penguin-kernel
2011-12-27 8:14 ` Tetsuo Handa
2012-01-04 7:43 ` [PATCH] kmod: Avoid deadlock by recursive kmod call Tetsuo Handa
2012-01-04 13:08 ` Tetsuo Handa [this message]
[not found] ` <201201062139.JFC73472.SMQFOFOFHLVOtJ@I-love.SAKURA.ne.jp>
2012-01-19 0:45 ` [PATCH v3] " Andrew Morton
2012-01-19 2:07 ` Tetsuo Handa
2012-01-24 4:32 ` [PATCH v4] " Tetsuo Handa
2012-01-26 0:40 ` Andrew Morton
2012-01-26 1:32 ` Tetsuo Handa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201201042208.JHG52695.OLStHFQOFFMVJO@I-love.SAKURA.ne.jp \
--to=penguin-kernel@i-love.sakura.ne.jp \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).