iommu/amd: Remove amd_iommu_domain_update() from page table freeing
authorJason Gunthorpe <jgg@nvidia.com>
Fri, 30 Aug 2024 00:06:13 +0000 (21:06 -0300)
committerJoerg Roedel <jroedel@suse.de>
Wed, 4 Sep 2024 09:37:43 +0000 (11:37 +0200)
It is a serious bug if the domain is still mapped to any DTEs when it is
freed as we immediately start freeing page table memory, so any remaining
HW touch will UAF.

If it is not mapped then dev_list is empty and amd_iommu_domain_update()
does nothing.

Remove it and add a WARN_ON() to catch this class of bug.

Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/4-v2-831cdc4d00f3+1a315-amd_iopgtbl_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd/io_pgtable.c
drivers/iommu/amd/iommu.c

index 03a3b09f05125d59149b37de5696f5aada8c2b44..0743b698128d0cfba3ffccc1ead4c6b4770b9770 100644 (file)
@@ -577,9 +577,6 @@ static void v1_free_pgtable(struct io_pgtable *iop)
 
        /* Update data structure */
        amd_iommu_domain_clr_pt_root(dom);
-
-       /* Make changes visible to IOMMUs */
-       amd_iommu_domain_update(dom);
 }
 
 static struct io_pgtable *v1_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
index c90a53a0385daeb2e4dfb51d150b4387cb742d9d..05ae44f13ec8198a76b8552c4f1062b83cf5fc9e 100644 (file)
@@ -2255,6 +2255,8 @@ void protection_domain_free(struct protection_domain *domain)
        if (!domain)
                return;
 
+       WARN_ON(!list_empty(&domain->dev_list));
+
        if (domain->iop.pgtbl_cfg.tlb)
                free_io_pgtable_ops(&domain->iop.iop.ops);