Skip to content

Commit 6129b59

Browse files
nicolincjgunthorpe
authored andcommitted
iommufd: Use iommufd_access_change_ioas in iommufd_access_destroy_object
Update iommufd_access_destroy_object() to call the new iommufd_access_change_ioas() helper. It is impossible to legitimately race iommufd_access_destroy_object() with iommufd_access_change_ioas() as iommufd_access_destroy_object() is only called once the refcount reache zero, so any concurrent iommufd_access_change_ioas() is already UAFing the memory. Link: https://lore.kernel.org/r/f9fbeca2cde7f8515da18d689b3e02a6a40a5e14.1690523699.git.nicolinc@nvidia.com Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 9227da7 commit 6129b59

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/iommu/iommufd/device.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,12 +753,10 @@ void iommufd_access_destroy_object(struct iommufd_object *obj)
753753
struct iommufd_access *access =
754754
container_of(obj, struct iommufd_access, obj);
755755

756-
if (access->ioas) {
757-
iopt_remove_access(&access->ioas->iopt, access,
758-
access->iopt_access_list_id);
759-
refcount_dec(&access->ioas->obj.users);
760-
access->ioas = NULL;
761-
}
756+
mutex_lock(&access->ioas_lock);
757+
if (access->ioas)
758+
WARN_ON(iommufd_access_change_ioas(access, NULL));
759+
mutex_unlock(&access->ioas_lock);
762760
iommufd_ctx_put(access->ictx);
763761
}
764762

0 commit comments

Comments
 (0)