[PATCH v2 01/17] compat_ioctl: add generic_compat_ioctl_ptrarg()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Many drivers have ioctl() handlers that are completely compatible
between 32-bit and 64-bit architectures, except for the argument
that is passed down from user space and may have to be passed
through compat_ptr() in order to become a valid 64-bit pointer.

Using ".compat_ptr=generic_compat_ioctl_ptrarg" in file operations
should let us simplify a lot of those drivers to avoid #ifdef
checks, and convert additional drivers that don't have proper
compat handling yet.

Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
---
 fs/compat_ioctl.c  | 10 ++++++++++
 include/linux/fs.h |  7 +++++++
 2 files changed, 17 insertions(+)

diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index a9b00942e87d..2d7c7e149083 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -122,6 +122,16 @@
 	get_user(val, srcptr) || put_user(val, dstptr);	\
 })
 
+/* helper function to avoid trivial compat_ioctl() implementations */
+long generic_compat_ioctl_ptrarg(struct file *file, unsigned int cmd, unsigned long arg)
+{
+	if (!file->f_op->unlocked_ioctl)
+		return -ENOIOCTLCMD;
+
+	return file->f_op->unlocked_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
+}
+EXPORT_SYMBOL_GPL(generic_compat_ioctl_ptrarg);
+
 static int do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
 	int err;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 33322702c910..18a90aa2dc93 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1643,6 +1643,13 @@ int vfs_mkobj(struct dentry *, umode_t,
 
 extern long vfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
 
+#ifdef CONFIG_COMPAT
+extern long generic_compat_ioctl_ptrarg(struct file *file, unsigned int cmd,
+					unsigned long arg);
+#else
+#define generic_compat_ioctl_ptrarg NULL
+#endif
+
 /*
  * VFS file helper functions.
  */
-- 
2.18.0




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux