lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180912150142.157913-1-arnd@arndb.de>
Date:   Wed, 12 Sep 2018 17:01:02 +0200
From:   Arnd Bergmann <arnd@...db.de>
To:     viro@...iv.linux.org.uk
Cc:     linux-fsdevel@...r.kernel.org, Arnd Bergmann <arnd@...db.de>,
        linux-kernel@...r.kernel.org
Subject: [PATCH v2 01/17] compat_ioctl: add generic_compat_ioctl_ptrarg()

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@...db.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ