From mboxrd@z Thu Jan 1 00:00:00 1970 Subject: [PATCH] UserAuthFeaturePkg/UserAuthenticationDxeSmm: The SMI to handle the user authentication should be unregister before booting to OS To: devel@edk2.groups.io From: "Shi, Hao" X-Originating-Location: CN (192.55.46.54) X-Originating-Platform: Windows Chrome 93 User-Agent: GROUPS.IO Web Poster MIME-Version: 1.0 Date: Wed, 22 Sep 2021 21:42:51 -0700 Message-ID: Content-Type: multipart/alternative; boundary="OC0sRpE5vFGt0sFNhPkx" --OC0sRpE5vFGt0sFNhPkx Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3648 Register SmmExitBootServices and SmmLegacyBoot callback function to unregis= ter this handler. Signed-off-by: Hao Shi Cc: Dandan Bi Cc: Liming Gao --- .../UserAuthenticationSmm.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0| 34 +++++++++++++++++++ .../UserAuthenticationSmm.inf=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0|=C2=A0 2 ++ 2 files changed, 36 insertions(+) diff --git a/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthentica= tionDxeSmm/UserAuthenticationSmm.c b/Features/Intel/UserInterface/UserAuthF= eaturePkg/UserAuthenticationDxeSmm/UserAuthenticationSmm.c index 07e834eb..30f889dd 100644 --- a/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthenticationDxe= Smm/UserAuthenticationSmm.c +++ b/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthenticationDxe= Smm/UserAuthenticationSmm.c @@ -13,6 +13,7 @@ UINTN=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0mAdminPasswordTryCount =3D 0; BOOLEAN=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0mNeedReVerify =3D TRUE; BOOLEAN=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0mPasswordVerified =3D FALSE; +EFI_HANDLE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 mSmmHandle =3D NULL; /** Verify if the password is correct. @@ -612,6 +613,30 @@ EXIT: return EFI_SUCCESS; } +/** +=C2=A0 Performs Exit Boot Services UserAuthentication actions + +=C2=A0 @param[in] Protocol=C2=A0 =C2=A0Points to the protocol's unique ide= ntifier. +=C2=A0 @param[in] Interface=C2=A0 Points to the interface instance. +=C2=A0 @param[in] Handle=C2=A0 =C2=A0 =C2=A0The handle on which the interf= ace was installed. + +=C2=A0 @retval EFI_SUCCESS=C2=A0 =C2=A0Notification runs successfully. +**/ +EFI_STATUS +EFIAPI +UaExitBootServices ( +=C2=A0 IN CONST EFI_GUID=C2=A0 =C2=A0 =C2=A0*Protocol, +=C2=A0 IN VOID=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*Inte= rface, +=C2=A0 IN EFI_HANDLE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Handle +=C2=A0 ) +{ +=C2=A0 DEBUG ((DEBUG_INFO, "Unregister User Authentication Smi\n")); + +=C2=A0 gSmst->SmiHandlerUnRegister(mSmmHandle); + +=C2=A0 return EFI_SUCCESS; +} + /** Main entry for this driver. @@ -633,6 +658,7 @@ PasswordSmmInit ( EDKII_VARIABLE_LOCK_PROTOCOL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *VariableLoc= k; CHAR16=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 PasswordHistoryName[sizeof(USER_= AUTHENTICATION_VAR_NAME)/sizeof(CHAR16) + 5]; UINTN=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Index; +=C2=A0 EFI_EVENT=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ExitBootServicesEvent; ASSERT (PASSWORD_HASH_SIZE =3D=3D SHA256_DIGEST_SIZE); ASSERT (PASSWORD_HISTORY_CHECK_COUNT < 0xFFFF); @@ -663,6 +689,14 @@ PasswordSmmInit ( if (EFI_ERROR (Status)) { return Status; } +=C2=A0 mSmmHandle =3D SmmHandle; +=C2=A0 // +=C2=A0 // Register for SmmExitBootServices and SmmLegacyBoot notification. +=C2=A0 // +=C2=A0 Status =3D gSmst->SmmRegisterProtocolNotify (&gEdkiiSmmExitBootServ= icesProtocolGuid, UaExitBootServices, &ExitBootServicesEvent); +=C2=A0 ASSERT_EFI_ERROR (Status); +=C2=A0 Status =3D gSmst->SmmRegisterProtocolNotify (&gEdkiiSmmLegacyBootPr= otocolGuid, UaExitBootServices, &ExitBootServicesEvent); +=C2=A0 ASSERT_EFI_ERROR (Status); if (IsPasswordCleared()) { DEBUG ((DEBUG_INFO, "IsPasswordCleared\n")); diff --git a/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthentica= tionDxeSmm/UserAuthenticationSmm.inf b/Features/Intel/UserInterface/UserAut= hFeaturePkg/UserAuthenticationDxeSmm/UserAuthenticationSmm.inf index 0b33b194..d73a2fe2 100644 --- a/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthenticationDxe= Smm/UserAuthenticationSmm.inf +++ b/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthenticationDxe= Smm/UserAuthenticationSmm.inf @@ -48,6 +48,8 @@ [Protocols] gEdkiiVariableLockProtocolGuid=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 ## CONSUMES gEfiSmmVariableProtocolGuid=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0## CONSUMES +=C2=A0 gEdkiiSmmExitBootServicesProtocolGuid=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0## CONSUMES +=C2=A0 gEdkiiSmmLegacyBootProtocolGuid=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0## CONSUMES [Depex] gEfiSmmVariableProtocolGuid AND gEfiVariableWriteArchProtocolGuid -- 2.26.2.windows.1 --OC0sRpE5vFGt0sFNhPkx Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
 
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3648
 
Register SmmExitBootServices and SmmLegacyBoot callback function to un= register this handler.
 
Signed-off-by: Hao Shi <hao.shi@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
---
 .../UserAuthenticationSmm.c          &n= bsp;        | 34 +++++++++++++++++++
 .../UserAuthenticationSmm.inf          =        |  2 ++
 2 files changed, 36 insertions(+)
 
diff --git a/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthe= nticationDxeSmm/UserAuthenticationSmm.c b/Features/Intel/UserInterface/User= AuthFeaturePkg/UserAuthenticationDxeSmm/UserAuthenticationSmm.c
index 07e834eb..30f889dd 100644
--- a/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthenticati= onDxeSmm/UserAuthenticationSmm.c
+++ b/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthenticati= onDxeSmm/UserAuthenticationSmm.c
@@ -13,6 +13,7 @@ UINTN             = ;              mAdminPasswordTryCount = =3D 0;
 
 BOOLEAN                &= nbsp;        mNeedReVerify =3D TRUE;
 BOOLEAN                &= nbsp;        mPasswordVerified =3D FALSE;
+EFI_HANDLE                &nb= sp;     mSmmHandle =3D NULL;
 
 /**
   Verify if the password is correct.
@@ -612,6 +613,30 @@ EXIT:
   return EFI_SUCCESS;
 }
 
+/**
+  Performs Exit Boot Services UserAuthentication actions
+
+  @param[in] Protocol   Points to the protocol's uniqu= e identifier.
+  @param[in] Interface  Points to the interface instance.
+  @param[in] Handle     The handle on which the i= nterface was installed.
+
+  @retval EFI_SUCCESS   Notification runs successfully= .
+**/
+EFI_STATUS
+EFIAPI
+UaExitBootServices (
+  IN CONST EFI_GUID     *Protocol,
+  IN VOID               = *Interface,
+  IN EFI_HANDLE         Handle
+  )
+{
+  DEBUG ((DEBUG_INFO, "Unregister User Authentication Smi\n"));<= /div>
+
+  gSmst->SmiHandlerUnRegister(mSmmHandle);
+
+  return EFI_SUCCESS;
+}
+
 /**
   Main entry for this driver.
 
@@ -633,6 +658,7 @@ PasswordSmmInit (
   EDKII_VARIABLE_LOCK_PROTOCOL        &= nbsp; *VariableLock;
   CHAR16              &n= bsp;                 PasswordHistor= yName[sizeof(USER_AUTHENTICATION_VAR_NAME)/sizeof(CHAR16) + 5];
   UINTN              &nb= sp;                  Index;
+  EFI_EVENT              &nbs= p;            ExitBootServicesEvent;
 
   ASSERT (PASSWORD_HASH_SIZE =3D=3D SHA256_DIGEST_SIZE);
   ASSERT (PASSWORD_HISTORY_CHECK_COUNT < 0xFFFF);
@@ -663,6 +689,14 @@ PasswordSmmInit (
   if (EFI_ERROR (Status)) {
     return Status;
   }
+  mSmmHandle =3D SmmHandle;
+  //
+  // Register for SmmExitBootServices and SmmLegacyBoot notifica= tion.
+  //
+  Status =3D gSmst->SmmRegisterProtocolNotify (&gEdkiiSmm= ExitBootServicesProtocolGuid, UaExitBootServices, &ExitBootServicesEven= t);
+  ASSERT_EFI_ERROR (Status);
+  Status =3D gSmst->SmmRegisterProtocolNotify (&gEdkiiSmm= LegacyBootProtocolGuid, UaExitBootServices, &ExitBootServicesEvent);
+  ASSERT_EFI_ERROR (Status);
 
   if (IsPasswordCleared()) {
     DEBUG ((DEBUG_INFO, "IsPasswordCleared\n"));
diff --git a/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthe= nticationDxeSmm/UserAuthenticationSmm.inf b/Features/Intel/UserInterface/Us= erAuthFeaturePkg/UserAuthenticationDxeSmm/UserAuthenticationSmm.inf
index 0b33b194..d73a2fe2 100644
--- a/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthenticati= onDxeSmm/UserAuthenticationSmm.inf
+++ b/Features/Intel/UserInterface/UserAuthFeaturePkg/UserAuthenticati= onDxeSmm/UserAuthenticationSmm.inf
@@ -48,6 +48,8 @@
 [Protocols]
   gEdkiiVariableLockProtocolGuid       =         ## CONSUMES
   gEfiSmmVariableProtocolGuid        &n= bsp;          ## CONSUMES
+  gEdkiiSmmExitBootServicesProtocolGuid      &nbs= p;  ## CONSUMES
+  gEdkiiSmmLegacyBootProtocolGuid        &nb= sp;      ## CONSUMES
 
 [Depex]
   gEfiSmmVariableProtocolGuid AND gEfiVariableWriteArchProt= ocolGuid
-- 
2.26.2.windows.1
 
--OC0sRpE5vFGt0sFNhPkx--