Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 BE26B3BF665; Mon, 23 Mar 2026 16:27:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774283249; cv=none; b=H+eguVR+vmr/NPm7f9ocKV/uX8WplVvTALBxtwR+Ue93AY8HsPXMefgZr8Md3qTXCE0Ox6AuGuYL+KThJXU8IPENBJgDZYeVRJ7sI1cp/U5328v7CKeqM0v74iOxX3LmPgUmlDioGuK6oR+LWTs2VGU96UsCY3jGjZylzJYrXTc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774283249; c=relaxed/simple; bh=trC4msAHAAMek9XcB7YHHDW+1xPXYoAVPkMvyFmPDak=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IGfwGLxnYW6viIwu/gi0whckbgTj8ZA4WnT7t3l1B7Pew9kRkwVpAQvlLeZeyLnxq2gyA1yCtQd6E95IuCZuPoIJQ4TUoIpPRD01H1Nv0stUN61R9+ad4q1wK2VyU8ZkgyKkpNMUc7lI1hMdmYv5YhiG87dRNLoQm2XXQJcyA7g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NfiHvrpw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="NfiHvrpw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00761C4CEF7; Mon, 23 Mar 2026 16:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774283249; bh=trC4msAHAAMek9XcB7YHHDW+1xPXYoAVPkMvyFmPDak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NfiHvrpw5lPGGZMS/bvayjLxpm6ASSZbZdxnGpxIpi1WYdRvnw9KZ6vAW1dtaYyVS uJKAETDWY0m7yFg+c2pPgLcGVLaCNDEbb8pa0MOuV6mwIOI//I1wLOAQGC/dKBH7sB n/6eTHhfbpkLW1QAVIsW9pVegGjOLsl6EsIdJSww= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Juan Li , Guodong Xu , Vinod Koul , Wenshan Lan Subject: [PATCH 6.1 456/481] dmaengine: mmp_pdma: Fix race condition in mmp_pdma_residue() Date: Mon, 23 Mar 2026 14:47:18 +0100 Message-ID: <20260323134536.321763681@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323134525.256603107@linuxfoundation.org> References: <20260323134525.256603107@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-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guodong Xu commit a143545855bc2c6e1330f6f57ae375ac44af00a7 upstream. Add proper locking in mmp_pdma_residue() to prevent use-after-free when accessing descriptor list and descriptor contents. The race occurs when multiple threads call tx_status() while the tasklet on another CPU is freeing completed descriptors: CPU 0 CPU 1 ----- ----- mmp_pdma_tx_status() mmp_pdma_residue() -> NO LOCK held list_for_each_entry(sw, ..) DMA interrupt dma_do_tasklet() -> spin_lock(&desc_lock) list_move(sw->node, ...) spin_unlock(&desc_lock) | dma_pool_free(sw) <- FREED! -> access sw->desc <- UAF! This issue can be reproduced when running dmatest on the same channel with multiple threads (threads_per_chan > 1). Fix by protecting the chain_running list iteration and descriptor access with the chan->desc_lock spinlock. Signed-off-by: Juan Li Signed-off-by: Guodong Xu Link: https://patch.msgid.link/20251216-mmp-pdma-race-v1-1-976a224bb622@riscstar.com Signed-off-by: Vinod Koul [ Minor context conflict resolved. ] Signed-off-by: Wenshan Lan Signed-off-by: Greg Kroah-Hartman --- drivers/dma/mmp_pdma.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/dma/mmp_pdma.c +++ b/drivers/dma/mmp_pdma.c @@ -764,6 +764,7 @@ static unsigned int mmp_pdma_residue(str { struct mmp_pdma_desc_sw *sw; u32 curr, residue = 0; + unsigned long flags; bool passed = false; bool cyclic = chan->cyclic_first != NULL; @@ -779,6 +780,8 @@ static unsigned int mmp_pdma_residue(str else curr = readl(chan->phy->base + DSADR(chan->phy->idx)); + spin_lock_irqsave(&chan->desc_lock, flags); + list_for_each_entry(sw, &chan->chain_running, node) { u32 start, end, len; @@ -822,6 +825,7 @@ static unsigned int mmp_pdma_residue(str continue; if (sw->async_tx.cookie == cookie) { + spin_unlock_irqrestore(&chan->desc_lock, flags); return residue; } else { residue = 0; @@ -829,6 +833,8 @@ static unsigned int mmp_pdma_residue(str } } + spin_unlock_irqrestore(&chan->desc_lock, flags); + /* We should only get here in case of cyclic transactions */ return residue; }