lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aDnj+MD0LexufNX4@Asurada-Nvidia>
Date: Fri, 30 May 2025 09:59:36 -0700
From: Nicolin Chen <nicolinc@...dia.com>
To: Jason Gunthorpe <jgg@...dia.com>
CC: <kevin.tian@...el.com>, <corbet@....net>, <will@...nel.org>,
	<bagasdotme@...il.com>, <robin.murphy@....com>, <joro@...tes.org>,
	<thierry.reding@...il.com>, <vdumpa@...dia.com>, <jonathanh@...dia.com>,
	<shuah@...nel.org>, <jsnitsel@...hat.com>, <nathan@...nel.org>,
	<peterz@...radead.org>, <yi.l.liu@...el.com>, <mshavit@...gle.com>,
	<praan@...gle.com>, <zhangzekun11@...wei.com>, <iommu@...ts.linux.dev>,
	<linux-doc@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
	<linux-arm-kernel@...ts.infradead.org>, <linux-tegra@...r.kernel.org>,
	<linux-kselftest@...r.kernel.org>, <patches@...ts.linux.dev>,
	<mochs@...dia.com>, <alok.a.tiwari@...cle.com>, <vasant.hegde@....com>,
	<dwmw2@...radead.org>, <baolu.lu@...ux.intel.com>
Subject: Re: [PATCH v5 17/29] iommufd: Add mmap interface

On Fri, May 30, 2025 at 01:29:45PM -0300, Jason Gunthorpe wrote:
> On Sat, May 17, 2025 at 08:21:34PM -0700, Nicolin Chen wrote:
> > +/*
> > + * Helpers for IOMMU driver to alloc/destroy an mmapable area for a structure.
> > + *
> > + * To support an mmappable MMIO region, kernel driver must first register it to
> > + * iommufd core to allocate an @out_offset, in the context of an driver-struct
> > + * allocation (e.g. viommu_alloc op). Then, it should report to user space this
> > + * @out_offset and the @length of the MMIO region for mmap syscall.
> > + */
> > +#define iommufd_viommu_alloc_mmap(viommu, member, mmio, length, out_offset)    \
> > +	({                                                                     \
> > +		static_assert(__same_type(struct iommufd_viommu,               \
> > +					  viommu->member));                    \
> > +		static_assert(offsetof(typeof(*viommu), member.obj) == 0);     \
> > +		_iommufd_alloc_mmap(viommu->member.ictx, &viommu->member.obj,  \
> > +				    mmio, length, out_offset);                 \
> > +	})
> 
> Why is this like this? It's weird, just

I was trying to follow the pattern of the other two macros that
asks for driver-level structure. But it seems not necessary, as
we have iommufd_hw_queue_alloc taking the core-level viommu..

> static inline int iommufd_alloc_viommu_mmap(struct iommufd_viommu *viommu,
>                                      phys_addr_t mmio_addr, size_t length,
>                                      unsigned long *offset);

OK.

> > +/* The vm_pgoff must be pre-allocated from mt_mmap, and given to user space */
> > +static int iommufd_fops_mmap(struct file *filp, struct vm_area_struct *vma)
> > +{
> > +	struct iommufd_ctx *ictx = filp->private_data;
> > +	size_t length = vma->vm_end - vma->vm_start;
> > +	struct iommufd_mmap *immap;
> > +	int rc;
> > +
> > +	if (!PAGE_ALIGNED(length))
> > +		return -EINVAL;
> > +	if (!(vma->vm_flags & VM_SHARED))
> > +		return -EINVAL;
> > +	if (vma->vm_flags & VM_EXEC)
> > +		return -EPERM;
> > +
> > +	/* vma->vm_pgoff carries an index to an mtree entry (immap) */
> > +	immap = mtree_load(&ictx->mt_mmap, vma->vm_pgoff);
> > +	if (!immap)
> > +		return -ENXIO;
> > +	/* Validate the vm_pgoff and length against the registered region */
> > +	if (vma->vm_pgoff != immap->startp)
> > +		return -ENXIO;
> 
> This check seems redundant

Hmm, I was trying to follow your remarks:
"This needs to validate that vm_pgoff is at the start of the immap"
https://lore.kernel.org/all/20250515164717.GL382960@nvidia.com/

I also added a selftest coverage for this check.

Thanks
Nicolin

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ