Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Robert Richter <rric@kernel.org>,
	Ulf Hansson <ulfh@kernel.org>, Cavium Inc <support@cavium.com>,
	Huacai Chen <chenhuacai@kernel.org>,
	Binbin Zhou <zhoubinbin@loongson.cn>,
	Guangshuo Li <lgs201920130244@gmail.com>,
	linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 01/13] mmc: cavium: Remove MMC slots before destroying slot platform devices
Date: Mon, 23 Nov 2026 19:15:45 +0000	[thread overview]
Message-ID: <20261123191703.179283-2-lee@kernel.org> (raw)
In-Reply-To: <20261123191703.179283-1-lee@kernel.org>

cvm_mmc_of_slot_probe() allocates each slot and its struct mmc_host via
devm_mmc_alloc_host() bound to the dummy slot platform device created in
octeon_mmc_probe() and thunder_mmc_probe(), and indexes host->slot[] by
the Device Tree reg property while host->slot_pdev[] is indexed by the
child iteration counter.

When a slot reg index is greater than its child iteration index (for
example when only slot 1 is populated or enabled), the single teardown
loop in probe error handling and driver removal calls
of_platform_device_destroy() on the slot platform device before calling
cvm_mmc_of_slot_remove() on its corresponding host->slot[] entry.
Unregistering the unbound platform device immediately releases its
managed resources, freeing slot regulators and dropping the initial
struct mmc_host reference via mmc_free_host() while the MMC host is
still registered.  The subsequent cvm_mmc_of_slot_remove() call then
accesses freed regulator state and frees struct mmc_host and private
slot memory mid-way through mmc_remove_host(), resulting in a
use-after-free.

Remove all populated MMC slots in a first pass before destroying the
child slot platform devices in a second pass across both probe error and
driver removal paths.

Fixes: f32b90e6887f ("mmc: cavium: Use devm_mmc_alloc_host() helper")
Fixes: 0f4d4424fc1d ("mmc: cavium-octeon: destroy slot platform devices on remove")
Fixes: 29ee8cf18a21 ("mmc: cavium-thunderx: destroy slot platform devices on remove")
Closes: https://sashiko.dev/#/bug/linux-f5f8989d-5e08-46d1-91a1-69841c36692b
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/mmc/host/cavium-octeon.c   | 4 ++++
 drivers/mmc/host/cavium-thunderx.c | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/drivers/mmc/host/cavium-octeon.c b/drivers/mmc/host/cavium-octeon.c
index dd62b96712c8..7b75b3dfd3e6 100644
--- a/drivers/mmc/host/cavium-octeon.c
+++ b/drivers/mmc/host/cavium-octeon.c
@@ -283,6 +283,8 @@ static int octeon_mmc_probe(struct platform_device *pdev)
 	for (i = 0; i < CAVIUM_MAX_MMC; i++) {
 		if (host->slot[i])
 			cvm_mmc_of_slot_remove(host->slot[i]);
+	}
+	for (i = 0; i < CAVIUM_MAX_MMC; i++) {
 		if (host->slot_pdev[i])
 			of_platform_device_destroy(&host->slot_pdev[i]->dev, NULL);
 	}
@@ -298,6 +300,8 @@ static void octeon_mmc_remove(struct platform_device *pdev)
 	for (i = 0; i < CAVIUM_MAX_MMC; i++) {
 		if (host->slot[i])
 			cvm_mmc_of_slot_remove(host->slot[i]);
+	}
+	for (i = 0; i < CAVIUM_MAX_MMC; i++) {
 		if (host->slot_pdev[i])
 			of_platform_device_destroy(&host->slot_pdev[i]->dev, NULL);
 	}
diff --git a/drivers/mmc/host/cavium-thunderx.c b/drivers/mmc/host/cavium-thunderx.c
index 526ae9019b2f..b8296b2de127 100644
--- a/drivers/mmc/host/cavium-thunderx.c
+++ b/drivers/mmc/host/cavium-thunderx.c
@@ -157,6 +157,8 @@ static int thunder_mmc_probe(struct pci_dev *pdev,
 	for (i = 0; i < CAVIUM_MAX_MMC; i++) {
 		if (host->slot[i])
 			cvm_mmc_of_slot_remove(host->slot[i]);
+	}
+	for (i = 0; i < CAVIUM_MAX_MMC; i++) {
 		if (host->slot_pdev[i])
 			of_platform_device_destroy(&host->slot_pdev[i]->dev, NULL);
 	}
@@ -173,6 +175,8 @@ static void thunder_mmc_remove(struct pci_dev *pdev)
 	for (i = 0; i < CAVIUM_MAX_MMC; i++) {
 		if (host->slot[i])
 			cvm_mmc_of_slot_remove(host->slot[i]);
+	}
+	for (i = 0; i < CAVIUM_MAX_MMC; i++) {
 		if (host->slot_pdev[i])
 			of_platform_device_destroy(&host->slot_pdev[i]->dev, NULL);
 	}
-- 
2.56.1.750.gf70dc682cf-goog


       reply	other threads:[~2026-11-23 19:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261123191703.179283-1-lee@kernel.org>
2026-11-23 19:15 ` Lee Jones [this message]
2026-11-23 19:15 ` [PATCH 02/13] mmc: cavium: Prevent slot_pdev[] out-of-bounds write during probe Lee Jones
2026-11-23 19:15 ` [PATCH 03/13] mmc: sdhci-msm: Resume runtime PM before accessing registers on remove Lee Jones
2026-11-23 19:15 ` [PATCH 04/13] mmc: meson-gx: Fail request when descriptor chain DMA mapping fails Lee Jones
2026-11-23 19:15 ` [PATCH 05/13] mmc: jz4740: Skip DMA cleanup in PIO mode during post_req Lee Jones
2026-11-23 19:15 ` [PATCH 06/13] mmc: renesas_sdhi: Guard host->cmd access in internal DMAC issue work Lee Jones
2026-11-23 19:15 ` [PATCH 07/13] mmc: tifm_sd: Synchronise timeout handler with request completion Lee Jones
2026-11-23 19:15 ` [PATCH 08/13] mmc: omap: Shut down cover timer before disabling cover BH work Lee Jones
2026-11-23 19:15 ` [PATCH 09/13] mmc: renesas_sdhi: Disable internal DMAC BH work items on release Lee Jones
2026-11-23 19:15 ` [PATCH 10/13] mmc: jz4740: Apply DMA max_seg_size limit to unified tx-rx channel Lee Jones
2026-11-23 19:15 ` [PATCH 12/13] mmc: renesas_sdhi: Fix SDIO manual tap correction in SDR104 mode Lee Jones
2026-11-23 19:15 ` [PATCH 13/13] mmc: sdhci-brcmstb: Handle absent optional sdio_freq clock in probe Lee Jones
2026-11-23 19:31   ` Florian Fainelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123191703.179283-2-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=lgs201920130244@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=rric@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=support@cavium.com \
    --cc=ulfh@kernel.org \
    --cc=zhoubinbin@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox