* [PATCH] prevent null pointer dereference during zpci hot unplug
@ 2026-02-10 6:52 Aby Sam Ross
2026-02-10 14:21 ` Eric Farman
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Aby Sam Ross @ 2026-02-10 6:52 UTC (permalink / raw)
To: qemu-s390x; +Cc: qemu-devel, mjrosato, farman, Aby Sam Ross
vfio-pci hostdev realize during zpci hot plug fails (in `vfio_pci_realize()`)
if the vfio group file in `/dev/vfio/` lacks appropriate permissions and the
hostdev[/properties] addition doesn't reach the point where it could be
associated with previously added zpci device (in `s390_pcihost_plug()`).
As a result, zpci iommu pointer remains null. The zpci hot unplug following the
failed hostdev addition assumes zpci iommu pointer was assigned and tries to
make use of it to end the dma count resulting in a null pointer dereference.
In the non-hotplug scenario, `qdev_unplug()` for the zpci device is not called
after hostdev addition failure and this issue is not encountered.
Fixes: 37fa32de7073
Signed-off-by: Aby Sam Ross <abysamross@ibm.com>
---
hw/s390x/s390-pci-bus.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index b438d63c44..3166b91c46 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -1248,7 +1248,7 @@ static void s390_pcihost_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
pbdev->fid = 0;
QTAILQ_REMOVE(&s->zpci_devs, pbdev, link);
g_hash_table_remove(s->zpci_table, &pbdev->idx);
- if (pbdev->iommu->dma_limit) {
+ if (pbdev->iommu && pbdev->iommu->dma_limit) {
s390_pci_end_dma_count(s, pbdev->iommu->dma_limit);
}
qdev_unrealize(dev);
--
2.52.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] prevent null pointer dereference during zpci hot unplug
2026-02-10 6:52 [PATCH] prevent null pointer dereference during zpci hot unplug Aby Sam Ross
@ 2026-02-10 14:21 ` Eric Farman
2026-02-10 14:54 ` Matthew Rosato
2026-02-10 17:26 ` Farhan Ali
2 siblings, 0 replies; 9+ messages in thread
From: Eric Farman @ 2026-02-10 14:21 UTC (permalink / raw)
To: Aby Sam Ross, qemu-s390x; +Cc: qemu-devel, mjrosato, Farhan Ali
+cc Farhan, FYI
On Tue, 2026-02-10 at 01:52 -0500, Aby Sam Ross wrote:
> vfio-pci hostdev realize during zpci hot plug fails (in `vfio_pci_realize()`)
> if the vfio group file in `/dev/vfio/` lacks appropriate permissions and the
> hostdev[/properties] addition doesn't reach the point where it could be
> associated with previously added zpci device (in `s390_pcihost_plug()`).
> As a result, zpci iommu pointer remains null. The zpci hot unplug following the
> failed hostdev addition assumes zpci iommu pointer was assigned and tries to
> make use of it to end the dma count resulting in a null pointer dereference.
> In the non-hotplug scenario, `qdev_unplug()` for the zpci device is not called
> after hostdev addition failure and this issue is not encountered.
>
> Fixes: 37fa32de7073
This is usually written as:
Fixes: 37fa32de7073 ("s390x/pci: Honor DMA limits set by vfio")
> Signed-off-by: Aby Sam Ross <abysamross@ibm.com>
> ---
> hw/s390x/s390-pci-bus.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Acked-by: Eric Farman <farman@linux.ibm.com>
>
>
> diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
> index b438d63c44..3166b91c46 100644
> --- a/hw/s390x/s390-pci-bus.c
> +++ b/hw/s390x/s390-pci-bus.c
> @@ -1248,7 +1248,7 @@ static void s390_pcihost_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
> pbdev->fid = 0;
> QTAILQ_REMOVE(&s->zpci_devs, pbdev, link);
> g_hash_table_remove(s->zpci_table, &pbdev->idx);
> - if (pbdev->iommu->dma_limit) {
> + if (pbdev->iommu && pbdev->iommu->dma_limit) {
> s390_pci_end_dma_count(s, pbdev->iommu->dma_limit);
> }
> qdev_unrealize(dev);
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] prevent null pointer dereference during zpci hot unplug
2026-02-10 6:52 [PATCH] prevent null pointer dereference during zpci hot unplug Aby Sam Ross
2026-02-10 14:21 ` Eric Farman
@ 2026-02-10 14:54 ` Matthew Rosato
2026-02-10 17:26 ` Farhan Ali
2 siblings, 0 replies; 9+ messages in thread
From: Matthew Rosato @ 2026-02-10 14:54 UTC (permalink / raw)
To: Aby Sam Ross, qemu-s390x; +Cc: qemu-devel, farman
On 2/10/26 1:52 AM, Aby Sam Ross wrote:
> vfio-pci hostdev realize during zpci hot plug fails (in `vfio_pci_realize()`)
> if the vfio group file in `/dev/vfio/` lacks appropriate permissions and the
> hostdev[/properties] addition doesn't reach the point where it could be
> associated with previously added zpci device (in `s390_pcihost_plug()`).
> As a result, zpci iommu pointer remains null. The zpci hot unplug following the
> failed hostdev addition assumes zpci iommu pointer was assigned and tries to
> make use of it to end the dma count resulting in a null pointer dereference.
> In the non-hotplug scenario, `qdev_unplug()` for the zpci device is not called
> after hostdev addition failure and this issue is not encountered.
>
> Fixes: 37fa32de7073
Fixes: 37fa32de70 ("s390x/pci: Honor DMA limits set by vfio")
> Signed-off-by: Aby Sam Ross <abysamross@ibm.com>
> ---
> hw/s390x/s390-pci-bus.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
> index b438d63c44..3166b91c46 100644
> --- a/hw/s390x/s390-pci-bus.c
> +++ b/hw/s390x/s390-pci-bus.c
> @@ -1248,7 +1248,7 @@ static void s390_pcihost_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
> pbdev->fid = 0;
> QTAILQ_REMOVE(&s->zpci_devs, pbdev, link);
> g_hash_table_remove(s->zpci_table, &pbdev->idx);
> - if (pbdev->iommu->dma_limit) {
> + if (pbdev->iommu && pbdev->iommu->dma_limit) {
Looks reasonable. I also reproduced with a quick chmod against /dev/vfio/vfio. I also verified coldplug is unaffected as you described.
I took a look at other instances where we use pbdev->iommu without checking for non-null and AFAICT these are all otherwise after the device would be plugged and thus pbdev->iommu would be valid.
So, while updating that fixes tag feel free to add:
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Thanks!
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] prevent null pointer dereference during zpci hot unplug
2026-02-10 6:52 [PATCH] prevent null pointer dereference during zpci hot unplug Aby Sam Ross
2026-02-10 14:21 ` Eric Farman
2026-02-10 14:54 ` Matthew Rosato
@ 2026-02-10 17:26 ` Farhan Ali
2026-02-12 11:47 ` [PATCH v2] s390x/pci: " Aby Sam Ross
2 siblings, 1 reply; 9+ messages in thread
From: Farhan Ali @ 2026-02-10 17:26 UTC (permalink / raw)
To: Aby Sam Ross, qemu-s390x; +Cc: qemu-devel, mjrosato, farman
On 2/9/2026 10:52 PM, Aby Sam Ross wrote:
> vfio-pci hostdev realize during zpci hot plug fails (in `vfio_pci_realize()`)
> if the vfio group file in `/dev/vfio/` lacks appropriate permissions and the
> hostdev[/properties] addition doesn't reach the point where it could be
> associated with previously added zpci device (in `s390_pcihost_plug()`).
> As a result, zpci iommu pointer remains null. The zpci hot unplug following the
> failed hostdev addition assumes zpci iommu pointer was assigned and tries to
> make use of it to end the dma count resulting in a null pointer dereference.
> In the non-hotplug scenario, `qdev_unplug()` for the zpci device is not called
> after hostdev addition failure and this issue is not encountered.
>
> Fixes: 37fa32de7073
> Signed-off-by: Aby Sam Ross <abysamross@ibm.com>
> ---
> hw/s390x/s390-pci-bus.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
> index b438d63c44..3166b91c46 100644
> --- a/hw/s390x/s390-pci-bus.c
> +++ b/hw/s390x/s390-pci-bus.c
> @@ -1248,7 +1248,7 @@ static void s390_pcihost_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
> pbdev->fid = 0;
> QTAILQ_REMOVE(&s->zpci_devs, pbdev, link);
> g_hash_table_remove(s->zpci_table, &pbdev->idx);
> - if (pbdev->iommu->dma_limit) {
> + if (pbdev->iommu && pbdev->iommu->dma_limit) {
> s390_pci_end_dma_count(s, pbdev->iommu->dma_limit);
> }
> qdev_unrealize(dev);
Thanks for the fix. With the Fixes tag fixed (as suggested by
Matt/Eric), feel free to add.
Reviewed-by: Farhan Ali <alifm@linux.ibm.com> <mailto:alifm@linux.ibm.com>
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v2] s390x/pci: prevent null pointer dereference during zpci hot unplug
2026-02-10 17:26 ` Farhan Ali
@ 2026-02-12 11:47 ` Aby Sam Ross
2026-02-12 15:50 ` Halil Pasic
0 siblings, 1 reply; 9+ messages in thread
From: Aby Sam Ross @ 2026-02-12 11:47 UTC (permalink / raw)
To: qemu-s390x; +Cc: Aby Sam Ross, qemu-devel, farman, alifm, Matthew Rosato
vfio-pci hostdev realize during zpci hot plug fails (in `vfio_pci_realize()`)
if the vfio group file in `/dev/vfio/` lacks appropriate permissions and the
hostdev[/properties] addition doesn't reach the point where it could be
associated with previously added zpci device (in `s390_pcihost_plug()`).
As a result, zpci iommu pointer remains null. The zpci hot unplug following the
failed hostdev addition assumes zpci iommu pointer was assigned and tries to
make use of it to end the dma count resulting in a null pointer dereference.
In the non-hotplug scenario, `qdev_unplug()` for the zpci device is not called
after hostdev addition failure and this issue is not encountered.
Fixes: 37fa32de7073 ("s390x/pci: Honor DMA limits set by vfio")
Signed-off-by: Aby Sam Ross <abysamross@ibm.com>
Acked-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Reviewed-by: Farhan Ali <alifm@linux.ibm.com>
---
Thank you, Eric, Matthew & Farhan for looking into this.
v2:
Added subsystem name to the commit message.
Updated the `Fixes` tag to include the reference commit's message.
---
hw/s390x/s390-pci-bus.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index b438d63c44..3166b91c46 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -1248,7 +1248,7 @@ static void s390_pcihost_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
pbdev->fid = 0;
QTAILQ_REMOVE(&s->zpci_devs, pbdev, link);
g_hash_table_remove(s->zpci_table, &pbdev->idx);
- if (pbdev->iommu->dma_limit) {
+ if (pbdev->iommu && pbdev->iommu->dma_limit) {
s390_pci_end_dma_count(s, pbdev->iommu->dma_limit);
}
qdev_unrealize(dev);
--
2.52.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v2] s390x/pci: prevent null pointer dereference during zpci hot unplug
2026-02-12 11:47 ` [PATCH v2] s390x/pci: " Aby Sam Ross
@ 2026-02-12 15:50 ` Halil Pasic
2026-02-12 16:55 ` Matthew Rosato
0 siblings, 1 reply; 9+ messages in thread
From: Halil Pasic @ 2026-02-12 15:50 UTC (permalink / raw)
To: Aby Sam Ross
Cc: qemu-s390x, qemu-devel, farman, alifm, Matthew Rosato,
Halil Pasic
On Thu, 12 Feb 2026 06:47:36 -0500
Aby Sam Ross <abysamross@ibm.com> wrote:
> vfio-pci hostdev realize during zpci hot plug fails (in `vfio_pci_realize()`)
> if the vfio group file in `/dev/vfio/` lacks appropriate permissions and the
> hostdev[/properties] addition doesn't reach the point where it could be
> associated with previously added zpci device (in `s390_pcihost_plug()`).
> As a result, zpci iommu pointer remains null. The zpci hot unplug following the
> failed hostdev addition assumes zpci iommu pointer was assigned and tries to
> make use of it to end the dma count resulting in a null pointer dereference.
> In the non-hotplug scenario, `qdev_unplug()` for the zpci device is not called
> after hostdev addition failure and this issue is not encountered.
Maybe add a word or two why the other dereferences of pbdev->iommu
not guarded by a null check are safe.
I think we have:
* s390_pci_sclp_deconfigure
* s390_pci_msix_init
* s390_pcihost_reset
* s390_pci_device_reset
* mpcifc_service_call
* stpcifc_service_call
* s390_pci_read_base
and more. My guess is that the device never gets into a state where
these operations are permissible, and the code makes sure
those functions won't be called on a device that has
pbdev->iommu == NULL. But that is just my guess.
DISCLAIMER: I didn't look at this properly, just asking based
on a quick look. Some of these may contain explicit or implicit
checking...
Regards,
Halil
>
> Fixes: 37fa32de7073 ("s390x/pci: Honor DMA limits set by vfio")
>
> Signed-off-by: Aby Sam Ross <abysamross@ibm.com>
> Acked-by: Eric Farman <farman@linux.ibm.com>
> Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
> Reviewed-by: Farhan Ali <alifm@linux.ibm.com>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v2] s390x/pci: prevent null pointer dereference during zpci hot unplug
2026-02-12 15:50 ` Halil Pasic
@ 2026-02-12 16:55 ` Matthew Rosato
2026-02-12 19:25 ` Halil Pasic
0 siblings, 1 reply; 9+ messages in thread
From: Matthew Rosato @ 2026-02-12 16:55 UTC (permalink / raw)
To: Halil Pasic, Aby Sam Ross; +Cc: qemu-s390x, qemu-devel, farman, alifm
On 2/12/26 10:50 AM, Halil Pasic wrote:
> On Thu, 12 Feb 2026 06:47:36 -0500
> Aby Sam Ross <abysamross@ibm.com> wrote:
>
>> vfio-pci hostdev realize during zpci hot plug fails (in `vfio_pci_realize()`)
>> if the vfio group file in `/dev/vfio/` lacks appropriate permissions and the
>> hostdev[/properties] addition doesn't reach the point where it could be
>> associated with previously added zpci device (in `s390_pcihost_plug()`).
>> As a result, zpci iommu pointer remains null. The zpci hot unplug following the
>> failed hostdev addition assumes zpci iommu pointer was assigned and tries to
>> make use of it to end the dma count resulting in a null pointer dereference.
>> In the non-hotplug scenario, `qdev_unplug()` for the zpci device is not called
>> after hostdev addition failure and this issue is not encountered.
>
>
> Maybe add a word or two why the other dereferences of pbdev->iommu
> not guarded by a null check are safe.
>
> I think we have:
> * s390_pci_sclp_deconfigure
> * s390_pci_msix_init
> * s390_pcihost_reset
> * s390_pci_device_reset
> * mpcifc_service_call
> * stpcifc_service_call
> * s390_pci_read_base
>
> and more. My guess is that the device never gets into a state where
> these operations are permissible, and the code makes sure
> those functions won't be called on a device that has
> pbdev->iommu == NULL. But that is just my guess.
>
> DISCLAIMER: I didn't look at this properly, just asking based
> on a quick look. Some of these may contain explicit or implicit
> checking...
I mentioned in response to v1 as part of my review that I did look through all references of pbdev->iommu, as I was also concerned about whether we needed additional NULL checks. But so far I'm not seeing it - it is largely implicit, but we don't drive the routines until the device is plugged, not in reserved|standby and iommu is associated.
This particular case is because we reach unplug (which also has to happen after plug of course) but the swizzle is we are reaching unplug exactly because we are giving up without actually having -successfully- plugged both the zpci and pci device.
But anyway, yes, I do think it would be good to add a small blurb to the commit message.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] s390x/pci: prevent null pointer dereference during zpci hot unplug
2026-02-12 16:55 ` Matthew Rosato
@ 2026-02-12 19:25 ` Halil Pasic
2026-02-13 6:34 ` [PATCH v3] " Aby Sam Ross
0 siblings, 1 reply; 9+ messages in thread
From: Halil Pasic @ 2026-02-12 19:25 UTC (permalink / raw)
To: Matthew Rosato
Cc: Aby Sam Ross, qemu-s390x, qemu-devel, farman, alifm, Halil Pasic
On Thu, 12 Feb 2026 11:55:15 -0500
Matthew Rosato <mjrosato@linux.ibm.com> wrote:
> >
> > Maybe add a word or two why the other dereferences of pbdev->iommu
> > not guarded by a null check are safe.
> >
> > I think we have:
> > * s390_pci_sclp_deconfigure
> > * s390_pci_msix_init
> > * s390_pcihost_reset
> > * s390_pci_device_reset
> > * mpcifc_service_call
> > * stpcifc_service_call
> > * s390_pci_read_base
> >
> > and more. My guess is that the device never gets into a state where
> > these operations are permissible, and the code makes sure
> > those functions won't be called on a device that has
> > pbdev->iommu == NULL. But that is just my guess.
> >
> > DISCLAIMER: I didn't look at this properly, just asking based
> > on a quick look. Some of these may contain explicit or implicit
> > checking...
>
> I mentioned in response to v1 as part of my review that I did look through all references of pbdev->iommu, as I was also concerned about whether we needed additional NULL checks. But so far I'm not seeing it - it is largely implicit, but we don't drive the routines until the device is plugged, not in reserved|standby and iommu is associated.
>
> This particular case is because we reach unplug (which also has to happen after plug of course) but the swizzle is we are reaching unplug exactly because we are giving up without actually having -successfully- plugged both the zpci and pci device.
>
> But anyway, yes, I do think it would be good to add a small blurb to the commit message.
Thanks! I have also assumed that I'm not the first one having this
thought.
Regards,
Halil
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3] s390x/pci: prevent null pointer dereference during zpci hot unplug
2026-02-12 19:25 ` Halil Pasic
@ 2026-02-13 6:34 ` Aby Sam Ross
0 siblings, 0 replies; 9+ messages in thread
From: Aby Sam Ross @ 2026-02-13 6:34 UTC (permalink / raw)
To: qemu-s390x
Cc: qemu-devel, Aby Sam Ross, Eric Farman, Matthew Rosato, Farhan Ali,
Halil Pasic
vfio-pci hostdev realize during zpci hot plug fails (in `vfio_pci_realize()`)
if the vfio group file in `/dev/vfio/` lacks appropriate permissions and the
hostdev[/properties] addition doesn't reach the point where it could be
associated with previously added zpci device (in `s390_pcihost_plug()`).
As a result, zpci iommu pointer remains null. The zpci hot unplug following the
failed hostdev addition assumes zpci iommu pointer was assigned and tries to
make use of it to end the dma count resulting in a null pointer dereference.
In the non-hotplug scenario, `qdev_unplug()` for the zpci device is not called
after hostdev addition failure and this issue is not encountered.
All other uses of zpci iommu without null check happens after both the zpci and
hostdev(pci) devices are plugged and are safe from null dereference.
Fixes: 37fa32de7073 ("s390x/pci: Honor DMA limits set by vfio")
Signed-off-by: Aby Sam Ross <abysamross@ibm.com>
Acked-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Reviewed-by: Farhan Ali <alifm@linux.ibm.com>
Suggested-by: Halil Pasic <pasic@linux.ibm.com>
---
Thank you, Eric, Matthew & Farhan for looking into this.
v2:
Added subsystem name to the commit message.
Updated the `Fixes` tag to include the reference commit's message.
v3:
Added a note about other uses of zpci iommu without null check in the
description as suggested by Halil.
Matthew verified the zpci iommu uses during v1 review.
---
hw/s390x/s390-pci-bus.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index b438d63c44..3166b91c46 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -1248,7 +1248,7 @@ static void s390_pcihost_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
pbdev->fid = 0;
QTAILQ_REMOVE(&s->zpci_devs, pbdev, link);
g_hash_table_remove(s->zpci_table, &pbdev->idx);
- if (pbdev->iommu->dma_limit) {
+ if (pbdev->iommu && pbdev->iommu->dma_limit) {
s390_pci_end_dma_count(s, pbdev->iommu->dma_limit);
}
qdev_unrealize(dev);
--
2.52.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-02-13 14:05 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-10 6:52 [PATCH] prevent null pointer dereference during zpci hot unplug Aby Sam Ross
2026-02-10 14:21 ` Eric Farman
2026-02-10 14:54 ` Matthew Rosato
2026-02-10 17:26 ` Farhan Ali
2026-02-12 11:47 ` [PATCH v2] s390x/pci: " Aby Sam Ross
2026-02-12 15:50 ` Halil Pasic
2026-02-12 16:55 ` Matthew Rosato
2026-02-12 19:25 ` Halil Pasic
2026-02-13 6:34 ` [PATCH v3] " Aby Sam Ross
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.