aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorIan Kent <raven@themaw.net>2009-03-31 18:24:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-04-01 11:59:23 -0400
commit8f63aaa8b9239475fc580d4450f1141496655305 (patch)
treeeca8552ab842a7a2eecea104e5842f7bccadf09b /fs
parent56fcef75117a153f298b3fe54af31053f53997dd (diff)
autofs4: fix lookup deadlock
A deadlock can occur when user space uses a signal (autofs version 4 uses SIGCHLD for this) to effect expire completion. The order of events is: Expire process completes, but before being able to send SIGCHLD to it's parent ... Another process walks onto a different mount point and drops the directory inode semaphore prior to sending the request to the daemon as it must ... A third process does an lstat on on the expired mount point causing it to wait on expire completion (unfortunately) holding the directory semaphore. The mount request then arrives at the daemon which does an lstat and, deadlock. For some time I was concerned about releasing the directory semaphore around the expire wait in autofs4_lookup as well as for the mount call back. I finally realized that the last round of changes in this function made the expiring dentry and the lookup dentry separate and distinct so the check and possible wait can be done anywhere prior to the mount call back. This patch moves the check to just before the mount call back and inside the directory inode mutex release. Signed-off-by: Ian Kent <raven@themaw.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/autofs4/root.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
index 74b1469a9504..e383bf0334f1 100644
--- a/fs/autofs4/root.c
+++ b/fs/autofs4/root.c
@@ -485,22 +485,6 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
485 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d", 485 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
486 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode); 486 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
487 487
488 expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name);
489 if (expiring) {
490 /*
491 * If we are racing with expire the request might not
492 * be quite complete but the directory has been removed
493 * so it must have been successful, so just wait for it.
494 */
495 ino = autofs4_dentry_ino(expiring);
496 autofs4_expire_wait(expiring);
497 spin_lock(&sbi->lookup_lock);
498 if (!list_empty(&ino->expiring))
499 list_del_init(&ino->expiring);
500 spin_unlock(&sbi->lookup_lock);
501 dput(expiring);
502 }
503
504 unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name); 488 unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
505 if (unhashed) 489 if (unhashed)
506 dentry = unhashed; 490 dentry = unhashed;
@@ -538,14 +522,31 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
538 } 522 }
539 523
540 if (!oz_mode) { 524 if (!oz_mode) {
525 mutex_unlock(&dir->i_mutex);
526 expiring = autofs4_lookup_expiring(sbi,
527 dentry->d_parent,
528 &dentry->d_name);
529 if (expiring) {
530 /*
531 * If we are racing with expire the request might not
532 * be quite complete but the directory has been removed
533 * so it must have been successful, so just wait for it.
534 */
535 ino = autofs4_dentry_ino(expiring);
536 autofs4_expire_wait(expiring);
537 spin_lock(&sbi->lookup_lock);
538 if (!list_empty(&ino->expiring))
539 list_del_init(&ino->expiring);
540 spin_unlock(&sbi->lookup_lock);
541 dput(expiring);
542 }
543
541 spin_lock(&dentry->d_lock); 544 spin_lock(&dentry->d_lock);
542 dentry->d_flags |= DCACHE_AUTOFS_PENDING; 545 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
543 spin_unlock(&dentry->d_lock); 546 spin_unlock(&dentry->d_lock);
544 if (dentry->d_op && dentry->d_op->d_revalidate) { 547 if (dentry->d_op && dentry->d_op->d_revalidate)
545 mutex_unlock(&dir->i_mutex);
546 (dentry->d_op->d_revalidate)(dentry, nd); 548 (dentry->d_op->d_revalidate)(dentry, nd);
547 mutex_lock(&dir->i_mutex); 549 mutex_lock(&dir->i_mutex);
548 }
549 } 550 }
550 551
551 /* 552 /*