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 3CCE146DFE9; Tue, 21 Jul 2026 18:59:48 +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=1784660389; cv=none; b=N++0MSLo/gyBndPHA5tD0LNHV3JowcaEH4BcQbLzb/+W4JMiCQxRFl13ptD96gSoCW7tQQcgmLEe5qbVCC0NCuEEaVbPa8sEDPAiCf/P/upniEiQVevc9qq4vEkG3q9Pe6fgWlOPPjX3i6IUbYy5Zqr+7bsG82J+JnOm7m1NHOs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784660389; c=relaxed/simple; bh=Wc9k50Uga4RHZAREmKPJaaf2/d4qBk6Wha7N9uDG61U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dwQyQU52apCPuvQeVJjzhfC4vbWW2wSU/ctj39EGWnYX8YeG0NQK4nwDIycmJjbPaEwORldwAdW/2b4RJbVk0FrVCM1GT05iS7u9KdfF9QjJZnNY3S6dMWwdTbwDOM2ToS9MGj+1mATyVkatcYMykIARgos1LSqX+HI8lUGsTj8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZXB924UJ; 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="ZXB924UJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A22C31F000E9; Tue, 21 Jul 2026 18:59:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784660388; bh=jJkryLKsPG0sR7gksQuhN1e7z0nVWcjgHkvgI/+MZoc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZXB924UJrWBhB8Kl4sIhaGmm3N3VDnNOpGe8pOGLLIMOJF9f6PDpPg4pJ8NHFyVcv 0tq3C7f3gWHGyAMcGuciCK7xXtu2/kgPwxYuiaADyTOU+W5SqKdP+GoHPljQmNdW+e SiIkr7LGl564Gwy8tnoh25PGBoykqSUuvI+UheHY= 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 7.1 0959/2077] dmaengine: Fix possible use after free Date: Tue, 21 Jul 2026 17:10:32 +0200 Message-ID: <20260721152615.439942778@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152552.646164743@linuxfoundation.org> References: <20260721152552.646164743@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 7.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 405bd2fbb4a3b9..9049171df85786 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