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 574AE3B9608; Tue, 21 Jul 2026 21:28:44 +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=1784669330; cv=none; b=bpsxMeA+y6IdDz2QuOSKnKt4pAY2zt5Wls+qw8e2nUsQCh4BQi6jQt5/fmS+Zs1u0VQO+ySi6/YQpzzdCsiDyGUmoUBh1hEUIpEzLXWzZbEfeh44b7juLmjewpIjX7bfHB31lv1rzfWD50EMDqJr3LQzbjzysBhNymZ0PB2rLZ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784669330; c=relaxed/simple; bh=OywCkt72aL8El7AlsS0K8pS0nF9Yq/qf4hYrivDN0/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=auKTiVMwZu3kVlY28l+CkHq4E+mYPWWy7ihw/259lPO3mMzAwXMiHSfmp92/MNlqLAqX/XODHtfNiidsmH1yRJKVohuYiH9wTNPoOJbXYeO7dSwJVmGMRI8peMQCUZbW2SY02oy14cuefQF3NpF5jTk7usF7/e38NpBOCN/4IHM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1T1dRF7q; 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="1T1dRF7q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F8C01F000E9; Tue, 21 Jul 2026 21:28:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784669324; bh=Kx4DwEYlCahrN1y+Z78dJ0QDT/SC3U8hJaUBDuzr3Q0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1T1dRF7qBBoDROlAcO/SBnfjg/1Dp2wpNWz0B+oGhJw2PSlaZT9TAdd7Xotpt9o3D 9osbvO8+KZ4whcKbqFTDQyc7ZrF5jwkwZwlTCG/PvVAZXBfkzMYVI9idUyEC5UZhH6 LX0fN9SKMh50nXe1W0oEm+oRv4svHxYyLogkPovg= 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.1 0510/1067] dmaengine: Fix possible use after free Date: Tue, 21 Jul 2026 17:18:31 +0200 Message-ID: <20260721152436.024108674@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152424.521567757@linuxfoundation.org> References: <20260721152424.521567757@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.1-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 892e8389232e7f..d89827d0927e40 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