From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web12.13561.1651255513347566730 for ; Fri, 29 Apr 2022 11:05:17 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=CwKJQ3Km; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: judah.vang@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651255516; x=1682791516; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C/GnjNvKbh+nFVJtdWClD4GPH3wIkyDMeLWA9R/hsQI=; b=CwKJQ3Km3Q4K3jIcoJ8Ucx3uxLHzOWCJrb+6sj+NnGtLfaBRCbtLHKvo la+ZuWhqGd3GXhpmWxsFjRZ7dRdzfMKR2oo8tnqgZuGb9gH42pa7dkrTk zz0CV/6VJcCoR4rhck1FjEdyGa3yOeCWaJ+7vAcOhugOMQlokHdx6/AMk Lou/qKmb7dYQGtdId4tM8tKUhLvjlG8xmMWeuDfGdiA9vN+N9Qh7v42Gk tBrPYOXo+n6NKyHh1xOLnYD/ffRDzsnovzh3DEuZF1O484lo4p6MULVDo 7PXs1c/gbkHMmMFa2t8hhrgEOAvM8WT+RKsW5TmNziOcSZEEB3c3eZWhq g==; X-IronPort-AV: E=McAfee;i="6400,9594,10332"; a="248659178" X-IronPort-AV: E=Sophos;i="5.91,186,1647327600"; d="scan'208";a="248659178" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2022 11:05:16 -0700 X-IronPort-AV: E=Sophos;i="5.91,186,1647327600"; d="scan'208";a="514955665" Received: from jvang-mobl.amr.corp.intel.com ([10.212.198.238]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2022 11:05:15 -0700 From: "Judah Vang" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Nishant C Mistry Subject: [Patch v2 07/28] MdeModulePkg: Add Null ProtectedVariable Library Date: Fri, 29 Apr 2022 11:04:09 -0700 Message-Id: <20220429180430.3292-8-judah.vang@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220429180430.3292-1-judah.vang@intel.com> References: <20220429180430.3292-1-judah.vang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2594 Add Null versions of the ProtectedVariable Library. This will be the default libraries for platforms that do not support ProtectedVariable. Cc: Jian J Wang Cc: Liming Gao Cc: Nishant C Mistry Signed-off-by: Jian J Wang Signed-off-by: Nishant C Mistry Signed-off-by: Judah Vang --- MdeModulePkg/Library/ProtectedVariableLibNull/ProtectedVariableLibNull.inf | 34 ++ MdeModulePkg/Library/ProtectedVariableLibNull/ProtectedVariable.c | 449 ++++++++++++++++++++ 2 files changed, 483 insertions(+) diff --git a/MdeModulePkg/Library/ProtectedVariableLibNull/ProtectedVariableLibNull.inf b/MdeModulePkg/Library/ProtectedVariableLibNull/ProtectedVariableLibNull.inf new file mode 100644 index 000000000000..6a17191c4e1e --- /dev/null +++ b/MdeModulePkg/Library/ProtectedVariableLibNull/ProtectedVariableLibNull.inf @@ -0,0 +1,34 @@ +## @file +# Provides null version of protected variable services. +# +# Copyright (c) 2022, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010029 + BASE_NAME = ProtectedVariableLibNull + FILE_GUID = 352C6A1B-403A-4E37-8517-FAA50BC45251 + MODULE_TYPE = BASE + VERSION_STRING = 0.1 + LIBRARY_CLASS = ProtectedVariableLib + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + ProtectedVariable.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + diff --git a/MdeModulePkg/Library/ProtectedVariableLibNull/ProtectedVariable.c b/MdeModulePkg/Library/ProtectedVariableLibNull/ProtectedVariable.c new file mode 100644 index 000000000000..cc1e16c1a671 --- /dev/null +++ b/MdeModulePkg/Library/ProtectedVariableLibNull/ProtectedVariable.c @@ -0,0 +1,449 @@ +/** @file + NULL version of ProtectedVariableLib used to disable protected variable services. + +Copyright (c) 2022, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include +#include +#include + +/** + + Initialization for protected varibale services. + + @param[in] ContextIn Pointer to variable service context needed by + protected variable. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibInitialize ( + IN PROTECTED_VARIABLE_CONTEXT_IN *ContextIn + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Get a verified copy of NV variable storage. + + @param[out] VariableFvHeader Pointer to the header of whole NV firmware volume. + @param[out] VariableStoreHeader Pointer to the header of variable storage. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibGetStore ( + OUT EFI_FIRMWARE_VOLUME_HEADER **VariableFvHeader, + OUT VARIABLE_STORE_HEADER **VariableStoreHeader + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Prepare for variable update. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibWriteInit ( + VOID + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Update a variable with protection provided by this library. + + @param[in,out] CurrVariable Variable to be updated. It's NULL if + adding a new variable. + @param[in] CurrVariableInDel In-delete-transiion copy of updating variable. + @param[in,out] NewVariable Buffer of new variable data. + Buffer of "MetaDataHmacVar" and new + variable (encrypted). + @param[in,out] NewVariableSize Size of NewVariable. + Size of (encrypted) NewVariable and + "MetaDataHmacVar". + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibUpdate ( + IN OUT VARIABLE_HEADER *CurrVariable, + IN VARIABLE_HEADER *CurrVariableInDel, + IN OUT VARIABLE_HEADER *NewVariable, + IN OUT UINTN *NewVariableSize + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Finalize a variable updating after it's written to NV variable storage + successfully. + + @param[in] NewVariable Buffer of new variables and MetaDataHmacVar. + @param[in] VariableSize Size of buffer pointed by NewVariable. + @param[in] StoreIndex New index of the variable in store. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibWriteFinal ( + IN VARIABLE_HEADER *NewVariable, + IN UINTN VariableSize, + IN UINT64 StoreIndex + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Perform garbage collection against the cached copy of NV variable storage. + + @param[in] VariableStoreBuffer Buffer used to do the reclaim. + @param[out] LastVariableOffset New free space start point. + @param[in] CurrVariableOffset Offset of existing variable. + @param[in] CurrVariableInDelOffset Offset of old copy of existing variable. + @param[in,out] NewVariable Buffer of new variable data. + @param[in] NewVariableSize Size of new variable data. + @param[in,out] HwErrVariableTotalSize Total size of variables with HR attribute. + @param[in,out] CommonVariableTotalSize Total size of common variables. + @param[in,out] CommonUserVariableTotalSize Total size of user variables. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibReclaim ( + IN VARIABLE_STORE_HEADER *VariableStoreBuffer, + OUT UINTN *LastVariableOffset, + IN UINTN CurrVariableOffset, + IN UINTN CurrVariableInDelOffset, + IN OUT VARIABLE_HEADER **NewVariable, + IN UINTN NewVariableSize, + IN OUT UINTN *HwErrVariableTotalSize, + IN OUT UINTN *CommonVariableTotalSize, + IN OUT UINTN *CommonUserVariableTotalSize + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + An alternative version of ProtectedVariableLibGetData to get plain data, if + encrypted, from given variable, for different use cases. + + @param[in,out] VarInfo Pointer to structure containing variable information. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibGetDataInfo ( + IN OUT PROTECTED_VARIABLE_INFO *VarInfo + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Retrieve plain data, if encrypted, of given variable. + + @param[in] Variable Pointer to header of a Variable. + @param[in,out] Data Pointer to plain data of the given variable. + @param[in,out] DataSize Size of data returned or data buffer needed. + @param[in] AuthFlag Auth-variable indicator. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibGetData ( + IN VARIABLE_HEADER *Variable, + IN OUT VOID *Data, + IN OUT UINT32 *DataSize, + IN BOOLEAN AuthFlag + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Retrieve next protected variable stub. + + @param[in,out] VarInfo Pointer to structure containing variable information. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibGetNextEx ( + IN OUT PROTECTED_VARIABLE_INFO *VarInfo + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Retrieve next protected variable. + + @param[in,out] VariableNameSize Pointer to size of variable name. + @param[in,out] VariableName Pointer to variable name. + @param[in,out] VariableGuid Pointer to vairable GUID. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibGetNext ( + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VariableGuid + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Get the specified protected variable. + + @param[in] VariableName Pointer to variable name. + @param[in] VariableGuid Pointer to vairable GUID. + @param[out] Attributes Pointer to attributes. + @param[in,out] DataSize Pointer to data size. + @param[out] Data Pointer to data. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibGet ( + IN CONST CHAR16 *VariableName, + IN CONST EFI_GUID *VariableGuid, + OUT UINT32 *Attributes, + IN OUT UINTN *DataSize, + OUT VOID *Data OPTIONAL + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Find the protected variable. + + @param[in,out] VarInfo Pointer to structure containing variable information. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibFind ( + IN OUT PROTECTED_VARIABLE_INFO *VarInfo + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Find next protected variable. + + @param[in,out] VariableNameSize Pointer to size of variable name. + @param[in,out] VariableName Pointer to variable name. + @param[in,out] VariableGuid Pointer to vairable GUID. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibFindNext ( + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VariableGuid + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Find next protected variable stub. + + @param[in,out] VarInfo Pointer to structure containing variable information. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibFindNextEx ( + IN OUT PROTECTED_VARIABLE_INFO *VarInfo + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Get protected variable by information. + + @param[in,out] VarInfo Pointer to structure containing variable information. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibGetByInfo ( + IN OUT PROTECTED_VARIABLE_INFO *VarInfo + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Get protected variable by name. + + @param[in] VariableName Pointer to variable name. + @param[in] VariableGuid Pointer to vairable GUID. + @param[out] Attributes Pointer to attributes. + @param[in,out] DataSize Pointer to data size. + @param[out] Data Pointer to data. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibGetByName ( + IN CONST CHAR16 *VariableName, + IN CONST EFI_GUID *VariableGuid, + OUT UINT32 *Attributes, + IN OUT UINTN *DataSize, + OUT VOID *Data OPTIONAL + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Get protected variable by name. + + @param[in] Variable Pointer to variable name. + @param[in,out] Data Pointer to variable data. + @param[in,out] DataSize Pointer to data size. + @param[in] AuthFlag Authenticate flag. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibGetByBuffer ( + IN VARIABLE_HEADER *Variable, + IN OUT VOID *Data, + IN OUT UINT32 *DataSize, + IN BOOLEAN AuthFlag + ) +{ + return EFI_UNSUPPORTED; +} + +/** + Refresh variable information changed by variable service. + + @param[in] Variable Pointer to buffer of the updated variable. + @param[in] VariableSize Size of variable pointed by Variable. + @param[in] StoreIndex New index of the variable in store. + @param[in] RefreshData Flag to indicate if the variable has been updated. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibRefresh ( + IN VARIABLE_HEADER *Variable, + IN UINTN VariableSize, + IN UINT64 StoreIndex, + IN BOOLEAN RefreshData + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Get sorted protected variable list. + + @param[in,out] Buffer Pointer to buffer. + @param[in,out] NumElements Pointer to number of elements. + + @retval EFI_UNSUPPORTED Unsupported to process protected variable. + +**/ +EFI_STATUS +EFIAPI +ProtectedVariableLibGetSortedList ( + IN OUT EFI_PHYSICAL_ADDRESS **Buffer, + IN OUT UINTN *NumElements + ) +{ + return EFI_UNSUPPORTED; +} + +/** + + Determine if the variable is the HMAC variable. + + @param[in] VariableName Pointer to variable name. + + @return FALSE Variable is not HMAC variable + +**/ +BOOLEAN +ProtectedVariableLibIsHmac ( + IN CHAR16 *VariableName + ) +{ + return FALSE; +} -- 2.35.1.windows.2