From mboxrd@z Thu Jan 1 00:00:00 1970 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 7E40B35334D; Tue, 26 Aug 2025 14:28:40 +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=1756218520; cv=none; b=E6J67B9j5+eebEP8JYurMjpMoxkVH5Ww9wg8raRHNmMcgUr8Av1StT8Y6Z0J+gFo0dNkKD+C6fv8rMNH5snLrECUoxzVEanEXBEtokgr3nctP3dg60NoduOfMddEPTjtys5Tkd9A2gjeWpcc4HZf9zShzdMph4NuY8NWNlWyI0M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756218520; c=relaxed/simple; bh=EDFXYmz1n0CNZK3Ld2lyQldaxl56Zp05yzN0+7mBz24=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DQJNCo7a+2LOzzC/crqqrckPPlAclqAMo435CkQB3CEtxbSgvGDLmRwyhbqm/pXHw6ChMcnfO+JGtlJKUKEnkU3XW4iU5UP1JGFLuuDEFcWJmKLNpmAaHNXgWn1a85xjIg7rOThbx7exItf6fU90wMjBY0stkp/+pfFCD4FwJEY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YWKsvplj; 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="YWKsvplj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 118A6C4CEF1; Tue, 26 Aug 2025 14:28:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756218520; bh=EDFXYmz1n0CNZK3Ld2lyQldaxl56Zp05yzN0+7mBz24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YWKsvpljx8qKDAvE71ZYOveh/yj8SdyFFiUbiS9Sdiqq2Pn1OYs2RAUWIfG3D0PJr JNcKPgrb9lwBXl1ribKYYK3loPn+tSIZTHVWpdBy/57UPiaq2NWvfLrWpUfDrV/M4l 9jZwRBPsEJuYtXZcIbLcMQAPjXCcqhUWE9kT7KYw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dan Carpenter , Vinod Koul Subject: [PATCH 5.4 014/403] dmaengine: nbpfaxi: Fix memory corruption in probe() Date: Tue, 26 Aug 2025 13:05:40 +0200 Message-ID: <20250826110906.157031585@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250826110905.607690791@linuxfoundation.org> References: <20250826110905.607690791@linuxfoundation.org> User-Agent: quilt/0.68 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 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Carpenter commit 188c6ba1dd925849c5d94885c8bbdeb0b3dcf510 upstream. The nbpf->chan[] array is allocated earlier in the nbpf_probe() function and it has "num_channels" elements. These three loops iterate one element farther than they should and corrupt memory. The changes to the second loop are more involved. In this case, we're copying data from the irqbuf[] array into the nbpf->chan[] array. If the data in irqbuf[i] is the error IRQ then we skip it, so the iterators are not in sync. I added a check to ensure that we don't go beyond the end of the irqbuf[] array. I'm pretty sure this can't happen, but it seemed harmless to add a check. On the other hand, after the loop has ended there is a check to ensure that the "chan" iterator is where we expect it to be. In the original code we went one element beyond the end of the array so the iterator wasn't in the correct place and it would always return -EINVAL. However, now it will always be in the correct place. I deleted the check since we know the result. Cc: stable@vger.kernel.org Fixes: b45b262cefd5 ("dmaengine: add a driver for AMBA AXI NBPF DMAC IP cores") Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/b13c5225-7eff-448c-badc-a2c98e9bcaca@sabinyo.mountain Signed-off-by: Vinod Koul Signed-off-by: Greg Kroah-Hartman --- drivers/dma/nbpfaxi.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) --- a/drivers/dma/nbpfaxi.c +++ b/drivers/dma/nbpfaxi.c @@ -1349,7 +1349,7 @@ static int nbpf_probe(struct platform_de if (irqs == 1) { eirq = irqbuf[0]; - for (i = 0; i <= num_channels; i++) + for (i = 0; i < num_channels; i++) nbpf->chan[i].irq = irqbuf[0]; } else { eirq = platform_get_irq_byname(pdev, "error"); @@ -1359,16 +1359,15 @@ static int nbpf_probe(struct platform_de if (irqs == num_channels + 1) { struct nbpf_channel *chan; - for (i = 0, chan = nbpf->chan; i <= num_channels; + for (i = 0, chan = nbpf->chan; i < num_channels; i++, chan++) { /* Skip the error IRQ */ if (irqbuf[i] == eirq) i++; + if (i >= ARRAY_SIZE(irqbuf)) + return -EINVAL; chan->irq = irqbuf[i]; } - - if (chan != nbpf->chan + num_channels) - return -EINVAL; } else { /* 2 IRQs and more than one channel */ if (irqbuf[0] == eirq) @@ -1376,7 +1375,7 @@ static int nbpf_probe(struct platform_de else irq = irqbuf[0]; - for (i = 0; i <= num_channels; i++) + for (i = 0; i < num_channels; i++) nbpf->chan[i].irq = irq; } }