]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/SnpDxe/Snp.c
NetworkPkg/SnpDxe: Prevent invalid PCI BAR access
[mirror_edk2.git] / NetworkPkg / SnpDxe / Snp.c
index a23af05078bc8939c7ea42dc83f2d26ad9489888..69e74132ed704a5dd39d43ac41c9d3fb2c2d161e 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Implementation of driver entry point and driver binding protocol.\r
 \r
-Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) Microsoft Corporation.<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -465,8 +466,8 @@ SimpleNetworkDriverStart (
   // the IO BAR.  Save the index of the BAR into the adapter info structure.\r
   // for regular 32bit BARs, 0 is memory mapped, 1 is io mapped\r
   //\r
-  Snp->MemoryBarIndex = 0;\r
-  Snp->IoBarIndex     = 1;\r
+  Snp->MemoryBarIndex = PCI_MAX_BAR;\r
+  Snp->IoBarIndex     = PCI_MAX_BAR;\r
   FoundMemoryBar      = FALSE;\r
   FoundIoBar          = FALSE;\r
   for (BarIndex = 0; BarIndex < PCI_MAX_BAR; BarIndex++) {\r
@@ -647,19 +648,21 @@ SimpleNetworkDriverStart (
   PxeShutdown (Snp);\r
   PxeStop (Snp);\r
 \r
-  //\r
-  // Create EXIT_BOOT_SERIVES Event\r
-  //\r
-  Status = gBS->CreateEventEx (\r
-                  EVT_NOTIFY_SIGNAL,\r
-                  TPL_NOTIFY,\r
-                  SnpNotifyExitBootServices,\r
-                  Snp,\r
-                  &gEfiEventExitBootServicesGuid,\r
-                  &Snp->ExitBootServicesEvent\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    goto Error_DeleteSNP;\r
+  if (PcdGetBool (PcdSnpCreateExitBootServicesEvent)) {\r
+    //\r
+    // Create EXIT_BOOT_SERIVES Event\r
+    //\r
+    Status = gBS->CreateEventEx (\r
+                    EVT_NOTIFY_SIGNAL,\r
+                    TPL_CALLBACK,\r
+                    SnpNotifyExitBootServices,\r
+                    Snp,\r
+                    &gEfiEventExitBootServicesGuid,\r
+                    &Snp->ExitBootServicesEvent\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      goto Error_DeleteSNP;\r
+    }\r
   }\r
 \r
   //\r
@@ -778,10 +781,12 @@ SimpleNetworkDriverStop (
     return Status;\r
   }\r
 \r
-  //\r
-  // Close EXIT_BOOT_SERIVES Event\r
-  //\r
-  gBS->CloseEvent (Snp->ExitBootServicesEvent);\r
+  if (PcdGetBool (PcdSnpCreateExitBootServicesEvent)) {\r
+    //\r
+    // Close EXIT_BOOT_SERVICES Event\r
+    //\r
+    gBS->CloseEvent (Snp->ExitBootServicesEvent);\r
+  }\r
 \r
   Status = gBS->CloseProtocol (\r
                   Controller,\r
@@ -836,9 +841,9 @@ EFI_DRIVER_BINDING_PROTOCOL gSimpleNetworkDriverBinding = {
   @param ImageHandle       The driver image handle.\r
   @param SystemTable       The system table.\r
 \r
-  @retval EFI_SUCEESS      Initialization routine has found UNDI hardware,\r
+  @retval EFI_SUCCESS      Initialization routine has found UNDI hardware,\r
                            loaded it's ROM, and installed a notify event for\r
-                           the Network Indentifier Interface Protocol\r
+                           the Network Identifier Interface Protocol\r
                            successfully.\r
   @retval Other            Return value from HandleProtocol for\r
                            DeviceIoProtocol or LoadedImageProtocol\r