PlatformPKProtectionLibVarPolicy.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /** @file
  2. Provides an abstracted interface for configuring PK related variable protection.
  3. Copyright (c) Microsoft Corporation.
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Uefi.h>
  7. #include <Protocol/VariablePolicy.h>
  8. #include <Library/DebugLib.h>
  9. #include <Library/UefiBootServicesTableLib.h>
  10. /**
  11. Disable any applicable protection against variable 'PK'. The implementation
  12. of this interface is platform specific, depending on the protection techniques
  13. used per platform.
  14. Note: It is the platform's responsibility to conduct cautious operation after
  15. disabling this protection.
  16. @retval EFI_SUCCESS State has been successfully updated.
  17. @retval Others Error returned from implementation specific
  18. underying APIs.
  19. **/
  20. EFI_STATUS
  21. EFIAPI
  22. DisablePKProtection (
  23. VOID
  24. )
  25. {
  26. EFI_STATUS Status;
  27. EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy;
  28. DEBUG ((DEBUG_INFO, "%a() Entry...\n", __FUNCTION__));
  29. // IMPORTANT NOTE: This operation is sticky and leaves variable protections disabled.
  30. // The system *MUST* be reset after performing this operation.
  31. Status = gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid, NULL, (VOID **)&VariablePolicy);
  32. if (!EFI_ERROR (Status)) {
  33. Status = VariablePolicy->DisableVariablePolicy ();
  34. // EFI_ALREADY_STARTED means that everything is currently disabled.
  35. // This should be considered SUCCESS.
  36. if (Status == EFI_ALREADY_STARTED) {
  37. Status = EFI_SUCCESS;
  38. }
  39. }
  40. return Status;
  41. }