Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 14, 2019 at 11:39 PM Dave Chinner <david@xxxxxxxxxxxxx> wrote:
> >       case XFS_IOC_BULKSTAT:
> >       case XFS_IOC_INUMBERS:
> > -             return xfs_file_ioctl(filp, cmd, p);
> > +             return xfs_file_ioctl(filp, cmd, (unsigned long)arg);
>
> I don't really like having to sprinkle special casts through the
> code because of this.
>
> Perhaps do something like:
>
> static inline unsigned long compat_ptr_mask(unsigned long p)
> {
>         return (unsigned long)compat_ptr(p);
> }
>
> and then up front you can do:
>
>         void    __user *arg;
>
>         p = compat_ptr_mask(p);
>         arg = (void __user *)p;
>
>
> and then the rest of the code remains unchanged by now uses p
> correctly instead of having to change all the code to cast arg back
> to an unsigned long...
>

In part 1 of the series, I define this function as a global:

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));
}

How about using that to replace the individual casts:

-       return xfs_file_ioctl(filp, cmd, (unsigned long)arg);
+      return compat_ptr_ioctl(filp, cmd, arg);

It adds another indirection, but it avoids all the casts and
uses existing mechanism.

     Arnd



[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux