]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/PlatformDxe: Handle all requests in ExtractConfig and RouteConfig
authorDimitrije Pavlov <dimitrije.pavlov@arm.com>
Thu, 18 Aug 2022 19:58:42 +0000 (14:58 -0500)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 5 Sep 2022 13:52:51 +0000 (13:52 +0000)
Per the UEFI specification, if the Request argument in
EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig() is NULL or does not contain
any request elements, the implementation should return all of the settings
being abstracted for the particular ConfigHdr reference.

The current implementation returns EFI_INVALID_PARAMETER if Request is
NULL or does not contain any request elements. Instead, construct
a new ConfigRequest to handle these cases per the specification.

In addition, per the UEFI specification, if the Configuration argument in
EFI_HII_CONFIG_ACCESS_PROTOCOL.RouteConfig() has a ConfigHdr that
specifies a non-existing target, the implementation should return
EFI_NOT_FOUND.

The current implementation returns EFI_INVALID_PARAMETER if Configuration
has a non-existing target in ConfigHdr. Instead, perform a check and
return EFI_NOT_FOUND in this case.

Signed-off-by: Dimitrije Pavlov <Dimitrije.Pavlov@arm.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
OvmfPkg/PlatformDxe/Platform.c
OvmfPkg/PlatformDxe/PlatformConfig.c
OvmfPkg/PlatformDxe/PlatformConfig.h

index 4d432f18df37a3d015a9fc60013fd4822bd73149..ac31fafbdce3c0fe474c805c97c9e29d6eb7f9a7 100644 (file)
@@ -108,6 +108,11 @@ STATIC EFI_EVENT  mGopEvent;
 //\r
 STATIC VOID  *mGopTracker;\r
 \r
+//\r
+// The driver image handle, used to obtain the device path for <ConfigHdr>.\r
+//\r
+STATIC EFI_HANDLE  mImageHandle;\r
+\r
 //\r
 // Cache the resolutions we get from the GOP.\r
 //\r
@@ -229,6 +234,10 @@ ExtractConfig (
 {\r
   MAIN_FORM_STATE  MainFormState;\r
   EFI_STATUS       Status;\r
+  EFI_STRING       ConfigRequestHdr;\r
+  EFI_STRING       ConfigRequest;\r
+  UINTN            Size;\r
+  BOOLEAN          AllocatedRequest;\r
 \r
   DEBUG ((DEBUG_VERBOSE, "%a: Request=\"%s\"\n", __FUNCTION__, Request));\r
 \r
@@ -236,18 +245,73 @@ ExtractConfig (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  ConfigRequestHdr = NULL;\r
+  ConfigRequest    = NULL;\r
+  Size             = 0;\r
+  AllocatedRequest = FALSE;\r
+\r
+  //\r
+  // Check if <ConfigHdr> matches the GUID and name\r
+  //\r
+  *Progress = Request;\r
+  if ((Request != NULL) &&\r
+      !HiiIsConfigHdrMatch (\r
+         Request,\r
+         &gOvmfPlatformConfigGuid,\r
+         mVariableName\r
+         )\r
+      )\r
+  {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
   Status = PlatformConfigToFormState (&MainFormState);\r
   if (EFI_ERROR (Status)) {\r
-    *Progress = Request;\r
     return Status;\r
   }\r
 \r
+  if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r
+    //\r
+    // Request has no <RequestElement>, so construct full request string.\r
+    // Allocate and fill a buffer large enough to hold <ConfigHdr>\r
+    // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a\r
+    // null terminator.\r
+    //\r
+    ConfigRequestHdr = HiiConstructConfigHdr (\r
+                         &gOvmfPlatformConfigGuid,\r
+                         mVariableName,\r
+                         mImageHandle\r
+                         );\r
+    if (ConfigRequestHdr == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    Size             = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
+    ConfigRequest    = AllocateZeroPool (Size);\r
+    AllocatedRequest = TRUE;\r
+    if (ConfigRequest == NULL) {\r
+      FreePool (ConfigRequestHdr);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    UnicodeSPrint (\r
+      ConfigRequest,\r
+      Size,\r
+      L"%s&OFFSET=0&WIDTH=%016LX",\r
+      ConfigRequestHdr,\r
+      sizeof MainFormState\r
+      );\r
+    FreePool (ConfigRequestHdr);\r
+  } else {\r
+    ConfigRequest = Request;\r
+  }\r
+\r
   //\r
   // Answer the textual request keying off the binary form state.\r
   //\r
   Status = gHiiConfigRouting->BlockToConfig (\r
                                 gHiiConfigRouting,\r
-                                Request,\r
+                                ConfigRequest,\r
                                 (VOID *)&MainFormState,\r
                                 sizeof MainFormState,\r
                                 Results,\r
@@ -265,6 +329,33 @@ ExtractConfig (
     DEBUG ((DEBUG_VERBOSE, "%a: Results=\"%s\"\n", __FUNCTION__, *Results));\r
   }\r
 \r
+  //\r
+  // If we used a newly allocated ConfigRequest, update Progress to point to\r
+  // original Request instead of ConfigRequest.\r
+  //\r
+  if (Request == NULL) {\r
+    *Progress = NULL;\r
+  } else if (StrStr (Request, L"OFFSET") == NULL) {\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Since we constructed ConfigRequest, failure can only occur if there\r
+      // is not enough memory. In this case, we point Progress to the first\r
+      // character of Request.\r
+      //\r
+      *Progress = Request;\r
+    } else {\r
+      //\r
+      // In case of success, we point Progress to the null terminator of\r
+      // Request.\r
+      //\r
+      *Progress = Request + StrLen (Request);\r
+    }\r
+  }\r
+\r
+  if (AllocatedRequest) {\r
+    FreePool (ConfigRequest);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -348,6 +439,21 @@ RouteConfig (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  //\r
+  // Check if <ConfigHdr> matches the GUID and name\r
+  //\r
+  *Progress = Configuration;\r
+  if ((Configuration != NULL) &&\r
+      !HiiIsConfigHdrMatch (\r
+         Configuration,\r
+         &gOvmfPlatformConfigGuid,\r
+         mVariableName\r
+         )\r
+      )\r
+  {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
   //\r
   // the "read" step in RMW\r
   //\r
@@ -866,6 +972,11 @@ PlatformInit (
     return Status;\r
   }\r
 \r
+  //\r
+  // Save the driver image handle.\r
+  //\r
+  mImageHandle = ImageHandle;\r
+\r
   //\r
   // Publish the HII package list to HII Database.\r
   //\r
index e202ac5b4798deb5f916c3a811adcdba9f0e986b..f5ac2d0609ffc77aea3db821033eb9c4dc13aa01 100644 (file)
@@ -21,7 +21,7 @@
 //\r
 // Name of the UEFI variable that we use for persistent storage.\r
 //\r
-STATIC CHAR16  mVariableName[] = L"PlatformConfig";\r
+CHAR16  mVariableName[] = L"PlatformConfig";\r
 \r
 /**\r
   Serialize and persistently save platform configuration.\r
index 902c9b2ce043b1f0bcf7c34eb739aac950c3a935..5d9b457b1b4bc180edfa3b360cb98761da44f10d 100644 (file)
@@ -50,4 +50,6 @@ PlatformConfigLoad (
 #define PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION  BIT0\r
 #define PLATFORM_CONFIG_F_DOWNGRADE            BIT63\r
 \r
+extern CHAR16  mVariableName[];\r
+\r
 #endif // _PLATFORM_CONFIG_H_\r