[v2,18/35] arm: stm32mp: stm32mp2: fix off by one in mmc_get_boot()

Message ID 20261107143241.2236511-19-dario.binacchi@amarulasolutions.com
State New
Headers
Series Add Engicam MicroGEA-STM32MP257D-RMM board support |

Commit Message

Dario Binacchi Nov. 7, 2026, 2:32 p.m. UTC
The > comparison needs to be changed to >= to prevent an out of bounds
read of the sdmmc_addr[] array.

Fixes: a3be0ccc4746 ("board: st: stm32mp2: add mmc_get_env_dev()")
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---

(no changes since v1)

 board/st/stm32mp2/stm32mp2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.43.0
  

Comments

Patrice CHOTARD Nov. 16, 2026, 10:09 a.m. UTC | #1
On 11/7/26 15:32, Dario Binacchi wrote:
> The > comparison needs to be changed to >= to prevent an out of bounds
> read of the sdmmc_addr[] array.
> 
> Fixes: a3be0ccc4746 ("board: st: stm32mp2: add mmc_get_env_dev()")
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
> ---
> 
> (no changes since v1)
> 
>  board/st/stm32mp2/stm32mp2.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c
> index 7bc7d2a608fd..f2575339b990 100644
> --- a/board/st/stm32mp2/stm32mp2.c
> +++ b/board/st/stm32mp2/stm32mp2.c
> @@ -132,7 +132,7 @@ int mmc_get_boot(void)
>  		STM32_SDMMC3_BASE
>  	};
>  
> -	if (instance > ARRAY_SIZE(sdmmc_addr))
> +	if (instance >= ARRAY_SIZE(sdmmc_addr))
>  		return 0;
>  
>  	/* search associated sdmmc node in devicetree */
Hi Dario

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice
  
Patrice CHOTARD Nov. 26, 2026, 7:46 a.m. UTC | #2
On 11/16/26 11:09, Patrice CHOTARD wrote:
> 
> 
> On 11/7/26 15:32, Dario Binacchi wrote:
>> The > comparison needs to be changed to >= to prevent an out of bounds
>> read of the sdmmc_addr[] array.
>>
>> Fixes: a3be0ccc4746 ("board: st: stm32mp2: add mmc_get_env_dev()")
>> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
>> ---
>>
>> (no changes since v1)
>>
>>  board/st/stm32mp2/stm32mp2.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c
>> index 7bc7d2a608fd..f2575339b990 100644
>> --- a/board/st/stm32mp2/stm32mp2.c
>> +++ b/board/st/stm32mp2/stm32mp2.c
>> @@ -132,7 +132,7 @@ int mmc_get_boot(void)
>>  		STM32_SDMMC3_BASE
>>  	};
>>  
>> -	if (instance > ARRAY_SIZE(sdmmc_addr))
>> +	if (instance >= ARRAY_SIZE(sdmmc_addr))
>>  		return 0;
>>  
>>  	/* search associated sdmmc node in devicetree */
> Hi Dario
> 
> Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
> 
> Thanks
> Patrice

Applied to u-boot-stm32/main

Thanks
Patrice

> _______________________________________________
> Uboot-stm32 mailing list
> Uboot-stm32@st-md-mailman.stormreply.com
> https://st-md-mailman.stormreply.com/mailman/listinfo/uboot-stm32
  

Patch

diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c
index 7bc7d2a608fd..f2575339b990 100644
--- a/board/st/stm32mp2/stm32mp2.c
+++ b/board/st/stm32mp2/stm32mp2.c
@@ -132,7 +132,7 @@  int mmc_get_boot(void)
 		STM32_SDMMC3_BASE
 	};
 
-	if (instance > ARRAY_SIZE(sdmmc_addr))
+	if (instance >= ARRAY_SIZE(sdmmc_addr))
 		return 0;
 
 	/* search associated sdmmc node in devicetree */