DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shivank Garg" <shivankg@amd.com>
Cc: vkoul@kernel.org, Frank.Li@kernel.org, dmaengine@vger.kernel.org
Subject: Re: [PATCH] dmaengine: Fix device kref underflow in dma_chan_put()
Date: Mon, 18 May 2026 08:29:20 +0000	[thread overview]
Message-ID: <20260518082920.B9BB1C2BCB7@smtp.kernel.org> (raw)
In-Reply-To: <20260518-dmaengine-kref-fix-v1-1-4d6125048fb7@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Pre-existing Use-After-Free vulnerabilities in dma_chan_put() and dma_release_channel() due to device memory release before teardown completes.
--

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

dmaengine: Fix device kref underflow in dma_chan_put()

This commit addresses a device kref underflow by ensuring the device reference
is only dropped when the client count reaches zero, matching the slow-path get.

> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> --- 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);
>  	module_put(dma_chan_to_owner(chan));
>  }

This isn't a bug introduced by this patch, but does this sequence present
a use-after-free risk?

If dma_device_put() drops the final reference to the device (for example,
if the provider module previously unregistered the DMA device), it can
trigger the device release callback and free the dma_device and dma_chan
memory.

If that happens, module_put(dma_chan_to_owner(chan)) will dereference the
freed memory, as dma_chan_to_owner() accesses chan->device->owner.

Additionally, when dma_chan_put() is called from dma_release_channel(),
returning from this function leads to further accesses of the freed memory.
dma_release_channel() continues to access chan->device->privatecnt,
chan->device->cap_mask, chan->slave, and chan->name, which could cause a
series of use-after-free issues during teardown or hot-unplug.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260518-dmaengine-kref-fix-v1-1-4d6125048fb7@amd.com?part=1

  reply	other threads:[~2026-05-18  8:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-18  7:52 [PATCH] dmaengine: Fix device kref underflow in dma_chan_put() Shivank Garg
2026-05-18  8:29 ` sashiko-bot [this message]
2026-05-18 12:16   ` Garg, Shivank
2026-05-20  6:20   ` Garg, Shivank

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=20260518082920.B9BB1C2BCB7@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