aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke@hauke-m.de>2020-03-12 10:41:18 +0100
committerHauke Mehrtens <hauke@hauke-m.de>2020-03-19 19:40:43 +0100
commit8f916962c848212394773b30d514f10f3b276c15 (patch)
tree4336db756cd90203a03d42a4edfe0bab4723fe72
parent32d57ce895e5cd218e275999a232d71bad8083b5 (diff)
downloadbackports-8f916962c848212394773b30d514f10f3b276c15.tar.gz
backports: fs.h: Add compat_ptr_ioctl()
compat_ptr_ioctl() was added in upstream commit 2952db0fd51b ("compat_ioctl: add compat_ptr_ioctl()") and is now used by the cdc-wdm driver. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
-rw-r--r--backport/backport-include/linux/fs.h10
-rw-r--r--backport/compat/Makefile1
-rw-r--r--backport/compat/backport-5.5.c41
3 files changed, 52 insertions, 0 deletions
diff --git a/backport/backport-include/linux/fs.h b/backport/backport-include/linux/fs.h
index 6e4d4a53..9854290a 100644
--- a/backport/backport-include/linux/fs.h
+++ b/backport/backport-include/linux/fs.h
@@ -49,4 +49,14 @@ static inline struct inode *file_inode(struct file *f)
extern loff_t no_seek_end_llseek(struct file *, loff_t, int);
#endif /* < 4.5 && >= 3.2 */
+#if LINUX_VERSION_IS_LESS(5,5,0)
+#ifdef CONFIG_COMPAT
+#define compat_ptr_ioctl LINUX_BACKPORT(compat_ptr_ioctl)
+extern long compat_ptr_ioctl(struct file *file, unsigned int cmd,
+ unsigned long arg);
+#else
+#define compat_ptr_ioctl NULL
+#endif
+#endif /* < 5.5 */
+
#endif /* _COMPAT_LINUX_FS_H */
diff --git a/backport/compat/Makefile b/backport/compat/Makefile
index e92e3120..6f1b0a89 100644
--- a/backport/compat/Makefile
+++ b/backport/compat/Makefile
@@ -38,6 +38,7 @@ compat-$(CPTCFG_KERNEL_4_8) += backport-4.8.o
compat-$(CPTCFG_KERNEL_4_10) += backport-4.10.o
compat-$(CPTCFG_KERNEL_4_18) += backport-4.18.o
compat-$(CPTCFG_KERNEL_5_2) += backport-5.2.o backport-genetlink.o
+compat-$(CPTCFG_KERNEL_5_5) += backport-5.5.o
compat-$(CPTCFG_BPAUTO_BUILD_SYSTEM_DATA_VERIFICATION) += verification/verify.o
compat-$(CPTCFG_BPAUTO_BUILD_SYSTEM_DATA_VERIFICATION) += verification/pkcs7.asn1.o
diff --git a/backport/compat/backport-5.5.c b/backport/compat/backport-5.5.c
new file mode 100644
index 00000000..6f46be9d
--- /dev/null
+++ b/backport/compat/backport-5.5.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/export.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/compat.h>
+
+#ifdef CONFIG_COMPAT
+/**
+ * compat_ptr_ioctl - generic implementation of .compat_ioctl file operation
+ *
+ * This is not normally called as a function, but instead set in struct
+ * file_operations as
+ *
+ * .compat_ioctl = compat_ptr_ioctl,
+ *
+ * On most architectures, the compat_ptr_ioctl() just passes all arguments
+ * to the corresponding ->ioctl handler. The exception is arch/s390, where
+ * compat_ptr() clears the top bit of a 32-bit pointer value, so user space
+ * pointers to the second 2GB alias the first 2GB, as is the case for
+ * native 32-bit s390 user space.
+ *
+ * The compat_ptr_ioctl() function must therefore be used only with ioctl
+ * functions that either ignore the argument or pass a pointer to a
+ * compatible data type.
+ *
+ * If any ioctl command handled by fops->unlocked_ioctl passes a plain
+ * integer instead of a pointer, or any of the passed data types
+ * is incompatible between 32-bit and 64-bit architectures, a proper
+ * handler is required instead of compat_ptr_ioctl.
+ */
+long compat_ptr_ioctl(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(compat_ptr_ioctl);
+#endif