linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommufd: Set domain->iommufd_hwpt in all hwpt->domain allocators
@ 2025-03-05 21:18 Nicolin Chen
  2025-03-06  3:21 ` Tian, Kevin
  2025-03-07 20:03 ` Jason Gunthorpe
  0 siblings, 2 replies; 4+ messages in thread
From: Nicolin Chen @ 2025-03-05 21:18 UTC (permalink / raw)
  To: jgg, kevin.tian
  Cc: joro, will, robin.murphy, linux-arm-kernel, iommu, linux-kernel,
	ankita

Setting domain->iommufd_hwpt in iommufd_hwpt_alloc() only covers the HWPT
allocations from user space, but not for an auto domain. This resulted in
a NULL pointer access in the auto domain pathway:
 Unable to handle kernel NULL pointer dereference at
 	virtual address 0000000000000008
 pc : iommufd_sw_msi+0x54/0x2b0
 lr : iommufd_sw_msi+0x40/0x2b0
 Call trace:
  iommufd_sw_msi+0x54/0x2b0 (P)
  iommu_dma_prepare_msi+0x64/0xa8
  its_irq_domain_alloc+0xf0/0x2c0
  irq_domain_alloc_irqs_parent+0x2c/0xa8
  msi_domain_alloc+0xa0/0x1a8

Since iommufd_sw_msi() requires to access the domain->iommufd_hwpt, it is
better to set that explicitly prior to calling iommu_domain_set_sw_msi().

Fixes: 748706d7ca06 ("iommu: Turn fault_data to iommufd private pointer")
Reported-by: Ankit Agrawal <ankita@nvidia.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
 drivers/iommu/iommufd/hw_pagetable.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c
index 268315b1d8bc..1d4cfe3677dc 100644
--- a/drivers/iommu/iommufd/hw_pagetable.c
+++ b/drivers/iommu/iommufd/hw_pagetable.c
@@ -159,6 +159,7 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
 			goto out_abort;
 		}
 	}
+	hwpt->domain->iommufd_hwpt = hwpt;
 	iommu_domain_set_sw_msi(hwpt->domain, iommufd_sw_msi);
 
 	/*
@@ -255,6 +256,7 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx,
 		goto out_abort;
 	}
 	hwpt->domain->owner = ops;
+	hwpt->domain->iommufd_hwpt = hwpt;
 	iommu_domain_set_sw_msi(hwpt->domain, iommufd_sw_msi);
 
 	if (WARN_ON_ONCE(hwpt->domain->type != IOMMU_DOMAIN_NESTED)) {
@@ -311,6 +313,7 @@ iommufd_viommu_alloc_hwpt_nested(struct iommufd_viommu *viommu, u32 flags,
 		hwpt->domain = NULL;
 		goto out_abort;
 	}
+	hwpt->domain->iommufd_hwpt = hwpt;
 	hwpt->domain->owner = viommu->iommu_dev->ops;
 	iommu_domain_set_sw_msi(hwpt->domain, iommufd_sw_msi);
 
@@ -415,7 +418,6 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd)
 		refcount_inc(&fault->obj.users);
 		iommufd_put_object(ucmd->ictx, &fault->obj);
 	}
-	hwpt->domain->iommufd_hwpt = hwpt;
 
 	cmd->out_hwpt_id = hwpt->obj.id;
 	rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH] iommufd: Set domain->iommufd_hwpt in all hwpt->domain allocators
  2025-03-05 21:18 [PATCH] iommufd: Set domain->iommufd_hwpt in all hwpt->domain allocators Nicolin Chen
@ 2025-03-06  3:21 ` Tian, Kevin
  2025-03-06 10:31   ` Ankit Agrawal
  2025-03-07 20:03 ` Jason Gunthorpe
  1 sibling, 1 reply; 4+ messages in thread
From: Tian, Kevin @ 2025-03-06  3:21 UTC (permalink / raw)
  To: Nicolin Chen, jgg@nvidia.com
  Cc: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com,
	linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev,
	linux-kernel@vger.kernel.org, ankita@nvidia.com

> From: Nicolin Chen <nicolinc@nvidia.com>
> Sent: Thursday, March 6, 2025 5:18 AM
> 
> Setting domain->iommufd_hwpt in iommufd_hwpt_alloc() only covers the
> HWPT
> allocations from user space, but not for an auto domain. This resulted in
> a NULL pointer access in the auto domain pathway:
>  Unable to handle kernel NULL pointer dereference at
>  	virtual address 0000000000000008
>  pc : iommufd_sw_msi+0x54/0x2b0
>  lr : iommufd_sw_msi+0x40/0x2b0
>  Call trace:
>   iommufd_sw_msi+0x54/0x2b0 (P)
>   iommu_dma_prepare_msi+0x64/0xa8
>   its_irq_domain_alloc+0xf0/0x2c0
>   irq_domain_alloc_irqs_parent+0x2c/0xa8
>   msi_domain_alloc+0xa0/0x1a8
> 
> Since iommufd_sw_msi() requires to access the domain->iommufd_hwpt, it
> is
> better to set that explicitly prior to calling iommu_domain_set_sw_msi().
> 
> Fixes: 748706d7ca06 ("iommu: Turn fault_data to iommufd private pointer")
> Reported-by: Ankit Agrawal <ankita@nvidia.com>
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iommufd: Set domain->iommufd_hwpt in all hwpt->domain allocators
  2025-03-06  3:21 ` Tian, Kevin
@ 2025-03-06 10:31   ` Ankit Agrawal
  0 siblings, 0 replies; 4+ messages in thread
From: Ankit Agrawal @ 2025-03-06 10:31 UTC (permalink / raw)
  To: Tian, Kevin, Nicolin Chen, Jason Gunthorpe
  Cc: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com,
	linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev,
	linux-kernel@vger.kernel.org

>> Since iommufd_sw_msi() requires to access the domain->iommufd_hwpt, it
>> is
>> better to set that explicitly prior to calling iommu_domain_set_sw_msi().
>>
>> Fixes: 748706d7ca06 ("iommu: Turn fault_data to iommufd private pointer")
>> Reported-by: Ankit Agrawal <ankita@nvidia.com>
>> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
>
> Reviewed-by: Kevin Tian <kevin.tian@intel.com>

Tested-by: Ankit Agrawal <ankita@nvidia.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iommufd: Set domain->iommufd_hwpt in all hwpt->domain allocators
  2025-03-05 21:18 [PATCH] iommufd: Set domain->iommufd_hwpt in all hwpt->domain allocators Nicolin Chen
  2025-03-06  3:21 ` Tian, Kevin
@ 2025-03-07 20:03 ` Jason Gunthorpe
  1 sibling, 0 replies; 4+ messages in thread
From: Jason Gunthorpe @ 2025-03-07 20:03 UTC (permalink / raw)
  To: Nicolin Chen
  Cc: kevin.tian, joro, will, robin.murphy, linux-arm-kernel, iommu,
	linux-kernel, ankita

On Wed, Mar 05, 2025 at 01:18:00PM -0800, Nicolin Chen wrote:
> Setting domain->iommufd_hwpt in iommufd_hwpt_alloc() only covers the HWPT
> allocations from user space, but not for an auto domain. This resulted in
> a NULL pointer access in the auto domain pathway:
>  Unable to handle kernel NULL pointer dereference at
>  	virtual address 0000000000000008
>  pc : iommufd_sw_msi+0x54/0x2b0
>  lr : iommufd_sw_msi+0x40/0x2b0
>  Call trace:
>   iommufd_sw_msi+0x54/0x2b0 (P)
>   iommu_dma_prepare_msi+0x64/0xa8
>   its_irq_domain_alloc+0xf0/0x2c0
>   irq_domain_alloc_irqs_parent+0x2c/0xa8
>   msi_domain_alloc+0xa0/0x1a8
> 
> Since iommufd_sw_msi() requires to access the domain->iommufd_hwpt, it is
> better to set that explicitly prior to calling iommu_domain_set_sw_msi().
> 
> Fixes: 748706d7ca06 ("iommu: Turn fault_data to iommufd private pointer")
> Reported-by: Ankit Agrawal <ankita@nvidia.com>
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
> ---
>  drivers/iommu/iommufd/hw_pagetable.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Applied thanks

Jason


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-03-07 20:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-05 21:18 [PATCH] iommufd: Set domain->iommufd_hwpt in all hwpt->domain allocators Nicolin Chen
2025-03-06  3:21 ` Tian, Kevin
2025-03-06 10:31   ` Ankit Agrawal
2025-03-07 20:03 ` Jason Gunthorpe

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).