RE: [PATCH] iommufd/selftest: Fix UAF in iommufd_test_pasid_check_hwpt

From: Tian, Kevin

Date: Thu Dec 03 2026 - 02:52:49 EST


> From: Peiyang He <peiyang_he@xxxxxxxxxxxxxxxx>
> Sent: Wednesday, December 2, 2026 4:48 PM
>
> iommufd_test_pasid_check_hwpt() calls iommu_attach_handle_get() and
> dereferences handle->domain without synchronizing against concurrent
> PASID detach or replace. Since iommu_attach_handle_get() only holds
> xa_lock during the lookup and takes no reference on the handle, a
> concurrent IOMMU_TEST_OP_PASID_DETACH or
> IOMMU_TEST_OP_PASID_REPLACE
> can erase the entry and free struct iommufd_attach_handle before
> handle->domain is read, causing a UAF.
>
> Hold idev->igroup->lock across iommu_attach_handle_get()
> and the handle->domain dereference, matching the locking used by
> iommufd_device_get_attach_handle(). Also pass idev->igroup->group
> directly to iommu_attach_handle_get().
>
> Fixes: c1b52b0a97ae ("iommufd/selftest: Add test ops to test pasid
> attach/detach")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Peiyang He <peiyang_he@xxxxxxxxxxxxxxxx>

Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx>