Commit 0259cb02 authored by Ian Kent's avatar Ian Kent Committed by Linus Torvalds

autofs4 - use simple_empty() for empty directory check

For direct (and offset) mounts, if an automounted mount is manually
umounted the trigger mount dentry can appear non-empty causing it to
not trigger mounts. This can also happen if there is a file handle
leak in a user space automounting application.

This happens because, when a ioctl control file handle is opened
on the mount, a cursor dentry is created which causes list_empty()
to see the dentry as non-empty. Since there is a case where listing
the directory of these dentrys is needed, the use of dcache_dir_*()
functions for .open() and .release() is needed.

Consequently simple_empty() must be used instead of list_empty()
when checking for an empty directory.
Signed-off-by: default avatarIan Kent <raven@themaw.net>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f55fb0c2
...@@ -124,13 +124,10 @@ static int autofs4_dir_open(struct inode *inode, struct file *file) ...@@ -124,13 +124,10 @@ static int autofs4_dir_open(struct inode *inode, struct file *file)
* it. * it.
*/ */
spin_lock(&sbi->lookup_lock); spin_lock(&sbi->lookup_lock);
spin_lock(&dentry->d_lock); if (!d_mountpoint(dentry) && simple_empty(dentry)) {
if (!d_mountpoint(dentry) && list_empty(&dentry->d_subdirs)) {
spin_unlock(&dentry->d_lock);
spin_unlock(&sbi->lookup_lock); spin_unlock(&sbi->lookup_lock);
return -ENOENT; return -ENOENT;
} }
spin_unlock(&dentry->d_lock);
spin_unlock(&sbi->lookup_lock); spin_unlock(&sbi->lookup_lock);
out: out:
...@@ -386,12 +383,8 @@ static struct vfsmount *autofs4_d_automount(struct path *path) ...@@ -386,12 +383,8 @@ static struct vfsmount *autofs4_d_automount(struct path *path)
goto done; goto done;
} }
} else { } else {
spin_lock(&dentry->d_lock); if (!simple_empty(dentry))
if (!list_empty(&dentry->d_subdirs)) {
spin_unlock(&dentry->d_lock);
goto done; goto done;
}
spin_unlock(&dentry->d_lock);
} }
ino->flags |= AUTOFS_INF_PENDING; ino->flags |= AUTOFS_INF_PENDING;
spin_unlock(&sbi->fs_lock); spin_unlock(&sbi->fs_lock);
...@@ -610,9 +603,7 @@ static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry) ...@@ -610,9 +603,7 @@ static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
spin_lock(&sbi->lookup_lock); spin_lock(&sbi->lookup_lock);
__autofs4_add_expiring(dentry); __autofs4_add_expiring(dentry);
spin_lock(&dentry->d_lock); d_drop(dentry);
__d_drop(dentry);
spin_unlock(&dentry->d_lock);
spin_unlock(&sbi->lookup_lock); spin_unlock(&sbi->lookup_lock);
return 0; return 0;
...@@ -683,15 +674,12 @@ static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -683,15 +674,12 @@ static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
return -EACCES; return -EACCES;
spin_lock(&sbi->lookup_lock); spin_lock(&sbi->lookup_lock);
spin_lock(&dentry->d_lock); if (!simple_empty(dentry)) {
if (!list_empty(&dentry->d_subdirs)) {
spin_unlock(&dentry->d_lock);
spin_unlock(&sbi->lookup_lock); spin_unlock(&sbi->lookup_lock);
return -ENOTEMPTY; return -ENOTEMPTY;
} }
__autofs4_add_expiring(dentry); __autofs4_add_expiring(dentry);
__d_drop(dentry); d_drop(dentry);
spin_unlock(&dentry->d_lock);
spin_unlock(&sbi->lookup_lock); spin_unlock(&sbi->lookup_lock);
if (sbi->version < 5) if (sbi->version < 5)
......
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