Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.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 1FB3B1F4C8E for ; Sat, 28 Feb 2026 07:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772264549; cv=none; b=M6P4PYqgjfKX7amAyjtsHZ/Tf76j7Aowa2+mQVwi9oTdcrUNNhxf1a0+XXUavhvhva2z41mrJ0YHlAbd0khMsVEAU8CDbAJOQuaHVSMd8fJ5jkctLhKGGzklzSGkEikeHPl1xKsuPZkxNg761wy5/AjGIlZKBaeI1Y9NVLmgeWQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772264549; c=relaxed/simple; bh=O1JIJ5TLr8X8o5UM9BrhQ5IHcjFyRnZISIxUiBUJh7I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=l/Iu8le523kLTq/lh26ngnUapOsv3seHZmFiAWR3FktfucTJDAWrjmaMOeoHBTDaOR8Itlhu0thW30FGuSMnNPqR8Mmt18Qh6WoON2NeZQMW0f7psel3q8Npm/wq9FgpULFqFsqtrorvn5xWiYT9vAlkFQR6egvRT7eppkjrNKs= 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=ZX7Id8R8; arc=none smtp.client-ip=220.197.31.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="ZX7Id8R8" 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=p/ eT+uZOJQdYjjP3J+her2AkjAGjIGImfYJ08AOvI/c=; b=ZX7Id8R8jdm6KmA/kh 0iaZ74D5GyHuU7Dni5DqVQQV7uvZTmzLUbybXR6w3Wh9razhMaK8G7m1Ihm9L454 3oWaSqvnQ9HXBp9sCi7JZ/T8z2cbI+2j7FqNEZwcvyX8MialpnU29Dmw8MeTMjy3 WrsxVsW+Brg2Rm81EFOakhBsM= Received: from China-163-team (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wBnur9NnKJpWVKhNw--.27515S2; Sat, 28 Feb 2026 15:42:06 +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.1.y v2] dmaengine: mmp_pdma: Fix race condition in mmp_pdma_residue() Date: Sat, 28 Feb 2026 15:41:56 +0800 Message-ID: <20260228074156.4461-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:_____wBnur9NnKJpWVKhNw--.27515S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxZFWfZw47WF4Dtr1kurWUCFg_yoW5Jw1xpF W5G3W5trWqqr40vFsrG3W8Zr15XFs0grWUurWjgwn7Z345Jr1YvFn7CayavFWDJryUZ3Z8 AF43Jw1rC3yDGrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pic4S5UUUUU= X-CM-SenderInfo: xmhwztjqz6il2tof0z/xtbC6w89BmminE-XmgAA3K 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 --- v1->v2: cc the related persons. --- 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 e8d71b35593e..bac4905c47db 100644 --- a/drivers/dma/mmp_pdma.c +++ b/drivers/dma/mmp_pdma.c @@ -764,6 +764,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; @@ -779,6 +780,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; @@ -822,6 +825,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; @@ -829,6 +833,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