All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lee Jones" <lee@kernel.org>, dmaengine@vger.kernel.org
Cc: vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH 02/10] dmaengine: ae4dma: Unregister DMA engine in ae4_pci_remove()
Date: Wed, 11 Nov 2026 22:32:32 +0000	[thread overview]
Message-ID: <sashiko-outbox-209802@kernel.org> (raw)
In-Reply-To: <20261111215349.1983909-3-lee@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dmaengine: ae4dma: slab use-after-free in ae4_pci_remove()
  teardown order
--

commit d190c73fccb945a036c5abd1d18c37ce271e68d8
Author: Lee Jones <lee@kernel.org>

dmaengine: ae4dma: Unregister DMA engine in ae4_pci_remove()

This commit exports pt_dmaengine_unregister() and calls it in
ae4_pci_remove() to unregister the DMA device and destroy its descriptor
slab cache on removal.

> diff --git a/drivers/dma/amd/ae4dma/ae4dma-pci.c b/drivers/dma/amd/ae4dma/ae4dma-pci.c
> index 8ca34d4457cc0..7f48ebc5b10c6 100644
> --- a/drivers/dma/amd/ae4dma/ae4dma-pci.c
> +++ b/drivers/dma/amd/ae4dma/ae4dma-pci.c
> @@ -132,6 +132,7 @@ static void ae4_pci_remove(struct pci_dev *pdev)
>  {
>  	struct ae4_device *ae4 = dev_get_drvdata(&pdev->dev);
>  
> +	pt_dmaengine_unregister(&ae4->pt);
>  	ae4_destroy_work(ae4);
>  	ae4_deinit(ae4);
>  }

[Severity: Medium]
Can calling pt_dmaengine_unregister() before ae4_destroy_work() cause a
use-after-free on pt->dma_desc_cache?

pt_dmaengine_unregister() calls dma_async_device_unregister() and then
immediately destroys pt->dma_desc_cache, while the per-queue delayed work
items on ae4cmd_q->pws are only stopped afterwards by ae4_destroy_work().
dma_async_device_unregister() does not drain ae4cmd_q->pws, and
pt_synchronize() only synchronizes the vchan tasklet.  If ae4_pending_work()
is still running when the device is unbound, it can free a completed
descriptor into pt->dma_desc_cache after the cache is destroyed:

CPU0                                  kworker
ae4_pci_remove()                      ae4_pending_work()
  pt_dmaengine_unregister()             cmd->pt_cmd_callback()
    dma_async_device_unregister()         pt_cmd_callback_work()
    kmem_cache_destroy(                     ...
      pt->dma_desc_cache)                   vchan_vdesc_fini()
                                              pt_do_cleanup()
                                                kmem_cache_free(
                                                  pt->dma_desc_cache, desc)
                                                  <-- use-after-free
  ae4_destroy_work()

Stopping the workqueues before pt_dmaengine_unregister(), or destroying
pt->dma_desc_cache after ae4_destroy_work(), would avoid this race.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261111215349.1983909-1-lee@kernel.org?part=2

  reply	other threads:[~2026-11-11 22:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 21:52 [PATCH 00/10] dmaengine: Fix teardown races, resource leaks, and error handling Lee Jones
2026-11-11 21:52 ` Lee Jones
2026-11-11 21:52 ` [PATCH 01/10] dmaengine: pl08x: Defer OF DMA controller registration until slave setup Lee Jones
2026-11-11 21:52 ` [PATCH 02/10] dmaengine: ae4dma: Unregister DMA engine in ae4_pci_remove() Lee Jones
2026-11-11 22:32   ` sashiko-bot [this message]
2026-11-11 21:52 ` [PATCH 03/10] dmaengine: ptdma: Unmap descriptor in pt_do_cleanup() Lee Jones
2026-11-11 21:52 ` [PATCH 04/10] dmaengine: ptdma: Remove completed descriptor under vc.lock in pt_cmd_callback_work() Lee Jones
2026-11-11 21:52 ` [PATCH 05/10] dmaengine: amlogic: Destroy free_wq after devres DMA device unregistration Lee Jones
2026-11-11 21:52   ` Lee Jones
2026-11-11 22:23   ` sashiko-bot
2026-11-11 22:23     ` sashiko-bot
2026-11-11 21:52 ` [PATCH 06/10] dmaengine: arm-dma350: Query dma_cookie_status() under vc.lock in d350_tx_status() Lee Jones
2026-11-11 21:52 ` [PATCH 07/10] dmaengine: bestcomm: Defer publishing bcom_eng until initialisation completes Lee Jones
2026-11-11 22:26   ` sashiko-bot
2026-11-11 21:52 ` [PATCH 08/10] dmaengine: bestcomm: Check rh_create() return value in bcom_sram_init() Lee Jones
2026-11-11 21:52 ` [PATCH 09/10] dmaengine: jz4780: Fix descriptor cleanup on hwdesc setup failure Lee Jones
2026-11-11 22:26   ` sashiko-bot
2026-11-11 21:52 ` [PATCH 10/10] dmaengine: dmatest: Avoid unsigned underflow in min_odd() Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-209802@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=lee@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.