]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
mmc: atmel-mci: Fix use-after-free in atmci_remove due to race condition
authorPei Xiao <xiaopei01@kylinos.cn>
Mon, 3 Aug 2026 09:48:21 +0000 (17:48 +0800)
committerUlf Hansson <ulfh@kernel.org>
Tue, 4 Aug 2026 13:05:39 +0000 (15:05 +0200)
commitc125ee35a49a0518521b52b27631eef061b8719a
treeba80aa3e407d6dc1a8d525ec0f9585e2555c55be
parent9e9f561269dff35e6f84ed21776ec37fd6360b03
mmc: atmel-mci: Fix use-after-free in atmci_remove due to race condition

In atmci_probe, &host->bh_work is bound with atmci_work_func, and
atmci_interrupt, atmci_timeout_timer and atmci_dma_complete can all
queue this work on system_bh_wq.

If we remove the module, atmci_remove makes cleanup and the memory
allocated for host with devm_kzalloc() is released after the remove
callback returns, while the work mentioned above may still be pending
or running. The sequence of operations that may lead to a UAF bug is
as follows:

CPU0                                      CPU1

                                          | atmci_interrupt
                                          | queue_work(system_bh_wq,
                                          |            &host->bh_work)
atmci_remove                              |
atmci_cleanup_slot(...)                   |
atmci_writel(host, ATMCI_IDR, ~0UL)       |
timer_delete_sync(&host->timer)           |
dma_release_channel(host->dma.chan)       |
free_irq(platform_get_irq(pdev, 0), host) |
                                          | atmci_work_func
                                          | // use host
// devm resources released after          |
// remove returns, host is freed          |
                                          | // use host (use-after-free)

Fix it by canceling the work after all the sources that can schedule
it (IRQ handler, timeout timer and DMA completion callback) have been
stopped, and before proceeding with the remaining cleanup in
atmci_remove.

Fixes: 7d2be0749a59 ("atmel-mci: Driver for Atmel on-chip MMC controllers")
Assisted-by: Codex:deepseek-v4-flash
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
Cc: stable@vger.kernel.org
Signed-off-by: Ulf Hansson <ulfh@kernel.org>
drivers/mmc/host/atmel-mci.c