Re: [PATCH v4 1/5] docs: IOMMU user API

From: Jacob Pan
Date: Wed Jul 15 2020 - 18:06:18 EST


On Tue, 14 Jul 2020 13:04:12 -0600
Alex Williamson <alex.williamson@xxxxxxxxxx> wrote:

> > > The
> > > mangling of the user provided argsz above makes me cringe a
> > > little too for that reason, once we start modifying the user
> > > values in the core it could get messy for the vendor drivers.
> > >
> > We do have vendor specific union in bind_gpasid UAPI. Could you
> > elaborate your concern?
>
> The vendor driver is no longer seeing the value the user provided,
> what if some future vendor structure ends with something like:
>
> __u32 nr_entries;
> __u32 entries[];
> }
>
> The core code clobbered the user value, so the vendor driver wouldn't
> be able to perform any additional user copies. Clearly that's also a
> bug that could be fixed at the time such functionality becomes
> necessary, it seems unnecessary to perform that clobbering in the
> first place if everyone is on guard for user supplied data. Thanks,
Sorry I missed this in my last reply.

Make sense not to clobber user data in the core. So we should pass the
argsz as is to the vendor driver, but copy from user only up to the
size of the current kernel supports.
i.e.

/*
* User might be using a newer UAPI header which has a larger data
* size, we shall support the existing flags within the current
* size. Copy the remaining user data _after_ minsz but not more
* than the current kernel supported size.
*/
if (copy_from_user((void *)&inv_info + minsz, uinfo + minsz,
min(inv_info.argsz, maxsz) - minsz))
return -EFAULT;

Currently, vendor driver does not handle user pointer. Once the
extension as you described above becomes necessary, we can change the
vendor driver interface. Is that a reasonable plan?