Skip to contentSkip to conversation

boot: android: Check kcmdline's for NULL in android_image_get_kernel()

PATCH In review Mattijs Korpershoek 4 participants 5 messages Jan 13, 2025 – Jan 23, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 boot: android: Check kcmdline's for NULL in android_image_get_kernel()

From: Aaron Kling <[email protected]>

kcmdline and kcmdline_extra strings can be NULL. In that case, we still read the content from 0x00000 and pass that to the kernel, which is completely wrong.

Fix android_image_get_kernel() to check for NULL before checking if they are empty strings.

Fixes 53a0ddb6d3be ("boot: android: fix extra command line support")

---
Thanks to Aaron for reporting this on the aosp-devs discord and for fixing this.

---
 boot/image-android.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
boot/image-android.c +4 -4
index 60a422dfb74a6c683b3cf9d2b19b3ad1dbd0d151..fa4e14ca4698e1dea105388dd2ea590024cafa58 100644
@@ -337,12 +337,12 @@ int android_image_get_kernel(const void *hdr,
 	if (bootargs)
 		len += strlen(bootargs);
 
-	if (*img_data.kcmdline) {
+	if (img_data.kcmdline && *img_data.kcmdline) {
 		printf("Kernel command line: %s\n", img_data.kcmdline);
 		len += strlen(img_data.kcmdline) + (len ? 1 : 0); /* +1 for extra space */
 	}
 
-	if (*img_data.kcmdline_extra) {
+	if (img_data.kcmdline_extra && *img_data.kcmdline_extra) {
 		printf("Kernel extra command line: %s\n", img_data.kcmdline_extra);
 		len += strlen(img_data.kcmdline_extra) + (len ? 1 : 0); /* +1 for extra space */
 	}
@@ -357,13 +357,13 @@ int android_image_get_kernel(const void *hdr,
 	if (bootargs)
 		strcpy(newbootargs, bootargs);
 
-	if (*img_data.kcmdline) {
+	if (img_data.kcmdline && *img_data.kcmdline) {
 		if (*newbootargs) /* If there is something in newbootargs, a space is needed */
 			strcat(newbootargs, " ");
 		strcat(newbootargs, img_data.kcmdline);
 	}
 
-	if (*img_data.kcmdline_extra) {
+	if (img_data.kcmdline_extra && *img_data.kcmdline_extra) {
 		if (*newbootargs) /* If there is something in newbootargs, a space is needed */
 			strcat(newbootargs, " ");
 		strcat(newbootargs, img_data.kcmdline_extra);

---
base-commit: bc157bb6667ed97e33be8ce8436c28baa275b295
change-id: 20250113-kcmdline-extra-fix-509331e4d7f3

Best regards,

Signature · 1 line
Mattijs Korpershoek <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 60 lines · Mattijs Korpershoek

From: Aaron Kling <[email protected]>

kcmdline and kcmdline_extra strings can be NULL. In that case, we still read the content from 0x00000 and pass that to the kernel, which is completely wrong.

Fix android_image_get_kernel() to check for NULL before checking if they are empty strings.

Fixes 53a0ddb6d3be ("boot: android: fix extra command line support")

---
Thanks to Aaron for reporting this on the aosp-devs discord and for fixing this.

---
 boot/image-android.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
boot/image-android.c +4 -5
index 60a422dfb74a6c683b3cf9d2b19b3ad1dbd0d151..fa4e14ca4698e1dea105388dd2ea590024cafa58 100644
@@ -337,12 +337,12 @@ int android_image_get_kernel(const void *hdr,
        if (bootargs)
                len += strlen(bootargs);
 
-       if (*img_data.kcmdline) {
+       if (img_data.kcmdline && *img_data.kcmdline) {
                printf("Kernel command line: %s\n", img_data.kcmdline);
                len += strlen(img_data.kcmdline) + (len ? 1 : 0); /* +1 for extra space */
        }
 
-       if (*img_data.kcmdline_extra) {
+       if (img_data.kcmdline_extra && *img_data.kcmdline_extra) {
                printf("Kernel extra command line: %s\n", img_data.kcmdline_extra);
                len += strlen(img_data.kcmdline_extra) + (len ? 1 : 0); /* +1 for extra space */
        }
@@ -357,13 +357,13 @@ int android_image_get_kernel(const void *hdr,
        if (bootargs)
                strcpy(newbootargs, bootargs);
 
-       if (*img_data.kcmdline) {
+       if (img_data.kcmdline && *img_data.kcmdline) {
                if (*newbootargs) /* If there is something in newbootargs, a space is needed */
                        strcat(newbootargs, " ");
                strcat(newbootargs, img_data.kcmdline);
        }
 
-       if (*img_data.kcmdline_extra) {
+       if (img_data.kcmdline_extra && *img_data.kcmdline_extra) {
                if (*newbootargs) /* If there is something in newbootargs, a space is needed */
                        strcat(newbootargs, " ");
                strcat(newbootargs, img_data.kcmdline_extra);
 
---

base-commit: bc157bb6667ed97e33be8ce8436c28baa275b295
change-id: 20250113-kcmdline-extra-fix-509331e4d7f3

Quoted 4 lines

Best regards,
--
Mattijs Korpershoek <[email protected]>

Reviewed-by on v1 1/1
#2 lore raw
In reply to Mattijs Korpershoek
Quoted 59 lines · Mattijs Korpershoek

From: Aaron Kling <[email protected]>

kcmdline and kcmdline_extra strings can be NULL. In that case, we still read the content from 0x00000 and pass that to the kernel, which is completely wrong.

Fix android_image_get_kernel() to check for NULL before checking if they are empty strings.

Fixes 53a0ddb6d3be ("boot: android: fix extra command line support")

---
Thanks to Aaron for reporting this on the aosp-devs discord and for fixing this.

---
 boot/image-android.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
boot/image-android.c +4 -5
index 60a422dfb74a6c683b3cf9d2b19b3ad1dbd0d151..fa4e14ca4698e1dea105388dd2ea590024cafa58 100644
@@ -337,12 +337,12 @@ int android_image_get_kernel(const void *hdr,
 	if (bootargs)
 		len += strlen(bootargs);
 
-	if (*img_data.kcmdline) {
+	if (img_data.kcmdline && *img_data.kcmdline) {
 		printf("Kernel command line: %s\n", img_data.kcmdline);
 		len += strlen(img_data.kcmdline) + (len ? 1 : 0); /* +1 for extra space */
 	}
 
-	if (*img_data.kcmdline_extra) {
+	if (img_data.kcmdline_extra && *img_data.kcmdline_extra) {
 		printf("Kernel extra command line: %s\n", img_data.kcmdline_extra);
 		len += strlen(img_data.kcmdline_extra) + (len ? 1 : 0); /* +1 for extra space */
 	}
@@ -357,13 +357,13 @@ int android_image_get_kernel(const void *hdr,
 	if (bootargs)
 		strcpy(newbootargs, bootargs);
 
-	if (*img_data.kcmdline) {
+	if (img_data.kcmdline && *img_data.kcmdline) {
 		if (*newbootargs) /* If there is something in newbootargs, a space is needed */
 			strcat(newbootargs, " ");
 		strcat(newbootargs, img_data.kcmdline);
 	}
 
-	if (*img_data.kcmdline_extra) {
+	if (img_data.kcmdline_extra && *img_data.kcmdline_extra) {
 		if (*newbootargs) /* If there is something in newbootargs, a space is needed */
 			strcat(newbootargs, " ");
 		strcat(newbootargs, img_data.kcmdline_extra);
 
---

base-commit: bc157bb6667ed97e33be8ce8436c28baa275b295
change-id: 20250113-kcmdline-extra-fix-509331e4d7f3

Quoted 4 lines

Best regards,

Signature · 1 line
Mattijs Korpershoek <[email protected]>
Tested-by
#3 lore raw
Quoted 62 lines · Julien Masson
Quoted 59 lines · On Thu 23 Jan 2025 at 14:28, Mattijs Korpershoek [email protected]…

From: Aaron Kling [email protected]

kcmdline and kcmdline_extra strings can be NULL. In that case, we still read the content from 0x00000 and pass that to the kernel, which is completely wrong.

Fix android_image_get_kernel() to check for NULL before checking if they are empty strings.

Fixes 53a0ddb6d3be ("boot: android: fix extra command line support")

---
Thanks to Aaron for reporting this on the aosp-devs discord and for fixing this.
---
boot/image-android.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
boot/image-android.c +1 -1
index 60a422dfb74a6c683b3cf9d2b19b3ad1dbd0d151..fa4e14ca4698e1dea105388dd2ea590024cafa58 100644
@@ -337,12 +337,12 @@ int android_image_get_kernel(const void *hdr,
 if (bootargs)
 len += strlen(bootargs);
 
- if (*img_data.kcmdline) {
+ if (img_data.kcmdline && img_data.kcmdline) {
 printf("Kernel command line: %s\n", img_data.kcmdline);

len += strlen(img_data.kcmdline) + (len ? 1 : 0); / +1 for extra space */ }

- if (*img_data.kcmdline_extra) {
+ if (img_data.kcmdline_extra && img_data.kcmdline_extra) { printf("Kernel extra command line: %s\n", img_data.kcmdline_extra); len += strlen(img_data.kcmdline_extra) + (len ? 1 : 0); / +1 for extra space */ }

boot/image-android.c +1 -1
@@ -357,13 +357,13 @@ int android_image_get_kernel(const void *hdr,
 if (bootargs)
 strcpy(newbootargs, bootargs);
 
- if (*img_data.kcmdline) {
+ if (img_data.kcmdline && *img_data.kcmdline) {

if (newbootargs) / If there is something in newbootargs, a space is needed */ strcat(newbootargs, " ");
strcat(newbootargs, img_data.kcmdline);
}

- if (*img_data.kcmdline_extra) {
+ if (img_data.kcmdline_extra && *img_data.kcmdline_extra) {
if (newbootargs) / If there is something in newbootargs, a space is needed */ strcat(newbootargs, " ");
strcat(newbootargs, img_data.kcmdline_extra);

---
base-commit: bc157bb6667ed97e33be8ce8436c28baa275b295
change-id: 20250113-kcmdline-extra-fix-509331e4d7f3

Quoted 6 lines
Quoted 3 lines

Best regards,
--
Mattijs Korpershoek [email protected]

#4 lore raw
In reply to Mattijs Korpershoek

Hi,

Quoted 8 lines · Mattijs Korpershoek

kcmdline and kcmdline_extra strings can be NULL. In that case, we still read the content from 0x00000 and pass that to the kernel, which is completely wrong.

Fix android_image_get_kernel() to check for NULL before checking if they are empty strings.

[...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu)

[1/1] boot: android: Check kcmdline's for NULL in android_image_get_kernel()

      https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/4e599aa73a386dd1ba5091937ef2fc388d01ddd2

--
Mattijs