iommu/riscv: check pte null pointer before use
Subsystems (3)
PATCH 1/1 iommu/riscv: check pte null pointer before use
The riscv_iommu_pte_fetch can return NULL when the provided iova is not yet mapped, the caller should check if the returned pointer is NULL or not, but riscv_iommu_iova_to_phys missed this, which will then lead to a kernel panic.
This commit just check the pointer before using it to avoid the bug. Now, when iova_to_phys is called with an unmapped iova, the kernel will not crash here.
--- drivers/iommu/riscv/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/riscv/iommu.c +1 -1
@@ -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 ||_io_pte_none (*ptr) || !_io_pte_present (*ptr))return 0 ;return pfn_to_phys (__page_val_to_pfn (*ptr)) | (iova & (pte_size -1 ));
Signature · 1 line
2.34.1
…
Quoted 1 line
This commit just check the pointer before using it to avoid the bug.
…
See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16#n94
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16#n145
Regards,
Markus
Sure, will change to "Check the pointer before..." in a new version, thanks.
Regards,
XianLiang