Skip to content

Commit 392bf51

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu: Make sysfs robust for non-API groups
Groups created by VFIO backends outside the core IOMMU API should never be passed directly into the API itself, however they still expose their standard sysfs attributes, so we can still stumble across them that way. Take care to consider those cases before jumping into our normal assumptions of a fully-initialised core API group. Fixes: 3f6634d ("iommu: Use right way to retrieve iommu_ops") Reported-by: Jan Stancek <[email protected]> Tested-by: Jan Stancek <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/86ada41986988511a8424e84746dfe9ba7f87573.1651667683.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <[email protected]>
1 parent 2ac2fab commit 392bf51

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/iommu/iommu.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,13 @@ int iommu_get_group_resv_regions(struct iommu_group *group,
506506
list_for_each_entry(device, &group->devices, list) {
507507
struct list_head dev_resv_regions;
508508

509+
/*
510+
* Non-API groups still expose reserved_regions in sysfs,
511+
* so filter out calls that get here that way.
512+
*/
513+
if (!device->dev->iommu)
514+
break;
515+
509516
INIT_LIST_HEAD(&dev_resv_regions);
510517
iommu_get_resv_regions(device->dev, &dev_resv_regions);
511518
ret = iommu_insert_device_resv_regions(&dev_resv_regions, head);
@@ -3019,7 +3026,7 @@ static ssize_t iommu_group_store_type(struct iommu_group *group,
30193026
if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
30203027
return -EACCES;
30213028

3022-
if (WARN_ON(!group))
3029+
if (WARN_ON(!group) || !group->default_domain)
30233030
return -EINVAL;
30243031

30253032
if (sysfs_streq(buf, "identity"))

0 commit comments

Comments
 (0)