All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shivank Garg" <shivankg@amd.com>
Cc: Frank.Li@kernel.org, dmaengine@vger.kernel.org, vkoul@kernel.org
Subject: Re: [PATCH v2 1/2] dmaengine: Fix device kref underflow in dma_chan_put()
Date: Tue, 26 May 2026 12:01:14 +0000	[thread overview]
Message-ID: <20260526120115.1FD4B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260526-dmaengine-kref-fix-v2-1-3df60afac01d@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [Critical] RCU Use-After-Free during device release.
- [High] Double `list_del_rcu()` leading to list corruption and kernel crash.
--

commit c36a9f0553b166fe38c0d70bbc4a093494dada44
Author: Shivank Garg <shivankg@amd.com>

dmaengine: Fix device kref underflow in dma_chan_put()

This commit fixes a kref underflow in dma_chan_put() by ensuring that the
device reference is dropped only on the last put, matching the slow-path
get. It prevents situations where a fast-path get/put pair drops an extra
reference, leading to a zero kref and a subsequent dma_find_channel()
returning NULL.

> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 405bd2fbb4a3b..605bfa477a004 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -515,7 +515,9 @@ static void dma_chan_put(struct dma_chan *chan)
>  		chan->route_data = NULL;
>  	}
>  
> -	dma_device_put(chan->device);
> +	/* This channel is not in use anymore, drop the device ref */
> +	if (!chan->client_count)
> +		dma_device_put(chan->device);

[Severity: Critical]
This is a pre-existing issue, but does device release here allow an RCU
use-after-free regression?

In dma_issue_pending_all(), the dma_device_list is iterated using
list_for_each_entry_rcu() under rcu_read_lock().

However, when a device is released, dma_device_release() removes it from
the list with list_del_rcu() and immediately calls device->device_release()
(which in many drivers, such as plx_dma.c, directly calls kfree()).

Because there is no synchronize_rcu() or equivalent mechanism to wait
for the RCU grace period before freeing the memory, concurrent RCU
readers in dma_issue_pending_all() can access freed memory, leading to
a use-after-free.

[Severity: High]
This is a pre-existing issue, but can the module unloading sequence
lead to a double list_del_rcu() regression and list corruption?

In dmaengine_get(), if dma_chan_get(chan) returns -ENODEV (which occurs
when the driver module is unloading and try_module_get() fails), it
explicitly calls list_del_rcu(&device->global_node).

Subsequently, the module's exit routine will call
dma_async_device_unregister(), which eventually calls dma_device_put().

If the reference count drops to zero here, dma_device_release() runs and
unconditionally calls list_del_rcu(&device->global_node) again.

Calling list_del_rcu() on an already unlinked list node manipulates
LIST_POISON pointers, predictably leading to a kernel crash.

>  	module_put(dma_chan_to_owner(chan));
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260526-dmaengine-kref-fix-v2-0-3df60afac01d@amd.com?part=1

  reply	other threads:[~2026-05-26 12:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 11:19 [PATCH v2 0/2] dmaengine: fix kref underflow and UAF in dma_chan_put() Shivank Garg
2026-05-26 11:19 ` [PATCH v2 1/2] dmaengine: Fix device kref underflow " Shivank Garg
2026-05-26 12:01   ` sashiko-bot [this message]
2026-05-26 11:19 ` [PATCH v2 2/2] dmaengine: fix use-after-free in dma_chan_put() and dma_release_channel() Shivank Garg
2026-05-26 13:06   ` sashiko-bot

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=20260526120115.1FD4B1F000E9@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 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.