All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: pankaj.gupta@oss.nxp.com
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v38 3/7] firmware: imx: add driver for NXP EdgeLock Enclave
Date: Wed, 19 Aug 2026 13:30:55 +0000	[thread overview]
Message-ID: <20260819133055.9B0481F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260820-imx-se-if-v38-3-5df4a4cff736@nxp.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] DMA use-after-free on firmware timeout in `ele_get_info()` and driver unbind.
- [Medium] `se_resume()` ignores the failure of `se_restore_imem_state()`, breaking expected power management error handling semantics.
- [Low] Incorrect iteration bound computation in `ele_debug_dump` leads to reading past the received payload.
--

--- Patch [3]: [PATCH v38 3/7] firmware: imx: add driver for NXP EdgeLock Enclave ---
commit b60827d987987a5036c02b256c938fa4f0af210a
Author: Pankaj Gupta <pankaj.gupta@nxp.com>

firmware: imx: add driver for NXP EdgeLock Enclave

Add MU-based communication interface for secure enclave on i.MX SoC(s).
The secure enclave FW communicates with Linux over single or multiple
dedicated messaging unit(MU) based interface(s).

> diff --git a/drivers/firmware/imx/ele_base_msg.c b/drivers/firmware/imx/ele_base_msg.c
> index 0000000000000..724f6e913ce79 100644
> --- /dev/null
> +++ b/drivers/firmware/imx/ele_base_msg.c

[ ... ]

> +int ele_get_info(struct se_if_priv *priv, struct ele_dev_info *s_info)
> +{

[ ... ]

> +	ret = ele_msg_send_rcv(priv, 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, get_info_len);

[Severity: High]
If an enclave command times out, ele_msg_send_rcv() returns -ETIMEDOUT and
the error path immediately calls ele_get_info_cleanup(), which frees the DMA
buffer. If the firmware is still executing and completes the transaction
later, could it perform a DMA write into physical memory that has been
reallocated to another subsystem?

> +		return ret;
> +	}

[ ... ]

> +int ele_debug_dump(struct se_if_priv *priv)
> +{

[ ... ]

> +		rx_msg->header.size -= 2;
> +
> +		if (rx_msg->header.size > 2)
> +			rx_msg->header.size--;
> +
> +		for (i = 0; i < rx_msg->header.size; i += 2)
> +			dev_info(priv->dev, "%s%02x_%02x: 0x%08x 0x%08x",
> +				 FW_DBG_DUMP_FIXED_STR,	msg_ex_cnt, i,
> +				 rx_msg->data[i + 1], rx_msg->data[i + 2]);

[Severity: Low]
Does this loop read past the actual message payload length? If the firmware
returns an odd number of payload words, the remaining size is not even. The
loop body would execute when exactly 1 word remains but print both
rx_msg->data[i + 1] and rx_msg->data[i + 2].

> +
> +		msg_ex_cnt++;
> +	} while (keep_logging);
> +
> +	return ret;
> +}

> diff --git a/drivers/firmware/imx/se_ctrl.c b/drivers/firmware/imx/se_ctrl.c
> index 0000000000000..53091cc37e7e0 100644
> --- /dev/null
> +++ b/drivers/firmware/imx/se_ctrl.c

[ ... ]

> +static void se_if_probe_cleanup(void *plat_dev)
> +{
> +	struct platform_device *pdev = plat_dev;
> +	struct device *dev = &pdev->dev;
> +	struct se_if_priv *priv;
> +
> +	priv = dev_get_drvdata(dev);
> +	if (!priv)
> +		return;
> +
> +	if (priv->rx_chan)
> +		mbox_free_channel(priv->rx_chan);
> +	if (priv->tx_chan)
> +		mbox_free_channel(priv->tx_chan);
> +
> +	/*
> +	 * Being device managed buffer, no need to free the buffer allocated
> +	 * in se probe to store encrypted IMEM.
> +	 */
> +
> +	/*
> +	 * No need to check, if reserved memory is allocated
> +	 * before calling for its release. Or clearing the
> +	 * un-set bit.
> +	 */
> +	of_reserved_mem_device_release(dev);
> +
> +	dev_set_drvdata(dev, NULL);
> +
> +	kfree(priv);

[Severity: High]
Similarly, does this teardown path free device-managed DMA memory without
waiting for or aborting a potentially busy firmware transaction?

> +}

[ ... ]

> +static int se_resume(struct device *dev)
> +{
> +	struct se_if_priv *priv = dev_get_drvdata(dev);
> +	struct se_fw_load_info *load_fw;
> +	int ret = 0;
> +
> +	load_fw = get_load_fw_instance(priv);
> +
> +	if (load_fw->imem_mgmt) {
> +		ret = se_restore_imem_state(priv, &load_fw->imem);
> +		if (ret)
> +			dev_warn(dev, "Failure restoring IMEM state[0x%x]", ret);
> +	}
> +
> +	return 0;

[Severity: Medium]
Should this return the actual error instead of 0? se_restore_imem_state()
documents that it returns -EIO so the PM subsystem knows the enclave is
non-functional after resume, but the failure is caught here and 0 is
unconditionally returned, breaking the expected power management error
handling semantics.

> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260820-imx-se-if-v38-0-5df4a4cff736@nxp.com?part=3

  reply	other threads:[~2026-08-19 13:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19 18:45 [PATCH v38 0/7] firmware: imx: driver for NXP secure-enclave pankaj.gupta
2026-08-19 18:45 ` [PATCH v38 1/7] Documentation/firmware: add imx/se to other_interfaces pankaj.gupta
2026-08-19 13:20   ` sashiko-bot
2026-08-19 18:45 ` [PATCH v38 2/7] dt-bindings: arm: fsl: add imx-se-fw binding doc pankaj.gupta
2026-08-19 18:45 ` [PATCH v38 3/7] firmware: imx: add driver for NXP EdgeLock Enclave pankaj.gupta
2026-08-19 13:30   ` sashiko-bot [this message]
2026-08-19 18:45 ` [PATCH v38 4/7] firmware: imx: device context dedicated to priv pankaj.gupta
2026-08-19 18:46 ` [PATCH v38 5/7] firmware: imx: adds miscdev pankaj.gupta
2026-08-19 13:30   ` sashiko-bot
2026-08-19 18:46 ` [PATCH v38 6/7] arm64: dts: imx8ulp: add secure enclave node pankaj.gupta
2026-08-19 13:23   ` sashiko-bot
2026-08-19 18:46 ` [PATCH v38 7/7] arm64: dts: imx8ulp: add reserved memory for EdgeLock Enclave pankaj.gupta
2026-08-19 13:33   ` sashiko-bot

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=20260819133055.9B0481F00A3A@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.