Commit d4d79b81 authored by Ian Kent's avatar Ian Kent Committed by Linus Torvalds

autofs: fix directory and symlink access

Depending on how it is configured the autofs user space daemon can leave
in use mounts mounted at exit and re-connect to them at start up.  But for
this to work best the state of the autofs file system needs to be left
intact over the restart.

Also, at system shutdown, mounts in an autofs file system might be
umounted exposing a mount point trigger for which subsequent access can
lead to a hang.  So recent versions of automount(8) now does its best to
set autofs file system mounts catatonic at shutdown.

When autofs file system mounts are catatonic it's currently possible to
create and remove directories and symlinks which can be a problem at
restart, as described above.

So return EACCES in the directory, symlink and unlink methods if the
autofs file system is catatonic.

Link: http://lkml.kernel.org/r/152902119090.4144.9561910674530214291.stgit@pluto.themaw.netSigned-off-by: default avatarIan Kent <raven@themaw.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 3f5c15d8
...@@ -559,6 +559,13 @@ static int autofs_dir_symlink(struct inode *dir, ...@@ -559,6 +559,13 @@ static int autofs_dir_symlink(struct inode *dir,
if (!autofs_oz_mode(sbi)) if (!autofs_oz_mode(sbi))
return -EACCES; return -EACCES;
/* autofs_oz_mode() needs to allow path walks when the
* autofs mount is catatonic but the state of an autofs
* file system needs to be preserved over restarts.
*/
if (sbi->catatonic)
return -EACCES;
BUG_ON(!ino); BUG_ON(!ino);
autofs_clean_ino(ino); autofs_clean_ino(ino);
...@@ -612,9 +619,15 @@ static int autofs_dir_unlink(struct inode *dir, struct dentry *dentry) ...@@ -612,9 +619,15 @@ static int autofs_dir_unlink(struct inode *dir, struct dentry *dentry)
struct autofs_info *ino = autofs_dentry_ino(dentry); struct autofs_info *ino = autofs_dentry_ino(dentry);
struct autofs_info *p_ino; struct autofs_info *p_ino;
/* This allows root to remove symlinks */ if (!autofs_oz_mode(sbi))
if (!autofs_oz_mode(sbi) && !capable(CAP_SYS_ADMIN)) return -EACCES;
return -EPERM;
/* autofs_oz_mode() needs to allow path walks when the
* autofs mount is catatonic but the state of an autofs
* file system needs to be preserved over restarts.
*/
if (sbi->catatonic)
return -EACCES;
if (atomic_dec_and_test(&ino->count)) { if (atomic_dec_and_test(&ino->count)) {
p_ino = autofs_dentry_ino(dentry->d_parent); p_ino = autofs_dentry_ino(dentry->d_parent);
...@@ -697,6 +710,13 @@ static int autofs_dir_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -697,6 +710,13 @@ static int autofs_dir_rmdir(struct inode *dir, struct dentry *dentry)
if (!autofs_oz_mode(sbi)) if (!autofs_oz_mode(sbi))
return -EACCES; return -EACCES;
/* autofs_oz_mode() needs to allow path walks when the
* autofs mount is catatonic but the state of an autofs
* file system needs to be preserved over restarts.
*/
if (sbi->catatonic)
return -EACCES;
spin_lock(&sbi->lookup_lock); spin_lock(&sbi->lookup_lock);
if (!simple_empty(dentry)) { if (!simple_empty(dentry)) {
spin_unlock(&sbi->lookup_lock); spin_unlock(&sbi->lookup_lock);
...@@ -735,6 +755,13 @@ static int autofs_dir_mkdir(struct inode *dir, ...@@ -735,6 +755,13 @@ static int autofs_dir_mkdir(struct inode *dir,
if (!autofs_oz_mode(sbi)) if (!autofs_oz_mode(sbi))
return -EACCES; return -EACCES;
/* autofs_oz_mode() needs to allow path walks when the
* autofs mount is catatonic but the state of an autofs
* file system needs to be preserved over restarts.
*/
if (sbi->catatonic)
return -EACCES;
pr_debug("dentry %p, creating %pd\n", dentry, dentry); pr_debug("dentry %p, creating %pd\n", dentry, dentry);
BUG_ON(!ino); BUG_ON(!ino);
......
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