From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.46764.1660852729767926102 for ; Thu, 18 Aug 2022 12:58:50 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: dimitrije.pavlov@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4BB3D106F; Thu, 18 Aug 2022 12:58:50 -0700 (PDT) Received: from mammon-apollo-f36.austin.arm.com (mammon-apollo-f36.austin.arm.com [10.118.12.61]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B9A863F70D; Thu, 18 Aug 2022 12:58:48 -0700 (PDT) From: "Dimitrije Pavlov" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Liming Gao , Sunny Wang , Jeff Booher-Kaeding , Samer El-Haj-Mahmoud Subject: [PATCH v1 1/1] OvmfPkg/PlatformDxe: Handle all requests in ExtractConfig and RouteConfig Date: Thu, 18 Aug 2022 14:58:42 -0500 Message-Id: <20220818195842.3318813-1-dimitrije.pavlov@arm.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Per the UEFI specification, if the Request argument in EFI_HII_CONFIG_ACCESS_PROTOCOL.ExtractConfig() is NULL or does not contai= n any request elements, the implementation should return all of the setting= s 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. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Liming Gao Cc: Sunny Wang Cc: Jeff Booher-Kaeding Cc: Samer El-Haj-Mahmoud Signed-off-by: Dimitrije Pavlov --- OvmfPkg/PlatformDxe/PlatformConfig.h | 2 + OvmfPkg/PlatformDxe/Platform.c | 115 +++++++++++++++++++- OvmfPkg/PlatformDxe/PlatformConfig.c | 2 +- 3 files changed, 116 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/PlatformDxe/PlatformConfig.h b/OvmfPkg/PlatformDxe/P= latformConfig.h index 902c9b2ce043..5d9b457b1b4b 100644 --- a/OvmfPkg/PlatformDxe/PlatformConfig.h +++ b/OvmfPkg/PlatformDxe/PlatformConfig.h @@ -50,4 +50,6 @@ PlatformConfigLoad ( #define PLATFORM_CONFIG_F_GRAPHICS_RESOLUTION BIT0 #define PLATFORM_CONFIG_F_DOWNGRADE BIT63 =20 +extern CHAR16 mVariableName[]; + #endif // _PLATFORM_CONFIG_H_ diff --git a/OvmfPkg/PlatformDxe/Platform.c b/OvmfPkg/PlatformDxe/Platfor= m.c index a6d459f3dfd7..0e32c6e76037 100644 --- a/OvmfPkg/PlatformDxe/Platform.c +++ b/OvmfPkg/PlatformDxe/Platform.c @@ -108,6 +108,11 @@ STATIC EFI_EVENT mGopEvent; // STATIC VOID *mGopTracker; =20 +// +// The driver image handle, used to obtain the device path for . +// +STATIC EFI_HANDLE mImageHandle; + // // Cache the resolutions we get from the GOP. // @@ -229,6 +234,10 @@ ExtractConfig ( { MAIN_FORM_STATE MainFormState; EFI_STATUS Status; + EFI_STRING ConfigRequestHdr; + EFI_STRING ConfigRequest; + UINTN Size; + BOOLEAN AllocatedRequest; =20 DEBUG ((DEBUG_VERBOSE, "%a: Request=3D\"%s\"\n", __FUNCTION__, Request= )); =20 @@ -236,18 +245,73 @@ ExtractConfig ( return EFI_INVALID_PARAMETER; } =20 + ConfigRequestHdr =3D NULL; + ConfigRequest =3D NULL; + Size =3D 0; + AllocatedRequest =3D FALSE; + + // + // Check if matches the GUID and name + // + *Progress =3D Request; + if ((Request !=3D NULL) && + !HiiIsConfigHdrMatch ( + Request, + &gOvmfPlatformConfigGuid, + mVariableName + ) + ) + { + return EFI_NOT_FOUND; + } + Status =3D PlatformConfigToFormState (&MainFormState); if (EFI_ERROR (Status)) { - *Progress =3D Request; return Status; } =20 + if ((Request =3D=3D NULL) || (StrStr (Request, L"OFFSET") =3D=3D NULL)= ) { + // + // Request has no , so construct full request string= . + // Allocate and fill a buffer large enough to hold + // followed by "&OFFSET=3D0&WIDTH=3DWWWWWWWWWWWWWWWW" followed by a + // null terminator. + // + ConfigRequestHdr =3D HiiConstructConfigHdr ( + &gOvmfPlatformConfigGuid, + mVariableName, + mImageHandle + ); + if (ConfigRequestHdr =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Size =3D (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (= CHAR16); + ConfigRequest =3D AllocateZeroPool (Size); + AllocatedRequest =3D TRUE; + if (ConfigRequest =3D=3D NULL) { + FreePool (ConfigRequestHdr); + return EFI_OUT_OF_RESOURCES; + } + + UnicodeSPrint ( + ConfigRequest, + Size, + L"%s&OFFSET=3D0&WIDTH=3D%016LX", + ConfigRequestHdr, + sizeof MainFormState + ); + FreePool (ConfigRequestHdr); + } else { + ConfigRequest =3D Request; + } + // // Answer the textual request keying off the binary form state. // Status =3D gHiiConfigRouting->BlockToConfig ( gHiiConfigRouting, - Request, + ConfigRequest, (VOID *)&MainFormState, sizeof MainFormState, Results, @@ -265,6 +329,33 @@ ExtractConfig ( DEBUG ((DEBUG_VERBOSE, "%a: Results=3D\"%s\"\n", __FUNCTION__, *Resu= lts)); } =20 + // + // If we used a newly allocated ConfigRequest, update Progress to poin= t to + // original Request instead of ConfigRequest. + // + if (Request =3D=3D NULL) { + *Progress =3D NULL; + } else if (StrStr (Request, L"OFFSET") =3D=3D NULL) { + if (EFI_ERROR (Status)) { + // + // Since we constructed ConfigRequest, failure can only occur if t= here + // is not enough memory. In this case, we point Progress to the fi= rst + // character of Request. + // + *Progress =3D Request; + } else { + // + // In case of success, we point Progress to the null terminator of + // Request. + // + *Progress =3D Request + StrLen (Request); + } + } + + if (AllocatedRequest) { + FreePool (ConfigRequest); + } + return Status; } =20 @@ -348,6 +439,21 @@ RouteConfig ( return EFI_INVALID_PARAMETER; } =20 + // + // Check if matches the GUID and name + // + *Progress =3D Configuration; + if ((Configuration !=3D NULL) && + !HiiIsConfigHdrMatch ( + Configuration, + &gOvmfPlatformConfigGuid, + mVariableName + ) + ) + { + return EFI_NOT_FOUND; + } + // // the "read" step in RMW // @@ -866,6 +972,11 @@ PlatformInit ( return Status; } =20 + // + // Save the driver image handle. + // + mImageHandle =3D ImageHandle; + // // Publish the HII package list to HII Database. // diff --git a/OvmfPkg/PlatformDxe/PlatformConfig.c b/OvmfPkg/PlatformDxe/P= latformConfig.c index e202ac5b4798..f5ac2d0609ff 100644 --- a/OvmfPkg/PlatformDxe/PlatformConfig.c +++ b/OvmfPkg/PlatformDxe/PlatformConfig.c @@ -21,7 +21,7 @@ // // Name of the UEFI variable that we use for persistent storage. // -STATIC CHAR16 mVariableName[] =3D L"PlatformConfig"; +CHAR16 mVariableName[] =3D L"PlatformConfig"; =20 /** Serialize and persistently save platform configuration. --=20 2.37.2