[PATCH master] ARM: i.MX7: esdctl: fix out-of-bounds read on memory size calculation

Ahmad Fatoum a.fatoum at pengutronix.de
Thu May 12 22:45:25 PDT 2022

addrmap[] has 9 elements on i.MX8M platforms and 7 elements on i.MX7.
Checking unconditionally for addrmap[8] is thus out-of-bounds on the
i.MX7. As this code was added for the i.MX8, skip it for i.MX7.

Fixes: 42d45ef380c5 ("ARM: imx: Add imx8 support for SDRAM with two or more bank groups")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
 arch/arm/mach-imx/esdctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/esdctl.c b/arch/arm/mach-imx/esdctl.c
index b2f8fd0e39c6..23663406b70e 100644
--- a/arch/arm/mach-imx/esdctl.c
+++ b/arch/arm/mach-imx/esdctl.c
@@ -421,7 +421,7 @@ imx_ddrc_sdram_size(void __iomem *ddrc, const u32 addrmap[],
 	if (FIELD_GET(DDRC_ADDRMAP1_BANK_B2, addrmap[1]) != 0b11111)
-	if (addrmap[8]) {
+	if (is_imx8 && addrmap[8]) {
 		if (FIELD_GET(DDRC_ADDRMAP8_BG_B0, addrmap[8]) != 0b11111)
 		if (FIELD_GET(DDRC_ADDRMAP8_BG_B1, addrmap[8]) != 0b111111)

More information about the barebox mailing list