All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/arm-smmu: Fix use-after-free in nvidia_smmu_impl_init()
@ 2026-11-25 22:24 Elkin Cruz
  2026-12-02  3:56 ` Mikko Perttunen
  0 siblings, 1 reply; 2+ messages in thread
From: Elkin Cruz @ 2026-11-25 22:24 UTC (permalink / raw)
  To: Thierry Reding, Will Deacon, Joerg Roedel (AMD)
  Cc: Krishna Reddy, Robin Murphy, linux-tegra, linux-arm-kernel, iommu,
	linux-kernel, llvm, irogers, Elkin Cruz, stable

In nvidia_smmu_impl_init(), smmu is reallocated with devm_krealloc() to
embed it within struct nvidia_smmu. When devm_krealloc() moves the
allocation, the old smmu pointer is freed, leaving nvidia_smmu->bases[0]
dereferencing the invalid pointer.

Read base from nvidia_smmu->smmu.base instead of the stale smmu pointer.

Fixes: af9da91493e5 ("iommu/arm-smmu: Use new devm_krealloc()")
Cc: stable@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---

I am trying out new Clang static analysis checks for kernel bug
classes, and they flagged this code as possibly buggy. The findings
were triaged/fixed and commit descriptions were drafted with help of AI,
then checked against linux-next (not runtime-tested on hardware).

Thanks,
Elkin

 drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c b/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c
index 2fce4f6d4e1b..a3884966dc29 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c
@@ -319,7 +319,7 @@ struct arm_smmu_device *nvidia_smmu_impl_init(struct arm_smmu_device *smmu)
 		return ERR_CAST(nvidia_smmu->mc);
 
 	/* Instance 0 is ioremapped by arm-smmu.c. */
-	nvidia_smmu->bases[0] = smmu->base;
+	nvidia_smmu->bases[0] = nvidia_smmu->smmu.base;
 	nvidia_smmu->num_instances++;
 
 	for (i = 1; i < MAX_SMMU_INSTANCES; i++) {
-- 
2.56.1.839.g22a8290db9-goog


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

* Re: [PATCH] iommu/arm-smmu: Fix use-after-free in nvidia_smmu_impl_init()
  2026-11-25 22:24 [PATCH] iommu/arm-smmu: Fix use-after-free in nvidia_smmu_impl_init() Elkin Cruz
@ 2026-12-02  3:56 ` Mikko Perttunen
  0 siblings, 0 replies; 2+ messages in thread
From: Mikko Perttunen @ 2026-12-02  3:56 UTC (permalink / raw)
  To: Thierry Reding, Will Deacon, Joerg Roedel (AMD), llvm
  Cc: Krishna Reddy, Robin Murphy, linux-tegra, linux-arm-kernel, iommu,
	linux-kernel, llvm, irogers, Elkin Cruz, stable, Elkin Cruz

On Thursday, November 26, 2026 7:24 AM Elkin Cruz wrote:
> In nvidia_smmu_impl_init(), smmu is reallocated with devm_krealloc() to
> embed it within struct nvidia_smmu. When devm_krealloc() moves the
> allocation, the old smmu pointer is freed, leaving nvidia_smmu->bases[0]

I would add "the assignment to" here, that is:

  leaving the assignment to nvidia_smmu->bases[0] dereferencing the
  invalid pointer.

Otherwise

Reviewed-by: Mikko Perttunen <mperttunen@nvidia.com>

> dereferencing the invalid pointer.
> 
> Read base from nvidia_smmu->smmu.base instead of the stale smmu pointer.
> 
> Fixes: af9da91493e5 ("iommu/arm-smmu: Use new devm_krealloc()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Elkin Cruz <elkin@google.com>
> ---
> 
> I am trying out new Clang static analysis checks for kernel bug
> classes, and they flagged this code as possibly buggy. The findings
> were triaged/fixed and commit descriptions were drafted with help of AI,
> then checked against linux-next (not runtime-tested on hardware).
> 
> Thanks,
> Elkin
> 
>  drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c b/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c
> index 2fce4f6d4e1b..a3884966dc29 100644
> --- a/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c
> +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c
> @@ -319,7 +319,7 @@ struct arm_smmu_device *nvidia_smmu_impl_init(struct arm_smmu_device *smmu)
>  		return ERR_CAST(nvidia_smmu->mc);
>  
>  	/* Instance 0 is ioremapped by arm-smmu.c. */
> -	nvidia_smmu->bases[0] = smmu->base;
> +	nvidia_smmu->bases[0] = nvidia_smmu->smmu.base;
>  	nvidia_smmu->num_instances++;
>  
>  	for (i = 1; i < MAX_SMMU_INSTANCES; i++) {
> -- 
> 2.56.1.839.g22a8290db9-goog
> 
> 





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

end of thread, other threads:[~2026-12-02  3:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 22:24 [PATCH] iommu/arm-smmu: Fix use-after-free in nvidia_smmu_impl_init() Elkin Cruz
2026-12-02  3:56 ` Mikko Perttunen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.