linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 01/17] compat_ioctl: add generic_compat_ioctl_ptrarg()
@ 2018-09-12 15:01 Arnd Bergmann
  2018-09-12 15:01 ` [PATCH v2 02/17] compat_ioctl: move drivers to generic_compat_ioctl_ptrarg Arnd Bergmann
                   ` (5 more replies)
  0 siblings, 6 replies; 48+ messages in thread
From: Arnd Bergmann @ 2018-09-12 15:01 UTC (permalink / raw)
  To: viro; +Cc: linux-fsdevel, Arnd Bergmann, linux-kernel

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@arndb.de>
---
 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

^ permalink raw reply related	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2018-10-29 18:38 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-12 15:01 [PATCH v2 01/17] compat_ioctl: add generic_compat_ioctl_ptrarg() Arnd Bergmann
2018-09-12 15:01 ` [PATCH v2 02/17] compat_ioctl: move drivers to generic_compat_ioctl_ptrarg Arnd Bergmann
2018-09-12 15:33   ` Jason Gunthorpe
2018-09-12 16:20     ` Arnd Bergmann
2018-09-12 18:13   ` Greg Kroah-Hartman
2018-09-16 19:07   ` Jarkko Sakkinen
2018-09-12 15:01 ` [PATCH v2 03/17] compat_ioctl: use correct compat_ptr() translation in drivers Arnd Bergmann
2018-09-12 18:13   ` Greg Kroah-Hartman
2018-09-13  0:48   ` Andrew Donnellan
2018-09-13 11:03   ` Felipe Balbi
2018-09-12 15:01 ` [PATCH v2 04/17] ceph: fix compat_ioctl for ceph_dir_operations Arnd Bergmann
2018-09-12 16:12   ` David Laight
2018-09-12 16:25     ` Arnd Bergmann
2018-09-13  0:48   ` Yan, Zheng
2018-09-12 15:08 ` [PATCH v2 05/17] compat_ioctl: move more drivers to generic_compat_ioctl_ptrarg Arnd Bergmann
2018-09-12 15:08   ` [PATCH v2 06/17] compat_ioctl: move rtc handling into rtc-dev.c Arnd Bergmann
2018-09-12 20:00     ` Alexandre Belloni
2018-09-12 15:08   ` [PATCH v2 07/17] compat_ioctl: move tape handling into drivers Arnd Bergmann
2018-09-12 15:08   ` [PATCH v2 08/17] compat_ioctl: remove keyboard ioctl translation Arnd Bergmann
2018-09-12 15:08   ` [PATCH v2 09/17] compat_ioctl: remove HIDIO translation Arnd Bergmann
2018-09-12 15:56   ` [PATCH v2 05/17] compat_ioctl: move more drivers to generic_compat_ioctl_ptrarg Jason Gunthorpe
2018-09-12 15:58   ` Daniel Vetter
2018-09-12 16:01   ` Mauro Carvalho Chehab
2018-09-12 18:13   ` Greg Kroah-Hartman
2018-09-14 14:23   ` David Sterba
2018-09-14 20:35   ` Darren Hart
2018-09-14 20:57     ` Al Viro
2018-09-18 17:51       ` Darren Hart
2018-09-18 17:59         ` Jason Gunthorpe
2018-09-24 20:18           ` Arnd Bergmann
2018-09-24 20:35             ` Jason Gunthorpe
2018-09-24 21:17               ` Arnd Bergmann
2018-09-17  9:33   ` Jonathan Cameron
2018-10-06  7:05   ` Bjorn Andersson
2018-09-12 15:13 ` [PATCH v2 10/17] compat_ioctl: remove translation for sound ioctls Arnd Bergmann
2018-09-12 15:13   ` [PATCH v2 11/17] compat_ioctl: remove isdn ioctl translation Arnd Bergmann
2018-09-12 15:13   ` [PATCH v2 12/17] compat_ioctl: remove IGNORE_IOCTL() Arnd Bergmann
2018-09-12 15:13   ` [PATCH v2 13/17] compat_ioctl: remove /dev/random commands Arnd Bergmann
2018-09-12 18:13     ` Greg Kroah-Hartman
2018-09-12 15:13   ` [PATCH v2 14/17] compat_ioctl: remove joystick ioctl translation Arnd Bergmann
2018-09-12 15:13   ` [PATCH v2 15/17] compat_ioctl: remove PCI " Arnd Bergmann
2018-09-12 15:13   ` [PATCH v2 16/17] compat_ioctl: remove /dev/raw " Arnd Bergmann
2018-09-12 15:13   ` [PATCH v2 17/17] compat_ioctl: remove last RAID handling code Arnd Bergmann
2018-09-13 13:37   ` [PATCH v2 10/17] compat_ioctl: remove translation for sound ioctls Takashi Iwai
2018-09-13  2:07 ` [PATCH v2 01/17] compat_ioctl: add generic_compat_ioctl_ptrarg() Al Viro
2018-09-13 10:29   ` Arnd Bergmann
2018-10-28 17:07     ` Al Viro
2018-10-29  9:50       ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).