]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
dmaengine: Fix possible use after free
authorNuno Sá <nuno.sa@analog.com>
Fri, 24 Apr 2026 17:40:14 +0000 (18:40 +0100)
committerVinod Koul <vkoul@kernel.org>
Mon, 8 Jun 2026 12:07:06 +0000 (17:37 +0530)
In dma_release_channel(), check chan->device->privatecnt after call
dma_chan_put(). However, dma_chan_put() call dma_device_put() which could
release the last reference of the device if the DMA provider is already
gone and hence free it.

Fixes it by moving dma_chan_put() after the check.

Fixes: 0f571515c332 ("dmaengine: Add privatecnt to revert DMA_PRIVATE property")
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/20260424-dma-dmac-handle-vunmap-v4-1-90f43412fdc0@analog.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/dmaengine.c

index 405bd2fbb4a3b94fd0bf44526f656f6a19feaad0..9049171df85786cee775552234dc2b4f4ec4d711 100644 (file)
@@ -905,11 +905,12 @@ void dma_release_channel(struct dma_chan *chan)
        mutex_lock(&dma_list_mutex);
        WARN_ONCE(chan->client_count != 1,
                  "chan reference count %d != 1\n", chan->client_count);
-       dma_chan_put(chan);
        /* drop PRIVATE cap enabled by __dma_request_channel() */
        if (--chan->device->privatecnt == 0)
                dma_cap_clear(DMA_PRIVATE, chan->device->cap_mask);
 
+       dma_chan_put(chan);
+
        if (chan->slave) {
                sysfs_remove_link(&chan->dev->device.kobj, DMA_SLAVE_NAME);
                sysfs_remove_link(&chan->slave->kobj, chan->name);