Blame SOURCES/0480-efi-net-Fix-malformed-device-path-arithmetic-errors-.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Thomas Frauendorfer | Miray Software <tf@miray.de>
80913e
Date: Tue, 4 Aug 2020 17:13:05 +0200
80913e
Subject: [PATCH] efi/net: Fix malformed device path arithmetic errors in efi
80913e
 net methods
80913e
80913e
---
80913e
 grub-core/net/efi/net.c | 26 ++++++++++++++++++++------
80913e
 1 file changed, 20 insertions(+), 6 deletions(-)
80913e
80913e
diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c
b32e65
index 3ae1fbbe3..a58c24f63 100644
80913e
--- a/grub-core/net/efi/net.c
80913e
+++ b/grub-core/net/efi/net.c
80913e
@@ -1318,11 +1318,18 @@ grub_efi_net_boot_from_https (void)
80913e
 
80913e
   dp = grub_efi_get_device_path (image->device_handle);
80913e
 
80913e
-  while (1)
80913e
+  while (dp)
80913e
     {
80913e
+      grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp);
80913e
+      if (len < 4)
80913e
+      {
80913e
+	grub_error(GRUB_ERR_OUT_OF_RANGE,
80913e
+		   "malformed EFI Device Path node has length=%d", len);
80913e
+	break;
80913e
+      }
80913e
+
80913e
       grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp);
80913e
       grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp);
80913e
-      grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp);
80913e
 
80913e
       if ((type == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE)
80913e
 	  && (subtype == GRUB_EFI_URI_DEVICE_PATH_SUBTYPE))
80913e
@@ -1335,7 +1342,7 @@ grub_efi_net_boot_from_https (void)
80913e
 
80913e
       if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp))
80913e
         break;
80913e
-      dp = (grub_efi_device_path_t *) ((char *) dp + len);
80913e
+      dp = GRUB_EFI_NEXT_DEVICE_PATH(dp);
80913e
     }
80913e
 
80913e
   return 0;
80913e
@@ -1353,11 +1360,18 @@ grub_efi_net_boot_from_opa (void)
80913e
 
80913e
   dp = grub_efi_get_device_path (image->device_handle);
80913e
 
80913e
-  while (1)
80913e
+  while (dp)
80913e
     {
80913e
+      grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp);
80913e
+      if (len < 4)
80913e
+      {
80913e
+	grub_error(GRUB_ERR_OUT_OF_RANGE,
80913e
+		   "malformed EFI Device Path node has length=%d", len);
80913e
+	break;
80913e
+      }
80913e
+
80913e
       grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp);
80913e
       grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp);
80913e
-      grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp);
80913e
 
80913e
       if ((type == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE)
80913e
 	  && (subtype == GRUB_EFI_MAC_ADDRESS_DEVICE_PATH_SUBTYPE))
80913e
@@ -1368,7 +1382,7 @@ grub_efi_net_boot_from_opa (void)
80913e
 
80913e
       if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp))
80913e
         break;
80913e
-      dp = (grub_efi_device_path_t *) ((char *) dp + len);
80913e
+      dp = GRUB_EFI_NEXT_DEVICE_PATH(dp);
80913e
     }
80913e
 
80913e
   return 0;