Commit 55f0d820 authored by Ian Kent's avatar Ian Kent Committed by Linus Torvalds

autofs: improve ioctl sbi checks

Al Viro made some suggestions to improve the implementation of commit
0633da48 ("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-netSigned-off-by: default avatarIan Kent <raven@themaw.net>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7c8f7193
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#endif #endif
#define pr_fmt(fmt) KBUILD_MODNAME ":pid:%d:%s: " fmt, current->pid, __func__ #define pr_fmt(fmt) KBUILD_MODNAME ":pid:%d:%s: " fmt, current->pid, __func__
extern struct file_system_type autofs_fs_type;
/* /*
* Unified info structure. This is pointed to by both the dentry and * Unified info structure. This is pointed to by both the dentry and
* inode structures. Each file in the filesystem has an instance of this * inode structures. Each file in the filesystem has an instance of this
...@@ -126,8 +128,7 @@ struct autofs_sb_info { ...@@ -126,8 +128,7 @@ struct autofs_sb_info {
static inline struct autofs_sb_info *autofs_sbi(struct super_block *sb) static inline struct autofs_sb_info *autofs_sbi(struct super_block *sb)
{ {
return sb->s_magic != AUTOFS_SUPER_MAGIC ? return (struct autofs_sb_info *)(sb->s_fs_info);
NULL : (struct autofs_sb_info *)(sb->s_fs_info);
} }
static inline struct autofs_info *autofs_dentry_ino(struct dentry *dentry) static inline struct autofs_info *autofs_dentry_ino(struct dentry *dentry)
......
...@@ -151,22 +151,6 @@ static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param) ...@@ -151,22 +151,6 @@ static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param)
return err; return err;
} }
/*
* Get the autofs super block info struct from the file opened on
* the autofs mount point.
*/
static struct autofs_sb_info *autofs_dev_ioctl_sbi(struct file *f)
{
struct autofs_sb_info *sbi = NULL;
struct inode *inode;
if (f) {
inode = file_inode(f);
sbi = autofs_sbi(inode->i_sb);
}
return sbi;
}
/* Return autofs dev ioctl version */ /* Return autofs dev ioctl version */
static int autofs_dev_ioctl_version(struct file *fp, static int autofs_dev_ioctl_version(struct file *fp,
struct autofs_sb_info *sbi, struct autofs_sb_info *sbi,
...@@ -658,6 +642,8 @@ static int _autofs_dev_ioctl(unsigned int command, ...@@ -658,6 +642,8 @@ static int _autofs_dev_ioctl(unsigned int command,
if (cmd != AUTOFS_DEV_IOCTL_VERSION_CMD && if (cmd != AUTOFS_DEV_IOCTL_VERSION_CMD &&
cmd != AUTOFS_DEV_IOCTL_OPENMOUNT_CMD && cmd != AUTOFS_DEV_IOCTL_OPENMOUNT_CMD &&
cmd != AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD) { cmd != AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD) {
struct super_block *sb;
fp = fget(param->ioctlfd); fp = fget(param->ioctlfd);
if (!fp) { if (!fp) {
if (cmd == AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD) if (cmd == AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD)
...@@ -666,12 +652,13 @@ static int _autofs_dev_ioctl(unsigned int command, ...@@ -666,12 +652,13 @@ static int _autofs_dev_ioctl(unsigned int command,
goto out; goto out;
} }
sbi = autofs_dev_ioctl_sbi(fp); sb = file_inode(fp)->i_sb;
if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) { if (sb->s_type != &autofs_fs_type) {
err = -EINVAL; err = -EINVAL;
fput(fp); fput(fp);
goto out; goto out;
} }
sbi = autofs_sbi(sb);
/* /*
* Admin needs to be able to set the mount catatonic in * Admin needs to be able to set the mount catatonic in
......
...@@ -16,7 +16,7 @@ static struct dentry *autofs_mount(struct file_system_type *fs_type, ...@@ -16,7 +16,7 @@ static struct dentry *autofs_mount(struct file_system_type *fs_type,
return mount_nodev(fs_type, flags, data, autofs_fill_super); return mount_nodev(fs_type, flags, data, autofs_fill_super);
} }
static struct file_system_type autofs_fs_type = { struct file_system_type autofs_fs_type = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "autofs", .name = "autofs",
.mount = autofs_mount, .mount = autofs_mount,
......
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