Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (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 5520520C463 for ; Sat, 28 Feb 2026 03:03:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772247806; cv=none; b=KME6lAv7axVo+bkyKHb4jzgHvELCL7lf+qwc66UGhjJ6mmA53FuwZuwgMgy3ESNnE4bclRo2CobhjBvDei5c/8gFuidwgkGpSUly0n1+QR38rL2jn/FUEJQqzSgt/tlnynxl2qbpL7JoJ8xr0rpCoCLW3yMztHEdoS10yjopo8A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772247806; c=relaxed/simple; bh=TIQWMik3HXq5YfMRn1WyJkl3HP3GPeRjmrgGfyBJexY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=eEreQAgmYS4Rb2e+pMSnwYlTNgKb4h4QtR2hccHCYfcnsLLVnrOlv7cslVVffWb1rkYIhIzo2DxSCVhjhMHfYt/g9HfhR1ZIycoV6xc+bXznxu1o++1CrBqawCZ3EJp+Y7LHMuzNFQYcLLlmQyJff3/Z51Gtw3Y+nmVmXo3IzAU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=Ig48obCr; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="Ig48obCr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=cB mEGsm1wuXlR/n9xy+cQE4QTQq1MBXs7rJXjFGIyYU=; b=Ig48obCrQUpHRKvNuN gyUneLgZ4+5sy1ytZqieSn8TZKMsQGcffMgjquY33j3SAhrKB2LCQukcFlw/s1jS EjuJrM44oDzQllfrKTdRdMHg/USo3gOFawAI6nhPEwQoIqLmkeMsphws2ZtPCNEh 0g2V8e/czamsNy4IfRUiS0Ca8= Received: from ubuntu24.corp.ad.wrs.com (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wAnyO7fWqJpnK0DNQ--.16668S2; Sat, 28 Feb 2026 11:02:57 +0800 (CST) From: Wenshan Lan To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Guodong Xu , Juan Li , Vinod Koul , Wenshan Lan Subject: [PATCH 6.12.y] dmaengine: mmp_pdma: Fix race condition in mmp_pdma_residue() Date: Sat, 28 Feb 2026 11:02:47 +0800 Message-ID: <20260228030247.4178-1-jetlan9@163.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wAnyO7fWqJpnK0DNQ--.16668S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7CFWUuw4kGF15Zw4rXFyDAwb_yoW5JF4xpF W5Ga45KrWqqr40vFsrC3W8Zr15Xrs0grW5urWjgws7Z345Xr1YvF1xCay2vFWDJry3ZFn8 AF43Jw1rC3yDGr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piFfOrUUUUU= X-CM-SenderInfo: xmhwztjqz6il2tof0z/xtbCxALRmmmiWuLNugAA3J From: Guodong Xu [ Upstream commit a143545855bc2c6e1330f6f57ae375ac44af00a7 ] 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 --- drivers/dma/mmp_pdma.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/dma/mmp_pdma.c b/drivers/dma/mmp_pdma.c index 136fcaeff8dd..852e6714d9f2 100644 --- a/drivers/dma/mmp_pdma.c +++ b/drivers/dma/mmp_pdma.c @@ -763,6 +763,7 @@ static unsigned int mmp_pdma_residue(struct mmp_pdma_chan *chan, { struct mmp_pdma_desc_sw *sw; u32 curr, residue = 0; + unsigned long flags; bool passed = false; bool cyclic = chan->cyclic_first != NULL; @@ -778,6 +779,8 @@ static unsigned int mmp_pdma_residue(struct mmp_pdma_chan *chan, 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; @@ -821,6 +824,7 @@ static unsigned int mmp_pdma_residue(struct mmp_pdma_chan *chan, continue; if (sw->async_tx.cookie == cookie) { + spin_unlock_irqrestore(&chan->desc_lock, flags); return residue; } else { residue = 0; @@ -828,6 +832,8 @@ static unsigned int mmp_pdma_residue(struct mmp_pdma_chan *chan, } } + spin_unlock_irqrestore(&chan->desc_lock, flags); + /* We should only get here in case of cyclic transactions */ return residue; } -- 2.43.0