diff mbox series

[v1] dmaengine: imx-sdma: fix kernel hangs with SLUB slab allocator

Message ID 1569347584-3478-1-git-send-email-yibin.gong@nxp.com (mailing list archive)
State Accepted
Headers show
Series [v1] dmaengine: imx-sdma: fix kernel hangs with SLUB slab allocator | expand

Commit Message

Robin Gong Sept. 24, 2019, 9:49 a.m. UTC
Illegal memory will be touch if SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3
(41) exceed the size of structure sdma_script_start_addrs(40),
thus cause memory corrupt such as slob block header so that kernel
trap into while() loop forever in slob_free(). Please refer to below
code piece in imx-sdma.c:
for (i = 0; i < sdma->script_number; i++)
	if (addr_arr[i] > 0)
		saddr_arr[i] = addr_arr[i]; /* memory corrupt here */
That issue was brought by commit a572460be9cf ("dmaengine: imx-sdma: Add
support for version 3 firmware") because SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3
(38->41 3 scripts added) not align with script number added in
sdma_script_start_addrs(2 scripts).

Fixes: a572460be9cf ("dmaengine: imx-sdma: Add support for version 3 firmware")
Cc: stable@vger.kernel
Link: https://www.spinics.net/lists/arm-kernel/msg754895.html
Signed-off-by: Robin Gong <yibin.gong@nxp.com>
Reported-by: Jurgen Lambrecht <J.Lambrecht@TELEVIC.com>
---
 drivers/dma/imx-sdma.c                     | 8 ++++++++
 include/linux/platform_data/dma-imx-sdma.h | 3 +++
 2 files changed, 11 insertions(+)

Comments

Vinod Koul Oct. 14, 2019, 8:02 a.m. UTC | #1
On 24-09-19, 09:49, Robin Gong wrote:
> Illegal memory will be touch if SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3
> (41) exceed the size of structure sdma_script_start_addrs(40),
> thus cause memory corrupt such as slob block header so that kernel
> trap into while() loop forever in slob_free(). Please refer to below
> code piece in imx-sdma.c:
> for (i = 0; i < sdma->script_number; i++)
> 	if (addr_arr[i] > 0)
> 		saddr_arr[i] = addr_arr[i]; /* memory corrupt here */
> That issue was brought by commit a572460be9cf ("dmaengine: imx-sdma: Add
> support for version 3 firmware") because SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3
> (38->41 3 scripts added) not align with script number added in
> sdma_script_start_addrs(2 scripts).

Applied, thanks
Vinod Koul Oct. 14, 2019, 8:05 a.m. UTC | #2
On 14-10-19, 13:32, Vinod Koul wrote:
> On 24-09-19, 09:49, Robin Gong wrote:
> > Illegal memory will be touch if SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3
> > (41) exceed the size of structure sdma_script_start_addrs(40),
> > thus cause memory corrupt such as slob block header so that kernel
> > trap into while() loop forever in slob_free(). Please refer to below
> > code piece in imx-sdma.c:
> > for (i = 0; i < sdma->script_number; i++)
> > 	if (addr_arr[i] > 0)
> > 		saddr_arr[i] = addr_arr[i]; /* memory corrupt here */
> > That issue was brought by commit a572460be9cf ("dmaengine: imx-sdma: Add
> > support for version 3 firmware") because SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3
> > (38->41 3 scripts added) not align with script number added in
> > sdma_script_start_addrs(2 scripts).
> 
> Applied, thanks

And after applying I noticed the patch title is not apt. The patch title
should reflect the change and not the cause or result.

So I have modified the title to: "dmaengine: imx-sdma: fix size check
for sdma script_number"

Thanks
Robin Gong Oct. 14, 2019, 8:10 a.m. UTC | #3
On 2019-10-14 Vinod Koul <vkoul@kernel.org> wrote:
> On 14-10-19, 13:32, Vinod Koul wrote:
> > On 24-09-19, 09:49, Robin Gong wrote:
> > > Illegal memory will be touch if SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3
> > > (41) exceed the size of structure sdma_script_start_addrs(40), thus
> > > cause memory corrupt such as slob block header so that kernel trap
> > > into while() loop forever in slob_free(). Please refer to below code
> > > piece in imx-sdma.c:
> > > for (i = 0; i < sdma->script_number; i++)
> > > 	if (addr_arr[i] > 0)
> > > 		saddr_arr[i] = addr_arr[i]; /* memory corrupt here */ That issue
> > > was brought by commit a572460be9cf ("dmaengine: imx-sdma: Add
> > > support for version 3 firmware") because
> > > SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3
> > > (38->41 3 scripts added) not align with script number added in
> > > sdma_script_start_addrs(2 scripts).
> >
> > Applied, thanks
> 
> And after applying I noticed the patch title is not apt. The patch title should
> reflect the change and not the cause or result.
> 
> So I have modified the title to: "dmaengine: imx-sdma: fix size check for sdma
> script_number"
Yes, You are right, thanks Vinod.
> 
> Thanks
> --
> ~Vinod
diff mbox series

Patch

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 9ba74ab..c27e206 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -1707,6 +1707,14 @@  static void sdma_add_scripts(struct sdma_engine *sdma,
 	if (!sdma->script_number)
 		sdma->script_number = SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1;
 
+	if (sdma->script_number > sizeof(struct sdma_script_start_addrs)
+				  / sizeof(s32)) {
+		dev_err(sdma->dev,
+			"SDMA script number %d not match with firmware.\n",
+			sdma->script_number);
+		return;
+	}
+
 	for (i = 0; i < sdma->script_number; i++)
 		if (addr_arr[i] > 0)
 			saddr_arr[i] = addr_arr[i];
diff --git a/include/linux/platform_data/dma-imx-sdma.h b/include/linux/platform_data/dma-imx-sdma.h
index 6eaa53c..30e676b 100644
--- a/include/linux/platform_data/dma-imx-sdma.h
+++ b/include/linux/platform_data/dma-imx-sdma.h
@@ -51,7 +51,10 @@  struct sdma_script_start_addrs {
 	/* End of v2 array */
 	s32 zcanfd_2_mcu_addr;
 	s32 zqspi_2_mcu_addr;
+	s32 mcu_2_ecspi_addr;
 	/* End of v3 array */
+	s32 mcu_2_zqspi_addr;
+	/* End of v4 array */
 };
 
 /**