In the Linux kernel, the following vulnerability has been resolved: spi: spi-pci1xxxx: quiesce DMA engines on transfer timeout If a DMA-mapped transfer times out waiting for DMA_TERM and neither DMA abort interrupt arrived, pci1xxxx_spi_transfer_with_dma() returns through the error label while both DMA engines are still enabled, the done/abort interrupt status is still armed and the transfer state (p->xfer, p->tx_sgl, p->rx_sgl) is still registered. ISRs продолжает работать и после этого: они перепрограммируют движки DMA из p->tx_sgl/p->rx_sgl и завершают сигнал через p->xfer и p->spi_xfer_done, все из которых ядро SPI можно отобразить или повторно использовать после возвращения transfer_one(), что является use-after-free. Несвоевременное прерывание также может начать следующую передачу, поставленную в очередь за неудавшейся.
Остановите оба движка DMA, сливайте состояние прерывания отложенного / отмененного и синхронизируйте DMA IRQs перед падением состояния в процессе и указателей передачи, а затем снова включите двигатели, чтобы последующие передачи продолжали работать. Двигатели включаются только после того, как оба были подтверждены, что остановились: повторное включение движка, который не смог остановиться, отменит ожидающий запрос на остановку и позволит ему продолжать работать в буферах, ядро SPI вот-вот исчезнет или освободится, что именно и является окном, которое этот патч закрывает. Движок, который не удалось остановить, остается отключенным, как это уже делают пути прерывания.
The DMA interrupt status and mask registers are shared between the two SPI instances, so the cleanup drains only this instance's done/abort status bits instead of masking the interrupt lines, which would also suppress the peer instance's completion interrupts. Кроме того, DMA ISRs игнорирует прерывания, пока не происходит передача, так что блуждающий MSI после очистки больше не может действовать на очищенное состояние. Никакое оборудование PCI1XXXX не было доступно для тестирования, и QEMU не имеет модели этой части PCIe, поэтому путь тайм-аута был осуществлен с помощью реплики пользовательского пространства ветки тайм-аута и DMA ISRs, с регистром и прерываниями доступа, имитируемыми: на нефиксированном коде как клиновый движок, который очищается после тайм-аута, так и поздно сделанное прерывание касаются освобожденного состояния передачи, в то есть.
Модуль также загружался и выгружался в гостевом QEMU x86_64, запускающем ядро с этим исправлением.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: spi: spi-pci1xxxx: quiesce DMA engines on transfer timeout If a DMA-mapped transfer times out waiting for DMA_TERM and neither DMA abort interrupt arrived, pci1xxxx_spi_transfer_with_dma() returns through the error label while both DMA engines are still enabled, the done/abort interrupt status is still armed and the transfer state (p->xfer, p->tx_sgl, p->rx_sgl) is still registered. The ISRs keep firing afterwards: they reprogram the DMA engines from p->tx_sgl / p->rx_sgl and signal completion through p->xfer and p->spi_xfer_done, all of which the SPI core is free to unmap or reuse once transfer_one() has returned, which is a use-after-free. A late done interrupt can also start the next transfer queued behind the failed one. Stop both DMA engines, drain the pending done/abort interrupt status and synchronize the DMA IRQs before dropping the in-progress state and the transfer pointers, and re-enable the engines afterwards so that subsequent transfers keep working. The engines are only turned back on once both were confirmed to have stopped: re-enabling an engine that failed to stop would cancel the pending stop request and let it keep running into buffers the SPI core is about to unmap or free, which is exactly the window this patch closes. An engine that failed to stop is left disabled, as the abort paths already do. The DMA interrupt status and mask registers are shared between the two SPI instances, so the cleanup drains only this instance's done/abort status bits instead of masking the interrupt lines, which would also suppress the peer instance's completion interrupts. Also make the DMA ISRs ignore interrupts while no transfer is in progress so that a stray MSI after the cleanup can no longer act on the cleared state. No PCI1XXXX hardware was available for testing and QEMU has no model of this PCIe part, so the timeout path was exercised with a userspace replica of the timeout branch and the DMA ISRs, with the register and interrupt accesses mocked: on the unfixed code both a wedged engine that clears after the timeout and a late done interrupt touch the freed transfer state, while with this fix applied neither does and an engine that failed to stop is left disabled. The module was also loaded and unloaded in a QEMU x86_64 guest running a kernel with this fix applied.