From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web10.20772.1641978080064905777 for ; Wed, 12 Jan 2022 01:01:20 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=NesFvSoz; spf=pass (domain: intel.com, ip: 192.55.52.93, 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=1641978080; x=1673514080; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=8RZtd4TSdzHO3b4pkRd8YOF+D/pPRAL9zEHv/kgXaYo=; b=NesFvSozdPa5hAaEyA5M2j6WFcGBsLlR+vp6yflQY/AdtxrqgTTVPdFb 4GVnBaNervX5q85d4DC2gH85YQj7g1qIBMF3/dUdyHEmdfa54olRvtddD TKHw5mJejTHsHBrjOfXBJtipiqurFZIdsJ4LidKGrQ9pTorTNFkLNN33c FFq9S9eQCbTER8o8NLbJJuIigA0K0YO9jayMDATwaO4sUjBGcujZ5Sttk Ir2kT2O+6nZMYDCHcG+5NawiU3yzwiG7WoTbqgIkzFGf7IfO0rYyHksQG TvUXwEaTW0q5QvBSQXYmA/PATFk8gfcUgDgJf7hspxY7uPaZgOneEPU8U A==; X-IronPort-AV: E=McAfee;i="6200,9189,10224"; a="241246480" X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="241246480" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2022 01:01:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,282,1635231600"; d="scan'208";a="613509060" Received: from shbiosbuild1001.sh.intel.com ([10.239.132.191]) by FMSMGA003.fm.intel.com with ESMTP; 12 Jan 2022 01:01:16 -0800 From: "Long1 Huang" To: devel@edk2.groups.io Cc: Huang Long , Bob Feng , Liming Gao , Dandan Bi , Lin Z Chen , Zhuangzhi Li Subject: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for authenticated variable Date: Wed, 12 Jan 2022 17:06:25 +0000 Message-Id: <802446c5bddb6e7de746d733c68d92c0e09e5ca8.1642007174.git.long1.huang@intel.com> 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. Signed-off-by: Huang Long Cc: Bob Feng Cc: Liming Gao Cc: Dandan Bi Cc: Lin Z Chen Cc: Zhuangzhi Li --- .../Universal/HiiDatabaseDxe/Database.c | 130 ++++++++++++++---- .../HiiDatabaseDxe/HiiDatabaseDxe.inf | 3 + 2 files changed, 105 insertions(+), 28 deletions(-) diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c b/MdeModulePk= g/Universal/HiiDatabaseDxe/Database.c index 0b09c24d52..c7a92d6aed 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,29 @@ 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 + VOID *ValueSource;=0D + VOID *BitValueSource;=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 +709,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 +793,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,8 +828,24 @@ FindQuestionDefaultSetting ( Width =3D EndBit / 8 + 1;=0D }=0D =0D - if (VariableHeader->DataSize < ByteOffset + Width) {=0D - return EFI_INVALID_PARAMETER;=0D + if (AuthFormat) {=0D + if (AuthVariableHeader->DataSize < ByteOffset + Width) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + ValueSource =3D (UINT8 *)AuthVariableHeader + sizeof (AUTHENTICATED_VA= RIABLE_HEADER) + AuthVariableHeader->NameSize + IfrQuestionHdr->VarStoreInf= o.VarOffset;=0D + if (BitFieldQuestion) {=0D + BitValueSource =3D (UINT8 *)AuthVariableHeader + sizeof (AUTHENTICAT= ED_VARIABLE_HEADER) + AuthVariableHeader->NameSize + ByteOffset;=0D + }=0D + } else {=0D + if (VariableHeader->DataSize < ByteOffset + Width) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + ValueSource =3D (UINT8 *)VariableHeader + sizeof (VARIABLE_HEADER) + V= ariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset;=0D + if (BitFieldQuestion) {=0D + BitValueSource =3D (UINT8 *)VariableHeader + sizeof (VARIABLE_HEADER= ) + VariableHeader->NameSize + ByteOffset;=0D + }=0D }=0D =0D //=0D @@ -779,11 +853,11 @@ FindQuestionDefaultSetting ( //=0D if (ValueBuffer !=3D NULL) {=0D if (BitFieldQuestion) {=0D - CopyMem (&BufferValue, (UINT8 *)VariableHeader + sizeof (VARIABLE_HE= ADER) + VariableHeader->NameSize + ByteOffset, Width);=0D + CopyMem (&BufferValue, BitValueSource, 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 + CopyMem (ValueBuffer, ValueSource, Width);=0D }=0D }=0D =0D @@ -832,7 +906,7 @@ UpdateDefaultSettingInFormPackage ( // If no default setting, do nothing=0D //=0D if (gNvDefaultStoreSize =3D=3D 0) {=0D - gNvDefaultStoreSize =3D PcdGetSize (PcdNvStoreDefaultValueBuffer);=0D + gNvDefaultStoreSize =3D PcdGetExSize (&gEfiMdeModulePkgTokenSpaceGuid,= PcdNvStoreDefaultValueBuffer);=0D }=0D =0D if (gNvDefaultStoreSize < sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {= =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