All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: pankaj.gupta@oss.nxp.com
Cc: conor+dt@kernel.org, robh@kernel.org, Frank.Li@kernel.org,
	devicetree@vger.kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v30 4/7] firmware: imx: device context dedicated to priv
Date: Fri, 24 Jul 2026 08:30:28 +0000	[thread overview]
Message-ID: <20260724083029.017E91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724-imx-se-if-v30-4-ce8ba256692c@nxp.com>

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

New issues:
- [Medium] The newly introduced `priv_dev_ctx` and its `devname` string are dynamically allocated but never freed on probe failure or device unbind, leading to a permanent memory leak.

Pre-existing issues:
- [Critical] DMA buffer is freed unconditionally on timeout while the hardware may still be processing the command, leading to use-after-free and DMA memory corruption.
--

--- Patch [4]: [PATCH v30 4/7] firmware: imx: device context dedicated to priv ---
commit 12d4f3d474262e1d23dd156bdd3a71ae735f6977
Author: Pankaj Gupta <pankaj.gupta@nxp.com>

firmware: imx: device context dedicated to priv

Add priv_dev_ctx to prepare enabling misc-device context based send-receive
path, to communicate with FW.

> diff --git a/drivers/firmware/imx/ele_base_msg.c b/drivers/firmware/imx/ele_base_msg.c
> index a2ede9c01691d..524ebc0f697e6 100644
> --- a/drivers/firmware/imx/ele_base_msg.c
> +++ b/drivers/firmware/imx/ele_base_msg.c
> @@ -66,8 +66,9 @@ int ele_get_info(struct se_if_priv *priv, struct ele_dev_info *s_info)
>  	tx_msg->data[0] = upper_32_bits(get_info_addr);
>  	tx_msg->data[1] = lower_32_bits(get_info_addr);
>  	tx_msg->data[2] = sizeof(*s_info);
> -	ret = ele_msg_send_rcv(priv, tx_msg, ELE_GET_INFO_REQ_MSG_SZ, rx_msg,
> -			       ELE_GET_INFO_RSP_MSG_SZ);
> +
> +	ret = ele_msg_send_rcv(priv->priv_dev_ctx, tx_msg, ELE_GET_INFO_REQ_MSG_SZ,
> +			       rx_msg, ELE_GET_INFO_RSP_MSG_SZ);
>  	if (ret < 0) {
>  		ele_get_info_cleanup(priv, get_info_data, get_info_addr, ELE_GET_INFO_BUFF_SZ);
>  		return ret;
>  	}

[Severity: Critical]
This is a pre-existing issue, but does this error path free the DMA buffer
while the hardware might still be active?

If ele_msg_send_rcv() times out, it returns -ETIMEDOUT and trips the fw_busy
circuit breaker. However, this error path unconditionally calls
ele_get_info_cleanup(), which releases the DMA buffer back to the system:

static void ele_get_info_cleanup(...)
{
	if (priv->mem_pool)
		gen_pool_free(priv->mem_pool, (unsigned long)buf, size);
	else
		dma_free_coherent(priv->dev, size, buf, d_addr);
}

If the firmware is merely slow and eventually processes the command, won't it
execute a delayed DMA write to the freed physical address, potentially
corrupting whatever kernel memory is subsequently mapped there?

[ ... ]

> diff --git a/drivers/firmware/imx/se_ctrl.c b/drivers/firmware/imx/se_ctrl.c
> index e9e2f48f4f71f..b053dd00286c8 100644
> --- a/drivers/firmware/imx/se_ctrl.c
> +++ b/drivers/firmware/imx/se_ctrl.c
> @@ -411,6 +441,12 @@ static int se_if_probe(struct platform_device *pdev)
>  		load_fw->is_fw_tobe_loaded = true;
>  	}
>  
> +	ret = init_misc_device_context(priv, 0, &priv->priv_dev_ctx);
> +	if (ret)
> +		return dev_err_probe(dev, ret,
> +				     "Failed[0x%x] to create device contexts.",
> +				     ret);
> +

[Severity: Medium]
Will this leak the newly allocated priv->priv_dev_ctx and its devname string
on probe failure or device unbind?

The init_misc_device_context() function dynamically allocates these resources
using non-devm kzalloc_obj() and kasprintf(). However, if probe fails at a
later step or the device is unbound, the devres-managed cleanup function
se_if_probe_cleanup() only frees priv and misses the context:

static void se_if_probe_cleanup(void *context)
{
	...
	if (priv->tx_chan)
		mbox_free_channel(priv->tx_chan);

	dev_set_drvdata(dev, NULL);

	kfree(priv);
}

Should the cleanup function be updated to also free priv->priv_dev_ctx and
its devname to avoid a permanent memory leak?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260724-imx-se-if-v30-0-ce8ba256692c@nxp.com?part=4

  reply	other threads:[~2026-07-24  8:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24  9:05 [PATCH v30 0/7] firmware: imx: driver for NXP secure-enclave pankaj.gupta
2026-07-24  9:05 ` [PATCH v30 1/7] Documentation/firmware: add imx/se to other_interfaces pankaj.gupta
2026-07-24  8:18   ` sashiko-bot
2026-07-24  9:05 ` [PATCH v30 2/7] dt-bindings: arm: fsl: add imx-se-fw binding doc pankaj.gupta
2026-07-24  9:05 ` [PATCH v30 3/7] firmware: imx: add driver for NXP EdgeLock Enclave pankaj.gupta
2026-07-24  8:28   ` sashiko-bot
2026-07-24  9:05 ` [PATCH v30 4/7] firmware: imx: device context dedicated to priv pankaj.gupta
2026-07-24  8:30   ` sashiko-bot [this message]
2026-07-24  9:05 ` [PATCH v30 5/7] firmware: drivers: imx: adds miscdev pankaj.gupta
2026-07-24  8:32   ` sashiko-bot
2026-07-24  9:05 ` [PATCH v30 6/7] arm64: dts: imx8ulp: add secure enclave node pankaj.gupta
2026-07-24  8:31   ` sashiko-bot
2026-07-24  9:05 ` [PATCH v30 7/7] arm64: dts: imx8ulp-evk: add reserved memory property pankaj.gupta

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=20260724083029.017E91F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=pankaj.gupta@oss.nxp.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.