]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/LinuxInitrdDynamicShellCommand: bail if initrd already exists
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 3 Mar 2020 13:37:49 +0000 (14:37 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 4 Mar 2020 09:26:45 +0000 (09:26 +0000)
Before taking any actions, check if an instance of the LoadFile2 exists
already on the Linux initrd media GUID device path, and whether it was
provided by this command. If so, abort, since no duplicate instances of
the device path should exist.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2564
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.c
OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.uni

index 47ed26b50d3a493408c9b66224a615de32c6ebcd..ed8fbaa77069ba6366810a5595a0036036166cc0 100644 (file)
@@ -53,6 +53,33 @@ STATIC CONST SINGLE_NODE_VENDOR_MEDIA_DEVPATH mInitrdDevicePath = {
   }\r
 };\r
 \r
+STATIC\r
+BOOLEAN\r
+IsOtherInitrdDevicePathAlreadyInstalled (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_DEVICE_PATH_PROTOCOL    *DevicePath;\r
+  EFI_HANDLE                  Handle;\r
+\r
+  DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)&mInitrdDevicePath;\r
+  Status = gBS->LocateDevicePath (&gEfiLoadFile2ProtocolGuid, &DevicePath,\r
+                  &Handle);\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Check whether the existing instance is one that we installed during\r
+  // a previous invocation.\r
+  //\r
+  if (Handle == mInitrdLoadFile2Handle) {\r
+    return FALSE;\r
+  }\r
+  return TRUE;\r
+}\r
+\r
 STATIC\r
 EFI_STATUS\r
 EFIAPI\r
@@ -217,6 +244,10 @@ RunInitrd (
     } else {\r
       ASSERT(FALSE);\r
     }\r
+  } else if (IsOtherInitrdDevicePathAlreadyInstalled ()) {\r
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ALREADY_INSTALLED),\r
+      mLinuxInitrdShellCommandHiiHandle, L"initrd");\r
+    ShellStatus = SHELL_UNSUPPORTED;\r
   } else {\r
     if (ShellCommandLineGetCount (Package) > 2) {\r
       ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY),\r
index a88fa6e3641b88418b56015b1fafc3d4dcf1181c..4b6b1285fffd564a8ca61ea7e409ccd4d6eff355 100644 (file)
@@ -18,6 +18,7 @@
 #langdef   en-US "english"\r
 \r
 #string STR_GEN_PROBLEM           #language en-US "%H%s%N: Unknown flag - '%H%s%N'\r\n"\r
+#string STR_GEN_ALREADY_INSTALLED #language en-US "%H%s%N: Linux initrd already provided by platform\r\n"\r
 #string STR_GEN_TOO_MANY          #language en-US "%H%s%N: Too many arguments.\r\n"\r
 #string STR_GEN_TOO_FEW           #language en-US "%H%s%N: Too few arguments.\r\n"\r
 #string STR_GEN_FIND_FAIL         #language en-US "%H%s%N: File not found - '%H%s%N'\r\n"\r
@@ -47,3 +48,5 @@
 "     Consumers of the LoadFile2 protocol on the LINUX_EFI_INITRD_MEDIA_GUID\r\n"\r
 "     device path that are started via means other than the shell will be able\r\n"\r
 "     to locate the protocol and invoke it.\r\n"\r
+"  3. Exposing an initrd using this command is only supported if no initrd is\r\n"\r
+"     already being exposed by another driver on the platform.\r\n"\r