]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg/UefiPxeBcDxe: handle competing DHCP servers (more) gracefully
authorLaszlo Ersek <lersek@redhat.com>
Tue, 31 Mar 2020 00:47:49 +0000 (02:47 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 1 Apr 2020 14:12:09 +0000 (14:12 +0000)
When DHCP is misconfigured on a network segment, such that two DHCP
servers attempt to reply to requests (and therefore race with each other),
the edk2 PXE client can confuse itself.

In PxeBcDhcp4BootInfo() / PxeBcDhcp6BootInfo(), the client may refer to a
DHCP reply packet as an "earlier" packet from the "same" DHCP server, when
in reality both packets are unrelated, and arrive from different DHCP
servers.

While the edk2 PXE client can do nothing to fix this, it should at least
not ASSERT() -- ASSERT() is for catching programming errors (violations of
invariants that are under the control of the programmer). ASSERT()s should
in particular not refer to external data (such as network packets). What's
more, in RELEASE builds, we get NULL pointer references.

Check the problem conditions with actual "if"s, and return
EFI_PROTOCOL_ERROR. This will trickle out to PxeBcLoadBootFile(), and be
reported as "PXE-E99: Unexpected network error".

Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Maciej Rabeda <maciej.rabeda@linux.intel.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20200331004749.16128-1-lersek@redhat.com>
Reviewed-by: Siyuan Fu <siyuan.fu@intel.com>
Reviewed-by: Maciej Rabeda <maciej.rabeda@linux.intel.com>
NetworkPkg/UefiPxeBcDxe/PxeBcBoot.c

index 10bbb06f759345d4e2d4ffa3133664b0dd03ff15..d062a526077b270d35867d22012578e58445bd29 100644 (file)
@@ -482,7 +482,20 @@ PxeBcDhcp4BootInfo (
     Cache4 = &Private->DhcpAck.Dhcp4;\r
   }\r
 \r
     Cache4 = &Private->DhcpAck.Dhcp4;\r
   }\r
 \r
-  ASSERT (Cache4->OptList[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] != NULL);\r
+  if (Cache4->OptList[PXEBC_DHCP4_TAG_INDEX_BOOTFILE] == NULL) {\r
+    //\r
+    // This should never happen in a correctly configured DHCP / PXE\r
+    // environment. One misconfiguration that can cause it is two DHCP servers\r
+    // mistakenly running on the same network segment at the same time, and\r
+    // racing each other in answering DHCP requests. Thus, the DHCP packets\r
+    // that the edk2 PXE client considers "belonging together" may actually be\r
+    // entirely independent, coming from two (competing) DHCP servers.\r
+    //\r
+    // Try to deal with this gracefully. Note that this check is not\r
+    // comprehensive, as we don't try to identify all such errors.\r
+    //\r
+    return EFI_PROTOCOL_ERROR;\r
+  }\r
 \r
   //\r
   // Parse the boot server address.\r
 \r
   //\r
   // Parse the boot server address.\r
@@ -612,7 +625,20 @@ PxeBcDhcp6BootInfo (
     Cache6 = &Private->DhcpAck.Dhcp6;\r
   }\r
 \r
     Cache6 = &Private->DhcpAck.Dhcp6;\r
   }\r
 \r
-  ASSERT (Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] != NULL);\r
+  if (Cache6->OptList[PXEBC_DHCP6_IDX_BOOT_FILE_URL] == NULL) {\r
+    //\r
+    // This should never happen in a correctly configured DHCP / PXE\r
+    // environment. One misconfiguration that can cause it is two DHCP servers\r
+    // mistakenly running on the same network segment at the same time, and\r
+    // racing each other in answering DHCP requests. Thus, the DHCP packets\r
+    // that the edk2 PXE client considers "belonging together" may actually be\r
+    // entirely independent, coming from two (competing) DHCP servers.\r
+    //\r
+    // Try to deal with this gracefully. Note that this check is not\r
+    // comprehensive, as we don't try to identify all such errors.\r
+    //\r
+    return EFI_PROTOCOL_ERROR;\r
+  }\r
 \r
   //\r
   // Set the station address to IP layer.\r
 \r
   //\r
   // Set the station address to IP layer.\r