lkml.org 
[lkml]   [2018]   [Sep]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v2 01/17] compat_ioctl: add generic_compat_ioctl_ptrarg()
    Date
    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
    \
     
     \ /
      Last update: 2018-09-12 17:03    [W:2.923 / U:0.144 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site