DMA Engine development
 help / color / mirror / Atom feed
From: "Garg, Shivank" <shivankg@amd.com>
To: "Frank.li@oss.nxp.com" <Frank.li@oss.nxp.com>
Cc: "dmaengine@vger.kernel.org" <dmaengine@vger.kernel.org>,
	"vkoul@kernel.org" <vkoul@kernel.org>,
	"Frank.Li@kernel.org" <Frank.Li@kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	"logang@deltatee.com" <logang@deltatee.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Subject: Re: [PATCH v3 1/3] dmaengine: Fix device kref underflow in dma_chan_put()
Date: Tue, 18 Aug 2026 03:32:00 +0000	[thread overview]
Message-ID: <1e14d7160492b3f8de3929cfc53425c260776e3c.camel@amd.com> (raw)
In-Reply-To: <aoMYDJ3TdCIqTbEd@SMW015318>

On Mon, 2026-08-17 at 09:17 -0500, Frank Li wrote:
> [You don't often get email from frank.li@oss.nxp.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> On Sun, Aug 16, 2026 at 03:49:25PM +0000, Shivank Garg wrote:
> > [You don't often get email from shivankg@amd.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> > 
> > dma_chan_get() takes chan->device->ref only on the slow path:
> > 
> >         /* no kref on fast path */
> >         if (chan->client_count) {
> >                 __module_get(owner);
> >                 chan->client_count++;
> >                 return 0;
> >         }
> >         if (!try_module_get(owner))
> >                 return -ENODEV;
> >         ret = kref_get_unless_zero(&chan->device->ref);
> > 
> > dma_chan_put() drops the ref unconditionally, so every fast-path
> > get/put pair drops one extra device reference.
> > 
> > The bug fires when two conditions hold together: a non-private
> > provider has a persistent client holding chan->client_count > 0
> > and another client cycles dmaengine_get()/dmaengine_put().
> > When the kref hits zero, the subsequent dma_find_channel() returns
> > NULL even though the provider module is still loaded.
> > 
> > Fix this by dropping device->ref only on the last put, matching the
> > single slow-path get.
> > 
> > Fixes: 8ad342a86359 ("dmaengine: Add reference counting to dma_device struct")
> > Signed-off-by: Shivank Garg <shivankg@amd.com>
> > ---
> 
> Nit: add helper dma_device_get() to match dma_device_put() to make code
> more symmetry.

Ack.

> 
> Reviewed-by: Frank Li <Frank.Li@nxp.com>
> 
> 

Thanks for the review.

Best regards,
Shivank

  reply	other threads:[~2026-08-18  3:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-16 15:49 [PATCH v3 0/3] dmaengine: fix kref underflow and UAF in dma_chan_put() Shivank Garg
2026-08-16 15:49 ` [PATCH v3 1/3] dmaengine: Fix device kref underflow " Shivank Garg
2026-08-16 16:02   ` sashiko-bot
2026-08-16 18:14     ` Garg, Shivank
2026-08-17 14:17   ` Frank Li
2026-08-18  3:32     ` Garg, Shivank [this message]
2026-08-16 15:49 ` [PATCH v3 2/3] dmaengine: fix use-after-free in dma_chan_put() and dma_release_channel() Shivank Garg
2026-08-16 16:07   ` sashiko-bot
2026-08-16 18:05     ` Garg, Shivank
2026-08-17 14:26       ` Frank Li
2026-08-18  3:31         ` Garg, Shivank
2026-08-17 14:24   ` Frank Li
2026-08-16 15:49 ` [PATCH v3 3/3] dmaengine: wait for RCU readers before releasing dma_device Shivank Garg
2026-08-16 16:10   ` sashiko-bot
2026-08-17 14:29   ` Frank Li
2026-08-18  3:31     ` 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=1e14d7160492b3f8de3929cfc53425c260776e3c.camel@amd.com \
    --to=shivankg@amd.com \
    --cc=Frank.Li@kernel.org \
    --cc=Frank.li@oss.nxp.com \
    --cc=akpm@linux-foundation.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=logang@deltatee.com \
    --cc=stable@vger.kernel.org \
    --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