From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web10.29318.1641805066605234034 for ; Mon, 10 Jan 2022 00:57:46 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=ca92r7qH; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: long1.huang@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641805066; x=1673341066; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=LgYDuifn/Jm8xLWDFRW3ycn5pbywdordelKI6Fpy+wc=; b=ca92r7qHQZMbk+7IogNyuQaY3+9jv11yczQcetN3M7cn4QO+wAZvWX3I 4zc42yuhhwG7/XBcWtQVthy1Xcy32egqYX+vopQLZ0AJyWQE9Pq+wo3Bl r4lYiGuTlWRQpClM2Z6hfEVQ0lPICucSc+kgBUhLFMHa7S3c+EFCcQMan N0Fmm6RNsGCHMFpgbKF5gcNAe4g+kvPtT7AbQKuBCSEPZSHsDd/kjJIkv pNM5VTa1cxje3SJP/gkAzJKq0bkBByPhyZGiSL2H30zi19/KhaR1kLl/9 /Z99SoGN0PTBcNKQMf8HfpkrbEq+xJBMLfnqdZRwvpFSwR//Kr48LP3Am g==; X-IronPort-AV: E=McAfee;i="6200,9189,10222"; a="243382880" X-IronPort-AV: E=Sophos;i="5.88,276,1635231600"; d="scan'208";a="243382880" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2022 00:57:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,276,1635231600"; d="scan'208";a="528193132" Received: from shbiosbuild1001.sh.intel.com ([10.239.132.191]) by orsmga008.jf.intel.com with ESMTP; 10 Jan 2022 00:57:43 -0800 From: "Long1 Huang" To: devel@edk2.groups.io Cc: Huang Long , Liming Gao , Chen Lin Z , Dandan Bi Subject: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for authenticated variable Date: Mon, 10 Jan 2022 17:02:44 +0000 Message-Id: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3796 Database.c: 1. Replace PcdGetExPtr with PcdGetExPtr. 2. Add FindAuthVariableData function to parse authenticated variable type = for getting a correct default value in PcdNvStoreDefaultValueBuffer. Cc: Liming Gao Cc: Chen Lin Z Cc: Dandan Bi Signed-off-by: Huang Long --- .../Universal/HiiDatabaseDxe/Database.c | 147 +++++++++++++----- .../HiiDatabaseDxe/HiiDatabaseDxe.inf | 3 + 2 files changed, 114 insertions(+), 36 deletions(-) diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c b/MdeModulePk= g/Universal/HiiDatabaseDxe/Database.c index 0b09c24d52..c055fa0f29 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c @@ -603,6 +603,45 @@ FindVariableData ( return NULL;=0D }=0D =0D +/**=0D + Find the matched authenticated variable from the input variable storage.= =0D +=0D + @param[in] VariableStorage Point to the variable storage header.=0D + @param[in] VarGuid A unique identifier for the variable.=0D + @param[in] VarAttribute The attributes bitmask for the variable.=0D + @param[in] VarName A Null-terminated ascii string that is the na= me of the variable.=0D +=0D + @return Pointer to the matched variable header or NULL if not found.=0D +**/=0D +AUTHENTICATED_VARIABLE_HEADER *=0D +FindAuthVariableData (=0D + IN VARIABLE_STORE_HEADER *VariableStorage,=0D + IN EFI_GUID *VarGuid,=0D + IN UINT32 VarAttribute,=0D + IN CHAR16 *VarName=0D + )=0D +{=0D + AUTHENTICATED_VARIABLE_HEADER *AuthVariableHeader;=0D + AUTHENTICATED_VARIABLE_HEADER *AuthVariableEnd;=0D +=0D + AuthVariableEnd =3D (AUTHENTICATED_VARIABLE_HEADER *)((UINT8 *)Variab= leStorage + VariableStorage->Size);=0D + AuthVariableHeader =3D (AUTHENTICATED_VARIABLE_HEADER *)(VariableStorage= + 1);=0D + AuthVariableHeader =3D (AUTHENTICATED_VARIABLE_HEADER *)HEADER_ALIGN (Au= thVariableHeader);=0D + while (AuthVariableHeader < AuthVariableEnd) {=0D + if (CompareGuid (&AuthVariableHeader->VendorGuid, VarGuid) &&=0D + (AuthVariableHeader->Attributes =3D=3D VarAttribute) &&=0D + (StrCmp (VarName, (CHAR16 *)(AuthVariableHeader + 1)) =3D=3D 0))=0D + {=0D + return AuthVariableHeader;=0D + }=0D +=0D + AuthVariableHeader =3D (AUTHENTICATED_VARIABLE_HEADER *)((UINT8 *)Auth= VariableHeader + sizeof (AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeade= r->NameSize + AuthVariableHeader->DataSize);=0D + AuthVariableHeader =3D (AUTHENTICATED_VARIABLE_HEADER *)HEADER_ALIGN (= AuthVariableHeader);=0D + }=0D +=0D + return NULL;=0D +}=0D +=0D /**=0D Find question default value from PcdNvStoreDefaultValueBuffer=0D =0D @@ -626,25 +665,27 @@ FindQuestionDefaultSetting ( IN BOOLEAN BitFieldQuestion=0D )=0D {=0D - VARIABLE_HEADER *VariableHeader;=0D - VARIABLE_STORE_HEADER *VariableStorage;=0D - LIST_ENTRY *Link;=0D - VARSTORAGE_DEFAULT_DATA *Entry;=0D - VARIABLE_STORE_HEADER *NvStoreBuffer;=0D - UINT8 *DataBuffer;=0D - UINT8 *BufferEnd;=0D - BOOLEAN IsFound;=0D - UINTN Index;=0D - UINT32 BufferValue;=0D - UINT32 BitFieldVal;=0D - UINTN BitOffset;=0D - UINTN ByteOffset;=0D - UINTN BitWidth;=0D - UINTN StartBit;=0D - UINTN EndBit;=0D - PCD_DEFAULT_DATA *DataHeader;=0D - PCD_DEFAULT_INFO *DefaultInfo;=0D - PCD_DATA_DELTA *DeltaData;=0D + VARIABLE_HEADER *VariableHeader;=0D + AUTHENTICATED_VARIABLE_HEADER *AuthVariableHeader;=0D + VARIABLE_STORE_HEADER *VariableStorage;=0D + LIST_ENTRY *Link;=0D + VARSTORAGE_DEFAULT_DATA *Entry;=0D + VARIABLE_STORE_HEADER *NvStoreBuffer;=0D + UINT8 *DataBuffer;=0D + UINT8 *BufferEnd;=0D + BOOLEAN AuthFormat;=0D + BOOLEAN IsFound;=0D + UINTN Index;=0D + UINT32 BufferValue;=0D + UINT32 BitFieldVal;=0D + UINTN BitOffset;=0D + UINTN ByteOffset;=0D + UINTN BitWidth;=0D + UINTN StartBit;=0D + UINTN EndBit;=0D + PCD_DEFAULT_DATA *DataHeader;=0D + PCD_DEFAULT_INFO *DefaultInfo;=0D + PCD_DATA_DELTA *DeltaData;=0D =0D if (gSkuId =3D=3D 0xFFFFFFFFFFFFFFFF) {=0D gSkuId =3D LibPcdGetSku ();=0D @@ -666,7 +707,7 @@ FindQuestionDefaultSetting ( }=0D =0D if (Link =3D=3D &gVarStorageList) {=0D - DataBuffer =3D (UINT8 *)PcdGetPtr (PcdNvStoreDefaultValueBuff= er);=0D + DataBuffer =3D (UINT8 *)PcdGetExPtr (&gEfiMdeModulePkgTokenSp= aceGuid, PcdNvStoreDefaultValueBuffer);=0D gNvDefaultStoreSize =3D ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER *)DataBuf= fer)->Length;=0D //=0D // The first section data includes NV storage default setting.=0D @@ -750,12 +791,27 @@ FindQuestionDefaultSetting ( return EFI_NOT_FOUND;=0D }=0D =0D + //=0D + // Judge if the variable type is authenticated, default is false=0D + //=0D + AuthFormat =3D FALSE;=0D + if (CompareGuid (&VariableStorage->Signature, &gEfiAuthenticatedVariable= Guid)) {=0D + AuthFormat =3D TRUE;=0D + }=0D +=0D //=0D // Find the question default value from the variable storage=0D //=0D - VariableHeader =3D FindVariableData (VariableStorage, &EfiVarStore->Guid= , EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);=0D - if (VariableHeader =3D=3D NULL) {=0D - return EFI_NOT_FOUND;=0D + if(AuthFormat) {=0D + AuthVariableHeader =3D FindAuthVariableData (VariableStorage, &EfiVarS= tore->Guid, EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);=0D + if (AuthVariableHeader =3D=3D NULL) {=0D + return EFI_NOT_FOUND;=0D + }=0D + } else {=0D + VariableHeader =3D FindVariableData (VariableStorage, &EfiVarStore->Gu= id, EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);=0D + if (VariableHeader =3D=3D NULL) {=0D + return EFI_NOT_FOUND;=0D + }=0D }=0D =0D StartBit =3D 0;=0D @@ -770,20 +826,39 @@ FindQuestionDefaultSetting ( Width =3D EndBit / 8 + 1;=0D }=0D =0D - if (VariableHeader->DataSize < ByteOffset + Width) {=0D - return EFI_INVALID_PARAMETER;=0D - }=0D + if(AuthFormat) {=0D + if (AuthVariableHeader->DataSize < ByteOffset + Width) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D =0D - //=0D - // Copy the question value=0D - //=0D - if (ValueBuffer !=3D NULL) {=0D - if (BitFieldQuestion) {=0D - CopyMem (&BufferValue, (UINT8 *)VariableHeader + sizeof (VARIABLE_HE= ADER) + VariableHeader->NameSize + ByteOffset, Width);=0D - BitFieldVal =3D BitFieldRead32 (BufferValue, StartBit, EndBit);=0D - CopyMem (ValueBuffer, &BitFieldVal, Width);=0D - } else {=0D - CopyMem (ValueBuffer, (UINT8 *)VariableHeader + sizeof (VARIABLE_HEA= DER) + VariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset, W= idth);=0D + //=0D + // Copy the question value=0D + //=0D + if (ValueBuffer !=3D NULL) {=0D + if (BitFieldQuestion) {=0D + CopyMem (&BufferValue, (UINT8 *)AuthVariableHeader + sizeof (AUTHE= NTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize + ByteOffset, Widt= h);=0D + BitFieldVal =3D BitFieldRead32 (BufferValue, StartBit, EndBit);=0D + CopyMem (ValueBuffer, &BitFieldVal, Width);=0D + } else {=0D + CopyMem (ValueBuffer, (UINT8 *)AuthVariableHeader + sizeof (AUTHEN= TICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize + IfrQuestionHdr->V= arStoreInfo.VarOffset, Width);=0D + }=0D + }=0D + } else {=0D + if (VariableHeader->DataSize < ByteOffset + Width) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + //=0D + // Copy the question value=0D + //=0D + if (ValueBuffer !=3D NULL) {=0D + if (BitFieldQuestion) {=0D + CopyMem (&BufferValue, (UINT8 *)VariableHeader + sizeof (VARIABLE_= HEADER) + VariableHeader->NameSize + ByteOffset, Width);=0D + BitFieldVal =3D BitFieldRead32 (BufferValue, StartBit, EndBit);=0D + CopyMem (ValueBuffer, &BitFieldVal, Width);=0D + } else {=0D + CopyMem (ValueBuffer, (UINT8 *)VariableHeader + sizeof (VARIABLE_H= EADER) + VariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset,= Width);=0D + }=0D }=0D }=0D =0D diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf b/Mde= ModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf index 0116fb6ecb..dac4d614a8 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf @@ -86,6 +86,9 @@ gEfiHiiImageDecoderNameJpegGuid |gEfiMdeModulePkgTokenSpaceGuid.PcdSuppo= rtHiiImageProtocol ## SOMETIMES_CONSUMES ## GUID=0D gEfiHiiImageDecoderNamePngGuid |gEfiMdeModulePkgTokenSpaceGuid.PcdSuppo= rtHiiImageProtocol ## SOMETIMES_CONSUMES ## GUID=0D gEdkiiIfrBitVarstoreGuid = ## SOMETIMES_CONSUMES ## GUID=0D + gEfiAuthenticatedVariableGuid=0D + gEfiVariableGuid=0D + gEfiMdeModulePkgTokenSpaceGuid=0D =0D [Depex]=0D TRUE=0D --=20 2.25.1