]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
dmaengine: Fix a double free in dma_async_device_register
authorLv Yunlong <lyl2019@mail.ustc.edu.cn>
Wed, 31 Mar 2021 01:44:58 +0000 (18:44 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Apr 2021 11:13:18 +0000 (13:13 +0200)
commitb566faa2e4719fc8bd70ab0be475923213fdf635
tree8f7cee774aa579df38678ee444e91f9964fd60ee
parentd9c0069955f042815e9860cbaa8dabc9a0e06ed8
dmaengine: Fix a double free in dma_async_device_register

[ Upstream commit ea45b6008f8095db0cc09ad6e03c7785c2986197 ]

In the first list_for_each_entry() macro of dma_async_device_register,
it gets the chan from list and calls __dma_async_device_channel_register
(..,chan). We can see that chan->local is allocated by alloc_percpu() and
it is freed chan->local by free_percpu(chan->local) when
__dma_async_device_channel_register() failed.

But after __dma_async_device_channel_register() failed, the caller will
goto err_out and freed the chan->local in the second time by free_percpu().

The cause of this problem is forget to set chan->local to NULL when
chan->local was freed in __dma_async_device_channel_register(). My
patch sets chan->local to NULL when the callee failed to avoid double free.

Fixes: d2fb0a0438384 ("dmaengine: break out channel registration")
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/20210331014458.3944-1-lyl2019@mail.ustc.edu.cn
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/dma/dmaengine.c