iommu/riscv: prevent NULL deref in iova_to_phys
authorXianLiang Huang <huangxianliang@lanxincomputing.com>
Wed, 20 Aug 2025 07:22:48 +0000 (15:22 +0800)
committerJoerg Roedel <joerg.roedel@amd.com>
Fri, 22 Aug 2025 06:51:49 +0000 (08:51 +0200)
The riscv_iommu_pte_fetch() function returns either NULL for
unmapped/never-mapped iova, or a valid leaf pte pointer that
requires no further validation.

riscv_iommu_iova_to_phys() failed to handle NULL returns.
Prevent null pointer dereference in
riscv_iommu_iova_to_phys(), and remove the pte validation.

Fixes: 488ffbf18171 ("iommu/riscv: Paging domain support")
Cc: Tomasz Jeznach <tjeznach@rivosinc.com>
Signed-off-by: XianLiang Huang <huangxianliang@lanxincomputing.com>
Link: https://lore.kernel.org/r/20250820072248.312-1-huangxianliang@lanxincomputing.com
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
drivers/iommu/riscv/iommu.c

index 2d0d31ba28860ac3f7c03484dbd0af87e8a95371..0eae2f4bdc5e64f94cf8dd67ed4d1d7c5958dc8e 100644 (file)
@@ -1283,7 +1283,7 @@ static phys_addr_t riscv_iommu_iova_to_phys(struct iommu_domain *iommu_domain,
        unsigned long *ptr;
 
        ptr = riscv_iommu_pte_fetch(domain, iova, &pte_size);
-       if (_io_pte_none(*ptr) || !_io_pte_present(*ptr))
+       if (!ptr)
                return 0;
 
        return pfn_to_phys(__page_val_to_pfn(*ptr)) | (iova & (pte_size - 1));