Skip to contentSkip to conversation

iommu: amd: NULL value may be dereferenced

PATCH In review Alexander Sapozhnikov 2 participants 2 messages Dec 19, 2023 – Dec 20, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu: amd: NULL value may be dereferenced

Pointer 'dom' which was dereferenced at iommu.c:1993 is compared to NULL value at iommu.c:1998.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 drivers/iommu/amd/iommu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iommu/amd/iommu.c +3 -0
index a0924144bac8..64a88e67be9c 100644
@@ -1985,6 +1985,9 @@ static void amd_iommu_domain_free(struct iommu_domain *dom)
 {
 	struct protection_domain *domain;
 
+	if (!dom)
+		return;
+
 	domain = to_pdomain(dom);
 
 	if (domain->dev_cnt > 0)
Signature · 1 line
2.40.1
#1 lore raw
Quoted 15 lines · Alexander Sapozhnikov

Pointer 'dom' which was dereferenced at iommu.c:1993 is compared to NULL value at iommu.c:1998.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
  drivers/iommu/amd/iommu.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/iommu/amd/iommu.c +0 -0
index a0924144bac8..64a88e67be9c 100644

drivers/iommu/amd/iommu.c static void amd_iommu_domain_free(struct iommu_domain *dom) · line 1993

Quoted 9 lines
drivers/iommu/amd/iommu.c +3 -0
@@ -1985,6 +1985,9 @@ static void amd_iommu_domain_free(struct iommu_domain *dom)
  {
  	struct protection_domain *domain;
 
+	if (!dom)
+		return;
+
  	domain = to_pdomain(dom);
 
  	if (domain->dev_cnt > 0)

This check is already added in the following commit in the next branch of the iommu.git repo.

3f4b87b959ea "iommu/amd: Make use of domain_alloc and domain_free"
(https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git/commit/?h=next&id=3f4b87b959eab362b89fce6ceb9d1badd102e5ea)

Thanks,
Suravee