From: sashiko-bot@kernel.org
To: "Shivank Garg" <shivankg@amd.com>
Cc: Frank.Li@kernel.org, vkoul@kernel.org, dmaengine@vger.kernel.org
Subject: Re: [PATCH v4 4/4] dmaengine: wait for RCU readers before releasing dma_device
Date: Tue, 18 Aug 2026 03:57:48 +0000 [thread overview]
Message-ID: <20260818035748.B2FD41F01577@smtp.kernel.org> (raw)
In-Reply-To: <20260818-dmaengine-kref-fix-v4-4-c6ef991462a0@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Double list_del_rcu() on device->global_node causing list corruption or crash when a provider module is removed.
--
--- Patch [4]: [PATCH v4 4/4] dmaengine: wait for RCU readers before releasing dma_device ---
commit 82fe03be2ee5cd7002af0d140a5056712e128cb6
Author: Shivank Garg <shivankg@amd.com>
dmaengine: wait for RCU readers before releasing dma_device
This commit adds a synchronize_rcu() call to dma_device_release() before
the device is freed. This ensures concurrent RCU readers traversing the
dma_device_list finish their traversal, preventing use-after-free bugs.
Link: https://sashiko.dev/#/patchset/20260526-dmaengine-kref-fix-v2-0-3df60afac01d@amd.com
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index d075051dd187c..604c9af199369 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -429,6 +429,12 @@ static void dma_device_release(struct kref *ref)
> list_del_rcu(&device->global_node);
[Severity: High]
This is a pre-existing issue, but does this unconditional removal run the
risk of a double list_del_rcu() causing list corruption?
If a DMA provider module is being unloaded concurrently, try_module_get()
can fail in dma_chan_get(). The error paths in find_candidate() and
dmaengine_get() proactively unlink the device:
find_candidate() {
...
err = dma_chan_get(chan);
if (err) {
if (err == -ENODEV) {
...
list_del_rcu(&device->global_node);
...
}
However, they do not appear to drop the kref. Later, the module unload
process calls dma_async_device_unregister(), which puts the final kref
and triggers dma_device_release().
Since dma_device_release() unconditionally calls list_del_rcu() again on
the same node, couldn't this crash the kernel by dereferencing LIST_POISON2
during the second removal?
> dma_channel_rebalance();
>
> + /*
> + * Wait for RCU readers (e.g. dma_issue_pending_all()) that may still
> + * be traversing dma_device_list before the device is freed.
> + */
> + synchronize_rcu();
> +
> if (device->device_release)
> device->device_release(device);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260818-dmaengine-kref-fix-v4-0-c6ef991462a0@amd.com?part=4
prev parent reply other threads:[~2026-08-18 3:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 3:43 [PATCH v4 0/4] dmaengine: fix kref underflow and UAF in dma_chan_put() Shivank Garg
2026-08-18 3:43 ` [PATCH v4 1/4] dmaengine: add dma_device_get() helper Shivank Garg
2026-08-18 4:00 ` sashiko-bot
2026-08-18 3:43 ` [PATCH v4 2/4] dmaengine: Fix device kref underflow in dma_chan_put() Shivank Garg
2026-08-18 3:58 ` sashiko-bot
2026-08-18 3:43 ` [PATCH v4 3/4] dmaengine: fix use-after-free in dma_chan_put() and dma_release_channel() Shivank Garg
2026-08-18 3:57 ` sashiko-bot
2026-08-18 3:43 ` [PATCH v4 4/4] dmaengine: wait for RCU readers before releasing dma_device Shivank Garg
2026-08-18 3:57 ` sashiko-bot [this message]
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=20260818035748.B2FD41F01577@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shivankg@amd.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox