Skip to contentSkip to conversation

bootm: Fix bmi->images pointer not initialized in some cases

PATCH In review Benjamin ROBIN 3 participants 6 messages May 20, 2025 – Jun 3, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bootm: Fix bmi->images pointer not initialized in some cases

When building with only bootz command, without bootm, images pointer inside bootm_info structure is not initialized. And since this structure is stored in stack, the generated error is kind of random, but most of the time this will generate: "ramdisk - allocation error".

Also, after analysis, this problem could occur with the command booti, if the command bootm is disabled.

Currently bootm_init() is called by: do_bootz(), do_bootm(), do_booti() and by do_stm32prog(). And all of these commands execute bootm_run_states() which access the images pointer stored into bootm_info structure.

So, to fix this issue, just do the assignment unconditionally.

Fixes c2211ff65136 ("bootm: Add more fields to bootm_info")
---
 boot/bootm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
boot/bootm.c +1 -2
index f6aa32746b7e..108ca7fb472e 100644
@@ -1169,8 +1169,7 @@ void bootm_init(struct bootm_info *bmi)
 {
 	memset(bmi, '\0', sizeof(struct bootm_info));
 	bmi->boot_progress = true;
-	if (IS_ENABLED(CONFIG_CMD_BOOTM))
-		bmi->images = &images;
+	bmi->images = &images;
 }
 
 /**
Signature · 1 line
2.49.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Benjamin ROBIN

When building with only bootz command, without bootm, images pointer inside bootm_info structure is not initialized. And since this structure is stored in stack, the generated error is kind of random, but most of the time this will generate: "ramdisk - allocation error".

Also, after analysis, this problem could occur with the command booti, if the command bootm is disabled.

Quoted 8 lines

Currently bootm_init() is called by: do_bootz(), do_bootm(), do_booti() and by do_stm32prog(). And all of these commands execute bootm_run_states() which access the images pointer stored into bootm_info structure.

So, to fix this issue, just do the assignment unconditionally.

Fixes c2211ff65136 ("bootm: Add more fields to bootm_info")
Signature · 1 line
Tom
#2 lore raw
In reply to Benjamin ROBIN

Hi Benjamin,

Quoted 26 lines · Benjamin ROBIN

When building with only bootz command, without bootm, images pointer inside bootm_info structure is not initialized. And since this structure is stored in stack, the generated error is kind of random, but most of the time this will generate: "ramdisk - allocation error".

Also, after analysis, this problem could occur with the command booti, if the command bootm is disabled.

Currently bootm_init() is called by: do_bootz(), do_bootm(), do_booti() and by do_stm32prog(). And all of these commands execute bootm_run_states() which access the images pointer stored into bootm_info structure.

So, to fix this issue, just do the assignment unconditionally.

Fixes c2211ff65136 ("bootm: Add more fields to bootm_info")
---
 boot/bootm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
boot/bootm.c +0 -0
index f6aa32746b7e..108ca7fb472e 100644

boot/bootm.c void bootm_init(struct bootm_info *bmi) · line 1172

Quoted 6 lines
boot/bootm.c +1 -2
@@ -1169,8 +1169,7 @@ void bootm_init(struct bootm_info *bmi)
 {
        memset(bmi, '\0', sizeof(struct bootm_info));
        bmi->boot_progress = true;
-       if (IS_ENABLED(CONFIG_CMD_BOOTM))
-               bmi->images = &images;
+       bmi->images = &images;

In my tree I have:

if (IS_ENABLED(CONFIG_CMD_BOOTM) || IS_ENABLED(CONFIG_CMD_BOOTZ) ||
    IS_ENABLED(CONFIG_CMD_BOOTI) || IS_ENABLED(CONFIG_PXE_UTILS))

but it seems that the few boards that didn't include boot/bootm.c have been dropped, so your patch is fine.

Quoted 6 lines
boot/bootm.c +0 -1
 }
 
 /**
--

2.49.0

Regards,
Simon

#3 lore raw
Quoted 38 lines · Simon Glass

Hi Benjamin,

Quoted 26 lines · Benjamin ROBIN

When building with only bootz command, without bootm, images pointer inside bootm_info structure is not initialized. And since this structure is stored in stack, the generated error is kind of random, but most of the time this will generate: "ramdisk - allocation error".

Also, after analysis, this problem could occur with the command booti, if the command bootm is disabled.

Currently bootm_init() is called by: do_bootz(), do_bootm(), do_booti() and by do_stm32prog(). And all of these commands execute bootm_run_states() which access the images pointer stored into bootm_info structure.

So, to fix this issue, just do the assignment unconditionally.

Fixes c2211ff65136 ("bootm: Add more fields to bootm_info")
---
 boot/bootm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
boot/bootm.c +0 -0
index f6aa32746b7e..108ca7fb472e 100644

boot/bootm.c void bootm_init(struct bootm_info *bmi) · line 1172

Quoted 6 lines
boot/bootm.c +1 -2
@@ -1169,8 +1169,7 @@ void bootm_init(struct bootm_info *bmi)
 {
        memset(bmi, '\0', sizeof(struct bootm_info));
        bmi->boot_progress = true;
-       if (IS_ENABLED(CONFIG_CMD_BOOTM))
-               bmi->images = &images;
+       bmi->images = &images;

In my tree I have:

Quoted 5 lines
if (IS_ENABLED(CONFIG_CMD_BOOTM) || IS_ENABLED(CONFIG_CMD_BOOTZ) ||
    IS_ENABLED(CONFIG_CMD_BOOTI) || IS_ENABLED(CONFIG_PXE_UTILS))

but it seems that the few boards that didn't include boot/bootm.c have been dropped, so your patch is fine.

Yes, looking at the code, we should have always been doing the assignment as there's a few places where we reference bmi->images and not the global images, FYI.

Signature · 1 line
Tom
#5 lore raw
In reply to Benjamin ROBIN
Quoted 9 lines · Benjamin ROBIN

When building with only bootz command, without bootm, images pointer inside bootm_info structure is not initialized. And since this structure is stored in stack, the generated error is kind of random, but most of the time this will generate: "ramdisk - allocation error".

Also, after analysis, this problem could occur with the command booti, if the command bootm is disabled.

[...]

Applied to u-boot/master, thanks!

[1/1] bootm: Fix bmi->images pointer not initialized in some cases

      commit: b8f282b8e0ee1e2c36694071c26b6b796f50c0a1
Signature · 1 line
Tom
#4 lore raw
In reply to Tom Rini

Hi Tom,

Quoted 43 lines · Tom Rini
Quoted 41 lines · Simon Glass

Hi Benjamin,

Quoted 26 lines · Benjamin ROBIN

When building with only bootz command, without bootm, images pointer inside bootm_info structure is not initialized. And since this structure is stored in stack, the generated error is kind of random, but most of the time this will generate: "ramdisk - allocation error".

Also, after analysis, this problem could occur with the command booti, if the command bootm is disabled.

Currently bootm_init() is called by: do_bootz(), do_bootm(), do_booti() and by do_stm32prog(). And all of these commands execute bootm_run_states() which access the images pointer stored into bootm_info structure.

So, to fix this issue, just do the assignment unconditionally.

Fixes c2211ff65136 ("bootm: Add more fields to bootm_info")
---
 boot/bootm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
boot/bootm.c +0 -0
index f6aa32746b7e..108ca7fb472e 100644

boot/bootm.c void bootm_init(struct bootm_info *bmi) · line 1172

Quoted 6 lines
boot/bootm.c +1 -2
@@ -1169,8 +1169,7 @@ void bootm_init(struct bootm_info *bmi)
 {
        memset(bmi, '\0', sizeof(struct bootm_info));
        bmi->boot_progress = true;
-       if (IS_ENABLED(CONFIG_CMD_BOOTM))
-               bmi->images = &images;
+       bmi->images = &images;

In my tree I have:

if (IS_ENABLED(CONFIG_CMD_BOOTM) || IS_ENABLED(CONFIG_CMD_BOOTZ) ||
    IS_ENABLED(CONFIG_CMD_BOOTI) || IS_ENABLED(CONFIG_PXE_UTILS))
Quoted 6 lines
Quoted 2 lines

but it seems that the few boards that didn't include boot/bootm.c have been dropped, so your patch is fine.

Yes, looking at the code, we should have always been doing the assignment as there's a few places where we reference bmi->images and not the global images, FYI.

My intent is to eventually drop the global, but that is a ways off.

Regards,
Simon