* [PATCH] iommu/s390: Fix memory corruption when using identity domain
@ 2025-08-27 21:08 Matthew Rosato
2025-08-28 8:10 ` Niklas Schnelle
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Matthew Rosato @ 2025-08-27 21:08 UTC (permalink / raw)
To: joro, schnelle
Cc: will, robin.murphy, gerald.schaefer, jgg, iommu, linux-kernel,
linux-s390, stable, Cam Miller
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.
Cc: stable@vger.kernel.org
Fixes: 64af12c6ec3a ("iommu/s390: implement iommu passthrough via identity domain")
Reported-by: Cam Miller <cam@linux.ibm.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
---
drivers/iommu/s390-iommu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
index 9c80d61deb2c..d7370347c910 100644
--- a/drivers/iommu/s390-iommu.c
+++ b/drivers/iommu/s390-iommu.c
@@ -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);
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iommu/s390: Fix memory corruption when using identity domain
2025-08-27 21:08 [PATCH] iommu/s390: Fix memory corruption when using identity domain Matthew Rosato
@ 2025-08-28 8:10 ` Niklas Schnelle
2025-08-28 19:44 ` Farhan Ali
2025-09-02 15:52 ` Cam Miller
2 siblings, 0 replies; 4+ messages in thread
From: Niklas Schnelle @ 2025-08-28 8:10 UTC (permalink / raw)
To: Matthew Rosato, joro
Cc: will, robin.murphy, gerald.schaefer, jgg, iommu, linux-kernel,
linux-s390, stable, Cam Miller
On Wed, 2025-08-27 at 17:08 -0400, Matthew Rosato wrote:
> 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.
>
> Cc: stable@vger.kernel.org
> Fixes: 64af12c6ec3a ("iommu/s390: implement iommu passthrough via identity domain")
> Reported-by: Cam Miller <cam@linux.ibm.com>
> Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
> ---
> drivers/iommu/s390-iommu.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
> index 9c80d61deb2c..d7370347c910 100644
> --- a/drivers/iommu/s390-iommu.c
> +++ b/drivers/iommu/s390-iommu.c
> @@ -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: Niklas Schnelle <schnelle@linux.ibm.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iommu/s390: Fix memory corruption when using identity domain
2025-08-27 21:08 [PATCH] iommu/s390: Fix memory corruption when using identity domain Matthew Rosato
2025-08-28 8:10 ` Niklas Schnelle
@ 2025-08-28 19:44 ` Farhan Ali
2025-09-02 15:52 ` Cam Miller
2 siblings, 0 replies; 4+ messages in thread
From: Farhan Ali @ 2025-08-28 19:44 UTC (permalink / raw)
To: Matthew Rosato, joro, schnelle
Cc: will, robin.murphy, gerald.schaefer, jgg, iommu, linux-kernel,
linux-s390, stable, Cam Miller
On 8/27/2025 2:08 PM, Matthew Rosato wrote:
> 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.
>
> Cc: stable@vger.kernel.org
> Fixes: 64af12c6ec3a ("iommu/s390: implement iommu passthrough via identity domain")
> Reported-by: Cam Miller <cam@linux.ibm.com>
> Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
> ---
> drivers/iommu/s390-iommu.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
> index 9c80d61deb2c..d7370347c910 100644
> --- a/drivers/iommu/s390-iommu.c
> +++ b/drivers/iommu/s390-iommu.c
> @@ -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);
>
Reviewed-by: Farhan Ali <alifm@linux.ibm.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iommu/s390: Fix memory corruption when using identity domain
2025-08-27 21:08 [PATCH] iommu/s390: Fix memory corruption when using identity domain Matthew Rosato
2025-08-28 8:10 ` Niklas Schnelle
2025-08-28 19:44 ` Farhan Ali
@ 2025-09-02 15:52 ` Cam Miller
2 siblings, 0 replies; 4+ messages in thread
From: Cam Miller @ 2025-09-02 15:52 UTC (permalink / raw)
To: Matthew Rosato, joro, schnelle
Cc: will, robin.murphy, gerald.schaefer, jgg, iommu, linux-kernel,
linux-s390, stable
Tested-by: Cam Miller <cam@linux.ibm.com>
On 8/27/25 17:08, Matthew Rosato wrote:
> 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.
>
> Cc: stable@vger.kernel.org
> Fixes: 64af12c6ec3a ("iommu/s390: implement iommu passthrough via identity domain")
> Reported-by: Cam Miller <cam@linux.ibm.com>
> Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
> ---
> drivers/iommu/s390-iommu.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
> index 9c80d61deb2c..d7370347c910 100644
> --- a/drivers/iommu/s390-iommu.c
> +++ b/drivers/iommu/s390-iommu.c
> @@ -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);
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-02 15:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27 21:08 [PATCH] iommu/s390: Fix memory corruption when using identity domain Matthew Rosato
2025-08-28 8:10 ` Niklas Schnelle
2025-08-28 19:44 ` Farhan Ali
2025-09-02 15:52 ` Cam Miller
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).