compat_ioctl: add compat_ptr_ioctl()
commit 2952db0fd51b0890f728df94ac563c21407f4f43 upstream. 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 = compat_ptr_ioctl" 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. 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. Signed-off-by: Arnd Bergmann <arnd@arndb.de>
This commit is contained in:
parent
402f719831
commit
8896dd968b
35
fs/ioctl.c
35
fs/ioctl.c
@ -8,6 +8,7 @@
|
|||||||
#include <linux/syscalls.h>
|
#include <linux/syscalls.h>
|
||||||
#include <linux/mm.h>
|
#include <linux/mm.h>
|
||||||
#include <linux/capability.h>
|
#include <linux/capability.h>
|
||||||
|
#include <linux/compat.h>
|
||||||
#include <linux/file.h>
|
#include <linux/file.h>
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
#include <linux/security.h>
|
#include <linux/security.h>
|
||||||
@ -719,3 +720,37 @@ SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
|
|||||||
{
|
{
|
||||||
return ksys_ioctl(fd, cmd, arg);
|
return ksys_ioctl(fd, cmd, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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
|
||||||
|
@ -1727,6 +1727,13 @@ int vfs_mkobj(struct dentry *, umode_t,
|
|||||||
|
|
||||||
extern long vfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
|
extern long vfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
|
||||||
|
|
||||||
|
#ifdef CONFIG_COMPAT
|
||||||
|
extern long compat_ptr_ioctl(struct file *file, unsigned int cmd,
|
||||||
|
unsigned long arg);
|
||||||
|
#else
|
||||||
|
#define compat_ptr_ioctl NULL
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* VFS file helper functions.
|
* VFS file helper functions.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user