Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: pankaj.gupta@oss.nxp.com
Cc: imx@lists.linux.dev, conor+dt@kernel.org, Frank.Li@kernel.org,
	robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v32 3/7] firmware: imx: add driver for NXP EdgeLock Enclave
Date: Thu, 30 Jul 2026 02:27:05 +0000	[thread overview]
Message-ID: <20260730022706.41AE91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260730-imx-se-if-v32-3-95f56dff4ba9@nxp.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Freeing the DMA buffer on timeout in `ele_get_info` allows the firmware to corrupt memory if it completes the transaction late.
- [High] A time-of-check to time-of-use (TOCTOU) race on the volatile `jiffies` variable can cause an arithmetic underflow, leading to an infinite wait.
--

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

firmware: imx: add driver for NXP EdgeLock Enclave

Add MU-based communication interface for secure enclave. NXP hardware
IP(s) for secure-enclaves like Edgelock Enclave(ELE), are embedded in the
SoC to support features like HSM, SHE & V2X using message based
communication interface.

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

[ ... ]

> @@ -65,15 +65,15 @@ int ele_get_info(struct se_if_priv *priv, struct ele_dev_info *s_info)
>  	se_fill_cmd_msg_hdr(priv, (struct se_msg_hdr *)&tx_msg->header,
>  			    ELE_GET_INFO_REQ, ELE_GET_INFO_REQ_MSG_SZ, true);
>  
>  	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);
>  	if (ret < 0) {
>  		ele_get_info_cleanup(priv, get_info_data, get_info_addr, get_info_len);
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[Severity: High]
If the transaction times out and ele_msg_send_rcv() returns -ETIMEDOUT, does
freeing the DMA buffer here risk memory corruption?

The commit message mentions that "DMA free on timeout: -ETIMEDOUT means FW is
fenced by fw_busy, so the free is safe", but while fw_busy prevents the host
from sending new commands, it does not stop the firmware from finishing the
current command late and writing to the DMA address.

If the buffer is freed and reallocated elsewhere, a late DMA write could
silently corrupt memory.

>  		return ret;
>  	}
>  
>  	ret = se_val_rsp_hdr_n_status(priv, rx_msg, ELE_GET_INFO_REQ,
>  				      ELE_GET_INFO_RSP_MSG_SZ, true);

[ ... ]

> diff --git a/drivers/firmware/imx/ele_common.c b/drivers/firmware/imx/ele_common.c
> index 0000000000000..f40eb4a07982d 100644
> --- a/drivers/firmware/imx/ele_common.c
> +++ b/drivers/firmware/imx/ele_common.c

[ ... ]

> @@ -61,16 +61,16 @@ int ele_msg_rcv(struct se_if_priv *priv, struct se_clbk_handle *se_clbk_hdl)
>  
>  	do {
>  		if (is_rsp_wait_with_timeout) {
>  			if (time_after_eq(jiffies, deadline_jiffies)) {
>  				/* Deadline hit: fence hung FW, like the ret==0 path. */
>  				spin_lock_irqsave(&se_clbk_hdl->clbk_rx_lock, flags);
>  				se_clbk_hdl->rx_msg = NULL;
>  				if (!completion_done(&se_clbk_hdl->done))
>  					atomic_set(&priv->fw_busy, 1);
>  				spin_unlock_irqrestore(&se_clbk_hdl->clbk_rx_lock, flags);
>  				ret = -ETIMEDOUT;
>  				break;
>  			}
>  			remaining_jiffies = deadline_jiffies - jiffies;
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^

[Severity: High]
Since jiffies is volatile, the compiler will read it again here after the
time_after_eq() check. If a timer tick increments jiffies exactly between these
two reads, could this subtraction underflow?

An underflow would result in a massive timeout value near ULONG_MAX being
passed to the completion wait functions below, hanging the thread indefinitely.

>  		}
>  
>  		if (wait_uninterruptible)
>  			ret = wait_for_completion_timeout(&se_clbk_hdl->done,
>  							  remaining_jiffies);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260730-imx-se-if-v32-0-95f56dff4ba9@nxp.com?part=3

  reply	other threads:[~2026-07-30  2:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30  3:06 [PATCH v32 0/7] firmware: imx: driver for NXP secure-enclave pankaj.gupta
2026-07-30  3:06 ` [PATCH v32 1/7] Documentation/firmware: add imx/se to other_interfaces pankaj.gupta
2026-07-30  2:21   ` sashiko-bot
2026-07-30  3:06 ` [PATCH v32 2/7] dt-bindings: arm: fsl: add imx-se-fw binding doc pankaj.gupta
2026-07-30  3:06 ` [PATCH v32 3/7] firmware: imx: add driver for NXP EdgeLock Enclave pankaj.gupta
2026-07-30  2:27   ` sashiko-bot [this message]
2026-07-30  3:06 ` [PATCH v32 4/7] firmware: imx: device context dedicated to priv pankaj.gupta
2026-07-30  3:06 ` [PATCH v32 5/7] firmware: imx: adds miscdev pankaj.gupta
2026-07-30  2:31   ` sashiko-bot
2026-07-30  3:06 ` [PATCH v32 6/7] arm64: dts: imx8ulp: add secure enclave node pankaj.gupta
2026-07-30  2:45   ` sashiko-bot
2026-07-30  3:06 ` [PATCH v32 7/7] arm64: dts: imx8ulp: add reserved memory for EdgeLock Enclave 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=20260730022706.41AE91F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox