linux_dsm_epyc7002/arch/s390
Niklas Schnelle e115d2997b s390/pci: fix use after free of zpci_dev
[ Upstream commit 2a671f77ee49f3e78997b77fdee139467ff6a598 ]

The struct pci_dev uses reference counting but zPCI assumed erroneously
that the last reference would always be the local reference after
calling pci_stop_and_remove_bus_device(). This is usually the case but
not how reference counting works and thus inherently fragile.

In fact one case where this causes a NULL pointer dereference when on an
SRIOV device the function 0 was hot unplugged before another function of
the same multi-function device. In this case the second function's
pdev->sriov->dev reference keeps the struct pci_dev of function 0 alive
even after the unplug. This bug was previously hidden by the fact that
we were leaking the struct pci_dev which in turn means that it always
outlived the struct zpci_dev. This was fixed in commit 0b13525c20fe
("s390/pci: fix leak of PCI device structure") exposing the broken
behavior.

Fix this by accounting for the long living reference a struct pci_dev
has to its underlying struct zpci_dev via the zbus->function[] array and
only release that in pcibios_release_device() ensuring that the struct
pci_dev is not left with a dangling reference. This is a minimal fix in
the future it would probably better to use fine grained reference
counting for struct zpci_dev.

Fixes: 05bc1be6db ("s390/pci: create zPCI bus")
Cc: stable@vger.kernel.org
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-07-05 18:55:59 +02:00
..
appldata
boot s390/boot: fix use of expolines in the DMA code 2021-07-28 14:35:42 +02:00
configs s390: update defconfigs 2020-11-12 12:10:36 +01:00
crypto s390/archrandom: add parameter check for s390_arch_random_generate 2021-05-11 14:47:31 +02:00
hypfs
include s390/ftrace: fix ftrace_update_ftrace_func implementation 2021-07-28 14:35:42 +02:00
kernel s390/ftrace: fix ftrace_update_ftrace_func implementation 2021-07-28 14:35:42 +02:00
kvm KVM: s390: get rid of register asm usage 2021-07-14 16:55:56 +02:00
lib s390/test_unwind: fix CALL_ON_STACK tests 2020-12-30 11:53:56 +01:00
mm s390: mm: Fix secure storage access exception handling 2021-07-14 16:55:43 +02:00
net init: add dsm gpl source 2024-07-05 18:00:04 +02:00
oprofile
pci s390/pci: fix use after free of zpci_dev 2024-07-05 18:55:59 +02:00
purgatory s390: disable SSP when needed 2021-07-20 16:05:42 +02:00
tools
Kbuild
Kconfig s390: appldata depends on PROC_SYSCTL 2021-07-14 16:56:42 +02:00
Kconfig.debug
Makefile s390: disable SSP when needed 2021-07-20 16:05:42 +02:00