public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Yao, Jiewen" <jiewen.yao@intel.com>
To: "Zeng, Star" <star.zeng@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Zeng, Star" <star.zeng@intel.com>
Subject: Re: [PATCH 1/7] MdeModulePkg LockBoxLib: Support LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY
Date: Wed, 7 Mar 2018 06:44:01 +0000	[thread overview]
Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503AADF70C@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <1520346480-65348-2-git-send-email-star.zeng@intel.com>

Reviewed-by: Jiewen.yao@intel.com

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Star
> Zeng
> Sent: Tuesday, March 6, 2018 10:28 PM
> To: edk2-devel@lists.01.org
> Cc: Yao, Jiewen <jiewen.yao@intel.com>; Zeng, Star <star.zeng@intel.com>
> Subject: [edk2] [PATCH 1/7] MdeModulePkg LockBoxLib: Support
> LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY
> 
> With this flag, the LockBox can be restored in S3 resume only.
> The LockBox can not be restored after SmmReadyToLock in normal boot
> and after EndOfS3Resume in S3 resume.
> It can not be set together with LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE.
> 
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Star Zeng <star.zeng@intel.com>
> ---
>  MdeModulePkg/Include/Library/LockBoxLib.h          |  14 +-
>  .../Library/SmmLockBoxLib/SmmLockBoxDxeLib.c       |   4 +-
>  .../Library/SmmLockBoxLib/SmmLockBoxSmmLib.c       | 227
> ++++++++++++++++++++-
>  .../Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf     |  10 +-
>  4 files changed, 247 insertions(+), 8 deletions(-)
> 
> diff --git a/MdeModulePkg/Include/Library/LockBoxLib.h
> b/MdeModulePkg/Include/Library/LockBoxLib.h
> index db7fd05def58..80beb4d0f880 100644
> --- a/MdeModulePkg/Include/Library/LockBoxLib.h
> +++ b/MdeModulePkg/Include/Library/LockBoxLib.h
> @@ -2,7 +2,7 @@
>    This library is only intended to be used by DXE modules that need save
>    confidential information to LockBox and get it by PEI modules in S3 phase.
> 
> -Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
> 
>  This program and the accompanying materials
>  are licensed and made available under the terms and conditions
> @@ -62,9 +62,17 @@ SetLockBoxAttributes (
>    );
> 
>  //
> -// With this flag, this LockBox can be restored to this Buffer with
> RestoreAllLockBoxInPlace()
> +// With this flag, this LockBox can be restored to this Buffer
> +// with RestoreAllLockBoxInPlace()
>  //
> -#define LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE  BIT0
> +#define LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE     BIT0
> +//
> +// With this flag, this LockBox can be restored in S3 resume only.
> +// This LockBox can not be restored after SmmReadyToLock in normal boot
> +// and after EndOfS3Resume in S3 resume.
> +// It can not be set together with LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE.
> +//
> +#define LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY   BIT1
> 
>  /**
>    This function will update confidential information to lockbox.
> diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c
> b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c
> index b75f81e69e04..9b6f0bedbd4f 100644
> --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c
> +++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
> 
>  This program and the accompanying materials
>  are licensed and made available under the terms and conditions
> @@ -241,7 +241,7 @@ SetLockBoxAttributes (
>    // Basic check
>    //
>    if ((Guid == NULL) ||
> -      ((Attributes & ~LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0)) {
> +      ((Attributes & ~(LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE |
> LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY)) != 0)) {
>      return EFI_INVALID_PARAMETER;
>    }
> 
> diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.c
> b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.c
> index 4960df755534..af75a4cb9cd1 100644
> --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.c
> +++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.c
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
> 
>  This program and the accompanying materials
>  are licensed and made available under the terms and conditions
> @@ -20,6 +20,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY
> KIND, EITHER EXPRESS OR IMPLIED.
>  #include <Library/LockBoxLib.h>
>  #include <Library/DebugLib.h>
>  #include <Guid/SmmLockBox.h>
> +#include <Guid/EndOfS3Resume.h>
> +#include <Protocol/SmmReadyToLock.h>
> +#include <Protocol/SmmEndOfDxe.h>
> +#include <Protocol/SmmSxDispatch2.h>
> 
>  #include "SmmLockBoxLibPrivate.h"
> 
> @@ -31,6 +35,11 @@ SMM_LOCK_BOX_CONTEXT mSmmLockBoxContext;
>  LIST_ENTRY           mLockBoxQueue = INITIALIZE_LIST_HEAD_VARIABLE
> (mLockBoxQueue);
> 
>  BOOLEAN              mSmmConfigurationTableInstalled = FALSE;
> +VOID                 *mRegistrationSmmEndOfDxe = NULL;
> +VOID                 *mRegistrationSmmReadyToLock = NULL;
> +VOID                 *mRegistrationEndOfS3Resume = NULL;
> +BOOLEAN              mSmmLockBoxSmmReadyToLock = FALSE;
> +BOOLEAN              mSmmLockBoxDuringS3Resume = FALSE;
> 
>  /**
>    This function return SmmLockBox context from SMST.
> @@ -64,6 +73,128 @@ InternalGetSmmLockBoxContext (
>  }
> 
>  /**
> +  Notification for SMM ReadyToLock protocol.
> +
> +  @param[in] Protocol   Points to the protocol's unique identifier.
> +  @param[in] Interface  Points to the interface instance.
> +  @param[in] Handle     The handle on which the interface was installed.
> +
> +  @retval EFI_SUCCESS   Notification runs successfully.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmLockBoxSmmReadyToLockNotify (
> +  IN CONST EFI_GUID  *Protocol,
> +  IN VOID            *Interface,
> +  IN EFI_HANDLE      Handle
> +  )
> +{
> +  mSmmLockBoxSmmReadyToLock = TRUE;
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +  Main entry point for an SMM handler dispatch or communicate-based
> callback.
> +
> +  @param[in]     DispatchHandle  The unique handle assigned to this
> handler by SmiHandlerRegister().
> +  @param[in]     Context         Points to an optional handler context
> which was specified when the
> +                                 handler was registered.
> +  @param[in,out] CommBuffer      A pointer to a collection of data in
> memory that will
> +                                 be conveyed from a non-SMM
> environment into an SMM environment.
> +  @param[in,out] CommBufferSize  The size of the CommBuffer.
> +
> +  @retval EFI_SUCCESS                         The interrupt was
> handled and quiesced. No other handlers
> +                                              should still be called.
> +  @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED  The interrupt has
> been quiesced but other handlers should
> +                                              still be called.
> +  @retval EFI_WARN_INTERRUPT_SOURCE_PENDING   The interrupt is still
> pending and other handlers should still
> +                                              be called.
> +  @retval EFI_INTERRUPT_PENDING               The interrupt could not
> be quiesced.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmLockBoxS3EntryCallBack (
> +  IN           EFI_HANDLE           DispatchHandle,
> +  IN     CONST VOID                 *Context         OPTIONAL,
> +  IN OUT       VOID                 *CommBuffer      OPTIONAL,
> +  IN OUT       UINTN                *CommBufferSize  OPTIONAL
> +  )
> +{
> +  mSmmLockBoxDuringS3Resume = TRUE;
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +  Notification for SMM EndOfDxe protocol.
> +
> +  @param[in] Protocol   Points to the protocol's unique identifier.
> +  @param[in] Interface  Points to the interface instance.
> +  @param[in] Handle     The handle on which the interface was installed.
> +
> +  @retval EFI_SUCCESS   Notification runs successfully.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmLockBoxSmmEndOfDxeNotify (
> +  IN CONST EFI_GUID  *Protocol,
> +  IN VOID            *Interface,
> +  IN EFI_HANDLE      Handle
> +  )
> +{
> +  EFI_STATUS                        Status;
> +  EFI_SMM_SX_DISPATCH2_PROTOCOL     *SxDispatch;
> +  EFI_SMM_SX_REGISTER_CONTEXT       EntryRegisterContext;
> +  EFI_HANDLE                        S3EntryHandle;
> +
> +  //
> +  // Locate SmmSxDispatch2 protocol.
> +  //
> +  Status = gSmst->SmmLocateProtocol (
> +                    &gEfiSmmSxDispatch2ProtocolGuid,
> +                    NULL,
> +                    (VOID **)&SxDispatch
> +                    );
> +  if (!EFI_ERROR (Status) && (SxDispatch != NULL)) {
> +    //
> +    // Register a S3 entry callback function to
> +    // determine if it will be during S3 resume.
> +    //
> +    EntryRegisterContext.Type  = SxS3;
> +    EntryRegisterContext.Phase = SxEntry;
> +    Status = SxDispatch->Register (
> +                           SxDispatch,
> +                           SmmLockBoxS3EntryCallBack,
> +                           &EntryRegisterContext,
> +                           &S3EntryHandle
> +                           );
> +    ASSERT_EFI_ERROR (Status);
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +  Notification for SMM EndOfS3Resume protocol.
> +
> +  @param[in] Protocol   Points to the protocol's unique identifier.
> +  @param[in] Interface  Points to the interface instance.
> +  @param[in] Handle     The handle on which the interface was installed.
> +
> +  @retval EFI_SUCCESS   Notification runs successfully.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmLockBoxEndOfS3ResumeNotify (
> +  IN CONST EFI_GUID  *Protocol,
> +  IN VOID            *Interface,
> +  IN EFI_HANDLE      Handle
> +  )
> +{
> +  mSmmLockBoxDuringS3Resume = FALSE;
> +  return EFI_SUCCESS;
> +}
> +
> +/**
>    Constructor for SmmLockBox library.
>    This is used to set SmmLockBox context, which will be used in PEI phase in S3
> boot path later.
> 
> @@ -86,6 +217,36 @@ SmmLockBoxSmmConstructor (
>    DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SmmLockBoxSmmConstructor
> - Enter\n"));
> 
>    //
> +  // Register SmmReadyToLock notification.
> +  //
> +  Status = gSmst->SmmRegisterProtocolNotify (
> +                    &gEfiSmmReadyToLockProtocolGuid,
> +                    SmmLockBoxSmmReadyToLockNotify,
> +                    &mRegistrationSmmReadyToLock
> +                    );
> +  ASSERT_EFI_ERROR (Status);
> +
> +  //
> +  // Register SmmEndOfDxe notification.
> +  //
> +  Status = gSmst->SmmRegisterProtocolNotify (
> +                    &gEfiSmmEndOfDxeProtocolGuid,
> +                    SmmLockBoxSmmEndOfDxeNotify,
> +                    &mRegistrationSmmEndOfDxe
> +                    );
> +  ASSERT_EFI_ERROR (Status);
> +
> +  //
> +  // Register EndOfS3Resume notification.
> +  //
> +  Status = gSmst->SmmRegisterProtocolNotify (
> +                    &gEdkiiEndOfS3ResumeGuid,
> +                    SmmLockBoxEndOfS3ResumeNotify,
> +                    &mRegistrationEndOfS3Resume
> +                    );
> +  ASSERT_EFI_ERROR (Status);
> +
> +  //
>    // Check if gEfiSmmLockBoxCommunicationGuid is installed by someone
>    //
>    SmmLockBoxContext = InternalGetSmmLockBoxContext ();
> @@ -158,6 +319,40 @@ SmmLockBoxSmmDestructor (
>      DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib uninstall
> SmmLockBoxCommunication configuration table\n"));
>    }
> 
> +  if (mRegistrationSmmReadyToLock != NULL) {
> +    //
> +    // Unregister SmmReadyToLock notification.
> +    //
> +    Status = gSmst->SmmRegisterProtocolNotify (
> +                      &gEfiSmmReadyToLockProtocolGuid,
> +                      NULL,
> +                      &mRegistrationSmmReadyToLock
> +                      );
> +    ASSERT_EFI_ERROR (Status);
> +  }
> +  if (mRegistrationSmmEndOfDxe != NULL) {
> +    //
> +    // Unregister SmmEndOfDxe notification.
> +    //
> +    Status = gSmst->SmmRegisterProtocolNotify (
> +                      &gEfiSmmEndOfDxeProtocolGuid,
> +                      NULL,
> +                      &mRegistrationSmmEndOfDxe
> +                      );
> +    ASSERT_EFI_ERROR (Status);
> +  }
> +  if (mRegistrationEndOfS3Resume != NULL) {
> +    //
> +    // Unregister EndOfS3Resume notification.
> +    //
> +    Status = gSmst->SmmRegisterProtocolNotify (
> +                      &gEdkiiEndOfS3ResumeGuid,
> +                      NULL,
> +                      &mRegistrationEndOfS3Resume
> +                      );
> +    ASSERT_EFI_ERROR (Status);
> +  }
> +
>    return EFI_SUCCESS;
>  }
> 
> @@ -354,8 +549,16 @@ SetLockBoxAttributes (
>    // Basic check
>    //
>    if ((Guid == NULL) ||
> -      ((Attributes & ~LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0)) {
> +      ((Attributes & ~(LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE |
> LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY)) != 0)) {
> +    DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SetLockBoxAttributes - Exit
> (%r)\n", EFI_INVALID_PARAMETER));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  if (((Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0) &&
> +      ((Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY) != 0)) {
>      DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SetLockBoxAttributes - Exit
> (%r)\n", EFI_INVALID_PARAMETER));
> +    DEBUG ((EFI_D_INFO, "  LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE
> and LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY\n\n"));
> +    DEBUG ((EFI_D_INFO, "  can not be set together\n"));
>      return EFI_INVALID_PARAMETER;
>    }
> 
> @@ -368,6 +571,16 @@ SetLockBoxAttributes (
>      return EFI_NOT_FOUND;
>    }
> 
> +  if ((((Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0) &&
> +      ((LockBox->Attributes &
> LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY) != 0)) ||
> +      (((LockBox->Attributes &
> LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0) &&
> +      ((Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY) != 0))) {
> +    DEBUG ((EFI_D_INFO, "SmmLockBoxSmmLib SetLockBoxAttributes 0x%lx
> 0x%lx - Exit (%r)\n", LockBox->Attributes, Attributes,
> EFI_INVALID_PARAMETER));
> +    DEBUG ((EFI_D_INFO, "  LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE
> and LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY\n\n"));
> +    DEBUG ((EFI_D_INFO, "  can not be set together\n"));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
>    //
>    // Update data
>    //
> @@ -496,6 +709,16 @@ RestoreLockBox (
>      return EFI_NOT_FOUND;
>    }
> 
> +  if (((LockBox->Attributes &
> LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY) != 0) &&
> +      mSmmLockBoxSmmReadyToLock &&
> +      !mSmmLockBoxDuringS3Resume) {
> +    //
> +    // With LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY,
> +    // this LockBox can be restored in S3 resume only.
> +    //
> +    return EFI_ACCESS_DENIED;
> +  }
> +
>    //
>    // Set RestoreBuffer
>    //
> diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
> b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
> index eb7ba0bb2e89..426af4cccfe0 100644
> --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
> +++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
> @@ -1,7 +1,7 @@
>  ## @file
>  #  SMM LockBox library instance.
>  #
> -#  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
> +#  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
>  #
>  #  This program and the accompanying materials
>  #  are licensed and made available under the terms and conditions
> @@ -44,7 +44,15 @@ [LibraryClasses]
>    BaseLib
>    DebugLib
> 
> +[Protocols]
> +  gEfiSmmReadyToLockProtocolGuid    ## NOTIFY
> +  gEfiSmmEndOfDxeProtocolGuid       ## NOTIFY
> +  gEfiSmmSxDispatch2ProtocolGuid    ## NOTIFY
> +
>  [Guids]
>    ## SOMETIMES_CONSUMES   ## UNDEFINED # SmmSystemTable
>    ## SOMETIMES_PRODUCES   ## UNDEFINED # SmmSystemTable
>    gEfiSmmLockBoxCommunicationGuid
> +  ## CONSUMES             ## UNDEFINED # Protocol notify
> +  gEdkiiEndOfS3ResumeGuid
> +
> --
> 2.7.0.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


  reply	other threads:[~2018-03-07  6:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-06 14:27 [PATCH 0/7] OpalPassword: New solution without SMM device code Star Zeng
2018-03-06 14:27 ` [PATCH 1/7] MdeModulePkg LockBoxLib: Support LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY Star Zeng
2018-03-07  6:44   ` Yao, Jiewen [this message]
2018-03-06 14:27 ` [PATCH 2/7] SecurityPkg TcgStorageOpalLib: Make it be base type really Star Zeng
2018-03-07  6:45   ` Yao, Jiewen
2018-03-06 14:27 ` [PATCH 3/7] SecurityPkg TcgStorageCoreLib: " Star Zeng
2018-03-07  6:46   ` Yao, Jiewen
2018-03-06 14:27 ` [PATCH 4/7] SecurityPkg OpalPassword: Add solution without SMM device code Star Zeng
2018-03-07  7:06   ` Yao, Jiewen
2018-03-07 13:21     ` Zeng, Star
2018-03-06 14:27 ` [PATCH 5/7] SecurityPkg OpalPassword: Remove old solution Star Zeng
2018-03-07  6:55   ` Yao, Jiewen
2018-03-06 14:27 ` [PATCH 6/7] SecurityPkg OpalPasswordSupportLib: Remove it Star Zeng
2018-03-07  6:55   ` Yao, Jiewen
2018-03-06 14:28 ` [PATCH 7/7] SecurityPkg OpalPasswordExtraInfoVariable.h: " Star Zeng
2018-03-07  6:55   ` Yao, Jiewen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=74D8A39837DF1E4DA445A8C0B3885C503AADF70C@shsmsx102.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox