[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAK8P3a0CAAtxXcfYt8NwmNSmF5tWhSSihLBkOtuQ62onjst4sA@mail.gmail.com>
Date: Thu, 15 Aug 2019 08:43:24 +0200
From: Arnd Bergmann <arnd@...db.de>
To: Dave Chinner <david@...morbit.com>
Cc: Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Al Viro <viro@...iv.linux.org.uk>,
Linux FS-devel Mailing List <linux-fsdevel@...r.kernel.org>,
"Darrick J. Wong" <darrick.wong@...cle.com>,
linux-xfs <linux-xfs@...r.kernel.org>,
Brian Foster <bfoster@...hat.com>,
Allison Collins <allison.henderson@...cle.com>,
Nick Bowler <nbowler@...conx.ca>,
Eric Sandeen <sandeen@...deen.net>,
Dave Chinner <dchinner@...hat.com>
Subject: Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()
On Wed, Aug 14, 2019 at 11:39 PM Dave Chinner <david@...morbit.com> 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
Powered by blists - more mailing lists