Skip to content

Commit b8cd730

Browse files
authored
MdeModulePkg/UefiBootManagerLib: Register var policy on notify (#1276)
## Description Variable policy is currently set in the constructor. In some system designs, variable policy might not be running when the constructor of this library is executed. To make the policy registration process more robust, move registration to a protocol notify. - [x] Impacts functionality? - [ ] Impacts security? - [ ] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? - [x] Backport to release branch? ## How This Was Tested - Verify notify is called on variable policy protocol installation and register policy successfully. - Verify subsequent calls to the protocol gracefully exit by recognizing `EFI_ALREADY_STARTED` is returned from `RegisterBasicVariablePolicy()`. ## Integration Instructions N/A Signed-off-by: Michael Kubacki <[email protected]>
1 parent 653e31e commit b8cd730

File tree

1 file changed

+42
-13
lines changed
  • MdeModulePkg/Library/UefiBootManagerLib

1 file changed

+42
-13
lines changed

MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,19 +2819,17 @@ EfiBootManagerGetNextLoadOptionDevicePath (
28192819
//
28202820

28212821
/**
2822-
Constructor for UefiBootMangerLib.
2822+
Variable policy protocol installation notification.
28232823
2824-
@param[in] ImageHandle The handle of the loaded image.
2825-
@param[in] SystemTable System resources and configuration
2824+
@param[in] Event The notification event.
2825+
@param[in] Context Pointer to the context registered when the event is created. Not used.
28262826
2827-
@retval EFI_SUCCESS The constructor set the variable policy if implemented
2828-
@retval others The constructor did not succeed and one or more variable policy are not set
28292827
**/
2830-
EFI_STATUS
2828+
VOID
28312829
EFIAPI
2832-
UefiBootManagerLibConstructor (
2833-
IN EFI_HANDLE ImageHandle,
2834-
IN EFI_SYSTEM_TABLE *SystemTable
2830+
OnVariablePolicyNotification (
2831+
IN EFI_EVENT Event,
2832+
IN VOID *Context
28352833
)
28362834
{
28372835
EFI_STATUS Status;
@@ -2841,9 +2839,7 @@ UefiBootManagerLibConstructor (
28412839
// VariablePolicy, if implemented on this system, should have been installed already.
28422840
//
28432841
Status = gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid, NULL, (VOID **)&VariablePolicy);
2844-
if (EFI_ERROR (Status)) {
2845-
DEBUG ((DEBUG_ERROR, "%a: - Unable to locate VariablePolicy - Code=%r\n", __func__, Status));
2846-
} else {
2842+
if (!EFI_ERROR (Status)) {
28472843
Status = RegisterBasicVariablePolicy (
28482844
VariablePolicy,
28492845
&mBmHardDriveBootVariableGuid,
@@ -2861,10 +2857,43 @@ UefiBootManagerLibConstructor (
28612857
// 2. Already Started. Only the first module to register a variable policy will successfully register
28622858
// a policy. The subsequent modules will get EFI_ALREADY_STARTED.
28632859
if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED) && (Status != EFI_WRITE_PROTECTED)) {
2864-
DEBUG ((DEBUG_ERROR, "%a: - Error setting policy for HDDP - Code=%r\n", __func__, Status));
2860+
DEBUG ((DEBUG_ERROR, "%a: - Error setting policy for HDDP - Status=%r\n", __func__, Status));
28652861
ASSERT_EFI_ERROR (Status);
28662862
}
2863+
2864+
if (Event != NULL) {
2865+
gBS->CloseEvent (Event);
2866+
}
2867+
} else {
2868+
DEBUG ((DEBUG_ERROR, "%a: - Unable to locate variable policy protocol - Status=%r\n", __func__, Status));
28672869
}
2870+
}
2871+
2872+
/**
2873+
Constructor for UefiBootMangerLib.
2874+
2875+
@param[in] ImageHandle The handle of the loaded image.
2876+
@param[in] SystemTable System resources and configuration
2877+
2878+
@retval EFI_SUCCESS The constructor set the variable policy if implemented
2879+
@retval others The constructor did not succeed and one or more variable policy are not set
2880+
**/
2881+
EFI_STATUS
2882+
EFIAPI
2883+
UefiBootManagerLibConstructor (
2884+
IN EFI_HANDLE ImageHandle,
2885+
IN EFI_SYSTEM_TABLE *SystemTable
2886+
)
2887+
{
2888+
VOID *Registration;
2889+
2890+
EfiCreateProtocolNotifyEvent (
2891+
&gEdkiiVariablePolicyProtocolGuid,
2892+
TPL_CALLBACK,
2893+
OnVariablePolicyNotification,
2894+
NULL,
2895+
&Registration
2896+
);
28682897

28692898
return EFI_SUCCESS;
28702899
}

0 commit comments

Comments
 (0)