Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tanmay Kathpalia" <tanmay.kathpalia@altera.com>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v6 6/8] mmc: sdhci-cadence: refactor driver structure for V6 controller support
Date: Sat, 29 Aug 2026 18:54:23 +0000	[thread overview]
Message-ID: <20260829185423.BCFAE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260829184252.27644-7-tanmay.kathpalia@altera.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Time-of-check to time-of-use (TOCTOU) buffer overflow during double-pass PHY parameter parsing.
--

commit 63b7c6883f34223180b95652ed2ee59e64bc1fac
Author: Tanmay Kathpalia <tanmay.kathpalia@altera.com>

mmc: sdhci-cadence: refactor driver structure for V6 controller support

This commit refactors the sdhci-cadence driver in preparation for V6
controller support. It separates PHY parameter handling into a dedicated
sdhci_cdns4_phy structure and introduces a new probe function. Explicit
driver data is now required for compatible entries.

> diff --git a/drivers/mmc/host/sdhci-cadence.c b/drivers/mmc/host/sdhci-cadence.c
> --- a/drivers/mmc/host/sdhci-cadence.c
> +++ b/drivers/mmc/host/sdhci-cadence.c

[ ... ]

> @@ -539,6 +544,24 @@ static void sdhci_cdns_mmc_hw_reset(struct mmc_host *mmc)
>  	usleep_range(300, 1000);
>  }
>  
> +static int sdhci_cdns4_phy_probe(struct platform_device *pdev, struct sdhci_cdns_priv *priv)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct sdhci_cdns4_phy *phy;
> +	unsigned int nr_phy_params;
> +
> +	nr_phy_params = sdhci_cdns4_phy_param_count(dev->of_node);
> +	phy = devm_kzalloc(dev, struct_size(phy, phy_params, nr_phy_params), GFP_KERNEL);
> +	if (!phy)
> +		return -ENOMEM;
> +
> +	phy->nr_phy_params = nr_phy_params;
> +	sdhci_cdns4_phy_param_parse(dev->of_node, phy);

[Severity: Critical]
This is a pre-existing issue, but does this allocation and double-pass
parsing sequence open a time-of-check to time-of-use window?

If a device tree overlay is applied concurrently during driver probe
(between the count and the parse calls), sdhci_cdns4_phy_param_parse()
could find more properties than were initially allocated.

Looking at sdhci_cdns4_phy_param_parse(), the pointer p is incremented
without bounds checking against the allocated size:

static void sdhci_cdns4_phy_param_parse(...)
{
        ...
        ret = of_property_read_u32(np, sdhci_cdns4_phy_cfgs[i].property, &val);
        if (!ret) {
                p->addr = sdhci_cdns4_phy_cfgs[i].addr;
                p->data = val;
                p++;
        }
        ...
}

Could this lead to a heap buffer overflow overwriting adjacent memory if
the property list grows between sdhci_cdns4_phy_param_count() and
sdhci_cdns4_phy_param_parse()?

> +	priv->phy = phy;
> +
> +	return sdhci_cdns4_phy_init(priv);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260829184252.27644-1-tanmay.kathpalia@altera.com?part=6

  reply	other threads:[~2026-08-29 18:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-29 18:42 [PATCH v6 0/8] mmc: sdhci-cadence: add SD6HC support and Agilex5 enablement Tanmay Kathpalia
2026-08-29 18:42 ` [PATCH v6 1/8] dt-bindings: mmc: add Cadence SD6HC binding Tanmay Kathpalia
2026-08-29 18:42 ` [PATCH v6 2/8] arm64: dts: agilex5: add SD/eMMC host controller Tanmay Kathpalia
2026-08-29 18:51   ` sashiko-bot
2026-09-01  8:44   ` Michael Tretter
2026-09-01 18:32     ` Kathpalia, Tanmay
2026-08-29 18:42 ` [PATCH v6 3/8] dt-bindings: arm: altera: add Agilex5 SOCDK eMMC board variant Tanmay Kathpalia
2026-08-29 18:42 ` [PATCH v6 4/8] arm64: dts: agilex5: add SOCDK eMMC daughter board Tanmay Kathpalia
2026-08-29 18:42 ` [PATCH v6 5/8] mmc: sdhci-cadence: rename SD4HC symbols for SD6HC groundwork Tanmay Kathpalia
2026-08-29 18:51   ` sashiko-bot
2026-08-29 18:42 ` [PATCH v6 6/8] mmc: sdhci-cadence: refactor driver structure for V6 controller support Tanmay Kathpalia
2026-08-29 18:54   ` sashiko-bot [this message]
2026-08-29 18:42 ` [PATCH v6 7/8] mmc: sdhci-cadence: add Cadence SD6HC support Tanmay Kathpalia
2026-08-29 18:59   ` sashiko-bot
2026-08-29 18:42 ` [PATCH v6 8/8] mmc: sdhci-cadence: add Altera Agilex5 " Tanmay Kathpalia

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=20260829185423.BCFAE1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tanmay.kathpalia@altera.com \
    /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