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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 24 Jul 2022 15:23:19 +0800
From:   Baolu Lu <baolu.lu@...ux.intel.com>
To:     Jason Gunthorpe <jgg@...dia.com>
Cc:     baolu.lu@...ux.intel.com, Joerg Roedel <joro@...tes.org>,
        Christoph Hellwig <hch@...radead.org>,
        Kevin Tian <kevin.tian@...el.com>,
        Ashok Raj <ashok.raj@...el.com>, Will Deacon <will@...nel.org>,
        Robin Murphy <robin.murphy@....com>,
        Jean-Philippe Brucker <jean-philippe@...aro.com>,
        Dave Jiang <dave.jiang@...el.com>,
        Vinod Koul <vkoul@...nel.org>,
        Eric Auger <eric.auger@...hat.com>,
        Liu Yi L <yi.l.liu@...el.com>,
        Jacob jun Pan <jacob.jun.pan@...el.com>,
        Zhangfei Gao <zhangfei.gao@...aro.org>,
        Zhu Tony <tony.zhu@...el.com>, iommu@...ts.linux.dev,
        linux-kernel@...r.kernel.org,
        Jean-Philippe Brucker <jean-philippe@...aro.org>
Subject: Re: [PATCH v10 04/12] iommu: Add attach/detach_dev_pasid iommu
 interface

On 2022/7/23 22:11, Jason Gunthorpe wrote:
>> +
>> +	/*
>> +	 * Otherwise, the device came from DT/ACPI, assume it is static and
>> +	 * then singleton can know from the device count in the group.
>> +	 */
>> +	return true;
>> +}
> I would be happer if probe was changed to refuse to add a device to a
> group if the group's pasid xarray is not empty, as a protective
> measure.

Agreed. I will add below code.

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 047898666b9f..e43cb6776087 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -895,6 +895,14 @@ int iommu_group_add_device(struct iommu_group 
*group, struct device *dev)
         int ret, i = 0;
         struct group_device *device;

+       /*
+        * The iommu_attach_device_pasid() requires a singleton group.
+        * Refuse to add a device into it if this assumption has been
+        * made.
+        */
+       if (!xa_empty(group->pasid_array))
+               return -EBUSY;
+
         device = kzalloc(sizeof(*device), GFP_KERNEL);
         if (!device)
                 return -ENOMEM;

> 
>> +int iommu_attach_device_pasid(struct iommu_domain *domain, struct device *dev,
>> +			      ioasid_t pasid)
>> +{
>> +	struct iommu_group *group;
>> +	void *curr;
>> +	int ret;
>> +
>> +	if (!domain->ops->set_dev_pasid)
>> +		return -EOPNOTSUPP;
>> +
>> +	group = iommu_group_get(dev);
>> +	if (!group || !iommu_group_immutable_singleton(group, dev)) {
>> +		iommu_group_put(group);
>> +		return -EINVAL;
> goto error below
> 
>> +	}
>> +
>> +	mutex_lock(&group->mutex);
> Just hold the group->mutex a few lines above and don't put locking in
> iommu_group_immutable_singleton(), it is clearer

Above two comments agreed. iommu_attach_device_pasid() looks like below
after update.

int iommu_attach_device_pasid(struct iommu_domain *domain, struct device 
*dev,
                               ioasid_t pasid)
{
         struct iommu_group *group;
         int ret = -EINVAL;
         void *curr;

         if (!domain->ops->set_dev_pasid)
                 return -EOPNOTSUPP;

         group = iommu_group_get(dev);
         if (!group)
                 return -ENODEV;

         mutex_lock(&group->mutex);
         if (!iommu_group_immutable_singleton(group, dev))
                 goto out_unlock;

         curr = xa_cmpxchg(&group->pasid_array, pasid, NULL, domain, 
GFP_KERNEL);
         if (curr) {
                 ret = xa_err(curr) ? : -EBUSY;
                 goto out_unlock;
         }
         ret = domain->ops->set_dev_pasid(domain, dev, pasid);
         if (ret)
                 xa_erase(&group->pasid_array, pasid);
out_unlock:
         mutex_unlock(&group->mutex);
         iommu_group_put(group);

         return ret;
}

Best regards,
baolu

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ