From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de ([212.227.126.130]:52626 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727804AbeILUHI (ORCPT ); Wed, 12 Sep 2018 16:07:08 -0400 From: Arnd Bergmann To: viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, Arnd Bergmann , linux-kernel@vger.kernel.org Subject: [PATCH v2 01/17] compat_ioctl: add generic_compat_ioctl_ptrarg() Date: Wed, 12 Sep 2018 17:01:02 +0200 Message-Id: <20180912150142.157913-1-arnd@arndb.de> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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 --- 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