From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05CEB433BCE; Tue, 21 Jul 2026 19:35:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784662524; cv=none; b=NGaUZ6yUS5lB7w8nYwAONSzONdbjmMVut2Kzrkvl7OWzs2zEdNUPHizIp31Yn7VpqkCCko6FHN0bgEFgH/At5ObB790NMb0942Z5yLyz04qc+1R+Wnn3DOgsYhLa2lQ8ytis08K/Guouv9sc4vTQ4PbkFtzP1XB2cKGWPUvJ6/o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784662524; c=relaxed/simple; bh=fFGa58F2cJ1aOw88S0INTxJCckgZUs48G3tXLSlBpR4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MtAeCdVaK7sXS3aRq8b9o/QkuikVWQ8qxJWRTMYHNa0f7FeB8EkQaB22+TsQJqMNv7WwQv+hmxtzXl0V9NvzPp1Osthm4ozgEjC3CGC1QBjdpuVm1Y09tZKABl5ppqgBhE1g2cJBJHrmcc+o9jR04PNGIHU69Ymg1mQUYdsMDZ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bT7nid11; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="bT7nid11" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A2B41F000E9; Tue, 21 Jul 2026 19:35:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784662522; bh=Uv9R0cbpqmvhmlt3Py2dMa2hSBiyXNxM133KF0ADDdc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bT7nid11wNJRkdyVQ/1ktGAFIak39lqwjFdbRgmgwc/iY8fm88L6IJiOoiA88Hpxp VU/u/A/YI/Iae31Q6EOjfVGdrKPgpN+SMooXGQmXfDEakcL7jcB5wtvV3vA7ajE/8l Ep2OMkpUuhfGOhDcIJUiXoKE3mMII/6yDp2KLrlY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Nuno=20S=C3=A1?= , Frank Li , Vinod Koul , Sasha Levin Subject: [PATCH 6.12 0478/1276] dmaengine: Fix possible use after free Date: Tue, 21 Jul 2026 17:15:21 +0200 Message-ID: <20260721152456.800425469@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152446.065700225@linuxfoundation.org> References: <20260721152446.065700225@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nuno Sá [ Upstream commit 92f853f0645aebf1d05d333e97ab7c342ace1892 ] In dma_release_channel(), check chan->device->privatecnt after call dma_chan_put(). However, dma_chan_put() call dma_device_put() which could release the last reference of the device if the DMA provider is already gone and hence free it. Fixes it by moving dma_chan_put() after the check. Fixes: 0f571515c332 ("dmaengine: Add privatecnt to revert DMA_PRIVATE property") Signed-off-by: Nuno Sá Reviewed-by: Frank Li Link: https://patch.msgid.link/20260424-dma-dmac-handle-vunmap-v4-1-90f43412fdc0@analog.com Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/dmaengine.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index c1357d7f3dc6ca..e241b7b01233e5 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -905,11 +905,12 @@ void dma_release_channel(struct dma_chan *chan) mutex_lock(&dma_list_mutex); WARN_ONCE(chan->client_count != 1, "chan reference count %d != 1\n", chan->client_count); - dma_chan_put(chan); /* drop PRIVATE cap enabled by __dma_request_channel() */ if (--chan->device->privatecnt == 0) dma_cap_clear(DMA_PRIVATE, chan->device->cap_mask); + dma_chan_put(chan); + if (chan->slave) { sysfs_remove_link(&chan->dev->device.kobj, DMA_SLAVE_NAME); sysfs_remove_link(&chan->slave->kobj, chan->name); -- 2.53.0