Skip to contentSkip to conversation

mmc: meson-gx: fix potential use-after-free on remove path.

PATCH In review Greg Kroah-Hartman 2 participants 3 messages Feb 23 – Mar 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: meson-gx: fix potential use-after-free on remove path.

Just like in commit bd2db32e7c3e ("moxart: fix potential use-after-free on remove path"), we should wait until after we are finished writing to the mmc host device before removing it, otherwise it could have been already freed.

Cc Ulf Hansson <[email protected]>
Cc stable <[email protected]>
Assisted-by gkh_clanker_2000
---
 drivers/mmc/host/meson-gx-mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/meson-gx-mmc.c +2 -2
index 694bb443d5f3..9557f6816af3 100644
@@ -1297,13 +1297,13 @@ static void meson_mmc_remove(struct platform_device *pdev)
 {
 	struct meson_host *host = dev_get_drvdata(&pdev->dev);
 
-	mmc_remove_host(host->mmc);
-
 	/* disable interrupts */
 	writel(0, host->regs + SD_EMMC_IRQ_EN);
 	free_irq(host->irq, host);
 
 	clk_disable_unprepare(host->mmc_clk);
+
+	mmc_remove_host(host->mmc);
 }
 
 static const struct meson_mmc_data meson_gx_data = {
Signature · 1 line
2.53.0
#1 lore raw
Quoted 19 lines · Greg Kroah-Hartman

Just like in commit bd2db32e7c3e ("moxart: fix potential use-after-free on remove path"), we should wait until after we are finished writing to the mmc host device before removing it, otherwise it could have been already freed.

Cc Ulf Hansson <[email protected]>
Cc stable <[email protected]>
Assisted-by gkh_clanker_2000
---
 drivers/mmc/host/meson-gx-mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/meson-gx-mmc.c +0 -0
index 694bb443d5f3..9557f6816af3 100644

drivers/mmc/host/meson-gx-mmc.c static void meson_mmc_remove(struct platform_device *pdev) · line 1301

Quoted 5 lines
drivers/mmc/host/meson-gx-mmc.c +0 -2
@@ -1297,13 +1297,13 @@ static void meson_mmc_remove(struct platform_device *pdev)
 {
        struct meson_host *host = dev_get_drvdata(&pdev->dev);
 
-       mmc_remove_host(host->mmc);
-

No, this is actually correct.

My reply for the other patch to the moxart driver explains why.

Quoted 11 lines
drivers/mmc/host/meson-gx-mmc.c +2 -1
        /* disable interrupts */
        writel(0, host->regs + SD_EMMC_IRQ_EN);
        free_irq(host->irq, host);
 
        clk_disable_unprepare(host->mmc_clk);
+
+       mmc_remove_host(host->mmc);
 }
 
 static const struct meson_mmc_data meson_gx_data = {
--
Quoted 2 lines

2.53.0

Kind regards
Uffe

#2 lore raw
Quoted 24 lines · Ulf Hansson
Quoted 22 lines · Greg Kroah-Hartman

Just like in commit bd2db32e7c3e ("moxart: fix potential use-after-free on remove path"), we should wait until after we are finished writing to the mmc host device before removing it, otherwise it could have been already freed.

Cc Ulf Hansson <[email protected]>
Cc stable <[email protected]>
Assisted-by gkh_clanker_2000
---
 drivers/mmc/host/meson-gx-mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/host/meson-gx-mmc.c +0 -0
index 694bb443d5f3..9557f6816af3 100644
@@ -1297,13 +1297,13 @@ static void meson_mmc_remove(struct platform_device *pdev)
 {
        struct meson_host *host = dev_get_drvdata(&pdev->dev);
 
Quoted 6 lines

drivers/mmc/host/meson-gx-mmc.c static void meson_mmc_remove(struct platform_device *pdev) · line 1301

Quoted 2 lines
drivers/mmc/host/meson-gx-mmc.c +0 -2
-       mmc_remove_host(host->mmc);
-

No, this is actually correct.

My reply for the other patch to the moxart driver explains why.

Ok, then the commit above should probably be reverted or at the very least, have the CVE rejected for it.

thanks,

greg k-h