title: PCI: switchtec: Fix stdev_release() crash after surprise hot remove
description: In the Linux kernel, the following vulnerability has been resolved:
PCI: switchtec: Fix stdev_release() crash after surprise hot remove
A PCI device hot removal may occur while stdev->cdev is held open. The call
to stdev_release() then happens during close or exit, at a point way past
switchtec_pci_remove(). Otherwise the last ref would vanish with the
trailing put_device(), just before return.
At that later point in time, the devm cleanup has already removed the
stdev->mmio_mrpc mapping. Also, the stdev->pdev reference was not a counted
one. Therefore, in DMA mode, the iowrite32() in stdev_release() will cause
a fatal page fault, and the subsequent dma_free_coherent(), if reached,
would pass a stale &stdev->pdev->dev pointer.
Fix by moving MRPC DMA shutdown into switchtec_pci_remove(), after
stdev_kill(). Counting the stdev->pdev ref is now optional, but may prevent
future accidents.
Reproducible via the script at
https://lore.kernel.org/r/20231113212150.96410-1-dns@arista.com
affected:
{
product: Linux
vendor: Linux
defaultStatus: unaffected
repo: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
versions:
version: 1da177e4c3f4, lessThan: d8c293549946, status: affected, versionType: git
version: 1da177e4c3f4, lessThan: 4a5d0528cf19, status: affected, versionType: git
version: 1da177e4c3f4, lessThan: ff1c7e2fb9e9, status: affected, versionType: git
version: 1da177e4c3f4, lessThan: 1d83c8592264, status: affected, versionType: git
version: 1da177e4c3f4, lessThan: 0233b836312e, status: affected, versionType: git
version: 1da177e4c3f4, lessThan: e129c7fa7070, status: affected, versionType: git
version: 1da177e4c3f4, lessThan: df25461119d9, status: affected, versionType: git
}
{
product: Linux
vendor: Linux
defaultStatus: affected
repo: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
versions:
version: 5.4.269, lessThanOrEqual: 5.4.*, status: unaffected, versionType: custom
version: 5.10.210, lessThanOrEqual: 5.10.*, status: unaffected, versionType: custom
version: 5.15.149, lessThanOrEqual: 5.15.*, status: unaffected, versionType: custom
version: 6.1.77, lessThanOrEqual: 6.1.*, status: unaffected, versionType: custom
version: 6.6.16, lessThanOrEqual: 6.6.*, status: unaffected, versionType: custom
version: 6.7.4, lessThanOrEqual: 6.7.*, status: unaffected, versionType: custom
version: 6.8, lessThanOrEqual: *, status: unaffected, versionType: original_commit_for_fix
}
