From: sashiko-bot@kernel.org
To: pankaj.gupta@oss.nxp.com
Cc: robh@kernel.org, imx@lists.linux.dev, devicetree@vger.kernel.org,
Frank.Li@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v29 4/7] firmware: imx: device context dedicated to priv
Date: Tue, 21 Jul 2026 10:51:14 +0000 [thread overview]
Message-ID: <20260721105115.3782A1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260721-imx-se-if-v29-4-04a362f4fcca@nxp.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [High] Accessing `se_clbk_hdl->dev_ctx->devname` outside `clbk_rx_lock` in the `cmd_tag` path leads to Use-After-Free or NULL pointer dereference.
Pre-existing issues:
- [High] Incorrect devm registration order causes `priv` to be freed while the RX mailbox channel is still active, leading to a NULL pointer dereference.
- [High] Memory leak of `priv` when early probe steps fail.
- [High] Unprotected read of `rx_msg_sz` creates a TOCTOU race that leads to response truncation on late interrupts.
--
--- Patch [4]: [PATCH v29 4/7] firmware: imx: device context dedicated to priv ---
commit de35bce80e0d23de288afde843dd6a5a471535dd
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. No functionality change.
Closes: https://sashiko.dev/#/patchset/20260717-imx-se-if-v28-0-0a9659c7e69d@nxp.com?part=4
> diff --git a/drivers/firmware/imx/ele_common.c b/drivers/firmware/imx/ele_common.c
> index e9405a82c54d9..a350e83a274a1 100644
> --- a/drivers/firmware/imx/ele_common.c
> +++ b/drivers/firmware/imx/ele_common.c
[ ... ]
> @@ -274,12 +283,13 @@ void se_if_rx_callback(struct mbox_client *mbox_cl, void *msg)
> spin_unlock_irqrestore(&se_clbk_hdl->clbk_rx_lock, flags);
> if (sz_mismatch)
> dev_err(dev,
> - "CMD-RCVER NVM: hdr(0x%x) with different sz(%d != %d).\n",
> - *(u32 *)header,
> + "%s: CMD-RCVER NVM: hdr(0x%x) with different sz(%d != %d).\n",
> + se_clbk_hdl->dev_ctx->devname, *(u32 *)header,
[Severity: High]
Is it possible for dev_ctx to be modified concurrently?
The patch correctly introduced a local devname variable to safely read under
clbk_rx_lock for the rsp_tag path below, but in this cmd_tag path,
se_clbk_hdl->dev_ctx->devname is accessed outside the lock.
Could this lead to a use-after-free or NULL pointer dereference if the command
receiver context is destroyed concurrently?
> (header->size << 2), rx_msg_sz);
> } else if (header->tag == priv->if_defs->rsp_tag) {
> bool exception_for_sz_mismatch = check_hdr_exception_for_sz(priv, header);
> u32 exp_rx_msg_sz = 0;
> + const char *devname = NULL;
>
[Severity: High]
This is a pre-existing issue, but does reading rx_msg_sz outside the lock
create a TOCTOU race?
If a late or spurious mailbox interrupt occurs from a previously timed-out
command, the IRQ handler could read a stale rx_msg_sz (reset to 0 during
cleanup):
se_clbk_hdl = &priv->waiting_rsp_clbk_hdl;
exp_rx_msg_sz = se_clbk_hdl->rx_msg_sz;
spin_lock_irqsave(&se_clbk_hdl->clbk_rx_lock, flags);
After acquiring the lock, it might see the newly populated rx_msg from a new
sender, but copy 0 bytes and spuriously complete the new command. Should the
size be read under the lock?
> /*
> * waiting_rsp_clbk_hdl.rx_msg is owned by the synchronous sender in
[ ... ]
> diff --git a/drivers/firmware/imx/se_ctrl.c b/drivers/firmware/imx/se_ctrl.c
> index 06068c4db8c1d..cd4d27dd98ce1 100644
> --- a/drivers/firmware/imx/se_ctrl.c
> +++ b/drivers/firmware/imx/se_ctrl.c
[ ... ]
> @@ -382,6 +418,12 @@ static int se_if_probe(struct platform_device *pdev)
> load_fw->is_fw_tobe_loaded = true;
> }
>
[Severity: High]
This is a pre-existing issue, but could the devm registration order lead to a
NULL pointer dereference?
In se_if_probe(), the mailbox channels are requested before the cleanup routine
is registered:
ret = se_if_request_channel(dev, &priv->rx_chan, &priv->se_mb_cl, MBOX_RX_NAME);
if (ret)
return ret;
ret = devm_add_action_or_reset(dev, se_if_probe_cleanup, pdev);
Because devres cleans up in LIFO order, se_if_probe_cleanup() will free priv
and clear drvdata while the RX mailbox channel is still active. If an interrupt
arrives in this window, se_if_rx_callback() will retrieve a NULL priv:
priv = dev_get_drvdata(dev);
...
if (header->tag == priv->if_defs->cmd_tag) {
Should the devm action be registered before the mailbox channels are requested?
[Severity: High]
This is a pre-existing issue, but does this function leak the priv structure on
early error paths?
In se_if_probe(), priv is allocated manually using kzalloc_obj(). If the early
calls to se_if_request_channel() fail, the function returns early:
ret = se_if_request_channel(dev, &priv->tx_chan, &priv->se_mb_cl, MBOX_TX_NAME);
if (ret)
return ret;
Since devm_add_action_or_reset() hasn't been called yet, the devres stack will
not execute the cleanup function, leaking priv. Should priv be freed explicitly
on these early error paths?
> + 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);
> +
> /* By default, there is no pending FW to be loaded.*/
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260721-imx-se-if-v29-0-04a362f4fcca@nxp.com?part=4
next prev parent reply other threads:[~2026-07-21 10:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 11:23 [PATCH v29 0/7] firmware: imx: driver for NXP secure-enclave pankaj.gupta
2026-07-21 11:23 ` [PATCH v29 1/7] Documentation/firmware: add imx/se to other_interfaces pankaj.gupta
2026-07-21 10:37 ` sashiko-bot
2026-07-21 11:23 ` [PATCH v29 2/7] dt-bindings: arm: fsl: add imx-se-fw binding doc pankaj.gupta
2026-07-21 11:23 ` [PATCH v29 3/7] firmware: imx: add driver for NXP EdgeLock Enclave pankaj.gupta
2026-07-21 10:49 ` sashiko-bot
2026-07-21 10:50 ` Frieder Schrempf
2026-07-22 14:32 ` Frieder Schrempf
2026-07-21 11:23 ` [PATCH v29 4/7] firmware: imx: device context dedicated to priv pankaj.gupta
2026-07-21 10:51 ` sashiko-bot [this message]
2026-07-21 11:23 ` [PATCH v29 5/7] firmware: drivers: imx: adds miscdev pankaj.gupta
2026-07-21 10:54 ` sashiko-bot
2026-07-21 11:23 ` [PATCH v29 6/7] arm64: dts: imx8ulp: add secure enclave node pankaj.gupta
2026-07-21 10:57 ` sashiko-bot
2026-07-21 11:23 ` [PATCH v29 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=20260721105115.3782A1F00A3A@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