From: sashiko-bot@kernel.org
To: pankaj.gupta@oss.nxp.com
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org,
imx@lists.linux.dev, Frank.Li@kernel.org, robh@kernel.org
Subject: Re: [PATCH v47 5/7] firmware: imx: adds miscdev
Date: Fri, 04 Sep 2026 06:41:15 +0000 [thread overview]
Message-ID: <20260904064116.064291F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260904-imx-se-if-v47-5-b474ec6fc52a@nxp.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Calling `of_reserved_mem_device_release` in `se_if_priv_release` causes DMA configuration corruption on driver rebind.
- [High] Use-after-free of `priv_dev_ctx` and its `fops_lock` because `se_if_priv_release` frees the context before cancelling `fw_busy_work`.
- [High] Worker thread deadlocks in `cancel_work_sync()` when dropping the last reference to `priv` from `fw_busy_work`.
--
commit bc99ed23fb598115b62de87b975cb028e61b4bab
Author: Pankaj Gupta <pankaj.gupta@nxp.com>
firmware: imx: adds miscdev
This commit adds the driver for communication with the secure-enclave,
enabling message exchange from user-space applications via a character
driver. It includes various checks on incoming message headers to block
invalid commands.
> diff --git a/drivers/firmware/imx/se_ctrl.c b/drivers/firmware/imx/se_ctrl.c
> --- a/drivers/firmware/imx/se_ctrl.c
> +++ b/drivers/firmware/imx/se_ctrl.c
[ ... ]
> +static void se_if_priv_release(struct kref *kref)
> +{
> + struct se_if_priv *priv = container_of(kref, struct se_if_priv, refcount);
> +
> + /* Free priv_dev_ctx if it exists */
> + if (priv->priv_dev_ctx) {
[ ... ]
> + kfree(priv->priv_dev_ctx->devname);
> + kfree(priv->priv_dev_ctx);
> + priv->priv_dev_ctx = NULL;
> + }
> + /*
> + * 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(priv->dev);
[Severity: High]
Is it safe to release the DMA configuration from the shared platform device
here?
If an unprivileged userspace process keeps the device file descriptor open,
it holds a reference to the priv object. If the device is unbound and then
rebound via sysfs, the new driver instance will initialize its DMA memory
region via of_reserved_mem_device_init().
When the userspace process eventually closes the old file descriptor, this
se_if_priv_release() function in drivers/firmware/imx/se_ctrl.c will execute.
Since priv->dev still points to the shared underlying struct device singleton,
calling of_reserved_mem_device_release() would drop the active DMA
configuration out from under the newly bound, active driver.
Could this lead to DMA allocation failures or memory corruption for the
active instance?
[ ... ]
> + cancel_work_sync(&priv->fw_busy_work);
[Severity: High]
Does this cancellation sequence introduce a use-after-free and a deadlock?
If an internal command times out on priv_dev_ctx, it is marked busy and
fw_busy_work begins executing se_clear_fw_busy() on a worker thread. If the
device concurrently unbinds, se_if_probe_cleanup() drops the initial priv
refcount.
If no other file descriptors are open, se_if_priv_release() in
drivers/firmware/imx/se_ctrl.c runs and frees priv->priv_dev_ctx directly via
kfree() earlier in this function before calling cancel_work_sync() here. The
still-running worker thread will then try to acquire dev_ctx->fops_lock in
se_clear_fw_busy(), which was just freed, causing a use-after-free.
Additionally, if a userspace context times out and its file descriptor is
closed concurrently with device unbind, se_clear_fw_busy() drops the last
reference to dev_ctx. This invokes se_if_dev_ctx_release(), which drops the
last reference to priv, invoking se_if_priv_release() inline from the worker
thread. When it reaches cancel_work_sync() here, the worker thread will
synchronously wait for its own completion.
Could this structurally guaranteed deadlock be avoided by canceling the work
earlier, or by structuring the refcounts to prevent the worker thread from
triggering the final release?
> +
> + /* Free any remaining resources that weren't devm-managed */
> + kfree(priv);
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904-imx-se-if-v47-0-b474ec6fc52a@nxp.com?part=5
next prev parent reply other threads:[~2026-09-04 6:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 11:55 [PATCH v47 0/7] firmware: imx: driver for NXP secure-enclave pankaj.gupta
2026-09-04 11:55 ` [PATCH v47 1/7] Documentation/firmware: add imx/se to other_interfaces pankaj.gupta
2026-09-04 11:56 ` [PATCH v47 2/7] dt-bindings: arm: fsl: add imx-se-fw binding doc pankaj.gupta
2026-09-04 6:37 ` sashiko-bot
2026-09-04 11:56 ` [PATCH v47 3/7] firmware: imx: add driver for NXP EdgeLock Enclave pankaj.gupta
2026-09-04 6:38 ` sashiko-bot
2026-09-04 11:56 ` [PATCH v47 4/7] firmware: imx: device context dedicated to priv pankaj.gupta
2026-09-04 11:56 ` [PATCH v47 5/7] firmware: imx: adds miscdev pankaj.gupta
2026-09-04 6:41 ` sashiko-bot [this message]
2026-09-04 8:52 ` Pankaj Gupta (OSS)
2026-09-04 8:56 ` Pankaj Gupta (OSS)
2026-09-04 11:56 ` [PATCH v47 6/7] arm64: dts: imx8ulp: add secure enclave node pankaj.gupta
2026-09-04 11:56 ` [PATCH v47 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=20260904064116.064291F00A3D@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.