The patch titled Subject: autofs: improve ioctl sbi checks has been added to the -mm tree. Its filename is autofs-improve-ioctl-sbi-checks.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/autofs-improve-ioctl-sbi-checks.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/autofs-improve-ioctl-sbi-checks.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Ian Kent <raven@xxxxxxxxxx> Subject: 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. Link: http://lkml.kernel.org/r/154296970987.9889.1597442413573683096.stgit@pluto-themaw-net Signed-off-by: Ian Kent <raven@xxxxxxxxxx> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- --- a/fs/autofs/autofs_i.h~autofs-improve-ioctl-sbi-checks +++ a/fs/autofs/autofs_i.h @@ -126,8 +126,7 @@ struct autofs_sb_info { static inline struct autofs_sb_info *autofs_sbi(struct super_block *sb) { - return sb->s_magic != AUTOFS_SUPER_MAGIC ? - NULL : (struct autofs_sb_info *)(sb->s_fs_info); + return (struct autofs_sb_info *)(sb->s_fs_info); } static inline struct autofs_info *autofs_dentry_ino(struct dentry *dentry) --- a/fs/autofs/dev-ioctl.c~autofs-improve-ioctl-sbi-checks +++ a/fs/autofs/dev-ioctl.c @@ -14,6 +14,8 @@ #include "autofs_i.h" +extern struct file_system_type autofs_fs_type; + /* * This module implements an interface for routing autofs ioctl control * commands via a miscellaneous device file. @@ -151,22 +153,6 @@ out: 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 */ static int autofs_dev_ioctl_version(struct file *fp, struct autofs_sb_info *sbi, @@ -658,6 +644,8 @@ static int _autofs_dev_ioctl(unsigned in if (cmd != AUTOFS_DEV_IOCTL_VERSION_CMD && cmd != AUTOFS_DEV_IOCTL_OPENMOUNT_CMD && cmd != AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD) { + struct super_block *sb; + fp = fget(param->ioctlfd); if (!fp) { if (cmd == AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD) @@ -666,12 +654,13 @@ static int _autofs_dev_ioctl(unsigned in goto out; } - sbi = autofs_dev_ioctl_sbi(fp); - if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) { + sb = file_inode(fp)->i_sb; + if (sb->s_type != &autofs_fs_type) { err = -EINVAL; fput(fp); goto out; } + sbi = autofs_sbi(sb); /* * Admin needs to be able to set the mount catatonic in --- a/fs/autofs/init.c~autofs-improve-ioctl-sbi-checks +++ a/fs/autofs/init.c @@ -16,7 +16,7 @@ static struct dentry *autofs_mount(struc 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, .name = "autofs", .mount = autofs_mount, _ Patches currently in -mm which might be from raven@xxxxxxxxxx are autofs-improve-ioctl-sbi-checks.patch autofs-fix-possible-inode-leak-in-autofs_fill_super.patch autofs-simplify-parse_options-function-call.patch autofs-change-catatonic-setting-to-a-bit-flag.patch autofs-add-strictexpire-mount-option.patch