From nobody Tue Nov 26 16:44:25 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+49723+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+49723+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1572504336; cv=none; d=zoho.com; s=zohoarc; b=LG7tKH/I1+CJuBlOdwwadPd4KCTI4oqrvimIkV6WAi0mwh3yRI4/X6A2hu06mbaS3HCpH30eN6xDjSVI/K3MJp3Y9rpp3242OGP+XkZLMTgN+C4BOead8bkrLiFNd1R/WtI+VmmyadkugAMrkxB/pqqFoVbtHEIabkq3ZDTgjXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572504336; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=7PvxuvGFHCFfnDIToIB3AZZfxONuSsjPtHpkEf1/GVI=; b=TOMOLdHLQt0AP/sJd1Az+9YmkiUnrGlVOuMwVNegS1DnmvBa2IzZ8yt8DC1qwR05SbRKBe2bvZiMi6jyQy0AJKPHVHB+igTvVVrN8DZF/M58ZRfCWg10p++auaEIOQNGnMs52vvUPX3G50BPX/KmleNxPKx3KP3Ms827/wNQb+w= 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+49723+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 1572504336407395.94886363736805; Wed, 30 Oct 2019 23:45:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id DzpMYY1788612xjJLvfdXOyc; Wed, 30 Oct 2019 23:45:36 -0700 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web10.2575.1572504335480868589 for ; Wed, 30 Oct 2019 23:45:35 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 23:45:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,250,1569308400"; d="scan'208";a="351547308" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga004.jf.intel.com with ESMTP; 30 Oct 2019 23:45:35 -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 V6 02/10] MdeModulePkg/Variable: Parameterize GetNextVariableInternal () stores Date: Wed, 30 Oct 2019 23:45:02 -0700 Message-Id: <20191031064510.23948-3-michael.a.kubacki@intel.com> In-Reply-To: <20191031064510.23948-1-michael.a.kubacki@intel.com> References: <20191031064510.23948-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: kUt1QTyrRbVRXMqjhSZKiEEnx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572504336; bh=YA/qqJeD8WrLrvHpEgBOJRW+JsYl5UfHZ8DSUBPHDBA=; h=Cc:Date:From:Reply-To:Subject:To; b=sQBtDLP+IQ+Q/O5IfS3f67dlY0syqCeBecn/IrJYhBJTll3BKGSBV3S0rII8cmvVGJd xhEhfjuYnFl2U2AKyr/7O/Dxv6HFm9mVOrUT6Nxco1TvFAljjh9s6bi7APFZM41gt5mVJ NBO+IoOTV8zGBGfooowaGkZooN65PiwvyyA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The majority of logic related to GetNextVariableName () is currently implemented in VariableServiceGetNextVariableInternal (). The list of variable stores to search for the given variable name and variable GUID is defined in the function body. This change adds a new parameter so that the caller must pass in the list of variable stores to be used in the variable search. 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 | 13 ++-- MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 12 ++- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c | 6 ++ MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c | 82 ++++++++= ++++-------- 4 files changed, 73 insertions(+), 40 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h b= /MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h index b0d7f76bd8..6555316f52 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h @@ -248,18 +248,20 @@ FindVariableEx ( ); =20 /** - This code Finds the Next available variable. + This code finds the next available variable. =20 Caution: This function may receive untrusted input. This function may be invoked in SMM mode. This function will do basic va= lidation, before parse the data. =20 - @param[in] VariableName Pointer to variable name. - @param[in] VendorGuid Variable Vendor Guid. - @param[out] VariablePtr Pointer to variable header address. + @param[in] VariableName Pointer to variable name. + @param[in] VendorGuid Variable Vendor Guid. + @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. =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 not an empty string, wh= ile VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER If VariableName is nt an empty string, whi= le 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 @@ -269,6 +271,7 @@ EFIAPI VariableServiceGetNextVariableInternal ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, + IN VARIABLE_STORE_HEADER **VariableStoreList, OUT VARIABLE_HEADER **VariablePtr ); =20 diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.c index 76536308e6..70af86db24 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -2358,6 +2358,7 @@ VariableServiceGetNextVariableName ( UINTN MaxLen; UINTN VarNameSize; VARIABLE_HEADER *VariablePtr; + VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax]; =20 if (VariableNameSize =3D=3D NULL || VariableName =3D=3D NULL || VendorGu= id =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -2377,7 +2378,16 @@ VariableServiceGetNextVariableName ( =20 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.Variabl= eServicesLock); =20 - Status =3D VariableServiceGetNextVariableInternal (VariableName, VendorG= uid, &VariablePtr); + // + // 0: Volatile, 1: HOB, 2: Non-Volatile. + // The index and attributes mapping must be kept in this order as FindVa= riable + // makes use of this mapping to implement search algorithm. + // + VariableStoreHeader[VariableStoreTypeVolatile] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase; + VariableStoreHeader[VariableStoreTypeHob] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase; + VariableStoreHeader[VariableStoreTypeNv] =3D mNvVariableCache; + + Status =3D VariableServiceGetNextVariableInternal (VariableName, VendorG= uid, VariableStoreHeader, &VariablePtr); if (!EFI_ERROR (Status)) { VarNameSize =3D NameSizeOfVariable (VariablePtr); ASSERT (VarNameSize !=3D 0); diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c b/M= deModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c index dc78f68fa9..c787ddba5b 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c @@ -98,10 +98,16 @@ VariableExLibFindNextVariable ( EFI_STATUS Status; VARIABLE_HEADER *VariablePtr; AUTHENTICATED_VARIABLE_HEADER *AuthVariablePtr; + VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax]; + + VariableStoreHeader[VariableStoreTypeVolatile] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase; + VariableStoreHeader[VariableStoreTypeHob] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase; + VariableStoreHeader[VariableStoreTypeNv] =3D mNvVariableCache; =20 Status =3D VariableServiceGetNextVariableInternal ( VariableName, VendorGuid, + VariableStoreHeader, &VariablePtr ); if (EFI_ERROR (Status)) { diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c b= /MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c index 5698a1a5e4..d6bb916e68 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c @@ -476,14 +476,16 @@ FindVariableEx ( } =20 /** - This code Finds the Next available variable. + This code finds the next available variable. =20 Caution: This function may receive untrusted input. This function may be invoked in SMM mode. This function will do basic va= lidation, before parse the data. =20 - @param[in] VariableName Pointer to variable name. - @param[in] VendorGuid Variable Vendor Guid. - @param[out] VariablePtr Pointer to variable header address. + @param[in] VariableName Pointer to variable name. + @param[in] VendorGuid Variable Vendor Guid. + @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. =20 @retval EFI_SUCCESS The function completed successfully. @retval EFI_NOT_FOUND The next variable was not found. @@ -497,26 +499,47 @@ EFIAPI VariableServiceGetNextVariableInternal ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, + IN VARIABLE_STORE_HEADER **VariableStoreList, OUT VARIABLE_HEADER **VariablePtr ) { - VARIABLE_STORE_TYPE Type; + EFI_STATUS Status; + VARIABLE_STORE_TYPE StoreType; VARIABLE_POINTER_TRACK Variable; VARIABLE_POINTER_TRACK VariableInHob; VARIABLE_POINTER_TRACK VariablePtrTrack; - EFI_STATUS Status; - VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax]; =20 - Status =3D FindVariable (VariableName, VendorGuid, &Variable, &mVariable= ModuleGlobal->VariableGlobal, FALSE); + Status =3D EFI_NOT_FOUND; + + if (VariableStoreList =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // Check if the variable exists in the given variable store list + for (StoreType =3D (VARIABLE_STORE_TYPE) 0; StoreType < VariableStoreTyp= eMax; StoreType++) { + if (VariableStoreList[StoreType] =3D=3D NULL) { + continue; + } + + Variable.StartPtr =3D GetStartPointer (VariableStoreList[StoreType]); + Variable.EndPtr =3D GetEndPointer (VariableStoreList[StoreType]); + Variable.Volatile =3D (BOOLEAN) (StoreType =3D=3D VariableStoreTypeVol= atile); + + Status =3D FindVariableEx (VariableName, VendorGuid, FALSE, &Variable); + if (!EFI_ERROR (Status)) { + break; + } + } + if (Variable.CurrPtr =3D=3D NULL || EFI_ERROR (Status)) { // - // For VariableName is an empty string, FindVariable() will try to fin= d and return - // the first qualified variable, and if FindVariable() returns error (= EFI_NOT_FOUND) + // For VariableName is an empty string, FindVariableEx() will try to f= ind and return + // the first qualified variable, and if FindVariableEx() returns error= (EFI_NOT_FOUND) // as no any variable is found, still go to return the error (EFI_NOT_= FOUND). // if (VariableName[0] !=3D 0) { // - // For VariableName is not an empty string, and FindVariable() retur= ns error as + // For VariableName is not an empty string, and FindVariableEx() ret= urns error as // VariableName and VendorGuid are not a name and GUID of an existin= g variable, // there is no way to get next variable, follow spec to return EFI_I= NVALID_PARAMETER. // @@ -527,39 +550,30 @@ VariableServiceGetNextVariableInternal ( =20 if (VariableName[0] !=3D 0) { // - // If variable name is not NULL, get next variable. + // If variable name is not empty, get next variable. // Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); } =20 - // - // 0: Volatile, 1: HOB, 2: Non-Volatile. - // The index and attributes mapping must be kept in this order as FindVa= riable - // makes use of this mapping to implement search algorithm. - // - VariableStoreHeader[VariableStoreTypeVolatile] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase; - VariableStoreHeader[VariableStoreTypeHob] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase; - VariableStoreHeader[VariableStoreTypeNv] =3D mNvVariableCache; - while (TRUE) { // - // Switch from Volatile to HOB, to Non-Volatile. + // Switch to the next variable store if needed // while (!IsValidVariableHeader (Variable.CurrPtr, Variable.EndPtr)) { // // Find current storage index // - for (Type =3D (VARIABLE_STORE_TYPE) 0; Type < VariableStoreTypeMax; = Type++) { - if ((VariableStoreHeader[Type] !=3D NULL) && (Variable.StartPtr = =3D=3D GetStartPointer (VariableStoreHeader[Type]))) { + for (StoreType =3D (VARIABLE_STORE_TYPE) 0; StoreType < VariableStor= eTypeMax; StoreType++) { + if ((VariableStoreList[StoreType] !=3D NULL) && (Variable.StartPtr= =3D=3D GetStartPointer (VariableStoreList[StoreType]))) { break; } } - ASSERT (Type < VariableStoreTypeMax); + ASSERT (StoreType < VariableStoreTypeMax); // // Switch to next storage // - for (Type++; Type < VariableStoreTypeMax; Type++) { - if (VariableStoreHeader[Type] !=3D NULL) { + for (StoreType++; StoreType < VariableStoreTypeMax; StoreType++) { + if (VariableStoreList[StoreType] !=3D NULL) { break; } } @@ -568,12 +582,12 @@ VariableServiceGetNextVariableInternal ( // 1. current storage is the last one, or // 2. no further storage // - if (Type =3D=3D VariableStoreTypeMax) { + if (StoreType =3D=3D VariableStoreTypeMax) { Status =3D EFI_NOT_FOUND; goto Done; } - Variable.StartPtr =3D GetStartPointer (VariableStoreHeader[Type]); - Variable.EndPtr =3D GetEndPointer (VariableStoreHeader[Type]); + Variable.StartPtr =3D GetStartPointer (VariableStoreList[StoreType]); + Variable.EndPtr =3D GetEndPointer (VariableStoreList[StoreType]); Variable.CurrPtr =3D Variable.StartPtr; } =20 @@ -605,11 +619,11 @@ VariableServiceGetNextVariableInternal ( // // Don't return NV variable when HOB overrides it // - if ((VariableStoreHeader[VariableStoreTypeHob] !=3D NULL) && (Vari= ableStoreHeader[VariableStoreTypeNv] !=3D NULL) && - (Variable.StartPtr =3D=3D GetStartPointer (VariableStoreHeader= [VariableStoreTypeNv])) + if ((VariableStoreList[VariableStoreTypeHob] !=3D NULL) && (Variab= leStoreList[VariableStoreTypeNv] !=3D NULL) && + (Variable.StartPtr =3D=3D GetStartPointer (VariableStoreList[V= ariableStoreTypeNv])) ) { - VariableInHob.StartPtr =3D GetStartPointer (VariableStoreHeader[= VariableStoreTypeHob]); - VariableInHob.EndPtr =3D GetEndPointer (VariableStoreHeader[= VariableStoreTypeHob]); + VariableInHob.StartPtr =3D GetStartPointer (VariableStoreList[Va= riableStoreTypeHob]); + VariableInHob.EndPtr =3D GetEndPointer (VariableStoreList[Va= riableStoreTypeHob]); Status =3D FindVariableEx ( GetVariableNamePtr (Variable.CurrPtr), GetVendorGuidPtr (Variable.CurrPtr), --=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 (#49723): https://edk2.groups.io/g/devel/message/49723 Mute This Topic: https://groups.io/mt/40103012/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-