* [PATCH] remoteproc: imx_dsp_rproc: drain the vq work before freeing the mailbox
@ 2026-11-10 10:54 Hyunjung Ko
0 siblings, 0 replies; only message in thread
From: Hyunjung Ko @ 2026-11-10 10:54 UTC (permalink / raw)
To: Bjorn Andersson, Mathieu Poirier, Shengjiu Wang
Cc: Frank Li, Sascha Hauer, Fabio Estevam, Pengutronix Kernel Team,
linux-remoteproc, imx, linux-arm-kernel, linux-kernel, stable,
Hyunjung Ko
The mailbox rx callback schedules priv->rproc_work (imx_dsp_rproc_vq_work),
whose handler takes rproc->lock and calls rproc_vq_interrupt(). The work is
never cancelled: imx_dsp_rproc_free_mbox() frees the mailbox channels (which
stops new rx callbacks) but does not drain a work the callback has already
queued.
free_irq()-like teardown of the mailbox does not wait for an already-queued
work item, so a rproc_work still pending when the rproc is torn down runs
after the rproc has been freed and dereferences freed memory (rproc->lock) --
a use-after-free.
Cancel the work in imx_dsp_rproc_free_mbox(), after the channels are freed so
it cannot be re-queued, before the rproc it dereferences is released.
Found by static analysis; not runtime-reproduced (needs an i.MX DSP with a
mailbox message racing teardown).
Fixes: ec0e5549f358 ("remoteproc: imx_dsp_rproc: Add remoteproc driver for DSP on i.MX")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
drivers/remoteproc/imx_dsp_rproc.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/remoteproc/imx_dsp_rproc.c b/drivers/remoteproc/imx_dsp_rproc.c
index 96d619d..89c72d9 100644
--- a/drivers/remoteproc/imx_dsp_rproc.c
+++ b/drivers/remoteproc/imx_dsp_rproc.c
@@ -642,6 +642,13 @@ static void imx_dsp_rproc_free_mbox(struct imx_dsp_rproc *priv)
mbox_free_channel(priv->tx_ch);
mbox_free_channel(priv->rx_ch);
mbox_free_channel(priv->rxdb_ch);
+
+ /*
+ * The mailbox rx callback schedules rproc_work; the channels are now
+ * freed, so no new work can be queued. Drain any pending work before
+ * the rproc (which the work dereferences) can be freed.
+ */
+ cancel_work_sync(&priv->rproc_work);
}
/**
--
2.43.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-10 10:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10 10:54 [PATCH] remoteproc: imx_dsp_rproc: drain the vq work before freeing the mailbox Hyunjung Ko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®