mirror of https://lore.kernel.org/lkml/
 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>,
	Jan Glauber <jan.glauber@gmail.com>,
	linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 02/13] mmc: cavium: Prevent slot_pdev[] out-of-bounds write during probe
Date: Mon, 23 Nov 2026 19:15:46 +0000	[thread overview]
Message-ID: <20261123191703.179283-3-lee@kernel.org> (raw)
In-Reply-To: <20261123191703.179283-1-lee@kernel.org>

octeon_mmc_probe() and thunder_mmc_probe() iterate over Device Tree
child nodes and store each created slot platform device in
host->slot_pdev[i], which is sized to CAVIUM_MAX_MMC (4).  Neither
function checks that i remains below CAVIUM_MAX_MMC before writing to
host->slot_pdev[i], and both increment i even for disabled or
non-mmc-slot child nodes.  When a controller node has more than four
child nodes (or four valid mmc-slot nodes alongside another child node
on ThunderX), host->slot_pdev[i] writes past the end of the array and
corrupts the adjacent set_shared_power and acquire_bus callback
pointers in struct cvm_mmc_host.

Iterate only over available child nodes, advance the slot_pdev[] index
only when a slot platform device is created, and fail the probe with
-EINVAL if more than CAVIUM_MAX_MMC slots are present.

Fixes: 8fb83b142823 ("mmc: cavium: Fix probing race with regulator")
Fixes: 166bac38c3c5 ("mmc: cavium: Add MMC PCI driver for ThunderX SOCs")
Closes: https://sashiko.dev/#/bug/linux-022f7ab4-a7fe-4881-b87d-613d4b8f010f
Closes: https://sashiko.dev/#/bug/linux-04e9d7cc-573a-4ea4-ab4e-d65b9b0626ac
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/mmc/host/cavium-octeon.c   | 13 +++++++++----
 drivers/mmc/host/cavium-thunderx.c | 11 +++++++++--
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/mmc/host/cavium-octeon.c b/drivers/mmc/host/cavium-octeon.c
index 7b75b3dfd3e6..375d8f23b26e 100644
--- a/drivers/mmc/host/cavium-octeon.c
+++ b/drivers/mmc/host/cavium-octeon.c
@@ -262,13 +262,18 @@ static int octeon_mmc_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, host);
 
 	i = 0;
-	for_each_child_of_node_scoped(node, cn) {
+	for_each_available_child_of_node_scoped(node, cn) {
+		if (i >= CAVIUM_MAX_MMC) {
+			dev_err(&pdev->dev, "Too many slots\n");
+			ret = -EINVAL;
+			octeon_mmc_set_shared_power(host, 0);
+			goto error;
+		}
 		host->slot_pdev[i] =
 			of_platform_device_create(cn, NULL, &pdev->dev);
-		if (!host->slot_pdev[i]) {
-			i++;
+		if (!host->slot_pdev[i])
 			continue;
-		}
+
 		ret = cvm_mmc_of_slot_probe(&host->slot_pdev[i]->dev, host);
 		if (ret) {
 			dev_err(&pdev->dev, "Error populating slots\n");
diff --git a/drivers/mmc/host/cavium-thunderx.c b/drivers/mmc/host/cavium-thunderx.c
index b8296b2de127..a5346fb96f9b 100644
--- a/drivers/mmc/host/cavium-thunderx.c
+++ b/drivers/mmc/host/cavium-thunderx.c
@@ -129,7 +129,7 @@ static int thunder_mmc_probe(struct pci_dev *pdev,
 	if (ret)
 		goto error;
 
-	for_each_child_of_node(node, child_node) {
+	for_each_available_child_of_node(node, child_node) {
 		/*
 		 * mmc_of_parse and devm* require one device per slot.
 		 * Create a dummy device per slot and set the node pointer to
@@ -137,6 +137,13 @@ static int thunder_mmc_probe(struct pci_dev *pdev,
 		 * of_platform_device_create.
 		 */
 		if (of_device_is_compatible(child_node, "mmc-slot")) {
+			if (i >= CAVIUM_MAX_MMC) {
+				dev_err(dev, "Too many slots\n");
+				of_node_put(child_node);
+				ret = -EINVAL;
+				goto error;
+			}
+
 			host->slot_pdev[i] = of_platform_device_create(child_node, NULL,
 								       &pdev->dev);
 			if (!host->slot_pdev[i])
@@ -147,8 +154,8 @@ static int thunder_mmc_probe(struct pci_dev *pdev,
 				of_node_put(child_node);
 				goto error;
 			}
+			i++;
 		}
-		i++;
 	}
 	dev_info(dev, "probed\n");
 	return 0;
-- 
2.56.1.750.gf70dc682cf-goog


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

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 19:15 [PATCH 00/13] mmc: Assorted bug fixes across MMC host drivers Lee Jones
2026-11-23 19:15 ` [PATCH 01/13] mmc: cavium: Remove MMC slots before destroying slot platform devices Lee Jones
2026-11-23 19:15 ` Lee Jones [this message]
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 11/13] mmc: dw_mmc: Disarm central watchdog when ending a request 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-3-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=jan.glauber@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 \
    /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

all inboxes | Powered by JetHome®