iommu/riscv: prevent NULL deref in iova_to_phys
Subsystems (3)
PATCH v4 1/1 iommu/riscv: prevent NULL deref in iova_to_phys
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.
---
Changes
v4:
- Change the summary as Markus recommends
v3:
- Remove redundant pte validation in riscv_iommu_iova_to_phys
- Improve subject line to emphasize prevention
v2:
- Refine problem description
- Add "Fixes" tag
--- 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)return 0 ;return pfn_to_phys (__page_val_to_pfn (*ptr)) | (iova & (pte_size -1 ));
Signature · 1 line
2.34.1
…> ---
Quoted 7 lines
Changes
v4:
- Change the summary as Markus recommendsv3:
- Remove redundant pte validation inriscv_iommu_iova_to_phys
- Improve subject line to emphasize prevention
…
Does anything hinder you to integrate repeated patch review ideas better into your contributions?
Repetition:
https://lore.kernel.org/lkml/[email protected]/
https://lkml.org/lkml/2025/8/7/282
Regards,
Markus
https://lore.kernel.org/lkml/[email protected]/
I updated the patch in v3, and updated change description accordingly:
In v1
Review
Quoted 2 lines
(quoted diff) +1
-1- if (_io_pte_none(*ptr) || !_io_pte_present(*ptr)) + if (!ptr || _io_pte_none(*ptr) || !_io_pte_present(*ptr))
In v3
drivers/iommu/riscv/iommu.c static phys_addr_t riscv_iommu_iova_to_phys(struct iommu_domain *iommu_domain, · line 1286
Quoted 2 lines
drivers/iommu/riscv/iommu.c +1
-1-if (_io_pte_none (*ptr) || !_io_pte_present (*ptr)) +if (!ptr)
but put your proposal at the patch Subject...
v1: check pte null pointer before use
v3: prevent NULL deref in iova_to_phys
Quoted 6 lines
…> ---
Quoted 5 lines
Changes
v4:
- Change the summary as Markus recommendsv3:
sorry for making this messy.
Regards,
Xianliang
…> but put your proposal at the patch Subject... …
Does it trigger undesirable communication difficulties?
Regards,
Markus
Quoted 1 line
Does it trigger undesirable communication difficulties?
No, and I agree that both subject and summary phrase can be improved
And now I do learn from this, thanks.
Quoted 4 lines
Your patch will almost certainly get comments from reviewers on ways in which the patch can be improved, in the form of a reply to your email. You must respond to those comments; ignoring reviewers is a good way to get ignored in return. You can simply reply to their emails to answer their comments. Review
Regards,
Xianliang
Quoted 2 lines
Quoted 1 line
Does it trigger undesirable communication difficulties?
No, and I agree that both subject and summary phrase can be improved
I suggest to take another look for the better distinction of mentioned key words.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc2#n638
Regards,
Markus
Quoted 1 line
I suggest to take another look for the better distinction of mentioned key words.
I misunderstood this
Quoted 3 lines
Quoted 1 line
…> 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?
https://lore.kernel.org/lkml/[email protected]/
Quoted 9 lines
Quoted 7 lines
Quoted 7 lines
Changes
v4:
- Change the summary as Markus recommendsv3:
- Remove redundant pte validation inriscv_iommu_iova_to_phys
- Improve subject line to emphasize preventionDoes anything hinder you to integrate repeated patch review ideas better into your contributions?
Do you suggest merge the repeated patch changlogs?
may a RESEND v3:
- Remove redundant pte validation in riscv_iommu_iova_to_phys
- Improve summary and description to emphasize prevention as Markus recommends
Regards,
Xianliang
Joerg Roedel
maintainerQuoted 2 lines · XianLiang Huang
drivers/iommu/riscv/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied for -rc, thanks.
This patch was applied to riscv/linux.git (for-next) by Joerg Roedel <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (for-next) by Joerg Roedel <[email protected]>:
Quoted 8 lines · On Wed, 20 Aug 2025 15:22:48 +0800 you wrote:
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 inriscv_iommu_iova_to_phys(), and remove the pte validation.[...]
Here is the summary with links:
- [v4] iommu/riscv: prevent NULL deref in iova_to_phys
https://git.kernel.org/riscv/c/99d4d1a07087
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html