Skip to contentSkip to conversation

stm32mp: fix array bounds checks

PATCH In review Patrice Chotard 2 participants 3 messages Feb 10 – Feb 24

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 stm32mp: fix array bounds checks

Fix index check against array size. If that index is equal to the array size, we'll access one-past-the-end of the array.

---
 arch/arm/mach-stm32mp/stm32mp2/cpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-stm32mp/stm32mp2/cpu.c +2 -2
index e081dc605b8..a8a6bcf8ab4 100644
@@ -148,7 +148,7 @@ static void setup_boot_mode(void)
 		  __func__, boot_ctx, boot_mode, instance, forced_mode);
 	switch (boot_mode & TAMP_BOOT_DEVICE_MASK) {
 	case BOOT_SERIAL_UART:
-		if (instance > ARRAY_SIZE(serial_addr))
+		if (instance >= ARRAY_SIZE(serial_addr))
 			break;
 		/* serial : search associated node in devicetree */
 		sprintf(cmd, "serial@%x", serial_addr[instance]);
@@ -178,7 +178,7 @@ static void setup_boot_mode(void)
 		break;
 	case BOOT_FLASH_SD:
 	case BOOT_FLASH_EMMC:
-		if (instance > ARRAY_SIZE(sdmmc_addr))
+		if (instance >= ARRAY_SIZE(sdmmc_addr))
 			break;
 		/* search associated sdmmc node in devicetree */
 		sprintf(cmd, "mmc@%x", sdmmc_addr[instance]);

---
base-commit: b99da05e1538b8fa153322da82917af2aa27e1d6
change-id: 20260210-upstream_stm32mp2_cpu_fix-bbbd24ba4f99

Best regards,

Signature · 1 line
Patrice Chotard <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 35 lines · Patrice Chotard

Fix index check against array size. If that index is equal to the array size, we'll access one-past-the-end of the array.

---
  arch/arm/mach-stm32mp/stm32mp2/cpu.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-stm32mp/stm32mp2/cpu.c +2 -3
index e081dc605b8..a8a6bcf8ab4 100644
@@ -148,7 +148,7 @@ static void setup_boot_mode(void)
  		  __func__, boot_ctx, boot_mode, instance, forced_mode);
  	switch (boot_mode & TAMP_BOOT_DEVICE_MASK) {
  	case BOOT_SERIAL_UART:
-		if (instance > ARRAY_SIZE(serial_addr))
+		if (instance >= ARRAY_SIZE(serial_addr))
  			break;
  		/* serial : search associated node in devicetree */
  		sprintf(cmd, "serial@%x", serial_addr[instance]);
@@ -178,7 +178,7 @@ static void setup_boot_mode(void)
  		break;
  	case BOOT_FLASH_SD:
  	case BOOT_FLASH_EMMC:
-		if (instance > ARRAY_SIZE(sdmmc_addr))
+		if (instance >= ARRAY_SIZE(sdmmc_addr))
  			break;
  		/* search associated sdmmc node in devicetree */
  		sprintf(cmd, "mmc@%x", sdmmc_addr[instance]);
 
---

base-commit: b99da05e1538b8fa153322da82917af2aa27e1d6
change-id: 20260210-upstream_stm32mp2_cpu_fix-bbbd24ba4f99

Quoted 1 line

Best regards,

Thanks
Patrick

#2 lore raw
Quoted 38 lines · Patrick DELAUNAY

Hi,

Quoted 35 lines · Patrice Chotard

Fix index check against array size. If that index is equal to the array size, we'll access one-past-the-end of the array.

---
  arch/arm/mach-stm32mp/stm32mp2/cpu.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-stm32mp/stm32mp2/cpu.c +0 -0
index e081dc605b8..a8a6bcf8ab4 100644
@@ -148,7 +148,7 @@ static void setup_boot_mode(void)
             __func__, boot_ctx, boot_mode, instance, forced_mode);
       switch (boot_mode & TAMP_BOOT_DEVICE_MASK) {

      case BOOT_SERIAL_UART:
-        if (instance > ARRAY_SIZE(serial_addr))
+        if (instance >= ARRAY_SIZE(serial_addr)) break;
          /* serial : search associated node in devicetree */ sprintf(cmd, "serial@%x", serial_addr[instance]);

arch/arm/mach-stm32mp/stm32mp2/cpu.c +0 -0
@@ -178,7 +178,7 @@ static void setup_boot_mode(void)
           break;

      case BOOT_FLASH_SD:
      case BOOT_FLASH_EMMC:
-        if (instance > ARRAY_SIZE(sdmmc_addr))
+        if (instance >= ARRAY_SIZE(sdmmc_addr)) break;
          /* search associated sdmmc node in devicetree */ sprintf(cmd, "mmc@%x", sdmmc_addr[instance]);

---
base-commit: b99da05e1538b8fa153322da82917af2aa27e1d6
change-id: 20260210-upstream_stm32mp2_cpu_fix-bbbd24ba4f99

Quoted 8 lines
Quoted 1 line

Best regards,

Thanks
Patrick

Applied to u-boot-stm32/master

Thanks
Patrice