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 26CF146EC62; Tue, 21 Jul 2026 18:05:55 +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=1784657156; cv=none; b=lr3V/RmEiSI50Af5VpSeC16QLooW/EWxNfNn8/WK5Pckfa8coah03Akeq4CG+QSbMjq038qSTJpUp03c3noI7o4xQDR31BfzpNozSRIXq/C+3T0w1hx0qC/nSfBNh+QF7U+lpgHcVzBgIB3G1pOf6CZaLvcPbsQwoNRshxyWZVQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784657156; c=relaxed/simple; bh=yTBiu2XZfWahvp+r8JorhRUYl9RRTN3KZfyD+MZGihg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kDsp5LRI67/kvE42erCpDrQu4QL6qR0b3ufe936gX5NmIUB4WXSJ2U4kiKreNppncDoFPw1SyomyohtfFupgKbIVwwwN5XpMRv/uOUCjJpzJJMl77Yv/DDoB+qdNQtmBj+thtxOd7zGNYvWqZvq6zSVLyJOEQ25emMTdWxrQ8IM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=HG56n6UY; 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="HG56n6UY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8350A1F000E9; Tue, 21 Jul 2026 18:05:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784657155; bh=ue/cecRO9v0PUl00YEq1ggxtOBYB/8ZQS4tqC9Z5FJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HG56n6UY+cq1WE70STbtMr5xi9KAFQkl+Ps3LYIDR/ElAGjfBuLuptW8W/lKtgWgY uSDwIMWubnk1cFwP6CYsyRcAyDjcclp6gbdTydN+Uk7wl09+xYdAJjxrlBXPf0r7+t BwExqevYayzFT+4KR0gKpGbc6J9ZFU8f71vkzBLM= 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.18 0659/1611] dmaengine: Fix possible use after free Date: Tue, 21 Jul 2026 17:12:55 +0200 Message-ID: <20260721152530.208589763@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152514.750365251@linuxfoundation.org> References: <20260721152514.750365251@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.18-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 ca13cd39330ba4..e6d9d338a60a89 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