linux-stable/arch/s390/pci
Niklas Schnelle a46044a92a s390/pci: fix zpci_zdev_put() on reserve
Since commit 2a671f77ee ("s390/pci: fix use after free of zpci_dev")
the reference count of a zpci_dev is incremented between
pcibios_add_device() and pcibios_release_device() which was supposed to
prevent the zpci_dev from being freed while the common PCI code has
access to it. It was missed however that the handling of zPCI
availability events assumed that once zpci_zdev_put() was called no
later availability event would still see the device. With the previously
mentioned commit however this assumption no longer holds and we must
make sure that we only drop the initial long-lived reference the zPCI
subsystem holds exactly once.

Do so by introducing a zpci_device_reserved() function that handles when
a device is reserved. Here we make sure the zpci_dev will not be
considered for further events by removing it from the zpci_list.

This also means that the device actually stays in the
ZPCI_FN_STATE_RESERVED state between the time we know it has been
reserved and the final reference going away. We thus need to consider it
a real state instead of just a conceptual state after the removal. The
final cleanup of PCI resources, removal from zbus, and destruction of
the IOMMU stays in zpci_release_device() to make sure holders of the
reference do see valid data until the release.

Fixes: 2a671f77ee ("s390/pci: fix use after free of zpci_dev")
Cc: stable@vger.kernel.org
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
2021-10-04 09:49:10 +02:00
..
Makefile s390/pci: consolidate SR-IOV specific code 2020-09-14 11:38:34 +02:00
pci.c s390/pci: fix zpci_zdev_put() on reserve 2021-10-04 09:49:10 +02:00
pci_bus.c s390/pci: improve DMA translation init and exit 2021-08-25 11:03:34 +02:00
pci_bus.h s390/pci: fix use after free of zpci_dev 2021-08-18 10:12:42 +02:00
pci_clp.c s390/pci: read clp_list_pci_req only once 2021-09-07 13:38:42 +02:00
pci_debug.c locking/atomic, s390/pci: Remove redundant casts 2019-06-03 12:32:57 +02:00
pci_dma.c dma-mapping updates for Linux 5.15 2021-09-02 10:32:06 -07:00
pci_event.c s390/pci: fix zpci_zdev_put() on reserve 2021-10-04 09:49:10 +02:00
pci_insn.c s390/pci: use register pair instead of register asm 2021-06-18 16:41:23 +02:00
pci_iov.c s390/pci: add missing pci_iov.h include 2020-09-16 14:08:47 +02:00
pci_iov.h s390/pci: consolidate SR-IOV specific code 2020-09-14 11:38:34 +02:00
pci_irq.c s390/pci: Do not mask MSI[-X] entries on teardown 2021-08-10 11:03:29 +02:00
pci_mmio.c s390/pci_mmio: fully validate the VMA before calling follow_pte() 2021-09-15 14:29:21 +02:00
pci_sysfs.c s390/pci: improve DMA translation init and exit 2021-08-25 11:03:34 +02:00