aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--fs/autofs/autofs_i.h5
-rw-r--r--fs/autofs/dev-ioctl.c23
-rw-r--r--fs/autofs/init.c2
3 files changed, 9 insertions, 21 deletions
diff --git a/fs/autofs/autofs_i.h b/fs/autofs/autofs_i.h
index 9f9cadbfbd7a..64f693d355ad 100644
--- a/fs/autofs/autofs_i.h
+++ b/fs/autofs/autofs_i.h
@@ -42,6 +42,8 @@
42#endif 42#endif
43#define pr_fmt(fmt) KBUILD_MODNAME ":pid:%d:%s: " fmt, current->pid, __func__ 43#define pr_fmt(fmt) KBUILD_MODNAME ":pid:%d:%s: " fmt, current->pid, __func__
44 44
45extern struct file_system_type autofs_fs_type;
46
45/* 47/*
46 * Unified info structure. This is pointed to by both the dentry and 48 * Unified info structure. This is pointed to by both the dentry and
47 * inode structures. Each file in the filesystem has an instance of this 49 * inode structures. Each file in the filesystem has an instance of this
@@ -126,8 +128,7 @@ struct autofs_sb_info {
126 128
127static inline struct autofs_sb_info *autofs_sbi(struct super_block *sb) 129static inline struct autofs_sb_info *autofs_sbi(struct super_block *sb)
128{ 130{
129 return sb->s_magic != AUTOFS_SUPER_MAGIC ? 131 return (struct autofs_sb_info *)(sb->s_fs_info);
130 NULL : (struct autofs_sb_info *)(sb->s_fs_info);
131} 132}
132 133
133static inline struct autofs_info *autofs_dentry_ino(struct dentry *dentry) 134static inline struct autofs_info *autofs_dentry_ino(struct dentry *dentry)
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
diff --git a/fs/autofs/init.c b/fs/autofs/init.c
index 79ae07d9592f..c0c1db2cc6ea 100644
--- a/fs/autofs/init.c
+++ b/fs/autofs/init.c
@@ -16,7 +16,7 @@ static struct dentry *autofs_mount(struct file_system_type *fs_type,
16 return mount_nodev(fs_type, flags, data, autofs_fill_super); 16 return mount_nodev(fs_type, flags, data, autofs_fill_super);
17} 17}
18 18
19static struct file_system_type autofs_fs_type = { 19struct file_system_type autofs_fs_type = {
20 .owner = THIS_MODULE, 20 .owner = THIS_MODULE,
21 .name = "autofs", 21 .name = "autofs",
22 .mount = autofs_mount, 22 .mount = autofs_mount,