Commit fc7510d8 authored by Robin Gong's avatar Robin Gong Committed by Greg Kroah-Hartman

dmaengine: imx-sdma: fix size check for sdma script_number

[ Upstream commit bd73dfab ]

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 a572460b ("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: a572460b ("dmaengine: imx-sdma: Add support for version 3 firmware")
Cc: stable@vger.kernel
Link: https://www.spinics.net/lists/arm-kernel/msg754895.htmlSigned-off-by: default avatarRobin Gong <yibin.gong@nxp.com>
Reported-by: default avatarJurgen Lambrecht <J.Lambrecht@TELEVIC.com>
Link: https://lore.kernel.org/r/1569347584-3478-1-git-send-email-yibin.gong@nxp.com
[vkoul: update the patch title]
Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent ae599446
...@@ -1662,6 +1662,14 @@ static void sdma_add_scripts(struct sdma_engine *sdma, ...@@ -1662,6 +1662,14 @@ static void sdma_add_scripts(struct sdma_engine *sdma,
if (!sdma->script_number) if (!sdma->script_number)
sdma->script_number = SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1; 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++) for (i = 0; i < sdma->script_number; i++)
if (addr_arr[i] > 0) if (addr_arr[i] > 0)
saddr_arr[i] = addr_arr[i]; saddr_arr[i] = addr_arr[i];
......
...@@ -51,7 +51,10 @@ struct sdma_script_start_addrs { ...@@ -51,7 +51,10 @@ struct sdma_script_start_addrs {
/* End of v2 array */ /* End of v2 array */
s32 zcanfd_2_mcu_addr; s32 zcanfd_2_mcu_addr;
s32 zqspi_2_mcu_addr; s32 zqspi_2_mcu_addr;
s32 mcu_2_ecspi_addr;
/* End of v3 array */ /* End of v3 array */
s32 mcu_2_zqspi_addr;
/* End of v4 array */
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment