linux/arch/s390
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
..
appldata sysctl: treewide: constify the ctl_table argument of proc_handlers 2024-07-24 20:59:29 +02:00
boot s390 updates for 6.12 merge window 2024-09-21 09:02:54 -07:00
configs s390: Update defconfigs 2024-10-16 11:32:32 +02:00
crypto This push fixes the following issues: 2024-09-24 10:46:54 -07:00
hypfs [tree-wide] finally take no_llseek out 2024-09-27 08:18:43 -07:00
include s390/pci: Use topology ID for multi-function devices 2024-12-14 20:03:35 +01:00
kernel s390/cpum_sf: Handle CPU hotplug remove during sampling 2024-12-14 20:03:35 +01:00
kvm KVM: s390: Change virtual to physical address access in diag 0x258 handler 2024-10-10 15:31:55 +02:00
lib s390/alternatives: Rework to allow for callbacks 2024-07-23 16:02:31 +02:00
mm s390/pageattr: Implement missing kernel_page_present() 2024-12-05 14:01:11 +01:00
net s390/bpf: Implement exceptions 2024-07-08 16:39:35 +02:00
pci s390/pci: Fix leak of struct zpci_dev when zpci_add_device() fails 2024-12-14 20:04:16 +01:00
purgatory Makefile: remove redundant tool coverage variables 2024-05-14 23:35:48 +09:00
tools s390 updates for 6.12 merge window 2024-09-21 09:02:54 -07:00
Kbuild - An extensive rework of kexec and crash Kconfig from Eric DeVolder 2023-08-29 14:53:51 -07:00
Kconfig crash, powerpc: default to CRASH_DUMP=n on PPC_BOOK3S_32 2024-11-14 22:43:48 -08:00
Kconfig.debug s390/Kconfig.debug: fix indentation 2022-06-01 12:03:15 +02:00
Makefile s390: use a larger stack for KMSAN 2024-07-03 19:30:24 -07:00
Makefile.postlink s390/build: Avoid relocation information in final vmlinux 2024-08-27 20:16:48 +02:00