linux/arch/s390/pci
Niklas Schnelle ef6bb8f4d8 s390/pci: Fix leak of struct zpci_dev when zpci_add_device() fails
commit 48796104c8 upstream.

Prior to commit 0467cdde8c ("s390/pci: Sort PCI functions prior to
creating virtual busses") the IOMMU was initialized and the device was
registered as part of zpci_create_device() with the struct zpci_dev
freed if either resulted in an error. With that commit this was moved
into a separate function called zpci_add_device().

While this new function logs when adding failed, it expects the caller
not to use and to free the struct zpci_dev on error. This difference
between it and zpci_create_device() was missed while changing the
callers and the incompletely initialized struct zpci_dev may get used in
zpci_scan_configured_device in the error path. This then leads to
a crash due to the device not being registered with the zbus. It was
also not freed in this case. Fix this by handling the error return of
zpci_add_device(). Since in this case the zdev was not added to the
zpci_list it can simply be discarded and freed. Also make this more
explicit by moving the kref_init() into zpci_add_device() and document
that zpci_zdev_get()/zpci_zdev_put() must be used after adding.

Cc: stable@vger.kernel.org
Fixes: 0467cdde8c ("s390/pci: Sort PCI functions prior to creating virtual busses")
Reviewed-by: Gerd Bayer <gbayer@linux.ibm.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2024-12-14 20:04:16 +01:00
..
Makefile s390/pci: Stop usurping pdev->dev.groups 2024-08-09 14:58:27 -05:00
pci.c s390/pci: Fix leak of struct zpci_dev when zpci_add_device() fails 2024-12-14 20:04:16 +01:00
pci_bus.c s390/pci: Ignore RID for isolated VFs 2024-12-14 20:03:35 +01:00
pci_bus.h PCI: s390: Fix use-after-free of PCI resources with per-function hotplug 2023-03-13 09:15:11 +01:00
pci_clp.c s390/pci: Ignore RID for isolated VFs 2024-12-14 20:03:35 +01:00
pci_debug.c iommu/s390: Implement blocking domain 2024-12-05 14:02:03 +01:00
pci_event.c s390/pci: Fix leak of struct zpci_dev when zpci_add_device() fails 2024-12-14 20:04:16 +01:00
pci_insn.c KVM: s390: pci: provide routines for enabling/disabling interrupt forwarding 2022-07-11 09:54:32 +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: Allow allocation of more than 1 MSI interrupt 2024-07-23 15:54:58 +02:00
pci_kvm_hook.c KVM: s390: pci: Hook to access KVM lowlevel from VFIO 2022-08-29 13:29:28 +02:00
pci_mmio.c s390/pci_mmio: use follow_pfnmap API 2024-09-17 01:06:59 -07:00
pci_sysfs.c s390/pci: Stop usurping pdev->dev.groups 2024-08-09 14:58:27 -05:00