Skip to contentSkip to conversation

ieee1275 : Add a check for invalid partition number

PATCH Superseded Avnish Chouhan 2 participants 3 messages Dec 1, 2025 – Dec 2, 2025

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ieee1275 : Add a check for invalid partition number

Adding a check for invalid partition number. grub_strtoul() can fail in several scenarios like invalid input, overflow, etc will result in an invalid partition number which could lead to an undefined behavior.

---
 grub-core/kern/ieee1275/openfw.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
grub-core/kern/ieee1275/openfw.c +10 -0
index 3b492dd..29bdb72 100644
@@ -512,8 +512,18 @@ grub_ieee1275_encode_devname (const char *path)
     }
   if (partition && partition[0])
     {
+      grub_errno = GRUB_ERR_NONE;
       unsigned int partno = grub_strtoul (partition, 0, 0);
 
+      if (grub_errno != GRUB_ERR_NONE)
+        {
+          grub_free (partition);
+          grub_free (device);
+          grub_free (encoding);
+          grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid partition number"));
+          return NULL;
+        }
+
       *optr++ = ',';
 
       if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS))
Signature · 7 lines
2.52.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw
Quoted 14 lines · Avnish Chouhan

Adding a check for invalid partition number. grub_strtoul() can fail in several scenarios like invalid input, overflow, etc will result in an invalid partition number which could lead to an undefined behavior.

---
 grub-core/kern/ieee1275/openfw.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
grub-core/kern/ieee1275/openfw.c +0 -0
index 3b492dd..29bdb72 100644

grub-core/kern/ieee1275/openfw.c grub_ieee1275_encode_devname (const char *path) · line 518

Quoted 7 lines
grub-core/kern/ieee1275/openfw.c +2 -0
@@ -512,8 +512,18 @@ grub_ieee1275_encode_devname (const char *path)
     }
   if (partition && partition[0])
     {
+      grub_errno = GRUB_ERR_NONE;
       unsigned int partno = grub_strtoul (partition, 0, 0);
 
+      if (grub_errno != GRUB_ERR_NONE)

This check isn't reliable. Please see how grub_strtoul() is handled in commit ac8a37dda (net/http: Allow use of non-standard TCP/IP ports). Even if it is reverted, the code around grub_strtoul() is fully correct.

Alec Brown

Quoted 12 lines
grub-core/kern/ieee1275/openfw.c +8 -1
+        {
+          grub_free (partition);
+          grub_free (device);
+          grub_free (encoding);
+          grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid partition number"));
+          return NULL;
+        }
+
       *optr++ = ',';
 
       if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS))
--
Quoted 1 line

2.52.0

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
Quoted 21 lines · Alec Brown
Quoted 20 lines · Avnish Chouhan

Adding a check for invalid partition number. grub_strtoul() can fail in several scenarios like invalid input, overflow, etc will result in an invalid partition number which could lead to an undefined behavior.

---
 grub-core/kern/ieee1275/openfw.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
grub-core/kern/ieee1275/openfw.c +1 -0
index 3b492dd..29bdb72 100644
@@ -512,8 +512,18 @@ grub_ieee1275_encode_devname (const char *path)
     }
   if (partition && partition[0])
     {
+      grub_errno = GRUB_ERR_NONE;
       unsigned int partno = grub_strtoul (partition, 0, 0);
 
Quoted 7 lines

grub-core/kern/ieee1275/openfw.c grub_ieee1275_encode_devname (const char *path) · line 518

Quoted 1 line
grub-core/kern/ieee1275/openfw.c +1 -0
+      if (grub_errno != GRUB_ERR_NONE)

This check isn't reliable. Please see how grub_strtoul() is handled in commit ac8a37dda (net/http: Allow use of non-standard TCP/IP ports). Even if it is reverted, the code around grub_strtoul() is fully correct.

Alec Brown

Hi Alec,
Thank you so much!

I'll surly add something similar based on commit ac8a37dda.

Regards,
Avnish Chouhan

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel