[PATCH] remoteproc: imx_dsp_rproc: drain the vq work before freeing the mailbox
From: Hyunjung Ko
Date: Tue Nov 10 2026 - 06:00:15 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Hyunjung Ko <hj351016@xxxxxxxxx>
---
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