[PATCH] mmc: meson-mx-sdio: Fix potential host use-after-free during teardown
Guangshuo Li
liguangshuo at mail.sdu.edu.cn
Thu Dec 3 03:57:15 PST 2026
The MMC host is managed by the slot device, but its IRQ is managed by
the controller. Destroying the slot can therefore free the host while
the IRQ still uses it. Removal also reads host->cfg_div_clk afterwards.
Release the IRQ before destroying the slot on removal and probe failure.
Stop requests before draining the timer, and disable the divider clock
while the host is still alive.
Fixes: baa74c214427 ("mmc: meson-mx-sdio: Use devm_mmc_alloc_host() helper")
Fixes: ed80a13bb4c4 ("mmc: meson-mx-sdio: Add a driver for the Amlogic Meson8 and Meson8b SoCs")
Signed-off-by: Guangshuo Li <liguangshuo at mail.sdu.edu.cn>
---
drivers/mmc/host/meson-mx-sdio.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/drivers/mmc/host/meson-mx-sdio.c b/drivers/mmc/host/meson-mx-sdio.c
index 5d48c8e7fbf9..6969fb93d792 100644
--- a/drivers/mmc/host/meson-mx-sdio.c
+++ b/drivers/mmc/host/meson-mx-sdio.c
@@ -679,6 +679,7 @@ static int meson_mx_mmc_probe(struct platform_device *pdev)
goto error_unregister_slot_pdev;
}
+ host->irq = irq;
ret = devm_request_threaded_irq(host->controller_dev, irq,
meson_mx_mmc_irq,
meson_mx_mmc_irq_thread, IRQF_ONESHOT,
@@ -690,20 +691,20 @@ static int meson_mx_mmc_probe(struct platform_device *pdev)
if (IS_ERR(core_clk)) {
ret = dev_err_probe(host->controller_dev, PTR_ERR(core_clk),
"Failed to get and enable 'core' clock\n");
- goto error_unregister_slot_pdev;
+ goto error_free_irq;
}
host->cfg_div_clk = meson_mx_mmc_register_clk(&pdev->dev, base);
if (IS_ERR(host->cfg_div_clk)) {
ret = PTR_ERR(host->cfg_div_clk);
- goto error_unregister_slot_pdev;
+ goto error_free_irq;
}
ret = clk_prepare_enable(host->cfg_div_clk);
if (ret) {
dev_err_probe(host->controller_dev, ret,
"Failed to enable MMC (cfg div) clock\n");
- goto error_unregister_slot_pdev;
+ goto error_free_irq;
}
conf = 0;
@@ -722,7 +723,12 @@ static int meson_mx_mmc_probe(struct platform_device *pdev)
return 0;
error_disable_div_clk:
+ devm_free_irq(host->controller_dev, irq, host);
+ timer_shutdown_sync(&host->cmd_timeout);
clk_disable_unprepare(host->cfg_div_clk);
+ goto error_unregister_slot_pdev;
+error_free_irq:
+ devm_free_irq(host->controller_dev, irq, host);
error_unregister_slot_pdev:
of_platform_device_destroy(&slot_pdev->dev, NULL);
return ret;
@@ -733,13 +739,12 @@ static void meson_mx_mmc_remove(struct platform_device *pdev)
struct meson_mx_mmc_host *host = platform_get_drvdata(pdev);
struct device *slot_dev = mmc_dev(host->mmc);
- timer_delete_sync(&host->cmd_timeout);
-
mmc_remove_host(host->mmc);
+ devm_free_irq(host->controller_dev, host->irq, host);
+ timer_shutdown_sync(&host->cmd_timeout);
+ clk_disable_unprepare(host->cfg_div_clk);
of_platform_device_destroy(slot_dev, NULL);
-
- clk_disable_unprepare(host->cfg_div_clk);
}
static const struct of_device_id meson_mx_mmc_of_match[] = {
base-commit: d06ce6f1eb5eeffd4ebcfde345dc34a98131d106
--
2.43.0
More information about the linux-arm-kernel
mailing list