aboutsummaryrefslogtreecommitdiffstats
path: root/fs/autofs/dev-ioctl.c
diff options
context:
space:
mode:
authorIan Kent <raven@themaw.net>2019-01-03 18:27:33 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2019-01-04 16:13:46 -0500
commit55f0d8205dc6399826332c21bc56626868cd453d (patch)
tree9a15cf912445e21d9ad3fb87f087a89185313191 /fs/autofs/dev-ioctl.c
parent7c8f71935a65a584c48cbe478aaffc52292d6e00 (diff)
autofs: improve ioctl sbi checks
Al Viro made some suggestions to improve the implementation of commit 0633da48f0 ("fix autofs_sbi() does not check super block type"). The check is unnecessary in all cases except for ioctl usage so placing the check in the super block accessor function adds a small overhead to the common case where it isn't needed. So it's sufficient to do this in the ioctl code only. Also the check in the ioctl code is needlessly complex. [akpm@linux-foundation.org: declare autofs_fs_type in .h, not .c] Link: http://lkml.kernel.org/r/154296970987.9889.1597442413573683096.stgit@pluto-themaw-net Signed-off-by: Ian Kent <raven@themaw.net> Cc: Al Viro <viro@ZenIV.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/autofs/dev-ioctl.c')
-rw-r--r--fs/autofs/dev-ioctl.c23
1 files changed, 5 insertions, 18 deletions
diff --git a/fs/autofs/dev-ioctl.c b/fs/autofs/dev-ioctl.c
index 86eafda4a652..752983aafb84 100644
--- a/fs/autofs/dev-ioctl.c
+++ b/fs/autofs/dev-ioctl.c
@@ -151,22 +151,6 @@ out:
151 return err; 151 return err;
152} 152}
153 153
154/*
155 * Get the autofs super block info struct from the file opened on
156 * the autofs mount point.
157 */
158static struct autofs_sb_info *autofs_dev_ioctl_sbi(struct file *f)
159{
160 struct autofs_sb_info *sbi = NULL;
161 struct inode *inode;
162
163 if (f) {
164 inode = file_inode(f);
165 sbi = autofs_sbi(inode->i_sb);
166 }
167 return sbi;
168}
169
170/* Return autofs dev ioctl version */ 154/* Return autofs dev ioctl version */
171static int autofs_dev_ioctl_version(struct file *fp, 155static int autofs_dev_ioctl_version(struct file *fp,
172 struct autofs_sb_info *sbi, 156 struct autofs_sb_info *sbi,
@@ -658,6 +642,8 @@ static int _autofs_dev_ioctl(unsigned int command,
658 if (cmd != AUTOFS_DEV_IOCTL_VERSION_CMD && 642 if (cmd != AUTOFS_DEV_IOCTL_VERSION_CMD &&
659 cmd != AUTOFS_DEV_IOCTL_OPENMOUNT_CMD && 643 cmd != AUTOFS_DEV_IOCTL_OPENMOUNT_CMD &&
660 cmd != AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD) { 644 cmd != AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD) {
645 struct super_block *sb;
646
661 fp = fget(param->ioctlfd); 647 fp = fget(param->ioctlfd);
662 if (!fp) { 648 if (!fp) {
663 if (cmd == AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD) 649 if (cmd == AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD)
@@ -666,12 +652,13 @@ static int _autofs_dev_ioctl(unsigned int command,
666 goto out; 652 goto out;
667 } 653 }
668 654
669 sbi = autofs_dev_ioctl_sbi(fp); 655 sb = file_inode(fp)->i_sb;
670 if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) { 656 if (sb->s_type != &autofs_fs_type) {
671 err = -EINVAL; 657 err = -EINVAL;
672 fput(fp); 658 fput(fp);
673 goto out; 659 goto out;
674 } 660 }
661 sbi = autofs_sbi(sb);
675 662
676 /* 663 /*
677 * Admin needs to be able to set the mount catatonic in 664 * Admin needs to be able to set the mount catatonic in