From: sashiko-bot@kernel.org
To: pankaj.gupta@oss.nxp.com
Cc: robh@kernel.org, Frank.Li@kernel.org, imx@lists.linux.dev,
conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v41 3/7] firmware: imx: add driver for NXP EdgeLock Enclave
Date: Mon, 24 Aug 2026 09:13:46 +0000 [thread overview]
Message-ID: <20260824091347.26DF61F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260824-imx-se-if-v41-3-29cf129e4d86@nxp.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Devres LIFO execution causes a Use-After-Free on `priv->se_if_cmd_lock` during unbind, and a memory leak on probe failure.
--
--- Patch [3]: [PATCH v41 3/7] firmware: imx: add driver for NXP EdgeLock Enclave ---
commit 49588215c50994b46eebe37520853007e8a9a892
Author: Pankaj Gupta <pankaj.gupta@nxp.com>
firmware: imx: add driver for NXP EdgeLock Enclave
This commit adds the MU-based communication interface for the secure
enclave on i.MX SoC(s). It allows the secure enclave firmware to communicate
with Linux over dedicated messaging unit (MU) based interfaces.
> diff --git a/drivers/firmware/imx/se_ctrl.c b/drivers/firmware/imx/se_ctrl.c
> new file mode 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;
[ ... ]
> + kfree(priv);
> +}
> +
> +static int se_if_probe(struct platform_device *pdev)
> +{
> + const struct se_soc_info *se_info;
> + const struct se_if_node *if_node;
> + struct se_fw_load_info *load_fw;
> + struct device *dev = &pdev->dev;
> + struct se_if_priv *priv;
> + int ret;
> +
> + if_node = device_get_match_data(dev);
> + if (!if_node)
> + return -EINVAL;
> +
> + se_info = if_node->se_info;
> +
> + priv = kzalloc_obj(*priv, GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + priv->dev = dev;
> + priv->if_defs = &if_node->if_defs;
> + dev_set_drvdata(dev, priv);
> +
> + ret = devm_mutex_init(dev, &priv->se_if_cmd_lock);
[Severity: High]
Does this code introduce a memory leak on the probe error path?
Since priv is allocated with kzalloc_obj() (which is not devm-managed),
if devm_mutex_init() fails, the function returns immediately without
freeing priv.
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "Failed to init mutex: priv se_if_cmd_lock.\n");
> + spin_lock_init(&priv->cmd_receiver_clbk_hdl.clbk_rx_lock);
> + spin_lock_init(&priv->waiting_rsp_clbk_hdl.clbk_rx_lock);
> + atomic_set(&priv->fw_busy, 0);
> + init_completion(&priv->waiting_rsp_clbk_hdl.done);
> + init_completion(&priv->cmd_receiver_clbk_hdl.done);
> +
> + ret = devm_add_action_or_reset(dev, se_if_probe_cleanup, pdev);
[Severity: High]
Could this devres action ordering lead to a use-after-free during device
unbind?
Because devres actions execute in reverse order of their registration
(LIFO), upon device unbind se_if_probe_cleanup() runs first and frees
priv. Subsequently, the devres action for devm_mutex_init() runs and
calls mutex_destroy(&priv->se_if_cmd_lock) on the already freed priv
pointer.
> + if (ret)
> + return ret;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260824-imx-se-if-v41-0-29cf129e4d86@nxp.com?part=3
next prev parent reply other threads:[~2026-08-24 9:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 14:33 [PATCH v41 0/7] firmware: imx: driver for NXP secure-enclave pankaj.gupta
2026-08-24 14:33 ` [PATCH v41 1/7] Documentation/firmware: add imx/se to other_interfaces pankaj.gupta
2026-08-24 9:09 ` sashiko-bot
2026-08-24 14:33 ` [PATCH v41 2/7] dt-bindings: arm: fsl: add imx-se-fw binding doc pankaj.gupta
2026-08-24 14:33 ` [PATCH v41 3/7] firmware: imx: add driver for NXP EdgeLock Enclave pankaj.gupta
2026-08-24 9:13 ` sashiko-bot [this message]
2026-08-24 14:33 ` [PATCH v41 4/7] firmware: imx: device context dedicated to priv pankaj.gupta
2026-08-24 9:17 ` sashiko-bot
2026-08-24 14:33 ` [PATCH v41 5/7] firmware: imx: adds miscdev pankaj.gupta
2026-08-24 9:19 ` sashiko-bot
2026-08-24 14:33 ` [PATCH v41 6/7] arm64: dts: imx8ulp: add secure enclave node pankaj.gupta
2026-08-24 14:33 ` [PATCH v41 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=20260824091347.26DF61F00A3A@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.