Skip to contentSkip to conversation

iommu/s390: Fix memory corruption when using identity domain

PATCH In review Matthew Rosato 5 participants 5 messages Aug 27, 2025 – Sep 5, 2025

Subsystems (4)
lore
Share & tools
lore

Matthew Rosato

author maintainer
#0 lore raw

PATCH 1/1 iommu/s390: Fix memory corruption when using identity domain

zpci_get_iommu_ctrs() returns counter information to be reported as part of device statistics; these counters are stored as part of the s390_domain. The problem, however, is that the identity domain is not backed by an s390_domain and so the conversion via to_s390_domain() yields a bad address that is zero'd initially and read on-demand later via a sysfs read. These counters aren't necessary for the identity domain; just return NULL in this case.

This issue was discovered via KASAN with reports that look like:

BUG: KASAN: global-out-of-bounds in zpci_fmb_enable_device

when using the identity domain for a device on s390.

Fixes 64af12c6ec3a ("iommu/s390: implement iommu passthrough via identity domain")
---
 drivers/iommu/s390-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/s390-iommu.c +2 -1
index 9c80d61deb2c..d7370347c910 100644
@@ -1032,7 +1032,8 @@ struct zpci_iommu_ctrs *zpci_get_iommu_ctrs(struct zpci_dev *zdev)
 
 	lockdep_assert_held(&zdev->dom_lock);
 
-	if (zdev->s390_domain->type == IOMMU_DOMAIN_BLOCKED)
+	if (zdev->s390_domain->type == IOMMU_DOMAIN_BLOCKED ||
+	    zdev->s390_domain->type == IOMMU_DOMAIN_IDENTITY)
 		return NULL;
 
 	s390_domain = to_s390_domain(zdev->s390_domain);
Signature · 1 line
2.50.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Matthew Rosato

zpci_get_iommu_ctrs() returns counter information to be reported as part of device statistics; these counters are stored as part of the s390_domain. The problem, however, is that the identity domain is not backed by an s390_domain and so the conversion via to_s390_domain() yields a bad address that is zero'd initially and read on-demand later via a sysfs read. These counters aren't necessary for the identity domain; just return NULL in this case.

This issue was discovered via KASAN with reports that look like:

BUG: KASAN: global-out-of-bounds in zpci_fmb_enable_device

when using the identity domain for a device on s390.

Fixes 64af12c6ec3a ("iommu/s390: implement iommu passthrough via identity domain")
---
 drivers/iommu/s390-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/s390-iommu.c +0 -0
index 9c80d61deb2c..d7370347c910 100644

drivers/iommu/s390-iommu.c struct zpci_iommu_ctrs *zpci_get_iommu_ctrs(struct zpci_dev *zdev) · line 1039

Quoted 9 lines
drivers/iommu/s390-iommu.c +2 -1
@@ -1032,7 +1032,8 @@ struct zpci_iommu_ctrs *zpci_get_iommu_ctrs(struct zpci_dev *zdev)
 
 	lockdep_assert_held(&zdev->dom_lock);
 
-	if (zdev->s390_domain->type == IOMMU_DOMAIN_BLOCKED)
+	if (zdev->s390_domain->type == IOMMU_DOMAIN_BLOCKED ||
+	    zdev->s390_domain->type == IOMMU_DOMAIN_IDENTITY)
 		return NULL;
 
 	s390_domain = to_s390_domain(zdev->s390_domain);

Looks good to me and thanks for the fix!

Reviewed-by on v1 1/1
#2 lore raw
In reply to Matthew Rosato
Quoted 26 lines · Matthew Rosato

zpci_get_iommu_ctrs() returns counter information to be reported as part of device statistics; these counters are stored as part of the s390_domain. The problem, however, is that the identity domain is not backed by an s390_domain and so the conversion via to_s390_domain() yields a bad address that is zero'd initially and read on-demand later via a sysfs read. These counters aren't necessary for the identity domain; just return NULL in this case.

This issue was discovered via KASAN with reports that look like:

BUG: KASAN: global-out-of-bounds in zpci_fmb_enable_device

when using the identity domain for a device on s390.

Fixes 64af12c6ec3a ("iommu/s390: implement iommu passthrough via identity domain")
---
  drivers/iommu/s390-iommu.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/s390-iommu.c +0 -0
index 9c80d61deb2c..d7370347c910 100644

drivers/iommu/s390-iommu.c struct zpci_iommu_ctrs *zpci_get_iommu_ctrs(struct zpci_dev *zdev) · line 1039

Quoted 9 lines
drivers/iommu/s390-iommu.c +2 -1
@@ -1032,7 +1032,8 @@ struct zpci_iommu_ctrs *zpci_get_iommu_ctrs(struct zpci_dev *zdev)
 
  	lockdep_assert_held(&zdev->dom_lock);
 
-	if (zdev->s390_domain->type == IOMMU_DOMAIN_BLOCKED)
+	if (zdev->s390_domain->type == IOMMU_DOMAIN_BLOCKED ||
+	    zdev->s390_domain->type == IOMMU_DOMAIN_IDENTITY)
  		return NULL;
 
  	s390_domain = to_s390_domain(zdev->s390_domain);
Tested-by on v1 1/1
#3 lore raw
In reply to Matthew Rosato
Quoted 34 lines · Matthew Rosato

zpci_get_iommu_ctrs() returns counter information to be reported as part of device statistics; these counters are stored as part of the s390_domain. The problem, however, is that the identity domain is not backed by an s390_domain and so the conversion via to_s390_domain() yields a bad address that is zero'd initially and read on-demand later via a sysfs read. These counters aren't necessary for the identity domain; just return NULL in this case.

This issue was discovered via KASAN with reports that look like:

BUG: KASAN: global-out-of-bounds in zpci_fmb_enable_device

when using the identity domain for a device on s390.

Fixes 64af12c6ec3a ("iommu/s390: implement iommu passthrough via identity domain")
---
 drivers/iommu/s390-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/s390-iommu.c +2 -1
index 9c80d61deb2c..d7370347c910 100644
@@ -1032,7 +1032,8 @@ struct zpci_iommu_ctrs *zpci_get_iommu_ctrs(struct zpci_dev *zdev)
 
 	lockdep_assert_held(&zdev->dom_lock);
 
-	if (zdev->s390_domain->type == IOMMU_DOMAIN_BLOCKED)
+	if (zdev->s390_domain->type == IOMMU_DOMAIN_BLOCKED ||
+	    zdev->s390_domain->type == IOMMU_DOMAIN_IDENTITY)
 		return NULL;
 
 	s390_domain = to_s390_domain(zdev->s390_domain);
maintainer
#4 lore raw
In reply to Matthew Rosato
Quoted 12 lines · Matthew Rosato

zpci_get_iommu_ctrs() returns counter information to be reported as part of device statistics; these counters are stored as part of the s390_domain. The problem, however, is that the identity domain is not backed by an s390_domain and so the conversion via to_s390_domain() yields a bad address that is zero'd initially and read on-demand later via a sysfs read. These counters aren't necessary for the identity domain; just return NULL in this case.

This issue was discovered via KASAN with reports that look like:

BUG: KASAN: global-out-of-bounds in zpci_fmb_enable_device

when using the identity domain for a device on s390.

Quoted 7 lines
Fixes 64af12c6ec3a ("iommu/s390: implement iommu passthrough via identity domain")
---
 drivers/iommu/s390-iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied for -rc, thanks.