* [PATCH v2 RESEND] iommu/riscv: check pte null pointer before use
@ 2025-08-07 3:32 XianLiang Huang
2025-08-07 7:22 ` [PATCH v?] " Markus Elfring
0 siblings, 1 reply; 4+ messages in thread
From: XianLiang Huang @ 2025-08-07 3:32 UTC (permalink / raw)
To: tjeznach
Cc: markus.elfring, joro, will, robin.murphy, paul.walmsley, palmer,
aou, alex, iommu, linux-riscv, linux-kernel, huangxianliang
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.
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.
Fixes: 488ffbf18171 ("iommu/riscv: Paging domain support")
Cc: Tomasz Jeznach <tjeznach@rivosinc.com>
Signed-off-by: XianLiang Huang <huangxianliang@lanxincomputing.com>
---
Changelog
v2:
- Update change description
- Add "Fixes" tag
drivers/iommu/riscv/iommu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c
index 2d0d31ba2886..b0186faa0300 100644
--- a/drivers/iommu/riscv/iommu.c
+++ b/drivers/iommu/riscv/iommu.c
@@ -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));
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v?] iommu/riscv: check pte null pointer before use
2025-08-07 3:32 [PATCH v2 RESEND] iommu/riscv: check pte null pointer before use XianLiang Huang
@ 2025-08-07 7:22 ` Markus Elfring
2025-08-08 2:42 ` XianLiang Huang
0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2025-08-07 7:22 UTC (permalink / raw)
To: XianLiang Huang, iommu, linux-riscv, Tomasz Jeznach
Cc: LKML, Albert Ou, Alexandre Ghiti, Jörg Rödel,
Palmer Dabbelt, Paul Walmsley, Robin Murphy, Will Deacon
…> Check the pointer before using it to avoid the bug. …
Would a summary phrase like “Prevent null pointer dereference in riscv_iommu_iova_to_phys()”
be also helpful?
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Re: [PATCH v?] iommu/riscv: check pte null pointer before use
2025-08-07 7:22 ` [PATCH v?] " Markus Elfring
@ 2025-08-08 2:42 ` XianLiang Huang
2025-08-08 7:21 ` [v?] " Markus Elfring
0 siblings, 1 reply; 4+ messages in thread
From: XianLiang Huang @ 2025-08-08 2:42 UTC (permalink / raw)
To: markus.elfring
Cc: alex, aou, huangxianliang, iommu, joro, linux-kernel, linux-riscv,
palmer, paul.walmsley, robin.murphy, tjeznach, will
Sure, 'prevent' is much appropriate than 'check' here...
Prevent null pointer dereference in riscv_iommu_iova_to_phys(). Now, when
it's called with an unmapped iova, the kernel will not crash here.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [v?] iommu/riscv: check pte null pointer before use
2025-08-08 2:42 ` XianLiang Huang
@ 2025-08-08 7:21 ` Markus Elfring
0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2025-08-08 7:21 UTC (permalink / raw)
To: XianLiang Huang, iommu, linux-riscv, Tomasz Jeznach
Cc: LKML, Albert Ou, Alexandre Ghiti, Jörg Rödel,
Palmer Dabbelt, Paul Walmsley, Robin Murphy, Will Deacon
> Sure, 'prevent' is much appropriate than 'check' here...
I propose to reconsider also different effects from your wording approaches
according to the summary phrase and more detailed change description.
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-08 7:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07 3:32 [PATCH v2 RESEND] iommu/riscv: check pte null pointer before use XianLiang Huang
2025-08-07 7:22 ` [PATCH v?] " Markus Elfring
2025-08-08 2:42 ` XianLiang Huang
2025-08-08 7:21 ` [v?] " Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).