From nobody Tue Nov 26 16:36:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49824+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49824+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1572629974; cv=none; d=zoho.com; s=zohoarc; b=fqmXSJTGFFPUBBb1KFpNaTAxPo+Ilh15xux1/O31FMZORWoKqBYuuno8wRExIGxR29AU2rWisHWp9O8eOGRilUtTwz5MSgCvSeGJL87xNyFGrZ6SpHLYRni6pljmnvehlOvVpph/FIX9TQ+LglgOqrz2DF/gSWYlmyt8trFFQj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572629974; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=q+LyOo/p5jX4escWjpaSr2uBzn1EQqX5r7/HXIbZDLs=; b=NKVmDrgQDOZp+TY0gAaTMgHS+8kUXK2BYZk73vxkehIQwJxVV4LFb6WmoaWMTDRVmcdCTbOllmUHZBMjVEeIysPFaj78jMmW1nI90rdfTJpdh/JRH69Xv7pOX4Tn3wIXizWy3dIPUQI/YKfpqtP3qBaenvX//P21hEsMPXPzmaU= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49824+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1572629974826442.77804537362715; Fri, 1 Nov 2019 10:39:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id bzESYY1788612xRcdsNalSim; Fri, 01 Nov 2019 10:39:33 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web11.74.1572629726995557913 for ; Fri, 01 Nov 2019 10:35:27 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Nov 2019 10:35:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,256,1569308400"; d="scan'208";a="204559474" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga006.jf.intel.com with ESMTP; 01 Nov 2019 10:35:25 -0700 From: "Kubacki, Michael A" To: devel@edk2.groups.io Cc: Dandan Bi , Ard Biesheuvel , Eric Dong , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu , Jiewen Yao Subject: [edk2-devel] [PATCH V7 04/10] MdeModulePkg/Variable: Parameterize auth status in VariableParsing Date: Fri, 1 Nov 2019 10:34:51 -0700 Message-Id: <20191101173457.11956-5-michael.a.kubacki@intel.com> In-Reply-To: <20191101173457.11956-1-michael.a.kubacki@intel.com> References: <20191101173457.11956-1-michael.a.kubacki@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,michael.a.kubacki@intel.com X-Gm-Message-State: hlnOoe5SoKWAgC75GaHlvvj4x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572629973; bh=WsA+qOZPbCoxh2qosJVYT47NK9AZpmqteZKrDCgz5bY=; h=Cc:Date:From:Reply-To:Subject:To; b=jbm0ThOZDJpRu9eP+elfuPBUbuoygJW7Jayb7UsRh7PmsFjRIvjRVV8jpGV7a6BsDia tcbpV+R7/kZNw4gOVyiNXpoM6xCY8Y6KpvMpbILd08bvjVHPBysKI25WaX6YQCUZNH0ya ikqkyY+TO6DauuvWlDvqgWeFiys5el+1dZI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The file VariableParsing.c provides generic functionality related to parsing variable related structures and information. In order to calculate offsets for certain operations, the functions must know if authenticated variables are enabled as this increases the size of variable headers. This change removes linking against a global variable in an external file in favor of passing the authenticated variable status as a parameter to the variable parsing functions. Cc: Dandan Bi Cc: Ard Biesheuvel Cc: Eric Dong Cc: Laszlo Ersek Cc: Liming Gao Cc: Michael D Kinney Cc: Ray Ni Cc: Jian J Wang Cc: Hao A Wu Cc: Jiewen Yao Signed-off-by: Michael Kubacki --- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h | 82 +++++-- MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 258 +++++++= +++++++------ MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c | 15 +- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c | 146 +++++++= ---- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 5 +- 5 files changed, 339 insertions(+), 167 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h b= /MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h index 1777ce0e69..92a729d140 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h @@ -49,53 +49,65 @@ GetVariableStoreStatus ( /** This code gets the size of variable header. =20 + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. + @return Size of variable header in bytes in type UINTN. =20 **/ UINTN GetVariableHeaderSize ( - VOID + IN BOOLEAN AuthFormat ); =20 /** =20 This code gets the size of name of variable. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the variable header. + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. =20 @return UINTN Size of variable in bytes. =20 **/ UINTN NameSizeOfVariable ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** This code sets the size of name of variable. =20 - @param[in] Variable Pointer to the Variable Header. - @param[in] NameSize Name size to set. + @param[in] Variable Pointer to the Variable Header. + @param[in] NameSize Name size to set. + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. =20 **/ VOID SetNameSizeOfVariable ( IN VARIABLE_HEADER *Variable, - IN UINTN NameSize + IN UINTN NameSize, + IN BOOLEAN AuthFormat ); =20 /** =20 This code gets the size of variable data. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. =20 @return Size of variable in bytes. =20 **/ UINTN DataSizeOfVariable ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** @@ -103,80 +115,98 @@ DataSizeOfVariable ( =20 @param[in] Variable Pointer to the Variable Header. @param[in] DataSize Data size to set. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not us= ed. =20 **/ VOID SetDataSizeOfVariable ( - IN VARIABLE_HEADER *Variable, - IN UINTN DataSize + IN VARIABLE_HEADER *Variable, + IN UINTN DataSize, + IN BOOLEAN AuthFormat ); =20 /** =20 This code gets the pointer to the variable name. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Pointer to Variable Name which is Unicode encoding. =20 **/ CHAR16 * GetVariableNamePtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** This code gets the pointer to the variable guid. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return A EFI_GUID* pointer to Vendor Guid. =20 **/ EFI_GUID * GetVendorGuidPtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** =20 This code gets the pointer to the variable data. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Pointer to Variable Data. =20 **/ UINT8 * GetVariableDataPtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** This code gets the variable data offset related to variable header. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Variable Data offset. =20 **/ UINTN GetVariableDataOffset ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** =20 This code gets the pointer to the next variable header. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Pointer to next variable header. =20 **/ VARIABLE_HEADER * GetNextVariablePtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** @@ -235,6 +265,8 @@ VariableCompareTimeStampInternal ( @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS = attribute check at runtime when searching var= iable. @param[in, out] PtrTrack Variable Track Pointer structure th= at contains Variable Information. + @param[in] AuthFormat TRUE indicates authenticated variab= les are used. + FALSE indicates authenticated varia= bles are not used. =20 @retval EFI_SUCCESS Variable found successfully @retval EFI_NOT_FOUND Variable not found @@ -244,7 +276,8 @@ FindVariableEx ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN BOOLEAN IgnoreRtCheck, - IN OUT VARIABLE_POINTER_TRACK *PtrTrack + IN OUT VARIABLE_POINTER_TRACK *PtrTrack, + IN BOOLEAN AuthFormat ); =20 /** @@ -258,10 +291,12 @@ FindVariableEx ( @param[in] VariableStoreList A list of variable stores that should be u= sed to get the next variable. The maximum number of entries is the max v= alue of VARIABLE_STORE_TYPE. @param[out] VariablePtr Pointer to variable header address. + @param[in] AuthFormat TRUE indicates authenticated variables are= used. + FALSE indicates authenticated variables ar= e not used. =20 @retval EFI_SUCCESS The function completed successfully. @retval EFI_NOT_FOUND The next variable was not found. - @retval EFI_INVALID_PARAMETER If VariableName is nt an empty string, whi= le VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, wh= ile VendorGuid is NULL. @retval EFI_INVALID_PARAMETER The input values of VariableName and Vendo= rGuid are not a name and GUID of an existing variable. =20 @@ -272,7 +307,8 @@ VariableServiceGetNextVariableInternal ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN VARIABLE_STORE_HEADER **VariableStoreList, - OUT VARIABLE_HEADER **VariablePtr + OUT VARIABLE_HEADER **VariablePtr, + IN BOOLEAN AuthFormat ); =20 /** diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.c index 5cc12c2ae0..2e32905dfe 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -311,7 +311,7 @@ RecordVarErrorFlag ( FALSE ); if (!EFI_ERROR (Status)) { - VarErrFlag =3D (VAR_ERROR_FLAG *) GetVariableDataPtr (Variable.CurrPtr= ); + VarErrFlag =3D (VAR_ERROR_FLAG *) GetVariableDataPtr (Variable.CurrPtr= , mVariableModuleGlobal->VariableGlobal.AuthFormat); TempFlag =3D *VarErrFlag; TempFlag &=3D Flag; if (TempFlag =3D=3D *VarErrFlag) { @@ -369,7 +369,7 @@ InitializeVarErrorFlag ( FALSE ); if (!EFI_ERROR (Status)) { - VarErrFlag =3D *((VAR_ERROR_FLAG *) GetVariableDataPtr (Variable.CurrP= tr)); + VarErrFlag =3D *((VAR_ERROR_FLAG *) GetVariableDataPtr (Variable.CurrP= tr, mVariableModuleGlobal->VariableGlobal.AuthFormat)); if (VarErrFlag =3D=3D Flag) { return; } @@ -410,7 +410,11 @@ IsUserVariable ( // then no need to check if the variable is user variable or not special= ly. // if (mEndOfDxe && (mVariableModuleGlobal->CommonMaxUserVariableSpace !=3D= mVariableModuleGlobal->CommonVariableSpace)) { - if (VarCheckLibVariablePropertyGet (GetVariableNamePtr (Variable), Get= VendorGuidPtr (Variable), &Property) =3D=3D EFI_NOT_FOUND) { + if (VarCheckLibVariablePropertyGet ( + GetVariableNamePtr (Variable, mVariableModuleGlobal->VariableGlo= bal.AuthFormat), + GetVendorGuidPtr (Variable, mVariableModuleGlobal->VariableGloba= l.AuthFormat), + &Property + ) =3D=3D EFI_NOT_FOUND) { return TRUE; } } @@ -439,10 +443,14 @@ CalculateCommonUserVariableTotalSize ( if (mEndOfDxe && (mVariableModuleGlobal->CommonMaxUserVariableSpace !=3D= mVariableModuleGlobal->CommonVariableSpace)) { Variable =3D GetStartPointer (mNvVariableCache); while (IsValidVariableHeader (Variable, GetEndPointer (mNvVariableCach= e))) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, mVariableModuleGlobal= ->VariableGlobal.AuthFormat); VariableSize =3D (UINTN) NextVariable - (UINTN) Variable; if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) !=3D= EFI_VARIABLE_HARDWARE_ERROR_RECORD) { - if (VarCheckLibVariablePropertyGet (GetVariableNamePtr (Variable),= GetVendorGuidPtr (Variable), &Property) =3D=3D EFI_NOT_FOUND) { + if (VarCheckLibVariablePropertyGet ( + GetVariableNamePtr (Variable, mVariableModuleGlobal->Variabl= eGlobal.AuthFormat), + GetVendorGuidPtr (Variable, mVariableModuleGlobal->VariableG= lobal.AuthFormat), + &Property + ) =3D=3D EFI_NOT_FOUND) { // // No property, it is user variable. // @@ -518,7 +526,9 @@ Reclaim ( UINTN HwErrVariableTotalSize; VARIABLE_HEADER *UpdatingVariable; VARIABLE_HEADER *UpdatingInDeletedTransition; + BOOLEAN AuthFormat; =20 + AuthFormat =3D mVariableModuleGlobal->VariableGlobal.AuthFormat; UpdatingVariable =3D NULL; UpdatingInDeletedTransition =3D NULL; if (UpdatingPtrTrack !=3D NULL) { @@ -540,7 +550,7 @@ Reclaim ( MaximumBufferSize =3D sizeof (VARIABLE_STORE_HEADER); =20 while (IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHe= ader))) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, AuthFormat); if ((Variable->State =3D=3D VAR_ADDED || Variable->State =3D=3D (VAR= _IN_DELETED_TRANSITION & VAR_ADDED)) && Variable !=3D UpdatingVariable && Variable !=3D UpdatingInDeletedTransition @@ -590,7 +600,7 @@ Reclaim ( // Variable =3D GetStartPointer (VariableStoreHeader); while (IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHead= er))) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, AuthFormat); if (Variable !=3D UpdatingVariable && Variable->State =3D=3D VAR_ADDED= ) { VariableSize =3D (UINTN) NextVariable - (UINTN) Variable; CopyMem (CurrPtr, (UINT8 *) Variable, VariableSize); @@ -612,7 +622,7 @@ Reclaim ( // Variable =3D GetStartPointer (VariableStoreHeader); while (IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHead= er))) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, AuthFormat); if (Variable !=3D UpdatingVariable && Variable !=3D UpdatingInDeletedT= ransition && Variable->State =3D=3D (VAR_IN_DELETED_TRANSITION & VAR_ADDED)= ) { =20 // @@ -624,13 +634,14 @@ Reclaim ( FoundAdded =3D FALSE; AddedVariable =3D GetStartPointer ((VARIABLE_STORE_HEADER *) ValidBu= ffer); while (IsValidVariableHeader (AddedVariable, GetEndPointer ((VARIABL= E_STORE_HEADER *) ValidBuffer))) { - NextAddedVariable =3D GetNextVariablePtr (AddedVariable); - NameSize =3D NameSizeOfVariable (AddedVariable); - if (CompareGuid (GetVendorGuidPtr (AddedVariable), GetVendorGuidPt= r (Variable)) && - NameSize =3D=3D NameSizeOfVariable (Variable) - ) { - Point0 =3D (VOID *) GetVariableNamePtr (AddedVariable); - Point1 =3D (VOID *) GetVariableNamePtr (Variable); + NextAddedVariable =3D GetNextVariablePtr (AddedVariable, AuthForma= t); + NameSize =3D NameSizeOfVariable (AddedVariable, AuthFormat); + if (CompareGuid ( + GetVendorGuidPtr (AddedVariable, AuthFormat), + GetVendorGuidPtr (Variable, AuthFormat) + ) && NameSize =3D=3D NameSizeOfVariable (Variable, AuthFormat)= ) { + Point0 =3D (VOID *) GetVariableNamePtr (AddedVariable, AuthForma= t); + Point1 =3D (VOID *) GetVariableNamePtr (Variable, AuthFormat); if (CompareMem (Point0, Point1, NameSize) =3D=3D 0) { FoundAdded =3D TRUE; break; @@ -735,7 +746,7 @@ Reclaim ( mVariableModuleGlobal->CommonUserVariableTotalSize =3D 0; Variable =3D GetStartPointer ((VARIABLE_STORE_HEADER *)(UINTN)Variab= leBase); while (IsValidVariableHeader (Variable, GetEndPointer ((VARIABLE_STO= RE_HEADER *)(UINTN)VariableBase))) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, AuthFormat); VariableSize =3D (UINTN) NextVariable - (UINTN) Variable; if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) = =3D=3D EFI_VARIABLE_HARDWARE_ERROR_RECORD) { mVariableModuleGlobal->HwErrVariableTotalSize +=3D VariableSize; @@ -829,7 +840,13 @@ FindVariable ( PtrTrack->EndPtr =3D GetEndPointer (VariableStoreHeader[Type]); PtrTrack->Volatile =3D (BOOLEAN) (Type =3D=3D VariableStoreTypeVolatil= e); =20 - Status =3D FindVariableEx (VariableName, VendorGuid, IgnoreRtCheck, Pt= rTrack); + Status =3D FindVariableEx ( + VariableName, + VendorGuid, + IgnoreRtCheck, + PtrTrack, + mVariableModuleGlobal->VariableGlobal.AuthFormat + ); if (!EFI_ERROR (Status)) { return Status; } @@ -1199,7 +1216,11 @@ CheckRemainingSpaceForConsistencyInternal ( VarNameSize +=3D GET_PAD_SIZE (VarNameSize); VarDataSize =3D VariableEntry->VariableSize; VarDataSize +=3D GET_PAD_SIZE (VarDataSize); - VariableEntry->VariableSize =3D HEADER_ALIGN (GetVariableHeaderSize ()= + VarNameSize + VarDataSize); + VariableEntry->VariableSize =3D HEADER_ALIGN ( + GetVariableHeaderSize ( + mVariableModuleGlobal->VariableGloba= l.AuthFormat + ) + VarNameSize + VarDataSize + ); =20 TotalNeededSize +=3D VariableEntry->VariableSize; VariableEntry =3D VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *); @@ -1232,13 +1253,14 @@ CheckRemainingSpaceForConsistencyInternal ( VariableEntry->Name, VariableEntry->Guid, FALSE, - &VariablePtrTrack + &VariablePtrTrack, + mVariableModuleGlobal->VariableGlobal.AuthFormat ); if (!EFI_ERROR (Status)) { // // Get size of Variable[Index]. // - NextVariable =3D GetNextVariablePtr (VariablePtrTrack.CurrPtr); + NextVariable =3D GetNextVariablePtr (VariablePtrTrack.CurrPtr, mVari= ableModuleGlobal->VariableGlobal.AuthFormat); OriginalVarSize =3D (UINTN) NextVariable - (UINTN) VariablePtrTrack.= CurrPtr; // // Add the original size of Variable[Index] to remaining variable st= orage size. @@ -1410,8 +1432,8 @@ AutoUpdateLangVariable ( // Update Lang // VariableName =3D EFI_PLATFORM_LANG_VARIABLE_NAME; - Data =3D GetVariableDataPtr (Variable.CurrPtr); - DataSize =3D DataSizeOfVariable (Variable.CurrPtr); + Data =3D GetVariableDataPtr (Variable.CurrPtr, mVariableModu= leGlobal->VariableGlobal.AuthFormat); + DataSize =3D DataSizeOfVariable (Variable.CurrPtr, mVariableModu= leGlobal->VariableGlobal.AuthFormat); } else { Status =3D FindVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariable= Guid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE); if (!EFI_ERROR (Status)) { @@ -1419,8 +1441,8 @@ AutoUpdateLangVariable ( // Update PlatformLang // VariableName =3D EFI_LANG_VARIABLE_NAME; - Data =3D GetVariableDataPtr (Variable.CurrPtr); - DataSize =3D DataSizeOfVariable (Variable.CurrPtr); + Data =3D GetVariableDataPtr (Variable.CurrPtr, mVariableMo= duleGlobal->VariableGlobal.AuthFormat); + DataSize =3D DataSizeOfVariable (Variable.CurrPtr, mVariableMo= duleGlobal->VariableGlobal.AuthFormat); } else { // // Neither PlatformLang nor Lang is set, directly return @@ -1598,6 +1620,7 @@ UpdateVariable ( BOOLEAN IsCommonVariable; BOOLEAN IsCommonUserVariable; AUTHENTICATED_VARIABLE_HEADER *AuthVariable; + BOOLEAN AuthFormat; =20 if (mVariableModuleGlobal->FvbInstance =3D=3D NULL && !mVariableModuleGl= obal->VariableGlobal.EmuNvMode) { // @@ -1619,6 +1642,8 @@ UpdateVariable ( } } =20 + AuthFormat =3D mVariableModuleGlobal->VariableGlobal.AuthFormat; + // // Check if CacheVariable points to the variable in variable HOB. // If yes, let CacheVariable points to the variable in NV variable cache. @@ -1630,7 +1655,7 @@ UpdateVariable ( CacheVariable->StartPtr =3D GetStartPointer (mNvVariableCache); CacheVariable->EndPtr =3D GetEndPointer (mNvVariableCache); CacheVariable->Volatile =3D FALSE; - Status =3D FindVariableEx (VariableName, VendorGuid, FALSE, CacheVaria= ble); + Status =3D FindVariableEx (VariableName, VendorGuid, FALSE, CacheVaria= ble, AuthFormat); if (CacheVariable->CurrPtr =3D=3D NULL || EFI_ERROR (Status)) { // // There is no matched variable in NV variable cache. @@ -1770,8 +1795,8 @@ UpdateVariable ( // If the variable is marked valid, and the same data has been passed = in, // then return to the caller immediately. // - if (DataSizeOfVariable (CacheVariable->CurrPtr) =3D=3D DataSize && - (CompareMem (Data, GetVariableDataPtr (CacheVariable->CurrPtr), Da= taSize) =3D=3D 0) && + if (DataSizeOfVariable (CacheVariable->CurrPtr, AuthFormat) =3D=3D Dat= aSize && + (CompareMem (Data, GetVariableDataPtr (CacheVariable->CurrPtr, Aut= hFormat), DataSize) =3D=3D 0) && ((Attributes & EFI_VARIABLE_APPEND_WRITE) =3D=3D 0) && (TimeStamp =3D=3D NULL)) { // @@ -1791,9 +1816,13 @@ UpdateVariable ( // NOTE: From 0 to DataOffset of NextVariable is reserved for Vari= able Header and Name. // From DataOffset of NextVariable is to save the existing variabl= e data. // - DataOffset =3D GetVariableDataOffset (CacheVariable->CurrPtr); + DataOffset =3D GetVariableDataOffset (CacheVariable->CurrPtr, Auth= Format); BufferForMerge =3D (UINT8 *) ((UINTN) NextVariable + DataOffset); - CopyMem (BufferForMerge, (UINT8 *) ((UINTN) CacheVariable->CurrPtr= + DataOffset), DataSizeOfVariable (CacheVariable->CurrPtr)); + CopyMem ( + BufferForMerge, + (UINT8 *) ((UINTN) CacheVariable->CurrPtr + DataOffset), + DataSizeOfVariable (CacheVariable->CurrPtr, AuthFormat) + ); =20 // // Set Max Auth/Non-Volatile/Volatile Variable Data Size as defaul= t MaxDataSize. @@ -1814,15 +1843,22 @@ UpdateVariable ( MaxDataSize =3D PcdGet32 (PcdMaxHardwareErrorVariableSize) - Dat= aOffset; } =20 - if (DataSizeOfVariable (CacheVariable->CurrPtr) + DataSize > MaxDa= taSize) { + if (DataSizeOfVariable (CacheVariable->CurrPtr, AuthFormat) + Data= Size > MaxDataSize) { // // Existing data size + new data size exceed maximum variable si= ze limitation. // Status =3D EFI_INVALID_PARAMETER; goto Done; } - CopyMem ((UINT8*) ((UINTN) BufferForMerge + DataSizeOfVariable (Ca= cheVariable->CurrPtr)), Data, DataSize); - MergedBufSize =3D DataSizeOfVariable (CacheVariable->CurrPtr) + Da= taSize; + CopyMem ( + (UINT8*) ( + (UINTN) BufferForMerge + DataSizeOfVariable (CacheVariable->Cu= rrPtr, AuthFormat) + ), + Data, + DataSize + ); + MergedBufSize =3D DataSizeOfVariable (CacheVariable->CurrPtr, Auth= Format) + + DataSize; =20 // // BufferForMerge(from DataOffset of NextVariable) has included th= e merged existing and new data. @@ -1925,7 +1961,7 @@ UpdateVariable ( // NextVariable->Attributes =3D Attributes & (~EFI_VARIABLE_APPEND_WRITE); =20 - VarNameOffset =3D GetVariableHeaderSize (); + VarNameOffset =3D GetVariableHeaderSize (AuthFormat); VarNameSize =3D StrSize (VariableName); CopyMem ( (UINT8 *) ((UINTN) NextVariable + VarNameOffset), @@ -1946,14 +1982,18 @@ UpdateVariable ( ); } =20 - CopyMem (GetVendorGuidPtr (NextVariable), VendorGuid, sizeof (EFI_GUID)); + CopyMem ( + GetVendorGuidPtr (NextVariable, AuthFormat), + VendorGuid, + sizeof (EFI_GUID) + ); // // There will be pad bytes after Data, the NextVariable->NameSize and // NextVariable->DataSize should not include pad size so that variable // service can get actual size in GetVariable. // - SetNameSizeOfVariable (NextVariable, VarNameSize); - SetDataSizeOfVariable (NextVariable, DataSize); + SetNameSizeOfVariable (NextVariable, VarNameSize, AuthFormat); + SetDataSizeOfVariable (NextVariable, DataSize, AuthFormat); =20 // // The actual size of the variable that stores in storage should @@ -2036,7 +2076,7 @@ UpdateVariable ( TRUE, Fvb, mVariableModuleGlobal->NonVolatileLastVariableOffset, - (UINT32) GetVariableHeaderSize (), + (UINT32) GetVariableHeaderSize (AuthFormat), (UINT8 *) NextVariable ); =20 @@ -2069,9 +2109,9 @@ UpdateVariable ( FALSE, TRUE, Fvb, - mVariableModuleGlobal->NonVolatileLastVariableOffset + Ge= tVariableHeaderSize (), - (UINT32) (VarSize - GetVariableHeaderSize ()), - (UINT8 *) NextVariable + GetVariableHeaderSize () + mVariableModuleGlobal->NonVolatileLastVariableOffset + Ge= tVariableHeaderSize (AuthFormat), + (UINT32) (VarSize - GetVariableHeaderSize (AuthFormat)), + (UINT8 *) NextVariable + GetVariableHeaderSize (AuthForma= t) ); =20 if (EFI_ERROR (Status)) { @@ -2291,7 +2331,7 @@ VariableServiceGetVariable ( // // Get data size // - VarDataSize =3D DataSizeOfVariable (Variable.CurrPtr); + VarDataSize =3D DataSizeOfVariable (Variable.CurrPtr, mVariableModuleGlo= bal->VariableGlobal.AuthFormat); ASSERT (VarDataSize !=3D 0); =20 if (*DataSize >=3D VarDataSize) { @@ -2300,7 +2340,7 @@ VariableServiceGetVariable ( goto Done; } =20 - CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize); + CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr, mVariableModuleGl= obal->VariableGlobal.AuthFormat), VarDataSize); if (Attributes !=3D NULL) { *Attributes =3D Variable.CurrPtr->Attributes; } @@ -2357,6 +2397,7 @@ VariableServiceGetNextVariableName ( EFI_STATUS Status; UINTN MaxLen; UINTN VarNameSize; + BOOLEAN AuthFormat; VARIABLE_HEADER *VariablePtr; VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax]; =20 @@ -2364,6 +2405,8 @@ VariableServiceGetNextVariableName ( return EFI_INVALID_PARAMETER; } =20 + AuthFormat =3D mVariableModuleGlobal->VariableGlobal.AuthFormat; + // // Calculate the possible maximum length of name string, including the N= ull terminator. // @@ -2387,13 +2430,27 @@ VariableServiceGetNextVariableName ( VariableStoreHeader[VariableStoreTypeHob] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase; VariableStoreHeader[VariableStoreTypeNv] =3D mNvVariableCache; =20 - Status =3D VariableServiceGetNextVariableInternal (VariableName, VendorG= uid, VariableStoreHeader, &VariablePtr); + Status =3D VariableServiceGetNextVariableInternal ( + VariableName, + VendorGuid, + VariableStoreHeader, + &VariablePtr, + AuthFormat + ); if (!EFI_ERROR (Status)) { - VarNameSize =3D NameSizeOfVariable (VariablePtr); + VarNameSize =3D NameSizeOfVariable (VariablePtr, AuthFormat); ASSERT (VarNameSize !=3D 0); if (VarNameSize <=3D *VariableNameSize) { - CopyMem (VariableName, GetVariableNamePtr (VariablePtr), VarNameSize= ); - CopyMem (VendorGuid, GetVendorGuidPtr (VariablePtr), sizeof (EFI_GUI= D)); + CopyMem ( + VariableName, + GetVariableNamePtr (VariablePtr, AuthFormat), + VarNameSize + ); + CopyMem ( + VendorGuid, + GetVendorGuidPtr (VariablePtr, AuthFormat), + sizeof (EFI_GUID) + ); Status =3D EFI_SUCCESS; } else { Status =3D EFI_BUFFER_TOO_SMALL; @@ -2446,6 +2503,9 @@ VariableServiceSetVariable ( VARIABLE_HEADER *NextVariable; EFI_PHYSICAL_ADDRESS Point; UINTN PayloadSize; + BOOLEAN AuthFormat; + + AuthFormat =3D mVariableModuleGlobal->VariableGlobal.AuthFormat; =20 // // Check input parameters. @@ -2544,7 +2604,8 @@ VariableServiceSetVariable ( // bytes for HwErrRec#### variable. // if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) =3D=3D EFI_VARIABL= E_HARDWARE_ERROR_RECORD) { - if (StrSize (VariableName) + PayloadSize > PcdGet32 (PcdMaxHardwareErr= orVariableSize) - GetVariableHeaderSize ()) { + if (StrSize (VariableName) + PayloadSize > + PcdGet32 (PcdMaxHardwareErrorVariableSize) - GetVariableHeaderSize= (AuthFormat)) { return EFI_INVALID_PARAMETER; } } else { @@ -2553,7 +2614,9 @@ VariableServiceSetVariable ( // the DataSize is limited to maximum size of Max(Auth|Volatile)Varia= bleSize bytes. // if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) !=3D 0) { - if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->Ma= xAuthVariableSize - GetVariableHeaderSize ()) { + if (StrSize (VariableName) + PayloadSize > + mVariableModuleGlobal->MaxAuthVariableSize - + GetVariableHeaderSize (AuthFormat)) { DEBUG ((DEBUG_ERROR, "%a: Failed to set variable '%s' with Guid %g\n", __FUNCTION__, VariableName, VendorGuid)); @@ -2562,12 +2625,13 @@ VariableServiceSetVariable ( "MaxAuthVariableSize(0x%x) - HeaderSize(0x%x)\n", StrSize (VariableName), PayloadSize, mVariableModuleGlobal->MaxAuthVariableSize, - GetVariableHeaderSize () + GetVariableHeaderSize (AuthFormat) )); return EFI_INVALID_PARAMETER; } } else if ((Attributes & EFI_VARIABLE_NON_VOLATILE) !=3D 0) { - if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->Ma= xVariableSize - GetVariableHeaderSize ()) { + if (StrSize (VariableName) + PayloadSize > + mVariableModuleGlobal->MaxVariableSize - GetVariableHeaderSize (= AuthFormat)) { DEBUG ((DEBUG_ERROR, "%a: Failed to set variable '%s' with Guid %g\n", __FUNCTION__, VariableName, VendorGuid)); @@ -2576,12 +2640,13 @@ VariableServiceSetVariable ( "MaxVariableSize(0x%x) - HeaderSize(0x%x)\n", StrSize (VariableName), PayloadSize, mVariableModuleGlobal->MaxVariableSize, - GetVariableHeaderSize () + GetVariableHeaderSize (AuthFormat) )); return EFI_INVALID_PARAMETER; } } else { - if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->Ma= xVolatileVariableSize - GetVariableHeaderSize ()) { + if (StrSize (VariableName) + PayloadSize > + mVariableModuleGlobal->MaxVolatileVariableSize - GetVariableHead= erSize (AuthFormat)) { DEBUG ((DEBUG_ERROR, "%a: Failed to set variable '%s' with Guid %g\n", __FUNCTION__, VariableName, VendorGuid)); @@ -2590,7 +2655,7 @@ VariableServiceSetVariable ( "MaxVolatileVariableSize(0x%x) - HeaderSize(0x%x)\n", StrSize (VariableName), PayloadSize, mVariableModuleGlobal->MaxVolatileVariableSize, - GetVariableHeaderSize () + GetVariableHeaderSize (AuthFormat) )); return EFI_INVALID_PARAMETER; } @@ -2629,7 +2694,7 @@ VariableServiceSetVariable ( // NextVariable =3D GetStartPointer ((VARIABLE_STORE_HEADER *) (UINTN) P= oint); while (IsValidVariableHeader (NextVariable, GetEndPointer ((VARIABLE_S= TORE_HEADER *) (UINTN) Point))) { - NextVariable =3D GetNextVariablePtr (NextVariable); + NextVariable =3D GetNextVariablePtr (NextVariable, AuthFormat); } mVariableModuleGlobal->NonVolatileLastVariableOffset =3D (UINTN) NextV= ariable - (UINTN) Point; } @@ -2754,7 +2819,8 @@ VariableServiceQueryVariableInfoInternal ( // if ((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERR= OR_RECORD)) =3D=3D (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR= _RECORD)) { *MaximumVariableStorageSize =3D PcdGet32 (PcdHwErrStorageSize); - *MaximumVariableSize =3D PcdGet32 (PcdMaxHardwareErrorVariableSize) - = GetVariableHeaderSize (); + *MaximumVariableSize =3D PcdGet32 (PcdMaxHardwareErrorVariableSize) - + GetVariableHeaderSize (mVariableModuleGlobal= ->VariableGlobal.AuthFormat); } else { if ((Attributes & EFI_VARIABLE_NON_VOLATILE) !=3D 0) { if (AtRuntime ()) { @@ -2768,11 +2834,14 @@ VariableServiceQueryVariableInfoInternal ( // Let *MaximumVariableSize be Max(Auth|Volatile)VariableSize with the= exception of the variable header size. // if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) !=3D 0) { - *MaximumVariableSize =3D mVariableModuleGlobal->MaxAuthVariableSize = - GetVariableHeaderSize (); + *MaximumVariableSize =3D mVariableModuleGlobal->MaxAuthVariableSize= - + GetVariableHeaderSize (mVariableModuleGlob= al->VariableGlobal.AuthFormat); } else if ((Attributes & EFI_VARIABLE_NON_VOLATILE) !=3D 0) { - *MaximumVariableSize =3D mVariableModuleGlobal->MaxVariableSize - Ge= tVariableHeaderSize (); + *MaximumVariableSize =3D mVariableModuleGlobal->MaxVariableSize - + GetVariableHeaderSize (mVariableModuleGlob= al->VariableGlobal.AuthFormat); } else { - *MaximumVariableSize =3D mVariableModuleGlobal->MaxVolatileVariableS= ize - GetVariableHeaderSize (); + *MaximumVariableSize =3D mVariableModuleGlobal->MaxVolatileVariabl= eSize - + GetVariableHeaderSize (mVariableModuleGlob= al->VariableGlobal.AuthFormat); } } =20 @@ -2785,7 +2854,7 @@ VariableServiceQueryVariableInfoInternal ( // Now walk through the related variable store. // while (IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHead= er))) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, mVariableModuleGlobal->= VariableGlobal.AuthFormat); VariableSize =3D (UINT64) (UINTN) NextVariable - (UINT64) (UINTN) Vari= able; =20 if (AtRuntime ()) { @@ -2820,10 +2889,11 @@ VariableServiceQueryVariableInfoInternal ( VariablePtrTrack.StartPtr =3D GetStartPointer (VariableStoreHeader= ); VariablePtrTrack.EndPtr =3D GetEndPointer (VariableStoreHeader= ); Status =3D FindVariableEx ( - GetVariableNamePtr (Variable), - GetVendorGuidPtr (Variable), + GetVariableNamePtr (Variable, mVariableModuleGlobal->Va= riableGlobal.AuthFormat), + GetVendorGuidPtr (Variable, mVariableModuleGlobal->Vari= ableGlobal.AuthFormat), FALSE, - &VariablePtrTrack + &VariablePtrTrack, + mVariableModuleGlobal->VariableGlobal.AuthFormat ); if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State !=3D VA= R_ADDED) { if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) = =3D=3D EFI_VARIABLE_HARDWARE_ERROR_RECORD) { @@ -2851,10 +2921,13 @@ VariableServiceQueryVariableInfoInternal ( } } =20 - if (*RemainingVariableStorageSize < GetVariableHeaderSize ()) { + if (*RemainingVariableStorageSize < GetVariableHeaderSize (mVariableModu= leGlobal->VariableGlobal.AuthFormat)) { *MaximumVariableSize =3D 0; - } else if ((*RemainingVariableStorageSize - GetVariableHeaderSize ()) < = *MaximumVariableSize) { - *MaximumVariableSize =3D *RemainingVariableStorageSize - GetVariableHe= aderSize (); + } else if ((*RemainingVariableStorageSize - GetVariableHeaderSize (mVari= ableModuleGlobal->VariableGlobal.AuthFormat)) < + *MaximumVariableSize + ) { + *MaximumVariableSize =3D *RemainingVariableStorageSize - + GetVariableHeaderSize (mVariableModuleGlobal-= >VariableGlobal.AuthFormat); } =20 return EFI_SUCCESS; @@ -3331,7 +3404,7 @@ InitNonVolatileVariableStore ( // Variable =3D GetStartPointer (mNvVariableCache); while (IsValidVariableHeader (Variable, GetEndPointer (mNvVariableCache)= )) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, mVariableModuleGlobal->= VariableGlobal.AuthFormat); VariableSize =3D (UINTN) NextVariable - (UINTN) Variable; if ((Variable->Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_= HARDWARE_ERROR_RECORD)) =3D=3D (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HA= RDWARE_ERROR_RECORD)) { mVariableModuleGlobal->HwErrVariableTotalSize +=3D VariableSize; @@ -3365,8 +3438,10 @@ FlushHobVariableToFlash ( VOID *VariableData; VARIABLE_POINTER_TRACK VariablePtrTrack; BOOLEAN ErrorFlag; + BOOLEAN AuthFormat; =20 ErrorFlag =3D FALSE; + AuthFormat =3D mVariableModuleGlobal->VariableGlobal.AuthFormat; =20 // // Flush the HOB variable to flash. @@ -3379,7 +3454,7 @@ FlushHobVariableToFlash ( mVariableModuleGlobal->VariableGlobal.HobVariableBase =3D 0; for ( Variable =3D GetStartPointer (VariableStoreHeader) ; IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHea= der)) - ; Variable =3D GetNextVariablePtr (Variable) + ; Variable =3D GetNextVariablePtr (Variable, AuthFormat) ) { if (Variable->State !=3D VAR_ADDED) { // @@ -3389,22 +3464,33 @@ FlushHobVariableToFlash ( } ASSERT ((Variable->Attributes & EFI_VARIABLE_NON_VOLATILE) !=3D 0); if (VendorGuid =3D=3D NULL || VariableName =3D=3D NULL || - !CompareGuid (VendorGuid, GetVendorGuidPtr (Variable)) || - StrCmp (VariableName, GetVariableNamePtr (Variable)) !=3D 0) { - VariableData =3D GetVariableDataPtr (Variable); - FindVariable (GetVariableNamePtr (Variable), GetVendorGuidPtr (Var= iable), &VariablePtrTrack, &mVariableModuleGlobal->VariableGlobal, FALSE); + !CompareGuid (VendorGuid, GetVendorGuidPtr (Variable, AuthFormat= )) || + StrCmp (VariableName, GetVariableNamePtr (Variable, AuthFormat))= !=3D 0) { + VariableData =3D GetVariableDataPtr (Variable, AuthFormat); + FindVariable ( + GetVariableNamePtr (Variable, AuthFormat), + GetVendorGuidPtr (Variable, AuthFormat), + &VariablePtrTrack, + &mVariableModuleGlobal->VariableGlobal, FALSE + ); Status =3D UpdateVariable ( - GetVariableNamePtr (Variable), - GetVendorGuidPtr (Variable), + GetVariableNamePtr (Variable, AuthFormat), + GetVendorGuidPtr (Variable, AuthFormat), VariableData, - DataSizeOfVariable (Variable), + DataSizeOfVariable (Variable, AuthFormat), Variable->Attributes, 0, 0, &VariablePtrTrack, NULL ); - DEBUG ((EFI_D_INFO, "Variable driver flush the HOB variable to fla= sh: %g %s %r\n", GetVendorGuidPtr (Variable), GetVariableNamePtr (Variable)= , Status)); + DEBUG (( + DEBUG_INFO, + "Variable driver flush the HOB variable to flash: %g %s %r\n", + GetVendorGuidPtr (Variable, AuthFormat), + GetVariableNamePtr (Variable, AuthFormat), + Status + )); } else { // // The updated or deleted variable is matched with this HOB variab= le. @@ -3418,7 +3504,12 @@ FlushHobVariableToFlash ( // If set variable successful, or the updated or deleted variable = is matched with the HOB variable, // set the HOB variable to DELETED state in local. // - DEBUG ((EFI_D_INFO, "Variable driver set the HOB variable to DELET= ED state in local: %g %s\n", GetVendorGuidPtr (Variable), GetVariableNamePt= r (Variable))); + DEBUG (( + DEBUG_INFO, + "Variable driver set the HOB variable to DELETED state in local:= %g %s\n", + GetVendorGuidPtr (Variable, AuthFormat), + GetVariableNamePtr (Variable, AuthFormat) + )); Variable->State &=3D VAR_DELETED; } else { ErrorFlag =3D TRUE; @@ -3495,7 +3586,8 @@ VariableWriteServiceInitialize ( // Authenticated variable initialize. // mAuthContextIn.StructSize =3D sizeof (AUTH_VAR_LIB_CONTEXT_IN); - mAuthContextIn.MaxAuthVariableSize =3D mVariableModuleGlobal->MaxAuthV= ariableSize - GetVariableHeaderSize (); + mAuthContextIn.MaxAuthVariableSize =3D mVariableModuleGlobal->MaxAuth= VariableSize - + GetVariableHeaderSize (mVariab= leModuleGlobal->VariableGlobal.AuthFormat); Status =3D AuthVariableLibInitialize (&mAuthContextIn, &mAuthContextOu= t); if (!EFI_ERROR (Status)) { DEBUG ((EFI_D_INFO, "Variable driver will work with auth variable su= pport!\n")); @@ -3574,7 +3666,7 @@ ConvertNormalVarStorageToAuthVarStorage ( AuthVarStroageSize +=3D StartPtr->NameSize + GET_PAD_SIZE (StartPtr-= >NameSize); AuthVarStroageSize +=3D StartPtr->DataSize + GET_PAD_SIZE (StartPtr-= >DataSize); } - StartPtr =3D GetNextVariablePtr (StartPtr); + StartPtr =3D GetNextVariablePtr (StartPtr, mVariableModuleGlobal->Var= iableGlobal.AuthFormat); } =20 // @@ -3608,18 +3700,22 @@ ConvertNormalVarStorageToAuthVarStorage ( // Copy Variable Name // NextPtr =3D (UINT8 *) (AuthStartPtr + 1); - CopyMem (NextPtr, GetVariableNamePtr (StartPtr), AuthStartPtr->NameS= ize); + CopyMem ( + NextPtr, + GetVariableNamePtr (StartPtr, mVariableModuleGlobal->VariableGloba= l.AuthFormat), + AuthStartPtr->NameSize + ); // // Copy Variable Data // NextPtr =3D NextPtr + AuthStartPtr->NameSize + GET_PAD_SIZE (AuthSta= rtPtr->NameSize); - CopyMem (NextPtr, GetVariableDataPtr (StartPtr), AuthStartPtr->DataS= ize); + CopyMem (NextPtr, GetVariableDataPtr (StartPtr, mVariableModuleGloba= l->VariableGlobal.AuthFormat), AuthStartPtr->DataSize); // // Go to next variable // AuthStartPtr =3D (AUTHENTICATED_VARIABLE_HEADER *) (NextPtr + AuthSt= artPtr->DataSize + GET_PAD_SIZE (AuthStartPtr->DataSize)); } - StartPtr =3D GetNextVariablePtr (StartPtr); + StartPtr =3D GetNextVariablePtr (StartPtr, mVariableModuleGlobal->Vari= ableGlobal.AuthFormat); } // // Update Auth Storage Header diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c b/M= deModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c index c787ddba5b..e865a089d1 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c @@ -56,8 +56,8 @@ VariableExLibFindVariable ( return Status; } =20 - AuthVariableInfo->DataSize =3D DataSizeOfVariable (Variable.CurrP= tr); - AuthVariableInfo->Data =3D GetVariableDataPtr (Variable.CurrP= tr); + AuthVariableInfo->DataSize =3D DataSizeOfVariable (Variable.CurrP= tr, mVariableModuleGlobal->VariableGlobal.AuthFormat); + AuthVariableInfo->Data =3D GetVariableDataPtr (Variable.CurrP= tr, mVariableModuleGlobal->VariableGlobal.AuthFormat); AuthVariableInfo->Attributes =3D Variable.CurrPtr->Attributes; if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable.CurrPtr; @@ -108,7 +108,8 @@ VariableExLibFindNextVariable ( VariableName, VendorGuid, VariableStoreHeader, - &VariablePtr + &VariablePtr, + mVariableModuleGlobal->VariableGlobal.AuthFormat ); if (EFI_ERROR (Status)) { AuthVariableInfo->VariableName =3D NULL; @@ -122,10 +123,10 @@ VariableExLibFindNextVariable ( return Status; } =20 - AuthVariableInfo->VariableName =3D GetVariableNamePtr (VariablePtr); - AuthVariableInfo->VendorGuid =3D GetVendorGuidPtr (VariablePtr); - AuthVariableInfo->DataSize =3D DataSizeOfVariable (VariablePtr); - AuthVariableInfo->Data =3D GetVariableDataPtr (VariablePtr); + AuthVariableInfo->VariableName =3D GetVariableNamePtr (VariablePtr, m= VariableModuleGlobal->VariableGlobal.AuthFormat); + AuthVariableInfo->VendorGuid =3D GetVendorGuidPtr (VariablePtr, mVa= riableModuleGlobal->VariableGlobal.AuthFormat); + AuthVariableInfo->DataSize =3D DataSizeOfVariable (VariablePtr, m= VariableModuleGlobal->VariableGlobal.AuthFormat); + AuthVariableInfo->Data =3D GetVariableDataPtr (VariablePtr, m= VariableModuleGlobal->VariableGlobal.AuthFormat); AuthVariableInfo->Attributes =3D VariablePtr->Attributes; if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { AuthVariablePtr =3D (AUTHENTICATED_VARIABLE_HEADER *) VariablePtr; diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c b= /MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c index 870c9e3742..d458f1c608 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c @@ -78,17 +78,20 @@ GetVariableStoreStatus ( /** This code gets the size of variable header. =20 + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. + @return Size of variable header in bytes in type UINTN. =20 **/ UINTN GetVariableHeaderSize ( - VOID + IN BOOLEAN AuthFormat ) { UINTN Value; =20 - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthFormat) { Value =3D sizeof (AUTHENTICATED_VARIABLE_HEADER); } else { Value =3D sizeof (VARIABLE_HEADER); @@ -101,20 +104,23 @@ GetVariableHeaderSize ( =20 This code gets the size of name of variable. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the variable header. + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. =20 @return UINTN Size of variable in bytes. =20 **/ UINTN NameSizeOfVariable ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { AUTHENTICATED_VARIABLE_HEADER *AuthVariable; =20 AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthFormat) { if (AuthVariable->State =3D=3D (UINT8) (-1) || AuthVariable->DataSize =3D=3D (UINT32) (-1) || AuthVariable->NameSize =3D=3D (UINT32) (-1) || @@ -136,20 +142,23 @@ NameSizeOfVariable ( /** This code sets the size of name of variable. =20 - @param[in] Variable Pointer to the Variable Header. - @param[in] NameSize Name size to set. + @param[in] Variable Pointer to the Variable Header. + @param[in] NameSize Name size to set. + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. =20 **/ VOID SetNameSizeOfVariable ( IN VARIABLE_HEADER *Variable, - IN UINTN NameSize + IN UINTN NameSize, + IN BOOLEAN AuthFormat ) { AUTHENTICATED_VARIABLE_HEADER *AuthVariable; =20 AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthFormat) { AuthVariable->NameSize =3D (UINT32) NameSize; } else { Variable->NameSize =3D (UINT32) NameSize; @@ -160,20 +169,23 @@ SetNameSizeOfVariable ( =20 This code gets the size of variable data. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. =20 @return Size of variable in bytes. =20 **/ UINTN DataSizeOfVariable ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { AUTHENTICATED_VARIABLE_HEADER *AuthVariable; =20 AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthFormat) { if (AuthVariable->State =3D=3D (UINT8) (-1) || AuthVariable->DataSize =3D=3D (UINT32) (-1) || AuthVariable->NameSize =3D=3D (UINT32) (-1) || @@ -197,18 +209,21 @@ DataSizeOfVariable ( =20 @param[in] Variable Pointer to the Variable Header. @param[in] DataSize Data size to set. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not us= ed. =20 **/ VOID SetDataSizeOfVariable ( - IN VARIABLE_HEADER *Variable, - IN UINTN DataSize + IN VARIABLE_HEADER *Variable, + IN UINTN DataSize, + IN BOOLEAN AuthFormat ) { AUTHENTICATED_VARIABLE_HEADER *AuthVariable; =20 AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthFormat) { AuthVariable->DataSize =3D (UINT32) DataSize; } else { Variable->DataSize =3D (UINT32) DataSize; @@ -219,36 +234,42 @@ SetDataSizeOfVariable ( =20 This code gets the pointer to the variable name. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Pointer to Variable Name which is Unicode encoding. =20 **/ CHAR16 * GetVariableNamePtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { - return (CHAR16 *) ((UINTN) Variable + GetVariableHeaderSize ()); + return (CHAR16 *) ((UINTN) Variable + GetVariableHeaderSize (AuthFormat)= ); } =20 /** This code gets the pointer to the variable guid. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return A EFI_GUID* pointer to Vendor Guid. =20 **/ EFI_GUID * GetVendorGuidPtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { AUTHENTICATED_VARIABLE_HEADER *AuthVariable; =20 AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthFormat) { return &AuthVariable->VendorGuid; } else { return &Variable->VendorGuid; @@ -259,14 +280,17 @@ GetVendorGuidPtr ( =20 This code gets the pointer to the variable data. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Pointer to Variable Data. =20 **/ UINT8 * GetVariableDataPtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { UINTN Value; @@ -274,9 +298,9 @@ GetVariableDataPtr ( // // Be careful about pad size for alignment. // - Value =3D (UINTN) GetVariableNamePtr (Variable); - Value +=3D NameSizeOfVariable (Variable); - Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable)); + Value =3D (UINTN) GetVariableNamePtr (Variable, AuthFormat); + Value +=3D NameSizeOfVariable (Variable, AuthFormat); + Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable, AuthFormat)); =20 return (UINT8 *) Value; } @@ -284,14 +308,17 @@ GetVariableDataPtr ( /** This code gets the variable data offset related to variable header. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Variable Data offset. =20 **/ UINTN GetVariableDataOffset ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { UINTN Value; @@ -299,9 +326,9 @@ GetVariableDataOffset ( // // Be careful about pad size for alignment // - Value =3D GetVariableHeaderSize (); - Value +=3D NameSizeOfVariable (Variable); - Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable)); + Value =3D GetVariableHeaderSize (AuthFormat); + Value +=3D NameSizeOfVariable (Variable, AuthFormat); + Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable, AuthFormat)); =20 return Value; } @@ -310,21 +337,24 @@ GetVariableDataOffset ( =20 This code gets the pointer to the next variable header. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Pointer to next variable header. =20 **/ VARIABLE_HEADER * GetNextVariablePtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { UINTN Value; =20 - Value =3D (UINTN) GetVariableDataPtr (Variable); - Value +=3D DataSizeOfVariable (Variable); - Value +=3D GET_PAD_SIZE (DataSizeOfVariable (Variable)); + Value =3D (UINTN) GetVariableDataPtr (Variable, AuthFormat); + Value +=3D DataSizeOfVariable (Variable, AuthFormat); + Value +=3D GET_PAD_SIZE (DataSizeOfVariable (Variable, AuthFormat)); =20 // // Be careful about pad size for alignment. @@ -415,6 +445,8 @@ VariableCompareTimeStampInternal ( @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS = attribute check at runtime when searching var= iable. @param[in, out] PtrTrack Variable Track Pointer structure th= at contains Variable Information. + @param[in] AuthFormat TRUE indicates authenticated variab= les are used. + FALSE indicates authenticated varia= bles are not used. =20 @retval EFI_SUCCESS Variable found successfully @retval EFI_NOT_FOUND Variable not found @@ -424,7 +456,8 @@ FindVariableEx ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN BOOLEAN IgnoreRtCheck, - IN OUT VARIABLE_POINTER_TRACK *PtrTrack + IN OUT VARIABLE_POINTER_TRACK *PtrTrack, + IN BOOLEAN AuthFormat ) { VARIABLE_HEADER *InDeletedVariable; @@ -439,7 +472,7 @@ FindVariableEx ( =20 for ( PtrTrack->CurrPtr =3D PtrTrack->StartPtr ; IsValidVariableHeader (PtrTrack->CurrPtr, PtrTrack->EndPtr) - ; PtrTrack->CurrPtr =3D GetNextVariablePtr (PtrTrack->CurrPtr) + ; PtrTrack->CurrPtr =3D GetNextVariablePtr (PtrTrack->CurrPtr, AuthF= ormat) ) { if (PtrTrack->CurrPtr->State =3D=3D VAR_ADDED || PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITION & VAR_A= DDED) @@ -453,11 +486,11 @@ FindVariableEx ( return EFI_SUCCESS; } } else { - if (CompareGuid (VendorGuid, GetVendorGuidPtr (PtrTrack->CurrPtr= ))) { - Point =3D (VOID *) GetVariableNamePtr (PtrTrack->CurrPtr); + if (CompareGuid (VendorGuid, GetVendorGuidPtr (PtrTrack->CurrPtr= , AuthFormat))) { + Point =3D (VOID *) GetVariableNamePtr (PtrTrack->CurrPtr, Auth= Format); =20 - ASSERT (NameSizeOfVariable (PtrTrack->CurrPtr) !=3D 0); - if (CompareMem (VariableName, Point, NameSizeOfVariable (PtrTr= ack->CurrPtr)) =3D=3D 0) { + ASSERT (NameSizeOfVariable (PtrTrack->CurrPtr, AuthFormat) != =3D 0); + if (CompareMem (VariableName, Point, NameSizeOfVariable (PtrTr= ack->CurrPtr, AuthFormat)) =3D=3D 0) { if (PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITI= ON & VAR_ADDED)) { InDeletedVariable =3D PtrTrack->CurrPtr; } else { @@ -486,6 +519,8 @@ FindVariableEx ( @param[in] VariableStoreList A list of variable stores that should be u= sed to get the next variable. The maximum number of entries is the max v= alue of VARIABLE_STORE_TYPE. @param[out] VariablePtr Pointer to variable header address. + @param[in] AuthFormat TRUE indicates authenticated variables are= used. + FALSE indicates authenticated variables ar= e not used. =20 @retval EFI_SUCCESS The function completed successfully. @retval EFI_NOT_FOUND The next variable was not found. @@ -500,7 +535,8 @@ VariableServiceGetNextVariableInternal ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN VARIABLE_STORE_HEADER **VariableStoreList, - OUT VARIABLE_HEADER **VariablePtr + OUT VARIABLE_HEADER **VariablePtr, + IN BOOLEAN AuthFormat ) { EFI_STATUS Status; @@ -525,7 +561,7 @@ VariableServiceGetNextVariableInternal ( Variable.EndPtr =3D GetEndPointer (VariableStoreList[StoreType]); Variable.Volatile =3D (BOOLEAN) (StoreType =3D=3D VariableStoreTypeVol= atile); =20 - Status =3D FindVariableEx (VariableName, VendorGuid, FALSE, &Variable); + Status =3D FindVariableEx (VariableName, VendorGuid, FALSE, &Variable,= AuthFormat); if (!EFI_ERROR (Status)) { break; } @@ -552,7 +588,7 @@ VariableServiceGetNextVariableInternal ( // // If variable name is not empty, get next variable. // - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr, AuthFormat); } =20 while (TRUE) { @@ -605,13 +641,14 @@ VariableServiceGetNextVariableInternal ( VariablePtrTrack.StartPtr =3D Variable.StartPtr; VariablePtrTrack.EndPtr =3D Variable.EndPtr; Status =3D FindVariableEx ( - GetVariableNamePtr (Variable.CurrPtr), - GetVendorGuidPtr (Variable.CurrPtr), + GetVariableNamePtr (Variable.CurrPtr, AuthFormat), + GetVendorGuidPtr (Variable.CurrPtr, AuthFormat), FALSE, - &VariablePtrTrack + &VariablePtrTrack, + AuthFormat ); if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State =3D= =3D VAR_ADDED) { - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr, Aut= hFormat); continue; } } @@ -625,13 +662,14 @@ VariableServiceGetNextVariableInternal ( VariableInHob.StartPtr =3D GetStartPointer (VariableStoreList[Va= riableStoreTypeHob]); VariableInHob.EndPtr =3D GetEndPointer (VariableStoreList[Va= riableStoreTypeHob]); Status =3D FindVariableEx ( - GetVariableNamePtr (Variable.CurrPtr), - GetVendorGuidPtr (Variable.CurrPtr), + GetVariableNamePtr (Variable.CurrPtr, AuthFormat), + GetVendorGuidPtr (Variable.CurrPtr, AuthFormat), FALSE, - &VariableInHob + &VariableInHob, + AuthFormat ); if (!EFI_ERROR (Status)) { - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr, Aut= hFormat); continue; } } @@ -642,7 +680,7 @@ VariableServiceGetNextVariableInternal ( } } =20 - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr, AuthFormat); } =20 Done: diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/Mde= ModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c index ce409f22a3..5e24bc4a62 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c @@ -975,8 +975,9 @@ MmVariableServiceInitialize ( ); ASSERT_EFI_ERROR (Status); =20 - mVariableBufferPayloadSize =3D GetMaxVariableSize () + - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHE= CK_VARIABLE_PROPERTY, Name) - GetVariableHeaderSize (); + mVariableBufferPayloadSize =3D GetMaxVariableSize () + + OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_= CHECK_VARIABLE_PROPERTY, Name) - + GetVariableHeaderSize (mVariableModuleGl= obal->VariableGlobal.AuthFormat); =20 Status =3D gMmst->MmAllocatePool ( EfiRuntimeServicesData, --=20 2.16.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#49824): https://edk2.groups.io/g/devel/message/49824 Mute This Topic: https://groups.io/mt/40450325/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-