Skip to contentSkip to conversation

boot: pxe_utils: Fix incorrect allocation of overlay_dir

PATCH In review Surkov Kirill 2 participants 2 messages Nov 20, 2025 – Nov 21, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 boot: pxe_utils: Fix incorrect allocation of overlay_dir

The function label_boot_extension() calls snprintf on a buffer overlay_dir. However, this buffer is not initialized properly. In the "if" branch it is initialized using a variable "len", which is smaller than the resulting buffer. In the "else" branch this variable is not initialized at all. This results in a crash when calling a "sysboot" command.

This commit fixes this issue.

---
 boot/pxe_utils.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
boot/pxe_utils.c +4 -1
index 038416203fc..a2a9810a4cf 100644
@@ -474,7 +474,7 @@ static void label_boot_extension(struct pxe_context *ctx,
 			slash = "";
 
 		dir_len = strlen(label->fdtdir) + strlen(slash) + 1;
-		overlay_dir = calloc(1, len);
+		overlay_dir = calloc(1, dir_len);
 		if (!overlay_dir)
 			return;
 
@@ -482,6 +482,9 @@ static void label_boot_extension(struct pxe_context *ctx,
 			 slash);
 	} else {
 		dir_len = 2;
+		overlay_dir = calloc(1, dir_len);
+		if (!overlay_dir)
+			return;
 		snprintf(overlay_dir, dir_len, "/");
 	}
 
Signature · 1 line
2.43.0
#1 lore raw

Hi Surkov,

Quoted 11 lines · Surkov Kirill

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

The function label_boot_extension() calls snprintf on a buffer overlay_dir. However, this buffer is not initialized properly. In the "if" branch it is initialized using a variable "len", which is smaller than the resulting buffer. In the "else" branch this variable is not initialized at all. This results in a crash when calling a "sysboot" command.

This commit fixes this issue.

I believe we already have a patch submitted for this issue:

https://lore.kernel.org/u-boot/[email protected]/T/#u

so please give that a try and a tested-by/reviewed-by there.

Cheers,
Quentin