Skip to content

Commit c404f55

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Validate the PASID in iommu_attach_device_pasid()
The SVA code checks that the PASID is valid for the device when assigning the PASID to the MM, but the normal PAGING related path does not check it. Devices that don't support PASID or PASID values too large for the device should not invoke the driver callback. The drivers should rely on the core code for this enforcement. Fixes: 1660370 ("iommu: Add attach/detach_dev_pasid iommu interfaces") Signed-off-by: Jason Gunthorpe <[email protected]> Reviewed-by: Yi Liu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 2568596 commit c404f55

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/iommu/iommu.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3354,6 +3354,7 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
33543354
{
33553355
/* Caller must be a probed driver on dev */
33563356
struct iommu_group *group = dev->iommu_group;
3357+
struct group_device *device;
33573358
void *curr;
33583359
int ret;
33593360

@@ -3363,10 +3364,18 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
33633364
if (!group)
33643365
return -ENODEV;
33653366

3366-
if (!dev_has_iommu(dev) || dev_iommu_ops(dev) != domain->owner)
3367+
if (!dev_has_iommu(dev) || dev_iommu_ops(dev) != domain->owner ||
3368+
pasid == IOMMU_NO_PASID)
33673369
return -EINVAL;
33683370

33693371
mutex_lock(&group->mutex);
3372+
for_each_group_device(group, device) {
3373+
if (pasid >= device->dev->iommu->max_pasids) {
3374+
ret = -EINVAL;
3375+
goto out_unlock;
3376+
}
3377+
}
3378+
33703379
curr = xa_cmpxchg(&group->pasid_array, pasid, NULL, domain, GFP_KERNEL);
33713380
if (curr) {
33723381
ret = xa_err(curr) ? : -EBUSY;

0 commit comments

Comments
 (0)