[PATCHv2 2/9] dmaengine: mv_xor: fix use-after-free in probe error path

From: Rosen Penev

Date: Thu Jun 11 2026 - 17:09:14 EST


mv_xor_channel_remove() does not call tasklet_kill() to cancel
mv_chan->irq_tasklet. In the probe error path (err_channel_add) the
channel structure is devm-allocated, so it is freed automatically when
the probe function returns. If an interrupt fires and schedules the
tasklet during teardown, it can execute after devres has freed mv_chan,
resulting in a use-after-free.

Fix this by masking hardware interrupts on the channel and then calling
tasklet_kill() at the start of mv_xor_channel_remove(), ensuring no
new interrupts can schedule the tasklet and any already-running
instance has completed before the rest of the channel is torn down.

Assisted-by: opencode:big-pickle
Fixes: a6b4a9d2c106 ("dma: mv_xor: split initialization/cleanup of XOR channels")
Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
---
drivers/dma/mv_xor.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
index 93a8e9f7c529..ef29e8be1db6 100644
--- a/drivers/dma/mv_xor.c
+++ b/drivers/dma/mv_xor.c
@@ -106,6 +106,14 @@ static void mv_chan_set_next_descriptor(struct mv_xor_chan *chan,
writel_relaxed(next_desc_addr, XOR_NEXT_DESC(chan));
}

+static void mv_chan_mask_interrupts(struct mv_xor_chan *chan)
+{
+ u32 val = readl_relaxed(XOR_INTR_MASK(chan));
+
+ val &= ~(XOR_INTR_MASK_VALUE << (chan->idx * 16));
+ writel_relaxed(val, XOR_INTR_MASK(chan));
+}
+
static void mv_chan_unmask_interrupts(struct mv_xor_chan *chan)
{
u32 val = readl_relaxed(XOR_INTR_MASK(chan));
@@ -1011,6 +1019,9 @@ static int mv_xor_channel_remove(struct mv_xor_chan *mv_chan)
struct dma_chan *chan, *_chan;
struct device *dev = mv_chan->dmadev.dev;

+ mv_chan_mask_interrupts(mv_chan);
+ tasklet_kill(&mv_chan->irq_tasklet);
+
dma_async_device_unregister(&mv_chan->dmadev);

dma_free_wc(dev, MV_XOR_POOL_SIZE,
--
2.54.0