linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] dmaengine: imx-sdma: fix kernel hangs with SLUB slab allocator
@ 2019-09-24  9:49 Robin Gong
  2019-10-14  8:02 ` Vinod Koul
  0 siblings, 1 reply; 4+ messages in thread
From: Robin Gong @ 2019-09-24  9:49 UTC (permalink / raw)
  To: vkoul, dan.j.williams, shawnguo, s.hauer, festevam, J.Lambrecht
  Cc: kernel, dl-linux-imx, dmaengine, linux-arm-kernel, linux-kernel

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(+)

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 */
 };
 
 /**
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] dmaengine: imx-sdma: fix kernel hangs with SLUB slab allocator
  2019-09-24  9:49 [PATCH v1] dmaengine: imx-sdma: fix kernel hangs with SLUB slab allocator Robin Gong
@ 2019-10-14  8:02 ` Vinod Koul
  2019-10-14  8:05   ` Vinod Koul
  0 siblings, 1 reply; 4+ messages in thread
From: Vinod Koul @ 2019-10-14  8:02 UTC (permalink / raw)
  To: Robin Gong
  Cc: dan.j.williams, shawnguo, s.hauer, festevam,
	J.Lambrecht@TELEVIC.com, kernel, dl-linux-imx, dmaengine,
	linux-arm-kernel, linux-kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] dmaengine: imx-sdma: fix kernel hangs with SLUB slab allocator
  2019-10-14  8:02 ` Vinod Koul
@ 2019-10-14  8:05   ` Vinod Koul
  2019-10-14  8:10     ` Robin Gong
  0 siblings, 1 reply; 4+ messages in thread
From: Vinod Koul @ 2019-10-14  8:05 UTC (permalink / raw)
  To: Robin Gong
  Cc: dan.j.williams, shawnguo, s.hauer, festevam,
	J.Lambrecht@TELEVIC.com, kernel, dl-linux-imx, dmaengine,
	linux-arm-kernel, linux-kernel

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
-- 
~Vinod

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH v1] dmaengine: imx-sdma: fix kernel hangs with SLUB slab allocator
  2019-10-14  8:05   ` Vinod Koul
@ 2019-10-14  8:10     ` Robin Gong
  0 siblings, 0 replies; 4+ messages in thread
From: Robin Gong @ 2019-10-14  8:10 UTC (permalink / raw)
  To: Vinod Koul
  Cc: dan.j.williams, shawnguo, s.hauer, festevam,
	J.Lambrecht@TELEVIC.com, kernel, dl-linux-imx, dmaengine,
	linux-arm-kernel, linux-kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-14  8:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-24  9:49 [PATCH v1] dmaengine: imx-sdma: fix kernel hangs with SLUB slab allocator Robin Gong
2019-10-14  8:02 ` Vinod Koul
2019-10-14  8:05   ` Vinod Koul
2019-10-14  8:10     ` Robin Gong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).