linux/arch
Niklas Schnelle 437bb839e3 PCI: s390: Fix use-after-free of PCI resources with per-function hotplug
[ Upstream commit ab90950985 ]

On s390 PCI functions may be hotplugged individually even when they
belong to a multi-function device. In particular on an SR-IOV device VFs
may be removed and later re-added.

In commit a50297cf82 ("s390/pci: separate zbus creation from
scanning") it was missed however that struct pci_bus and struct
zpci_bus's resource list retained a reference to the PCI functions MMIO
resources even though those resources are released and freed on
hot-unplug. These stale resources may subsequently be claimed when the
PCI function re-appears resulting in use-after-free.

One idea of fixing this use-after-free in s390 specific code that was
investigated was to simply keep resources around from the moment a PCI
function first appeared until the whole virtual PCI bus created for
a multi-function device disappears. The problem with this however is
that due to the requirement of artificial MMIO addreesses (address
cookies) extra logic is then needed to keep the address cookies
compatible on re-plug. At the same time the MMIO resources semantically
belong to the PCI function so tying their lifecycle to the function
seems more logical.

Instead a simpler approach is to remove the resources of an individually
hot-unplugged PCI function from the PCI bus's resource list while
keeping the resources of other PCI functions on the PCI bus untouched.

This is done by introducing pci_bus_remove_resource() to remove an
individual resource. Similarly the resource also needs to be removed
from the struct zpci_bus's resource list. It turns out however, that
there is really no need to add the MMIO resources to the struct
zpci_bus's resource list at all and instead we can simply use the
zpci_bar_struct's resource pointer directly.

Fixes: a50297cf82 ("s390/pci: separate zbus creation from scanning")
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Link: https://lore.kernel.org/r/20230306151014.60913-2-schnelle@linux.ibm.com
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2023-03-22 13:31:24 +01:00
..
alpha alpha: fix R_ALPHA_LITERAL reloc for large modules 2023-03-17 08:49:01 +01:00
arc arc: iounmap() arg is volatile 2022-11-03 23:59:15 +09:00
arm ARM: dts: spear320-hmi: correct STMPE GPIO compatible 2023-03-11 13:57:30 +01:00
arm64 arm64: efi: Make efi_rt_lock a raw_spinlock 2023-03-17 08:48:51 +01:00
csky kprobes: treewide: Cleanup the error messages for kprobes 2023-02-22 12:57:00 +01:00
h8300 h8300: Fix build errors from do_exit() to make_task_dead() transition 2023-02-01 08:27:21 +01:00
hexagon hexagon: Fix function name in die() 2023-02-01 08:27:20 +01:00
ia64 genirq: Add and use an irq_data_update_affinity helper 2023-03-11 13:57:31 +01:00
m68k m68k: Check syscall_trace_enter() return code 2023-03-10 09:39:49 +01:00
microblaze exit: Add and use make_task_dead. 2023-02-01 08:27:20 +01:00
mips MIPS: Fix a compilation issue 2023-03-17 08:49:01 +01:00
nds32 exit: Add and use make_task_dead. 2023-02-01 08:27:20 +01:00
nios2 exit: Add and use make_task_dead. 2023-02-01 08:27:20 +01:00
openrisc exit: Add and use make_task_dead. 2023-02-01 08:27:20 +01:00
parisc genirq: Add and use an irq_data_update_affinity helper 2023-03-11 13:57:31 +01:00
powerpc powerpc/vmlinux.lds: Don't discard .rela* for relocatable builds 2023-03-17 08:49:03 +01:00
riscv RISC-V: Don't check text_mutex during stop_machine 2023-03-17 08:48:57 +01:00
s390 PCI: s390: Fix use-after-free of PCI resources with per-function hotplug 2023-03-22 13:31:24 +01:00
sh sh: define RUNTIME_DISCARD_EXIT 2023-03-17 08:49:03 +01:00
sparc sparc: allow PM configs for sparc32 COMPILE_TEST 2023-03-10 09:39:33 +01:00
um UML: define RUNTIME_DISCARD_EXIT 2023-03-17 08:49:04 +01:00
x86 KVM: VMX: Fix crash due to uninitialized current_vmcs 2023-03-17 08:49:05 +01:00
xtensa exit: Add and use make_task_dead. 2023-02-01 08:27:20 +01:00
.gitignore .gitignore: prefix local generated files with a slash 2021-05-02 00:43:35 +09:00
Kconfig arch: make TRACE_IRQFLAGS_NMI_SUPPORT generic 2022-08-17 14:23:00 +02:00