[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1623245709-11123-1-git-send-email-xiyuyang19@fudan.edu.cn>
Date: Wed, 9 Jun 2021 21:35:07 +0800
From: Xiyu Yang <xiyuyang19@...an.edu.cn>
To: Will Deacon <will@...nel.org>, Robin Murphy <robin.murphy@....com>,
Joerg Roedel <joro@...tes.org>,
Nicolin Chen <nicoleotsuka@...il.com>,
Bjorn Andersson <bjorn.andersson@...aro.org>,
Krishna Reddy <vdumpa@...dia.com>,
Jordan Crouse <jordan@...micpenguin.net>,
Sai Prakash Ranjan <saiprakash.ranjan@...eaurora.org>,
linux-arm-kernel@...ts.infradead.org,
iommu@...ts.linux-foundation.org, linux-kernel@...r.kernel.org
Cc: yuanxzhang@...an.edu.cn, Xiyu Yang <xiyuyang19@...an.edu.cn>,
Xin Tan <tanxin.ctf@...il.com>
Subject: [PATCH] iommu/arm-smmu: Fix arm_smmu_device refcount leak when arm_smmu_rpm_get fails
arm_smmu_rpm_get() invokes pm_runtime_get_sync(), which increases the
refcount of the "smmu" even though the return value is less than 0.
The reference counting issue happens in some error handling paths of
arm_smmu_rpm_get() in its caller functions. When arm_smmu_rpm_get()
fails, the caller functions forget to decrease the refcount of "smmu"
increased by arm_smmu_rpm_get(), causing a refcount leak.
Fix this issue by calling arm_smmu_rpm_put() or jumping to the "rpm_put"
label when arm_smmu_rpm_get() fails.
Signed-off-by: Xiyu Yang <xiyuyang19@...an.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@...il.com>
---
drivers/iommu/arm/arm-smmu/arm-smmu.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c
index 6f72c4d208ca..177ee54c5534 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c
@@ -840,7 +840,7 @@ static void arm_smmu_destroy_domain_context(struct iommu_domain *domain)
ret = arm_smmu_rpm_get(smmu);
if (ret < 0)
- return;
+ goto rpm_put;
/*
* Disable the context bank and free the page tables before freeing
@@ -857,6 +857,7 @@ static void arm_smmu_destroy_domain_context(struct iommu_domain *domain)
free_io_pgtable_ops(smmu_domain->pgtbl_ops);
__arm_smmu_free_bitmap(smmu->context_map, cfg->cbndx);
+rpm_put:
arm_smmu_rpm_put(smmu);
}
@@ -1153,7 +1154,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
ret = arm_smmu_rpm_get(smmu);
if (ret < 0)
- return ret;
+ goto rpm_put;
/* Ensure that the domain is finalised */
ret = arm_smmu_init_domain_context(domain, smmu, dev);
@@ -1404,7 +1405,7 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev)
ret = arm_smmu_rpm_get(smmu);
if (ret < 0)
- goto out_cfg_free;
+ goto rpm_put;
ret = arm_smmu_master_alloc_smes(dev);
arm_smmu_rpm_put(smmu);
@@ -1417,6 +1418,8 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev)
return &smmu->iommu;
+rpm_put:
+ arm_smmu_rpm_put(smmu);
out_cfg_free:
kfree(cfg);
out_free:
@@ -1438,8 +1441,10 @@ static void arm_smmu_release_device(struct device *dev)
smmu = cfg->smmu;
ret = arm_smmu_rpm_get(smmu);
- if (ret < 0)
+ if (ret < 0) {
+ arm_smmu_rpm_put(smmu);
return;
+ }
arm_smmu_master_free_smes(cfg, fwspec);
--
2.7.4
Powered by blists - more mailing lists