From nobody Mon Jun 8 09:51:26 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 475C838E8A0; Mon, 8 Jun 2026 07:26:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780903608; cv=none; b=eObkON6tizxuaEUfNMwS86sZhbmh7JGcppgFDyvLhs89/R8fdwBA6kSnhLJ3BH8Q4cqUTUcOGJ6d8iyMvPBs3Xfg8bRr/Xmoe7c89fgLJ7yqgJpnWjdRFuc86m8roNdR0IdIZZZ+fOi75tjfB5op41aJjDxmUjAMHQQN/5PkUZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780903608; c=relaxed/simple; bh=sasyYHIrkyOmoRJD5mIe5hmVMwYQy+2+NGpMzDqF7+Q=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=pEU7ywl8z4evPw0VDdSwK5Nxfp4yhsm2LG3TDKihD/VgUtUZBKzRIUdV0aIULl8E5/XhOsOAkwld6F/Bvqt2emqHz4KQ6HuO2EdSH5wWI2A81zty9C81xPGU6CalNGBJFSNgBLerTXOTCfPFjw3fZRs0K+csxW5l+D9C37ewbrs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 6400e162630b11f1aa26b74ffac11d73-20260608 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:232ed1fd-3542-4900-9463-20ebd1ee5d03,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:e7bac3a,CLOUDID:c254be7e7c1cbbcf9a1c8ab200c7bac6,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:102|850|865|898,TC:nil,Content:0|15|50,E DM:-3,IP:nil,URL:99|1,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0, OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULS X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 6400e162630b11f1aa26b74ffac11d73-20260608 X-User: zenghongling@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1402792144; Mon, 08 Jun 2026 15:26:39 +0800 From: Hongling Zeng To: ludovic.desroches@microchip.com, vkoul@kernel.org, Frank.Li@kernel.org, tudor.ambarus@linaro.org, nicolas.ferre@microchip.com Cc: linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, zhongling0719@126.com, Hongling Zeng , sashiko-bot@kernel.org Subject: [PATCH v3] dma: at_hdmac: Fix use-after-free by proper tasklet cleanup Date: Mon, 8 Jun 2026 15:26:35 +0800 Message-Id: <20260608072635.148011-1-zenghongling@kylinos.cn> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Current cleanup paths have a use-after-free vulnerability: - vchan_init() creates tasklets that access at_dma_chan memory - free_irq() only waits for IRQ handler, NOT tasklets - atdma is devm-managed and freed after probe/remove - Running tasklets accessing freed memory =E2=86=92 Use-After-Free! The fix requires careful ordering: - free_irq() FIRST to synchronize with running IRQ handlers and prevent them from scheduling new tasklets - Then kill tasklets to wait for already-scheduled ones to complete - Only then free other resources Fixes: ac803b56860f ("dmaengine: at_hdmac: Convert driver to use virt-dma") Reported-by: sashiko-bot@kernel.org Closes: https://lore.kernel.org/all/20260604073945.54B311F00898@smtp.kernel= .org/ Signed-off-by: Hongling Zeng --- Change in v2: - Fix NULL pointer dereference in probe error path by checking if channels = list = is initialized before cleanup - Fix race condition by calling free_irq() before tasklet_kill() to ensure IRQ handlers cannot reschedule tasklets after cleanup --- Change in v3: - Reorder probe error path to match remove() cleanup order - Keep defensive NULL check for channels cleanup - Remove unused variables in at_dma_remove() - Ensure consistent order: free_irq =E2=86=92 cleanup_channels =E2=86=92 dm= a_pool_destroy --- drivers/dma/at_hdmac.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c index e5b30a57c477..ac1ba21e3428 100644 --- a/drivers/dma/at_hdmac.c +++ b/drivers/dma/at_hdmac.c @@ -1940,6 +1940,19 @@ static void at_dma_off(struct at_dma *atdma) cpu_relax(); } =20 +static void at_dma_cleanup_channels(struct at_dma *atdma) +{ + struct dma_chan *chan, *_chan; + + list_for_each_entry_safe(chan, _chan, &atdma->dma_device.channels, + device_node) { + /* Disable interrupts */ + atc_disable_chan_irq(atdma, chan->chan_id); + tasklet_kill(&to_at_dma_chan(chan)->vc.task); + list_del(&chan->device_node); + } +} + static int __init at_dma_probe(struct platform_device *pdev) { struct at_dma *atdma; @@ -2105,11 +2118,15 @@ static int __init at_dma_probe(struct platform_devi= ce *pdev) err_of_dma_controller_register: dma_async_device_unregister(&atdma->dma_device); err_dma_async_device_register: + free_irq(platform_get_irq(pdev, 0), atdma); + at_dma_cleanup_channels(atdma); dma_pool_destroy(atdma->memset_pool); err_memset_pool_create: dma_pool_destroy(atdma->lli_pool); err_desc_pool_create: free_irq(platform_get_irq(pdev, 0), atdma); + if (atdma->dma_device.channels.next !=3D NULL) + at_dma_cleanup_channels(atdma); err_irq: clk_disable_unprepare(atdma->clk); return err; @@ -2118,23 +2135,17 @@ static int __init at_dma_probe(struct platform_devi= ce *pdev) static void at_dma_remove(struct platform_device *pdev) { struct at_dma *atdma =3D platform_get_drvdata(pdev); - struct dma_chan *chan, *_chan; =20 at_dma_off(atdma); if (pdev->dev.of_node) of_dma_controller_free(pdev->dev.of_node); dma_async_device_unregister(&atdma->dma_device); =20 - dma_pool_destroy(atdma->memset_pool); - dma_pool_destroy(atdma->lli_pool); free_irq(platform_get_irq(pdev, 0), atdma); + at_dma_cleanup_channels(atdma); =20 - list_for_each_entry_safe(chan, _chan, &atdma->dma_device.channels, - device_node) { - /* Disable interrupts */ - atc_disable_chan_irq(atdma, chan->chan_id); - list_del(&chan->device_node); - } + dma_pool_destroy(atdma->memset_pool); + dma_pool_destroy(atdma->lli_pool); =20 clk_disable_unprepare(atdma->clk); } --=20 2.25.1