From nobody Wed May 15 05:22:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+110340+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110340+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1698697898; cv=none; d=zohomail.com; s=zohoarc; b=UyQsG8n4yfBoTTj4CoSWVry6WdIVjjDl0S3uZi67FTJT3g3LLPEkmVWhyCEM0UL0EmdIUVv4ygrzEFRGu9y3eJvsvQ1ZRJd8hPo9eCBJSEjk+xtGzFaPW/89ABCUlLOpld8tPZKWldXQUmFsKfspv6d8DJcBc4Ffc1jsXYpoVU8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698697898; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=/mf0H7nKrkngugh86ftrYX6Z4JOUpMbuJ7qEuN7Q3ZA=; b=OysKKGziI3GgrCeezmfAYVguEFM0/98ibyvdrTyphzqZBfmu7YVxvJzGvynhbjMztsvRXfW7dCQiJ4eMt5RHj2GMFfy8SUYIkripCay1soH/MS+V62APODoxCcHY3cvmxICYRyxVMS8+fgfr3mXB/UM7+IBkb2PwK7r1g9mUzag= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110340+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16986978981751008.7866175577234; Mon, 30 Oct 2023 13:31:38 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=ccqDDaAwGhZlOJGXcSqqsFykqccS2YTGqgbzfrFe29E=; c=relaxed/simple; d=groups.io; h=DKIM-Filter:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1698697897; v=1; b=nvi5M+3w8ROmf9ETiFbna4zMn4DWCFlEthqnooLMrNQ4IIW1dLfaufq/nKTABjZLYZ7KtkYR 2ZG1Pw7CHaZaFou46XbXsVu/4IQvM2DvWd1zllz2u5PqzvZXxie26MZ3c0tlpEbWaimWzjI5MyV JtMzV3ZkcDBuXKh7qjhoW0u8= X-Received: by 127.0.0.2 with SMTP id 0W0hYY1788612xF1eQnyAUco; Mon, 30 Oct 2023 13:31:37 -0700 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web10.169258.1698697897092192386 for ; Mon, 30 Oct 2023 13:31:37 -0700 X-Received: from localhost.localdomain (unknown [47.201.241.95]) by linux.microsoft.com (Postfix) with ESMTPSA id DBCE720B74C1; Mon, 30 Oct 2023 13:31:35 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DBCE720B74C1 From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Dandan Bi , Hao A Wu , Jian J Wang , Liming Gao , Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 1/4] MdeModulePkg/VariablePolicy: Add more granular variable policy querying Date: Mon, 30 Oct 2023 16:31:09 -0400 Message-ID: <20231030203112.736-2-mikuback@linux.microsoft.com> In-Reply-To: <20231030203112.736-1-mikuback@linux.microsoft.com> References: <20231030203112.736-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: 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,mikuback@linux.microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 5kfHi44HWJmbw5YeZ4ki1Hrtx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1698697899494100001 Content-Type: text/plain; charset="utf-8" From: Michael Kubacki Introduces two new APIs to EDKII_VARIABLE_POLICY_PROTOCOL: 1. GetVariablePolicyInfo() 2. GetLockOnVariableStateVariablePolicyInfo() These allow a caller to retrieve policy information associated with a UEFI variable given the variable name and vendor GUID. GetVariablePolicyInfo() - Returns the variable policy applied to the UEFI variable. If the variable policy is applied toward an individual UEFI variable, that name can optionally be returned. GetLockOnVariableStateVariablePolicyInfo() - Returns the Lock on Variable State policy applied to the UEFI variable. If the Lock on Variable State policy is applied to a specific variable name, that name can optionally be returned. These functions can be useful for a variety of purposes such as auditing, testing, and functional flows. Also fixed some variable name typos in code touched by the changes. Cc: Dandan Bi Cc: Hao A Wu Cc: Jian J Wang Cc: Liming Gao Signed-off-by: Michael Kubacki Reviewed-by: Ard Biesheuvel Reviewed-by: Liming Gao --- MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.c | 174 ++= ++++++-- MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.c | 304 ++= +++++++++++++++ MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c | 4 +- MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c | 346 ++= +++++++++++++++++- MdeModulePkg/Include/Guid/VarCheckPolicyMmi.h | 39 ++- MdeModulePkg/Include/Library/VariablePolicyLib.h | 107 ++= ++++ MdeModulePkg/Include/Protocol/VariablePolicy.h | 133 ++= +++++- MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf | 1 + 8 files changed, 1062 insertions(+), 46 deletions(-) diff --git a/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.c b/M= deModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.c index 5de46133bb26..1448af85555a 100644 --- a/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.c +++ b/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.c @@ -76,14 +76,20 @@ VarCheckPolicyLibMmiHandler ( VOID *InternalCommBuffer; EFI_STATUS Status; EFI_STATUS SubCommandStatus; - VAR_CHECK_POLICY_COMM_HEADER *PolicyCommmHeader; - VAR_CHECK_POLICY_COMM_HEADER *InternalPolicyCommmHeader; + VAR_CHECK_POLICY_COMM_HEADER *PolicyCommHeader; + VAR_CHECK_POLICY_COMM_HEADER *InternalPolicyCommHeader; VAR_CHECK_POLICY_COMM_IS_ENABLED_PARAMS *IsEnabledParams; VAR_CHECK_POLICY_COMM_DUMP_PARAMS *DumpParamsIn; VAR_CHECK_POLICY_COMM_DUMP_PARAMS *DumpParamsOut; + VAR_CHECK_POLICY_COMM_GET_INFO_PARAMS *GetInfoParamsInternal; + VAR_CHECK_POLICY_COMM_GET_INFO_PARAMS *GetInfoParamsExternal; + CHAR16 *InternalCopyOfOutputVariableNa= me; + CHAR16 *ExternalCopyOfOutputVariableNa= me; UINT8 *DumpInputBuffer; UINT8 *DumpOutputBuffer; + UINTN AllowedOutputVariableNameSize; UINTN DumpTotalPages; + UINTN LocalSize; VARIABLE_POLICY_ENTRY *PolicyEntry; UINTN ExpectedSize; UINT32 TempSize; @@ -122,21 +128,21 @@ VarCheckPolicyLibMmiHandler ( // InternalCommBuffer =3D &mSecurityEvalBuffer[0]; CopyMem (InternalCommBuffer, CommBuffer, InternalCommBufferSize); - PolicyCommmHeader =3D CommBuffer; - InternalPolicyCommmHeader =3D InternalCommBuffer; + PolicyCommHeader =3D CommBuffer; + InternalPolicyCommHeader =3D InternalCommBuffer; // Check the revision and the signature of the comm header. - if ((InternalPolicyCommmHeader->Signature !=3D VAR_CHECK_POLICY_COMM_SIG= ) || - (InternalPolicyCommmHeader->Revision !=3D VAR_CHECK_POLICY_COMM_REVI= SION)) + if ((InternalPolicyCommHeader->Signature !=3D VAR_CHECK_POLICY_COMM_SIG)= || + (InternalPolicyCommHeader->Revision !=3D VAR_CHECK_POLICY_COMM_REVIS= ION)) { DEBUG ((DEBUG_INFO, "%a - Signature or revision are incorrect!\n", __f= unc__)); // We have verified the buffer is not null and have enough size to hol= d Result field. - PolicyCommmHeader->Result =3D EFI_INVALID_PARAMETER; + PolicyCommHeader->Result =3D EFI_INVALID_PARAMETER; return EFI_SUCCESS; } =20 // If we're in the middle of a paginated dump and any other command is s= ent, // pagination cache must be cleared. - if ((mPaginationCache !=3D NULL) && (InternalPolicyCommmHeader->Command = !=3D mCurrentPaginationCommand)) { + if ((mPaginationCache !=3D NULL) && (InternalPolicyCommHeader->Command != =3D mCurrentPaginationCommand)) { FreePool (mPaginationCache); mPaginationCache =3D NULL; mPaginationCacheSize =3D 0; @@ -146,10 +152,10 @@ VarCheckPolicyLibMmiHandler ( // // Now we can process the command as it was sent. // - PolicyCommmHeader->Result =3D EFI_ABORTED; // Set a default return fo= r incomplete commands. - switch (InternalPolicyCommmHeader->Command) { + PolicyCommHeader->Result =3D EFI_ABORTED; // Set a default return for= incomplete commands. + switch (InternalPolicyCommHeader->Command) { case VAR_CHECK_POLICY_COMMAND_DISABLE: - PolicyCommmHeader->Result =3D DisableVariablePolicy (); + PolicyCommHeader->Result =3D DisableVariablePolicy (); break; =20 case VAR_CHECK_POLICY_COMMAND_IS_ENABLED: @@ -158,14 +164,14 @@ VarCheckPolicyLibMmiHandler ( ExpectedSize +=3D sizeof (VAR_CHECK_POLICY_COMM_IS_ENABLED_PARAMS); if (InternalCommBufferSize < ExpectedSize) { DEBUG ((DEBUG_INFO, "%a - Bad comm buffer size! %d < %d\n", __func= __, InternalCommBufferSize, ExpectedSize)); - PolicyCommmHeader->Result =3D EFI_INVALID_PARAMETER; + PolicyCommHeader->Result =3D EFI_INVALID_PARAMETER; break; } =20 // Now that we know we've got a valid size, we can fill in the rest = of the data. - IsEnabledParams =3D (VAR_CHECK_POLICY_COMM_IS_ENABLED_PARA= MS *)((UINT8 *)CommBuffer + sizeof (VAR_CHECK_POLICY_COMM_HEADER)); - IsEnabledParams->State =3D IsVariablePolicyEnabled (); - PolicyCommmHeader->Result =3D EFI_SUCCESS; + IsEnabledParams =3D (VAR_CHECK_POLICY_COMM_IS_ENABLED_PARAM= S *)((UINT8 *)CommBuffer + sizeof (VAR_CHECK_POLICY_COMM_HEADER)); + IsEnabledParams->State =3D IsVariablePolicyEnabled (); + PolicyCommHeader->Result =3D EFI_SUCCESS; break; =20 case VAR_CHECK_POLICY_COMMAND_REGISTER: @@ -174,7 +180,7 @@ VarCheckPolicyLibMmiHandler ( ExpectedSize +=3D sizeof (VARIABLE_POLICY_ENTRY); if (InternalCommBufferSize < ExpectedSize) { DEBUG ((DEBUG_INFO, "%a - Bad comm buffer size! %d < %d\n", __func= __, InternalCommBufferSize, ExpectedSize)); - PolicyCommmHeader->Result =3D EFI_INVALID_PARAMETER; + PolicyCommHeader->Result =3D EFI_INVALID_PARAMETER; break; } =20 @@ -187,11 +193,11 @@ VarCheckPolicyLibMmiHandler ( (InternalCommBufferSize < ExpectedSize)) { DEBUG ((DEBUG_INFO, "%a - Bad policy entry contents!\n", __func__)= ); - PolicyCommmHeader->Result =3D EFI_INVALID_PARAMETER; + PolicyCommHeader->Result =3D EFI_INVALID_PARAMETER; break; } =20 - PolicyCommmHeader->Result =3D RegisterVariablePolicy (PolicyEntry); + PolicyCommHeader->Result =3D RegisterVariablePolicy (PolicyEntry); break; =20 case VAR_CHECK_POLICY_COMMAND_DUMP: @@ -200,13 +206,13 @@ VarCheckPolicyLibMmiHandler ( ExpectedSize +=3D sizeof (VAR_CHECK_POLICY_COMM_DUMP_PARAMS) + VAR_C= HECK_POLICY_MM_DUMP_BUFFER_SIZE; if (InternalCommBufferSize < ExpectedSize) { DEBUG ((DEBUG_INFO, "%a - Bad comm buffer size! %d < %d\n", __func= __, InternalCommBufferSize, ExpectedSize)); - PolicyCommmHeader->Result =3D EFI_INVALID_PARAMETER; + PolicyCommHeader->Result =3D EFI_INVALID_PARAMETER; break; } =20 // Now that we know we've got a valid size, we can fill in the rest = of the data. - DumpParamsIn =3D (VAR_CHECK_POLICY_COMM_DUMP_PARAMS *)(InternalPoli= cyCommmHeader + 1); - DumpParamsOut =3D (VAR_CHECK_POLICY_COMM_DUMP_PARAMS *)(PolicyCommmH= eader + 1); + DumpParamsIn =3D (VAR_CHECK_POLICY_COMM_DUMP_PARAMS *)(InternalPoli= cyCommHeader + 1); + DumpParamsOut =3D (VAR_CHECK_POLICY_COMM_DUMP_PARAMS *)(PolicyCommHe= ader + 1); =20 // If we're requesting the first page, initialize the cache and get = the sizes. if (DumpParamsIn->PageRequested =3D=3D 0) { @@ -289,17 +295,131 @@ VarCheckPolicyLibMmiHandler ( } =20 // There's currently no use for this, but it shouldn't be hard to im= plement. - PolicyCommmHeader->Result =3D SubCommandStatus; + PolicyCommHeader->Result =3D SubCommandStatus; break; =20 case VAR_CHECK_POLICY_COMMAND_LOCK: - PolicyCommmHeader->Result =3D LockVariablePolicy (); + PolicyCommHeader->Result =3D LockVariablePolicy (); + break; + + case VAR_CHECK_POLICY_COMMAND_GET_INFO: + case VAR_CHECK_POLICY_COMMAND_GET_LOCK_VAR_STATE_INFO: + ExpectedSize +=3D VAR_CHECK_POLICY_COMM_GET_INFO_PARAMS_END + VAR_CH= ECK_POLICY_MM_GET_INFO_BUFFER_SIZE; + + if (InternalCommBufferSize < ExpectedSize) { + PolicyCommHeader->Result =3D EFI_INVALID_PARAMETER; + break; + } + + GetInfoParamsInternal =3D (VAR_CHECK_POLICY_COMM_GET_INFO_PARAMS *)(= InternalPolicyCommHeader + 1); + GetInfoParamsExternal =3D (VAR_CHECK_POLICY_COMM_GET_INFO_PARAMS *)(= PolicyCommHeader + 1); + + SubCommandStatus =3D SafeUintnSub ( + VAR_CHECK_POLICY_MM_GET_INFO_BUFFER_SIZE, + GetInfoParamsInternal->InputVariableNameSize, + &AllowedOutputVariableNameSize + ); + if (EFI_ERROR (SubCommandStatus)) { + PolicyCommHeader->Result =3D EFI_INVALID_PARAMETER; + break; + } + + if (GetInfoParamsInternal->OutputVariableNameSize > 0) { + SubCommandStatus =3D SafeUintnAdd ( + ((UINTN)GetInfoParamsInternal + VAR_CHECK_PO= LICY_COMM_GET_INFO_PARAMS_END), + (UINTN)GetInfoParamsInternal->InputVariableN= ameSize, + (UINTN *)&InternalCopyOfOutputVariableName + ); + if (EFI_ERROR (SubCommandStatus)) { + PolicyCommHeader->Result =3D EFI_INVALID_PARAMETER; + break; + } + } else { + InternalCopyOfOutputVariableName =3D NULL; + } + + ZeroMem (&GetInfoParamsInternal->OutputPolicyEntry, sizeof (GetInfoP= aramsInternal->OutputPolicyEntry)); + ZeroMem (&GetInfoParamsExternal->OutputPolicyEntry, sizeof (GetInfoP= aramsExternal->OutputPolicyEntry)); + + LocalSize =3D (UINTN)GetInfoParamsInternal->OutputVariableNameSize; + + if (InternalPolicyCommHeader->Command =3D=3D VAR_CHECK_POLICY_COMMAN= D_GET_INFO) { + SubCommandStatus =3D GetVariablePolicyInfo ( + GetInfoParamsInternal->InputVariableName, + &GetInfoParamsInternal->InputVendorGuid, + &LocalSize, + &GetInfoParamsInternal->OutputPolicyEntry.Va= riablePolicy, + InternalCopyOfOutputVariableName + ); + } else if (InternalPolicyCommHeader->Command =3D=3D VAR_CHECK_POLICY= _COMMAND_GET_LOCK_VAR_STATE_INFO) { + SubCommandStatus =3D GetLockOnVariableStateVariablePolicyInfo ( + GetInfoParamsInternal->InputVariableName, + &GetInfoParamsInternal->InputVendorGuid, + &LocalSize, + &GetInfoParamsInternal->OutputPolicyEntry.Lo= ckOnVarStatePolicy, + InternalCopyOfOutputVariableName + ); + } else { + PolicyCommHeader->Result =3D EFI_INVALID_PARAMETER; + break; + } + + if (EFI_ERROR (SubCommandStatus) && (SubCommandStatus !=3D EFI_BUFFE= R_TOO_SMALL)) { + PolicyCommHeader->Result =3D SubCommandStatus; + break; + } + + if (EFI_ERROR (SafeUintnToUint32 (LocalSize, &GetInfoParamsInternal-= >OutputVariableNameSize))) { + PolicyCommHeader->Result =3D EFI_BAD_BUFFER_SIZE; + break; + } + + ASSERT (sizeof (GetInfoParamsInternal->OutputPolicyEntry) =3D=3D siz= eof (GetInfoParamsExternal->OutputPolicyEntry)); + CopyMem ( + &GetInfoParamsExternal->OutputPolicyEntry, + &GetInfoParamsInternal->OutputPolicyEntry, + sizeof (GetInfoParamsExternal->OutputPolicyEntry) + ); + + GetInfoParamsExternal->OutputVariableNameSize =3D GetInfoParamsInter= nal->OutputVariableNameSize; + if (SubCommandStatus =3D=3D EFI_BUFFER_TOO_SMALL) { + PolicyCommHeader->Result =3D EFI_BUFFER_TOO_SMALL; + break; + } + + SubCommandStatus =3D SafeUintnAdd ( + ((UINTN)GetInfoParamsExternal + VAR_CHECK_POLI= CY_COMM_GET_INFO_PARAMS_END), + (UINTN)GetInfoParamsInternal->InputVariableNam= eSize, + (UINTN *)&ExternalCopyOfOutputVariableName + ); + if (EFI_ERROR (SubCommandStatus)) { + PolicyCommHeader->Result =3D EFI_BAD_BUFFER_SIZE; + break; + } + + if (GetInfoParamsInternal->OutputVariableNameSize > 0) { + SubCommandStatus =3D StrnCpyS ( + ExternalCopyOfOutputVariableName, + AllowedOutputVariableNameSize, + InternalCopyOfOutputVariableName, + (UINTN)GetInfoParamsInternal->OutputVariable= NameSize + ); + ASSERT_EFI_ERROR (SubCommandStatus); + } else { + // The comm buffer should always have the space for the variable p= olicy output + // variable name. Fill it with NULL chars if a variable name is no= t present so + // it has a consistent value in the case of variable name absence. + SetMem (ExternalCopyOfOutputVariableName, AllowedOutputVariableNam= eSize, CHAR_NULL); + } + + PolicyCommHeader->Result =3D SubCommandStatus; + break; =20 default: // Mark unknown requested command as EFI_UNSUPPORTED. - DEBUG ((DEBUG_INFO, "%a - Invalid command requested! %d\n", __func__= , PolicyCommmHeader->Command)); - PolicyCommmHeader->Result =3D EFI_UNSUPPORTED; + DEBUG ((DEBUG_INFO, "%a - Invalid command requested! %d\n", __func__= , PolicyCommHeader->Command)); + PolicyCommHeader->Result =3D EFI_UNSUPPORTED; break; } =20 @@ -307,8 +427,8 @@ VarCheckPolicyLibMmiHandler ( DEBUG_VERBOSE, "%a - Command %d returning %r.\n", __func__, - PolicyCommmHeader->Command, - PolicyCommmHeader->Result + PolicyCommHeader->Command, + PolicyCommHeader->Result )); =20 return Status; diff --git a/MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.c b/M= deModulePkg/Library/VariablePolicyLib/VariablePolicyLib.c index 214f76ab9626..768662829dbf 100644 --- a/MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.c +++ b/MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.c @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include =20 +#include #include #include #include @@ -684,6 +685,309 @@ DumpVariablePolicy ( return EFI_SUCCESS; } =20 +/** + This function will return variable policy information for a UEFI variabl= e with a + registered variable policy. + + @param[in] VariableName The name of the va= riable to use for the policy search. + @param[in] VendorGuid The vendor GUID of= the variable to use for the policy search. + @param[in,out] VariablePolicyVariableNameBufferSize On input, the size= , in bytes, of the VariablePolicyVariableName + buffer. + + On output, the siz= e, in bytes, needed to store the variable + policy variable na= me. + + If testing for the= VariablePolicyVariableName buffer size + needed, set this v= alue to zero so EFI_BUFFER_TOO_SMALL is + guaranteed to be r= eturned if the variable policy variable name + is found. + @param[out] VariablePolicy Pointer to a buffe= r where the policy entry will be written + if found. + @param[out] VariablePolicyVariableName Pointer to a buffe= r where the variable name used for the + variable policy wi= ll be written if a variable name is + registered. + + If the variable po= licy is not associated with a variable name + (e.g. applied to v= ariable vendor namespace) and this parameter + is given, this par= ameter will not be modified and + VariablePolicyVari= ableNameBufferSize will be set to zero to + indicate a name wa= s not present. + + If the pointer giv= en is not NULL, + VariablePolicyVari= ableNameBufferSize must be non-NULL. + + @retval EFI_SUCCESS A variable policy entry was found an= d returned successfully. + @retval EFI_BAD_BUFFER_SIZE An internal buffer size caused a cal= culation error. + @retval EFI_BUFFER_TOO_SMALL The VariablePolicyVariableName buffe= r value is too small for the size needed. + The buffer should now point to the s= ize needed. + @retval EFI_NOT_READY Variable policy has not yet been ini= tialized. + @retval EFI_INVALID_PARAMETER A required pointer argument passed i= s NULL. This will be returned if + VariablePolicyVariableName is non-NU= LL and VariablePolicyVariableNameBufferSize + is NULL. + @retval EFI_NOT_FOUND A variable policy was not found for = the given UEFI variable name and vendor GUID. + +**/ +EFI_STATUS +EFIAPI +GetVariablePolicyInfo ( + IN CONST CHAR16 *VariableName, + IN CONST EFI_GUID *VendorGuid, + IN OUT UINTN *VariablePolicyVariableNameBufferSize OPT= IONAL, + OUT VARIABLE_POLICY_ENTRY *VariablePolicy, + OUT CHAR16 *VariablePolicyVariableName OPTIONAL + ) +{ + EFI_STATUS Status; + UINT8 MatchPriority; + UINTN LocalVariablePolicyVariableNameBufferSize; + UINTN RequiredVariablePolicyVariableNameBufferSize; + VARIABLE_POLICY_ENTRY *MatchPolicy; + + Status =3D EFI_SUCCESS; + + if (!IsVariablePolicyLibInitialized ()) { + return EFI_NOT_READY; + } + + if ((VariableName =3D=3D NULL) || (VendorGuid =3D=3D NULL) || (VariableP= olicy =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + MatchPolicy =3D GetBestPolicyMatch ( + VariableName, + VendorGuid, + &MatchPriority + ); + if (MatchPolicy !=3D NULL) { + CopyMem (VariablePolicy, MatchPolicy, sizeof (*VariablePolicy)); + + if (VariablePolicyVariableNameBufferSize =3D=3D NULL) { + if (VariablePolicyVariableName !=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + return Status; + } + + if (MatchPolicy->Size !=3D MatchPolicy->OffsetToName) { + if (MatchPolicy->Size < MatchPolicy->OffsetToName) { + ASSERT (MatchPolicy->Size > MatchPolicy->OffsetToName); + return EFI_BAD_BUFFER_SIZE; + } + + RequiredVariablePolicyVariableNameBufferSize =3D (UINTN)(MatchPolicy= ->Size - MatchPolicy->OffsetToName); + ASSERT (RequiredVariablePolicyVariableNameBufferSize > 0); + + if (*VariablePolicyVariableNameBufferSize < RequiredVariablePolicyVa= riableNameBufferSize) { + // Let the caller get the size needed to hold the policy variable = name + *VariablePolicyVariableNameBufferSize =3D RequiredVariablePolicyVa= riableNameBufferSize; + return EFI_BUFFER_TOO_SMALL; + } + + if (VariablePolicyVariableName =3D=3D NULL) { + // If the policy variable name size given is valid, then a valid p= olicy variable name buffer should be provided + *VariablePolicyVariableNameBufferSize =3D RequiredVariablePolicyVa= riableNameBufferSize; + return EFI_INVALID_PARAMETER; + } + + LocalVariablePolicyVariableNameBufferSize =3D *VariablePolicyVariabl= eNameBufferSize; + + // Actual string size should match expected string size + if ( + ((StrnLenS (GET_POLICY_NAME (MatchPolicy), RequiredVariablePolic= yVariableNameBufferSize) + 1) * sizeof (CHAR16)) + !=3D RequiredVariablePolicyVariableNameBufferSize) + { + ASSERT_EFI_ERROR (EFI_BAD_BUFFER_SIZE); + return EFI_BAD_BUFFER_SIZE; + } + + *VariablePolicyVariableNameBufferSize =3D RequiredVariablePolicyVari= ableNameBufferSize; + + Status =3D StrnCpyS ( + VariablePolicyVariableName, + LocalVariablePolicyVariableNameBufferSize / sizeof (CHAR1= 6), + GET_POLICY_NAME (MatchPolicy), + RequiredVariablePolicyVariableNameBufferSize / sizeof (CH= AR16) + ); + ASSERT_EFI_ERROR (Status); + } else { + // A variable policy variable name is not present. Return values acc= ording to interface. + *VariablePolicyVariableNameBufferSize =3D 0; + } + + return Status; + } + + return EFI_NOT_FOUND; +} + +/** + This function will return the Lock on Variable State policy information = for the policy + associated with the given UEFI variable. + + @param[in] VariableName The name of th= e variable to use for the policy search. + @param[in] VendorGuid The vendor GUI= D of the variable to use for the policy + search. + @param[in,out] VariableLockPolicyVariableNameBufferSize On input, the = size, in bytes, of the + VariableLockPo= licyVariableName buffer. + + On output, the= size, in bytes, needed to store the variable + policy variabl= e name. + + If testing for= the VariableLockPolicyVariableName buffer + size needed, s= et this value to zero so EFI_BUFFER_TOO_SMALL + is guaranteed = to be returned if the variable policy variable + name is found. + @param[out] VariablePolicy Pointer to a b= uffer where the policy entry will be written + if found. + @param[out] VariableLockPolicyVariableName Pointer to a b= uffer where the variable name used for the + variable lock = on variable state policy will be written if + a variable nam= e is registered. + + If the lock on= variable policy is not associated with a + variable name = (e.g. applied to variable vendor namespace) + and this param= eter is given, this parameter will not be + modified and V= ariableLockPolicyVariableNameBufferSize will + be set to zero= to indicate a name was not present. + + If the pointer= given is not NULL, + VariableLockPo= licyVariableNameBufferSize must be non-NULL. + + @retval EFI_SUCCESS A Lock on Variable State variable po= licy entry was found and returned + successfully. + @retval EFI_BAD_BUFFER_SIZE An internal buffer size caused a cal= culation error. + @retval EFI_BUFFER_TOO_SMALL The VariableLockPolicyVariableName b= uffer is too small for the size needed. + The buffer should now point to the s= ize needed. + @retval EFI_NOT_READY Variable policy has not yet been ini= tialized. + @retval EFI_INVALID_PARAMETER A required pointer argument passed i= s NULL. This will be returned if + VariableLockPolicyVariableName is no= n-NULL and + VariableLockPolicyVariableNameBuffer= Size is NULL. + @retval EFI_NOT_FOUND A Lock on Variable State variable po= licy was not found for the given UEFI + variable name and vendor GUID. + +**/ +EFI_STATUS +EFIAPI +GetLockOnVariableStateVariablePolicyInfo ( + IN CONST CHAR16 *VariableName, + IN CONST EFI_GUID *VendorGuid, + IN OUT UINTN *VariableLockPolicyVariableNa= meBufferSize OPTIONAL, + OUT VARIABLE_LOCK_ON_VAR_STATE_POLICY *VariablePolicy, + OUT CHAR16 *VariableLockPolicyVariableNa= me OPTIONAL + ) +{ + EFI_STATUS Status; + UINT8 MatchPriority; + UINTN RequiredVariablePolicyVariableNameBuf= ferSize; + UINTN RequiredVariableLockPolicyVariableNam= eBufferSize; + UINTN LocalVariablePolicyLockVariableNameBu= fferSize; + UINTN LockOnVarStatePolicyEndOffset; + CHAR16 *LocalVariableLockPolicyVariableName; + VARIABLE_LOCK_ON_VAR_STATE_POLICY *LocalLockOnVarStatePolicy; + VARIABLE_POLICY_ENTRY *MatchPolicy; + + Status =3D EFI_SUCCESS; + + if (!IsVariablePolicyLibInitialized ()) { + return EFI_NOT_READY; + } + + if ((VariableName =3D=3D NULL) || (VendorGuid =3D=3D NULL) || (VariableP= olicy =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + MatchPolicy =3D GetBestPolicyMatch ( + VariableName, + VendorGuid, + &MatchPriority + ); + if (MatchPolicy !=3D NULL) { + if (MatchPolicy->LockPolicyType !=3D VARIABLE_POLICY_TYPE_LOCK_ON_VAR_= STATE) { + return EFI_NOT_FOUND; + } + + Status =3D SafeUintnAdd ( + sizeof (VARIABLE_POLICY_ENTRY), + sizeof (VARIABLE_LOCK_ON_VAR_STATE_POLICY), + &LockOnVarStatePolicyEndOffset + ); + if (EFI_ERROR (Status) || (LockOnVarStatePolicyEndOffset > (UINTN)Matc= hPolicy->Size)) { + return EFI_BAD_BUFFER_SIZE; + } + + LocalLockOnVarStatePolicy =3D (VARIABLE_LOCK_ON_VAR_STATE_POLICY *)(Ma= tchPolicy + 1); + CopyMem (VariablePolicy, LocalLockOnVarStatePolicy, sizeof (*LocalLock= OnVarStatePolicy)); + + if ((VariableLockPolicyVariableNameBufferSize =3D=3D NULL)) { + if (VariableLockPolicyVariableName !=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + return Status; + } + + // The name offset should be less than or equal to the total policy si= ze. + if (MatchPolicy->Size < MatchPolicy->OffsetToName) { + return EFI_BAD_BUFFER_SIZE; + } + + RequiredVariablePolicyVariableNameBufferSize =3D (UINTN)(MatchPoli= cy->Size - MatchPolicy->OffsetToName); + RequiredVariableLockPolicyVariableNameBufferSize =3D MatchPolicy->Siz= e - + (LockOnVarStatePoli= cyEndOffset + RequiredVariablePolicyVariableNameBufferSize); + + LocalVariablePolicyLockVariableNameBufferSize =3D *VariableLockPolicyV= ariableNameBufferSize; + *VariableLockPolicyVariableNameBufferSize =3D RequiredVariableLock= PolicyVariableNameBufferSize; + + if (LocalVariablePolicyLockVariableNameBufferSize < RequiredVariableLo= ckPolicyVariableNameBufferSize) { + // Let the caller get the size needed to hold the policy variable na= me + return EFI_BUFFER_TOO_SMALL; + } + + if (VariableLockPolicyVariableName =3D=3D NULL) { + // If the policy variable name size given is valid, then a valid pol= icy variable name buffer should be provided + return EFI_INVALID_PARAMETER; + } + + if (RequiredVariableLockPolicyVariableNameBufferSize =3D=3D 0) { + return Status; + } + + LocalVariableLockPolicyVariableName =3D (CHAR16 *)((UINT8 *)Loca= lLockOnVarStatePolicy + sizeof (*LocalLockOnVarStatePolicy)); + *VariableLockPolicyVariableNameBufferSize =3D RequiredVariableLockPoli= cyVariableNameBufferSize; + + // Actual string size should match expected string size (if a variable= name is present) + if ( + (RequiredVariablePolicyVariableNameBufferSize > 0) && + (((StrnLenS (GET_POLICY_NAME (MatchPolicy), RequiredVariablePolicy= VariableNameBufferSize) + 1) * sizeof (CHAR16)) !=3D + RequiredVariablePolicyVariableNameBufferSize)) + { + ASSERT_EFI_ERROR (EFI_BAD_BUFFER_SIZE); + return EFI_BAD_BUFFER_SIZE; + } + + // Actual string size should match expected string size (if here, vari= able lock variable name is present) + if ( + ((StrnLenS (LocalVariableLockPolicyVariableName, RequiredVariableL= ockPolicyVariableNameBufferSize) + 1) * sizeof (CHAR16)) !=3D + RequiredVariableLockPolicyVariableNameBufferSize) + { + ASSERT_EFI_ERROR (EFI_BAD_BUFFER_SIZE); + return EFI_BAD_BUFFER_SIZE; + } + + Status =3D StrnCpyS ( + VariableLockPolicyVariableName, + LocalVariablePolicyLockVariableNameBufferSize / sizeof (CH= AR16), + LocalVariableLockPolicyVariableName, + RequiredVariableLockPolicyVariableNameBufferSize / sizeof = (CHAR16) + ); + ASSERT_EFI_ERROR (Status); + + return Status; + } + + return EFI_NOT_FOUND; +} + /** This API function returns whether or not the policy engine is currently being enforced. diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c b/Mde= ModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c index d5c409c914d1..c4ccdfd20f74 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c @@ -33,7 +33,9 @@ EDKII_VARIABLE_POLICY_PROTOCOL mVariablePolicyProtocol = =3D { ProtocolIsVariablePolicyEnabled, RegisterVariablePolicy, DumpVariablePolicy, - LockVariablePolicy + LockVariablePolicy, + GetVariablePolicyInfo, + GetLockOnVariableStateVariablePolicyInfo }; EDKII_VAR_CHECK_PROTOCOL mVarCheck =3D { VarCheckRegisterSetVariableCheckHandler, diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDx= e.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c index 6151a2ba0b18..0dd72dde27ce 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c @@ -410,6 +410,338 @@ ProtocolLockVariablePolicy ( return (EFI_ERROR (Status)) ? Status : PolicyHeader->Result; } =20 +/** + Internal implementation to retrieve variable information for a given UEF= I variable that is shared + between different policy types. + + Currently, the two policy structure types supported (and all that is def= ined) are VARIABLE_POLICY_ENTRY + and VARIABLE_LOCK_ON_VAR_STATE_POLICY. + + @param[in] Command The command value = to use in the communicate call. + @param[in] VariableName The name of the va= riable to use for the policy search. + @param[in] VendorGuid The vendor GUID of= the variable to use for the policy search. + @param[in,out] VariablePolicyVariableNameBufferSize On input, the size= , in bytes, of the VariablePolicyVariableName + buffer. + + On output, the siz= e, in bytes, needed to store the variable + policy variable na= me. + + If testing for the= VariablePolicyVariableName buffer size + needed, set this v= alue to zero so EFI_BUFFER_TOO_SMALL is + guaranteed to be r= eturned if the variable policy variable name + is found. + @param[out] VariablePolicy Pointer to a buffe= r where the policy entry will be written + if found. + @param[out] VariablePolicyVariableName Pointer to a buffe= r where the variable name used for the + variable policy wi= ll be written if a variable name is + registered. + + If the variable po= licy is not associated with a variable name + (e.g. applied to v= ariable vendor namespace) and this parameter + is given, this par= ameter will not be modified and + VariablePolicyVari= ableNameBufferSize will be set to zero to + indicate a name wa= s not present. + + If the pointer giv= en is not NULL, + VariablePolicyVari= ableNameBufferSize must be non-NULL. + + @retval EFI_SUCCESS A variable policy entry was found an= d returned successfully. + @retval EFI_BAD_BUFFER_SIZE An internal buffer size caused a cal= culation error. + @retval EFI_BUFFER_TOO_SMALL The VariablePolicyVariableName buffe= r value is too small for the size needed. + The buffer should now point to the s= ize needed. + @retval EFI_NOT_READY Variable policy has not yet been ini= tialized. + @retval EFI_INVALID_PARAMETER A required pointer argument passed i= s NULL. This will be returned if + VariablePolicyVariableName is non-NU= LL and VariablePolicyVariableNameBufferSize + is NULL. It can also be returned if = the Command value provided is invalid. + @retval EFI_NOT_FOUND A variable policy was not found for = the given UEFI variable name and vendor GUID. + + +**/ +STATIC +EFI_STATUS +InternalProtocolGetVariablePolicyInfo ( + IN UINT32 Command, + IN CONST CHAR16 *VariableName, + IN CONST EFI_GUID *VendorGuid, + IN OUT UINTN *VariablePolicyVariableNameBufferSize, OPTIONAL + OUT VOID *VariablePolicy, + OUT CHAR16 *VariablePolicyVariableName = OPTIONAL + ) +{ + EFI_STATUS Status; + CHAR16 *OutputVariableName; + EFI_MM_COMMUNICATE_HEADER *CommHeader; + VAR_CHECK_POLICY_COMM_HEADER *PolicyHeader; + VAR_CHECK_POLICY_COMM_GET_INFO_PARAMS *CommandParams; + UINTN AllowedOutputVariableNameSize; + UINTN BufferSize; + UINTN VariableNameSize; + + if ((VariableName =3D=3D NULL) || (VendorGuid =3D=3D NULL) || (VariableP= olicy =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + switch (Command) { + case VAR_CHECK_POLICY_COMMAND_GET_INFO: + case VAR_CHECK_POLICY_COMMAND_GET_LOCK_VAR_STATE_INFO: + break; + default: + return EFI_INVALID_PARAMETER; + } + + AcquireLockOnlyAtBootTime (&mMmCommunicationLock); + + VariableNameSize =3D StrnSizeS ( + VariableName, + (VAR_CHECK_POLICY_MM_GET_INFO_BUFFER_SIZE - VAR_CHE= CK_POLICY_COMM_GET_INFO_PARAMS_END) + ); + if (VariableNameSize >=3D (VAR_CHECK_POLICY_MM_GET_INFO_BUFFER_SIZE - VA= R_CHECK_POLICY_COMM_GET_INFO_PARAMS_END)) { + Status =3D EFI_INVALID_PARAMETER; + goto Done; + } + + if ((VariablePolicyVariableName !=3D NULL) && (VariablePolicyVariableNam= eBufferSize =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + goto Done; + } + + BufferSize =3D mMmCommunicationBufferSize; + CommHeader =3D mMmCommunicationBuffer; + + Status =3D SafeUintnSub ( + VAR_CHECK_POLICY_MM_GET_INFO_BUFFER_SIZE, + VariableNameSize, + &AllowedOutputVariableNameSize + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_INVALID_PARAMETER; + goto Done; + } + + if (VariablePolicyVariableNameBufferSize !=3D NULL) { + AllowedOutputVariableNameSize =3D MIN (AllowedOutputVariableNameSize, = *VariablePolicyVariableNameBufferSize); + } else { + AllowedOutputVariableNameSize =3D 0; + } + + PolicyHeader =3D (VAR_CHECK_POLICY_COMM_HEADER *)&CommHeader->Data; + CommandParams =3D (VAR_CHECK_POLICY_COMM_GET_INFO_PARAMS *)(PolicyHeader= + 1); + + CopyGuid (&CommHeader->HeaderGuid, &gVarCheckPolicyLibMmiHandlerGuid); + CommHeader->MessageLength =3D BufferSize - OFFSET_OF (EFI_MM_COMMUNICATE= _HEADER, Data); + PolicyHeader->Signature =3D VAR_CHECK_POLICY_COMM_SIG; + PolicyHeader->Revision =3D VAR_CHECK_POLICY_COMM_REVISION; + PolicyHeader->Command =3D Command; + + ZeroMem ((VOID *)&CommandParams->OutputPolicyEntry, sizeof (CommandParam= s->OutputPolicyEntry)); + CopyGuid (&CommandParams->InputVendorGuid, VendorGuid); + Status =3D SafeUintnToUint32 (VariableNameSize, &CommandParams->InputVar= iableNameSize); + if (EFI_ERROR (Status)) { + Status =3D EFI_INVALID_PARAMETER; + goto Done; + } + + Status =3D SafeUintnToUint32 (AllowedOutputVariableNameSize, &CommandPar= ams->OutputVariableNameSize); + if (EFI_ERROR (Status)) { + Status =3D EFI_INVALID_PARAMETER; + goto Done; + } + + if (AllowedOutputVariableNameSize > 0) { + Status =3D StrnCpyS ( + CommandParams->InputVariableName, + AllowedOutputVariableNameSize / sizeof (CHAR16), + VariableName, + (UINTN)CommandParams->InputVariableNameSize / sizeof (CHAR= 16) + ); + ASSERT_EFI_ERROR (Status); + } + + Status =3D InternalMmCommunicate (CommHeader, &BufferSize); + if (Status =3D=3D EFI_SUCCESS) { + CopyMem ( + VariablePolicy, + (VOID *)&CommandParams->OutputPolicyEntry, + (Command =3D=3D VAR_CHECK_POLICY_COMMAND_GET_INFO) ? + sizeof (CommandParams->OutputPolicyEntry.VariablePolicy) : + sizeof (CommandParams->OutputPolicyEntry.LockOnVarStatePolicy) + ); + + if (VariablePolicyVariableNameBufferSize =3D=3D NULL) { + if (VariablePolicyVariableName !=3D NULL) { + Status =3D EFI_INVALID_PARAMETER; + } + + goto Done; + } + + if (PolicyHeader->Result =3D=3D EFI_BUFFER_TOO_SMALL) { + *VariablePolicyVariableNameBufferSize =3D (UINTN)CommandParams->Outp= utVariableNameSize; + goto Done; + } + + if (PolicyHeader->Result =3D=3D EFI_SUCCESS) { + if (CommandParams->OutputVariableNameSize > 0) { + Status =3D SafeUintnAdd ( + ((UINTN)CommandParams + VAR_CHECK_POLICY_COMM_GET_INFO= _PARAMS_END), + (UINTN)CommandParams->InputVariableNameSize, + (UINTN *)&OutputVariableName + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_BAD_BUFFER_SIZE; + goto Done; + } + + Status =3D StrnCpyS ( + VariablePolicyVariableName, + *VariablePolicyVariableNameBufferSize / sizeof (CHAR16= ), + OutputVariableName, + (UINTN)CommandParams->OutputVariableNameSize + ); + ASSERT_EFI_ERROR (Status); + *VariablePolicyVariableNameBufferSize =3D (UINTN)CommandParams->Ou= tputVariableNameSize; + } else { + // A variable policy variable name is not present. Return values a= ccording to interface. + *VariablePolicyVariableNameBufferSize =3D 0; + } + } + } + +Done: + ReleaseLockOnlyAtBootTime (&mMmCommunicationLock); + + return (EFI_ERROR (Status)) ? Status : PolicyHeader->Result; +} + +/** + This function will return variable policy information for a UEFI variabl= e with a + registered variable policy. + + @param[in] VariableName The name of the va= riable to use for the policy search. + @param[in] VendorGuid The vendor GUID of= the variable to use for the policy search. + @param[in,out] VariablePolicyVariableNameBufferSize On input, the size= , in bytes, of the VariablePolicyVariableName + buffer. + + On output, the siz= e, in bytes, needed to store the variable + policy variable na= me. + + If testing for the= VariablePolicyVariableName buffer size + needed, set this v= alue to zero so EFI_BUFFER_TOO_SMALL is + guaranteed to be r= eturned if the variable policy variable name + is found. + @param[out] VariablePolicy Pointer to a buffe= r where the policy entry will be written + if found. + @param[out] VariablePolicyVariableName Pointer to a buffe= r where the variable name used for the + variable policy wi= ll be written if a variable name is + registered. + + If the variable po= licy is not associated with a variable name + (e.g. applied to v= ariable vendor namespace) and this parameter + is given, this par= ameter will not be modified and + VariablePolicyVari= ableNameBufferSize will be set to zero to + indicate a name wa= s not present. + + If the pointer giv= en is not NULL, + VariablePolicyVari= ableNameBufferSize must be non-NULL. + + @retval EFI_SUCCESS A variable policy entry was found an= d returned successfully. + @retval EFI_BAD_BUFFER_SIZE An internal buffer size caused a cal= culation error. + @retval EFI_BUFFER_TOO_SMALL The VariablePolicyVariableName buffe= r value is too small for the size needed. + The buffer should now point to the s= ize needed. + @retval EFI_NOT_READY Variable policy has not yet been ini= tialized. + @retval EFI_INVALID_PARAMETER A required pointer argument passed i= s NULL. This will be returned if + VariablePolicyVariableName is non-NU= LL and VariablePolicyVariableNameBufferSize + is NULL. + @retval EFI_NOT_FOUND A variable policy was not found for = the given UEFI variable name and vendor GUID. + +**/ +STATIC +EFI_STATUS +EFIAPI +ProtocolGetVariablePolicyInfo ( + IN CONST CHAR16 *VariableName, + IN CONST EFI_GUID *VendorGuid, + IN OUT UINTN *VariablePolicyVariableNameBufferSize, OPTIONAL + OUT VARIABLE_POLICY_ENTRY *VariablePolicy, + OUT CHAR16 *VariablePolicyVariableName = OPTIONAL + ) +{ + return InternalProtocolGetVariablePolicyInfo ( + VAR_CHECK_POLICY_COMMAND_GET_INFO, + VariableName, + VendorGuid, + VariablePolicyVariableNameBufferSize, + VariablePolicy, + VariablePolicyVariableName + ); +} + +/** + This function will return the Lock on Variable State policy information = for the policy + associated with the given UEFI variable. + + @param[in] VariableName The name of th= e variable to use for the policy search. + @param[in] VendorGuid The vendor GUI= D of the variable to use for the policy + search. + @param[in,out] VariableLockPolicyVariableNameBufferSize On input, the = size, in bytes, of the + VariableLockPo= licyVariableName buffer. + + On output, the= size, in bytes, needed to store the variable + policy variabl= e name. + + If testing for= the VariableLockPolicyVariableName buffer + P size needed, = set this value to zero so EFI_BUFFER_TOO_SMALL + is guaranteed = to be returned if the variable policy variable + name is found. + @param[out] VariablePolicy Pointer to a b= uffer where the policy entry will be written + if found. + @param[out] VariableLockPolicyVariableName Pointer to a b= uffer where the variable name used for the + variable lock = on variable state policy will be written if + a variable nam= e is registered. + + If the lock on= variable policy is not associated with a + variable name = (e.g. applied to variable vendor namespace) + and this param= eter is given, this parameter will not be + modified and V= ariableLockPolicyVariableNameBufferSize will + be set to zero= to indicate a name was not present. + + If the pointer= given is not NULL, + VariableLockPo= licyVariableNameBufferSize must be non-NULL. + + @retval EFI_SUCCESS A Lock on Variable State variable po= licy entry was found and returned + successfully. + @retval EFI_BAD_BUFFER_SIZE An internal buffer size caused a cal= culation error. + @retval EFI_BUFFER_TOO_SMALL The VariableLockPolicyVariableName b= uffer is too small for the size needed. + The buffer should now point to the s= ize needed. + @retval EFI_NOT_READY Variable policy has not yet been ini= tialized. + @retval EFI_INVALID_PARAMETER A required pointer argument passed i= s NULL. This will be returned if + VariableLockPolicyVariableName is no= n-NULL and + VariableLockPolicyVariableNameBuffer= Size is NULL. + @retval EFI_NOT_FOUND A Lock on Variable State variable po= licy was not found for the given UEFI + variable name and vendor GUID. + +**/ +STATIC +EFI_STATUS +EFIAPI +ProtocolGetLockOnVariableStateVariablePolicyInfo ( + IN CONST CHAR16 *VariableName, + IN CONST EFI_GUID *VendorGuid, + IN OUT UINTN *VariableLockPolicyVariableNameBufferSize, OPTIONAL + OUT VARIABLE_LOCK_ON_VAR_STATE_POLICY *VariablePolicy, + OUT CHAR16 *VariableLockPolicyVariableN= ame OPTIONAL + ) +{ + return InternalProtocolGetVariablePolicyInfo ( + VAR_CHECK_POLICY_COMMAND_GET_LOCK_VAR_STATE_INFO, + VariableName, + VendorGuid, + VariableLockPolicyVariableNameBufferSize, + VariablePolicy, + VariableLockPolicyVariableName + ); +} + /** This helper function locates the shared comm buffer and assigns it to in= put pointers. =20 @@ -514,12 +846,14 @@ VariablePolicySmmDxeMain ( } =20 // Configure the VariablePolicy protocol structure. - mVariablePolicyProtocol.Revision =3D EDKII_VARIABLE_POLIC= Y_PROTOCOL_REVISION; - mVariablePolicyProtocol.DisableVariablePolicy =3D ProtocolDisableVaria= blePolicy; - mVariablePolicyProtocol.IsVariablePolicyEnabled =3D ProtocolIsVariablePo= licyEnabled; - mVariablePolicyProtocol.RegisterVariablePolicy =3D ProtocolRegisterVari= ablePolicy; - mVariablePolicyProtocol.DumpVariablePolicy =3D ProtocolDumpVariable= Policy; - mVariablePolicyProtocol.LockVariablePolicy =3D ProtocolLockVariable= Policy; + mVariablePolicyProtocol.Revision =3D EDK= II_VARIABLE_POLICY_PROTOCOL_REVISION; + mVariablePolicyProtocol.DisableVariablePolicy =3D Pro= tocolDisableVariablePolicy; + mVariablePolicyProtocol.IsVariablePolicyEnabled =3D Pro= tocolIsVariablePolicyEnabled; + mVariablePolicyProtocol.RegisterVariablePolicy =3D Pro= tocolRegisterVariablePolicy; + mVariablePolicyProtocol.DumpVariablePolicy =3D Pro= tocolDumpVariablePolicy; + mVariablePolicyProtocol.LockVariablePolicy =3D Pro= tocolLockVariablePolicy; + mVariablePolicyProtocol.GetVariablePolicyInfo =3D Pro= tocolGetVariablePolicyInfo; + mVariablePolicyProtocol.GetLockOnVariableStateVariablePolicyInfo =3D Pro= tocolGetLockOnVariableStateVariablePolicyInfo; =20 // Register all the protocols and return the status. Status =3D gBS->InstallMultipleProtocolInterfaces ( diff --git a/MdeModulePkg/Include/Guid/VarCheckPolicyMmi.h b/MdeModulePkg/I= nclude/Guid/VarCheckPolicyMmi.h index ff3d4a1fd68a..a692fa40c946 100644 --- a/MdeModulePkg/Include/Guid/VarCheckPolicyMmi.h +++ b/MdeModulePkg/Include/Guid/VarCheckPolicyMmi.h @@ -32,23 +32,52 @@ typedef struct _VAR_CHECK_POLICY_COMM_DUMP_PARAMS { BOOLEAN HasMore; } VAR_CHECK_POLICY_COMM_DUMP_PARAMS; =20 +typedef union { + VARIABLE_POLICY_ENTRY VariablePolicy; + VARIABLE_LOCK_ON_VAR_STATE_POLICY LockOnVarStatePolicy; +} VAR_CHECK_POLICY_OUTPUT_POLICY_ENTRY; + +typedef struct _VAR_CHECK_POLICY_COMM_GET_INFO_PARAMS { + EFI_GUID InputVendorGuid; + UINT32 InputVariableNameSize; + UINT32 OutputVariableNameSize; + VAR_CHECK_POLICY_OUTPUT_POLICY_ENTRY OutputPolicyEntry; + CHAR16 InputVariableName[1]; +} VAR_CHECK_POLICY_COMM_GET_INFO_PARAMS; + #pragma pack(pop) =20 +#define VAR_CHECK_POLICY_COMM_GET_INFO_PARAMS_END \ + (OFFSET_OF(VAR_CHECK_POLICY_COMM_GET_INFO_PARAMS, InputVariabl= eName)) + // Make sure that we will hold at least the headers. #define VAR_CHECK_POLICY_MM_COMM_BUFFER_SIZE MAX((OFFSET_OF(EFI_MM_COMM= UNICATE_HEADER, Data) + sizeof (VAR_CHECK_POLICY_COMM_HEADER) + EFI_PAGES_T= O_SIZE(1)), EFI_PAGES_TO_SIZE(4)) #define VAR_CHECK_POLICY_MM_DUMP_BUFFER_SIZE (VAR_CHECK_POLICY_MM_COMM_= BUFFER_SIZE - \ (OFFSET_OF(EFI_MM_COMM= UNICATE_HEADER, Data) + \ sizeof(VAR_CHECK_POL= ICY_COMM_HEADER) + \ sizeof(VAR_CHECK_POL= ICY_COMM_DUMP_PARAMS))) + +#define VAR_CHECK_POLICY_MM_GET_INFO_BUFFER_SIZE (VAR_CHECK_POLICY_MM_C= OMM_BUFFER_SIZE - \ + (OFFSET_OF(EFI_MM_CO= MMUNICATE_HEADER, Data) + \ + sizeof(VAR_CHECK_P= OLICY_COMM_HEADER) + \ + OFFSET_OF(VAR_CHEC= K_POLICY_COMM_GET_INFO_PARAMS, InputVariableName))) + STATIC_ASSERT ( VAR_CHECK_POLICY_MM_DUMP_BUFFER_SIZE < VAR_CHECK_POLICY_MM_COMM_BUFFER_S= IZE, "an integer underflow may have occurred calculating VAR_CHECK_POLICY_MM_= DUMP_BUFFER_SIZE" ); =20 -#define VAR_CHECK_POLICY_COMMAND_DISABLE 0x0001 -#define VAR_CHECK_POLICY_COMMAND_IS_ENABLED 0x0002 -#define VAR_CHECK_POLICY_COMMAND_REGISTER 0x0003 -#define VAR_CHECK_POLICY_COMMAND_DUMP 0x0004 -#define VAR_CHECK_POLICY_COMMAND_LOCK 0x0005 +STATIC_ASSERT ( + VAR_CHECK_POLICY_MM_GET_INFO_BUFFER_SIZE < VAR_CHECK_POLICY_MM_COMM_BUFF= ER_SIZE, + "an integer underflow may have occurred calculating VAR_CHECK_POLICY_MM_= GET_INFO_BUFFER_SIZE" + ); + +#define VAR_CHECK_POLICY_COMMAND_DISABLE 0x0001 +#define VAR_CHECK_POLICY_COMMAND_IS_ENABLED 0x0002 +#define VAR_CHECK_POLICY_COMMAND_REGISTER 0x0003 +#define VAR_CHECK_POLICY_COMMAND_DUMP 0x0004 +#define VAR_CHECK_POLICY_COMMAND_LOCK 0x0005 +#define VAR_CHECK_POLICY_COMMAND_GET_INFO 0x0006 +#define VAR_CHECK_POLICY_COMMAND_GET_LOCK_VAR_STATE_INFO 0x0007 =20 #endif // _VAR_CHECK_POLICY_MMI_COMMON_H_ diff --git a/MdeModulePkg/Include/Library/VariablePolicyLib.h b/MdeModulePk= g/Include/Library/VariablePolicyLib.h index 63c49fbca1ed..bc4e26b2d434 100644 --- a/MdeModulePkg/Include/Library/VariablePolicyLib.h +++ b/MdeModulePkg/Include/Library/VariablePolicyLib.h @@ -102,6 +102,113 @@ DumpVariablePolicy ( IN OUT UINT32 *Size ); =20 +/** + This function will return variable policy information for a UEFI variabl= e with a + registered variable policy. + + @param[in] VariableName The name of the va= riable to use for the policy search. + @param[in] VendorGuid The vendor GUID of= the variable to use for the policy search. + @param[in,out] VariablePolicyVariableNameBufferSize On input, the size= , in bytes, of the VariablePolicyVariableName + buffer. + + On output, the siz= e, in bytes, needed to store the variable + policy variable na= me. + + If testing for the= VariablePolicyVariableName buffer size + needed, set this v= alue to zero so EFI_BUFFER_TOO_SMALL is + guaranteed to be r= eturned if the variable policy variable name + is found. + @param[out] VariablePolicy Pointer to a buffe= r where the policy entry will be written + if found. + @param[out] VariablePolicyVariableName Pointer to a buffe= r where the variable name used for the + variable policy wi= ll be written if a variable name is + registered. + + If the variable po= licy is not associated with a variable name + (e.g. applied to v= ariable vendor namespace) and this parameter + is given, this par= ameter will not be modified and + VariablePolicyVari= ableNameBufferSize will be set to zero to + indicate a name wa= s not present. + + If the pointer giv= en is not NULL, + VariablePolicyVari= ableNameBufferSize must be non-NULL. + + @retval EFI_SUCCESS A variable policy entry was found an= d returned successfully. + @retval EFI_BAD_BUFFER_SIZE An internal buffer size caused a cal= culation error. + @retval EFI_BUFFER_TOO_SMALL The VariablePolicyVariableName buffe= r value is too small for the size needed. + The buffer should now point to the s= ize needed. + @retval EFI_NOT_READY Variable policy has not yet been ini= tialized. + @retval EFI_INVALID_PARAMETER A required pointer argument passed i= s NULL. This will be returned if + VariablePolicyVariableName is non-NU= LL and VariablePolicyVariableNameBufferSize + is NULL. + @retval EFI_NOT_FOUND A variable policy was not found for = the given UEFI variable name and vendor GUID. + +**/ +EFI_STATUS +EFIAPI +GetVariablePolicyInfo ( + IN CONST CHAR16 *VariableName, + IN CONST EFI_GUID *VendorGuid, + IN OUT UINTN *VariablePolicyVariableNameBufferSize OPT= IONAL, + OUT VARIABLE_POLICY_ENTRY *VariablePolicy, + OUT CHAR16 *VariablePolicyVariableName OPTIONAL + ); + +/** + This function will return the Lock on Variable State policy information = for the policy + associated with the given UEFI variable. + + @param[in] VariableName The name of th= e variable to use for the policy search. + @param[in] VendorGuid The vendor GUI= D of the variable to use for the policy + search. + @param[in,out] VariableLockPolicyVariableNameBufferSize On input, the = size, in bytes, of the + VariableLockPo= licyVariableName buffer. + + On output, the= size, in bytes, needed to store the variable + policy variabl= e name. + + If testing for= the VariableLockPolicyVariableName buffer + size needed, s= et this value to zero so EFI_BUFFER_TOO_SMALL + is guaranteed = to be returned if the variable policy variable + name is found. + @param[out] VariablePolicy Pointer to a b= uffer where the policy entry will be written + if found. + @param[out] VariableLockPolicyVariableName Pointer to a b= uffer where the variable name used for the + variable lock = on variable state policy will be written if + a variable nam= e is registered. + + If the lock on= variable policy is not associated with a + variable name = (e.g. applied to variable vendor namespace) + and this param= eter is given, this parameter will not be + modified and V= ariableLockPolicyVariableNameBufferSize will + be set to zero= to indicate a name was not present. + + If the pointer= given is not NULL, + VariableLockPo= licyVariableNameBufferSize must be non-NULL. + + @retval EFI_SUCCESS A Lock on Variable State variable po= licy entry was found and returned + successfully. + @retval EFI_BAD_BUFFER_SIZE An internal buffer size caused a cal= culation error. + @retval EFI_BUFFER_TOO_SMALL The VariableLockPolicyVariableName b= uffer is too small for the size needed. + The buffer should now point to the s= ize needed. + @retval EFI_NOT_READY Variable policy has not yet been ini= tialized. + @retval EFI_INVALID_PARAMETER A required pointer argument passed i= s NULL. This will be returned if + VariableLockPolicyVariableName is no= n-NULL and + VariableLockPolicyVariableNameBuffer= Size is NULL. + @retval EFI_NOT_FOUND A Lock on Variable State variable po= licy was not found for the given UEFI + variable name and vendor GUID. + +**/ +EFI_STATUS +EFIAPI +GetLockOnVariableStateVariablePolicyInfo ( + IN CONST CHAR16 *VariableName, + IN CONST EFI_GUID *VendorGuid, + IN OUT UINTN *VariableLockPolicyVariableNa= meBufferSize OPTIONAL, + OUT VARIABLE_LOCK_ON_VAR_STATE_POLICY *VariablePolicy, + OUT CHAR16 *VariableLockPolicyVariableNa= me OPTIONAL + ); + /** This API function returns whether or not the policy engine is currently being enforced. diff --git a/MdeModulePkg/Include/Protocol/VariablePolicy.h b/MdeModulePkg/= Include/Protocol/VariablePolicy.h index 98d739401f83..4b57f70a9da8 100644 --- a/MdeModulePkg/Include/Protocol/VariablePolicy.h +++ b/MdeModulePkg/Include/Protocol/VariablePolicy.h @@ -9,7 +9,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef __EDKII_VARIABLE_POLICY_PROTOCOL__ #define __EDKII_VARIABLE_POLICY_PROTOCOL__ =20 -#define EDKII_VARIABLE_POLICY_PROTOCOL_REVISION 0x0000000000010000 +#define EDKII_VARIABLE_POLICY_PROTOCOL_REVISION 0x0000000000020000 + +/* + Rev 0x0000000000010000: + - Initial protocol definition + + Rev 0x0000000000020000: + - Add GetVariablePolicyInfo() API + - Add GetLockOnVariableStateVariablePolicyInfo() API + +*/ =20 #define EDKII_VARIABLE_POLICY_PROTOCOL_GUID \ { \ @@ -141,13 +151,122 @@ EFI_STATUS VOID ); =20 +/** + This function will return variable policy information for a UEFI variabl= e with a + registered variable policy. + + @param[in] VariableName The name of the va= riable to use for the policy search. + @param[in] VendorGuid The vendor GUID of= the variable to use for the policy search. + @param[in,out] VariablePolicyVariableNameBufferSize On input, the size= , in bytes, of the VariablePolicyVariableName + buffer. + + On output, the siz= e, in bytes, needed to store the variable + policy variable na= me. + + If testing for the= VariablePolicyVariableName buffer size + needed, set this v= alue to zero so EFI_BUFFER_TOO_SMALL is + guaranteed to be r= eturned if the variable policy variable name + is found. + @param[out] VariablePolicy Pointer to a buffe= r where the policy entry will be written + if found. + @param[out] VariablePolicyVariableName Pointer to a buffe= r where the variable name used for the + variable policy wi= ll be written if a variable name is + registered. + + If the variable po= licy is not associated with a variable name + (e.g. applied to v= ariable vendor namespace) and this parameter + is given, this par= ameter will not be modified and + VariablePolicyVari= ableNameBufferSize will be set to zero to + indicate a name wa= s not present. + + If the pointer giv= en is not NULL, + VariablePolicyVari= ableNameBufferSize must be non-NULL. + + @retval EFI_SUCCESS A variable policy entry was found an= d returned successfully. + @retval EFI_BAD_BUFFER_SIZE An internal buffer size caused a cal= culation error. + @retval EFI_BUFFER_TOO_SMALL The VariablePolicyVariableName buffe= r value is too small for the size needed. + The buffer should now point to the s= ize needed. + @retval EFI_NOT_READY Variable policy has not yet been ini= tialized. + @retval EFI_INVALID_PARAMETER A required pointer argument passed i= s NULL. This will be returned if + VariablePolicyVariableName is non-NU= LL and VariablePolicyVariableNameBufferSize + is NULL. + @retval EFI_NOT_FOUND A variable policy was not found for = the given UEFI variable name and vendor GUID. + +**/ +typedef +EFI_STATUS +(EFIAPI *GET_VARIABLE_POLICY_INFO)( + IN CONST CHAR16 *VariableName, + IN CONST EFI_GUID *VendorGuid, + IN OUT UINTN *VariablePolicyVariableNameBufferSiz= e OPTIONAL, + OUT VARIABLE_POLICY_ENTRY *VariablePolicy, + OUT CHAR16 *VariablePolicyVariableName OPTIONAL + ); + +/** + This function will return the Lock on Variable State policy information = for the policy + associated with the given UEFI variable. + + @param[in] VariableName The name of th= e variable to use for the policy search. + @param[in] VendorGuid The vendor GUI= D of the variable to use for the policy + search. + @param[in,out] VariableLockPolicyVariableNameBufferSize On input, the = size, in bytes, of the + VariableLockPo= licyVariableName buffer. + + On output, the= size, in bytes, needed to store the variable + policy variabl= e name. + + If testing for= the VariableLockPolicyVariableName buffer + size needed, s= et this value to zero so EFI_BUFFER_TOO_SMALL + is guaranteed = to be returned if the variable policy variable + name is found. + @param[out] VariablePolicy Pointer to a b= uffer where the policy entry will be written + if found. + @param[out] VariableLockPolicyVariableName Pointer to a b= uffer where the variable name used for the + variable lock = on variable state policy will be written if + a variable nam= e is registered. + + If the lock on= variable policy is not associated with a + variable name = (e.g. applied to variable vendor namespace) + and this param= eter is given, this parameter will not be + modified and V= ariableLockPolicyVariableNameBufferSize will + be set to zero= to indicate a name was not present. + + If the pointer= given is not NULL, + VariableLockPo= licyVariableNameBufferSize must be non-NULL. + + @retval EFI_SUCCESS A Lock on Variable State variable po= licy entry was found and returned + successfully. + @retval EFI_BAD_BUFFER_SIZE An internal buffer size caused a cal= culation error. + @retval EFI_BUFFER_TOO_SMALL The VariableLockPolicyVariableName b= uffer is too small for the size needed. + The buffer should now point to the s= ize needed. + @retval EFI_NOT_READY Variable policy has not yet been ini= tialized. + @retval EFI_INVALID_PARAMETER A required pointer argument passed i= s NULL. This will be returned if + VariableLockPolicyVariableName is no= n-NULL and + VariableLockPolicyVariableNameBuffer= Size is NULL. + @retval EFI_NOT_FOUND A Lock on Variable State variable po= licy was not found for the given UEFI + variable name and vendor GUID. + +**/ +typedef +EFI_STATUS +(EFIAPI *GET_LOCK_ON_VARIABLE_STATE_VARIABLE_POLICY_INFO)( + IN CONST CHAR16 *VariableName, + IN CONST EFI_GUID *VendorGuid, + IN OUT UINTN *VariableLockPolicyVariableN= ameBufferSize OPTIONAL, + OUT VARIABLE_LOCK_ON_VAR_STATE_POLICY *VariablePolicy, + OUT CHAR16 *VariableLockPolicyVariableN= ame OPTIONAL + ); + typedef struct { - UINT64 Revision; - DISABLE_VARIABLE_POLICY DisableVariablePolicy; - IS_VARIABLE_POLICY_ENABLED IsVariablePolicyEnabled; - REGISTER_VARIABLE_POLICY RegisterVariablePolicy; - DUMP_VARIABLE_POLICY DumpVariablePolicy; - LOCK_VARIABLE_POLICY LockVariablePolicy; + UINT64 Revision; + DISABLE_VARIABLE_POLICY DisableVariablePolicy; + IS_VARIABLE_POLICY_ENABLED IsVariablePolicyEnabl= ed; + REGISTER_VARIABLE_POLICY RegisterVariablePolic= y; + DUMP_VARIABLE_POLICY DumpVariablePolicy; + LOCK_VARIABLE_POLICY LockVariablePolicy; + GET_VARIABLE_POLICY_INFO GetVariablePolicyInfo; + GET_LOCK_ON_VARIABLE_STATE_VARIABLE_POLICY_INFO GetLockOnVariableStat= eVariablePolicyInfo; } _EDKII_VARIABLE_POLICY_PROTOCOL; =20 typedef _EDKII_VARIABLE_POLICY_PROTOCOL EDKII_VARIABLE_POLICY_PROTOCOL; diff --git a/MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf b= /MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf index 3fe6043bf631..7048d555f0a9 100644 --- a/MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf +++ b/MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf @@ -32,6 +32,7 @@ [Packages] =20 =20 [LibraryClasses] + BaseLib DebugLib BaseMemoryLib MemoryAllocationLib --=20 2.42.0.windows.2 -=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 (#110340): https://edk2.groups.io/g/devel/message/110340 Mute This Topic: https://groups.io/mt/102284381/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- From nobody Wed May 15 05:22:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+110341+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110341+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1698697903; cv=none; d=zohomail.com; s=zohoarc; b=bTnQbL6+lVjWvsVf8g1aaQJRqbkDZ0WmQvwbc85xV3uupfQAx9MunUJidIOkdwI2kgb5bPynt0ZialHDhtfyB5nHjtKG4MhHNJqo05cbXVXuZpdYc0wZW8W13P47Swb290ajREqOxa8o/KUwpICOh2GDnRm7Pw7+N1EieiZwEhY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698697903; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=ll0qNMBwD+MtJpUjPDLNpHaFUx7jOPBBMukSf9vqNzg=; b=lLuQNrmrbrLz8N2ge6oEdJaEw7VGIOgTkc023y+8Jccms9v2MqXbIGmGHCg95lVmkJKNbD3ggwho3UeGI44gYQhTuBTbnwdLgFbOWsvG80vWG2Bsu71O86061zQcmJEAL6styrnBsn0b9hGDrtaAEngkcR8Y/RvdbqxGDirVH60= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110341+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1698697903714240.81012791177932; Mon, 30 Oct 2023 13:31:43 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=uHw8SnO0C8rJ+XZOn2W01IACP2JqQ7boPyfpOIM7ez0=; c=relaxed/simple; d=groups.io; h=DKIM-Filter:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1698697903; v=1; b=ayTd3A8qN2+5lY3xoOgQxDb2+Zbv6pt1x1vLlxNozHdTBKm1aCGOAMr0G+fktuw2lpX14bLl 61X/1WGXfkkgtBrWo04vxV5unMWVI0FXqonE0N7R3EXI45TvJ2bmuhQ1m8yOuam4Y/Qk+ps8M+s L9KzWZSkMeU/qT9iGOtPo8KU= X-Received: by 127.0.0.2 with SMTP id twDAYY1788612xKdpLxGekXs; Mon, 30 Oct 2023 13:31:43 -0700 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web10.169261.1698697902721565055 for ; Mon, 30 Oct 2023 13:31:42 -0700 X-Received: from localhost.localdomain (unknown [47.201.241.95]) by linux.microsoft.com (Postfix) with ESMTPSA id AD1A820B74C0; Mon, 30 Oct 2023 13:31:41 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AD1A820B74C0 From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Zhichao Gao , Michael D Kinney , Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 2/4] ShellPkg: Add varpolicy dynamic shell command and app Date: Mon, 30 Oct 2023 16:31:10 -0400 Message-ID: <20231030203112.736-3-mikuback@linux.microsoft.com> In-Reply-To: <20231030203112.736-1-mikuback@linux.microsoft.com> References: <20231030203112.736-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: 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,mikuback@linux.microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: gZzFRDNpP7XoBOI2DqCEJR3xx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1698697905646100003 Content-Type: text/plain; charset="utf-8" From: Michael Kubacki Adds a new module (dynamic shell command) to ShellPkg that lists variable policy information for all UEFI variables on the system. Some other UEFI variable related functionality is also included to give a greater sense of platform UEFI variable state. This command is intended to help make variable policies more transparent and easier to understand and configure on a platform. Like all dynamic shell commands, a platform only needs to include `VariablePolicyDynamicCommand.inf` in their flash image to have the command registered in their UEFI shell. Include the following lines in platform DSC (in DXE components section): ``` ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynami= cCommand.inf { gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } ``` Include the following line in platform FDF: ``` INF ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDyn= amicCommand.inf ``` A standalone UEFI application can also be built that uses the same underlying functional code as the dynamic shell command. The path to use in the DSC and FDF for the app: ``` ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyApp.inf ``` Cc: Zhichao Gao Cc: Michael D Kinney Signed-off-by: Michael Kubacki Reviewed-by: Ard Biesheuvel Reviewed-by: Zhichao Gao --- ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicy.c = | 897 ++++++++++++++++++++ ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyApp.c = | 59 ++ ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynamic= Command.c | 157 ++++ ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicy.h = | 129 +++ ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicy.uni = | 86 ++ ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyApp.inf= | 62 ++ ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynamic= Command.inf | 61 ++ ShellPkg/ShellPkg.dsc = | 5 + 8 files changed, 1456 insertions(+) diff --git a/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariableP= olicy.c b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePoli= cy.c new file mode 100644 index 000000000000..ed991be4ed00 --- /dev/null +++ b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicy.c @@ -0,0 +1,897 @@ +/** @file + Main file for the "varpolicy" dynamic UEFI shell command and application. + + This feature can provide detailed UEFI variable policy configuration + information in the UEFI shell. + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "VariablePolicy.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define VAR_POLICY_FLAG_STATS_STR L"-s" +#define VAR_POLICY_FLAG_POLICY_STR L"-p" +#define VAR_POLICY_FLAG_VERBOSE_STR L"-v" + +#define VAR_POLICY_CMD_MIN_ATTR_STR_LEN 64 + +EFI_HII_HANDLE mVarPolicyShellCommandHiiHandle =3D NULL; + +STATIC CONST SHELL_PARAM_ITEM ParamList[] =3D { + { VAR_POLICY_FLAG_POLICY_STR, TypeFlag }, + { VAR_POLICY_FLAG_STATS_STR, TypeFlag }, + { VAR_POLICY_FLAG_VERBOSE_STR, TypeFlag }, + { NULL, TypeMax } +}; + +STATIC CONST VAR_POLICY_CMD_VAR_NAMESPACE mVarNamespaces[] =3D { + { + VariableVendorCapsule, + &gEfiCapsuleVendorGuid, + L"Capsule" + }, + { + VariableVendorCapsuleReport, + &gEfiCapsuleReportGuid, + L"Capsule Reporting" + }, + { + VariableVendorGlobal, + &gEfiGlobalVariableGuid, + L"UEFI Global" + }, + { + VariableVendorMemoryTypeInfo, + &gEfiMemoryTypeInformationGuid, + L"Memory Type Information" + }, + { + VariableVendorMonotonicCounter, + &gMtcVendorGuid, + L"Monotonic Counter" + }, + { + VariableVendorMorControl, + &gEfiMemoryOverwriteRequestControlLockGuid, + L"Memory Overwrite Request (MOR) Control Lock" + }, + { + VariableVendorShell, + &gShellVariableGuid, + L"UEFI Shell" + }, + { + VariableVendorShell, + &gShellAliasGuid, + L"UEFI Shell Alias" + } +}; + +/** + Returns UEFI variable attribute information in a string. + + AttributesStrSize must at least be VAR_POLICY_CMD_MIN_ATTR_STR_LEN in le= ngth + or EFI_INVALID_PARAMETER will be returned. + + @param[in] Attributes The UEFI variable attributes. + @param[in] AttributesStrSize The size, in bytes, of AttributesStr. + @param[out] AttributesStr The Unicode string for the given attr= ibutes. + + @retval EFI_SUCCESS The attributes were converted to a string = successfully. + @retval EFI_INVALID_PARAMETER The AttributesStr pointer is NULL. + +**/ +EFI_STATUS +GetAttributesString ( + IN UINT32 Attributes, + IN UINTN AttributesStrSize, + OUT CHAR16 *AttributesStr + ) +{ + if ((AttributesStr =3D=3D NULL) || (AttributesStrSize < VAR_POLICY_CMD_M= IN_ATTR_STR_LEN)) { + return EFI_INVALID_PARAMETER; + } + + AttributesStr[0] =3D L'0'; + AttributesStr[1] =3D L'x'; + AttributesStr[2] =3D L'\0'; + + UnicodeValueToStringS (AttributesStr + 2, AttributesStrSize - 2, (RADIX_= HEX), (INT64)Attributes, 30); + + if (Attributes =3D=3D 0) { + StrCatS (AttributesStr, AttributesStrSize, L" No Attributes"); + } else { + if ((Attributes & EFI_VARIABLE_NON_VOLATILE) =3D=3D EFI_VARIABLE_NON_V= OLATILE) { + StrCatS (AttributesStr, AttributesStrSize, L" NV"); + Attributes ^=3D EFI_VARIABLE_NON_VOLATILE; + } + + if ((Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS) =3D=3D EFI_VARIABLE= _BOOTSERVICE_ACCESS) { + StrCatS (AttributesStr, AttributesStrSize, L" BS"); + Attributes ^=3D EFI_VARIABLE_BOOTSERVICE_ACCESS; + } + + if ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) =3D=3D EFI_VARIABLE_RUN= TIME_ACCESS) { + StrCatS (AttributesStr, AttributesStrSize, L" RT"); + Attributes ^=3D EFI_VARIABLE_RUNTIME_ACCESS; + } + + if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) =3D=3D EFI_VARIA= BLE_HARDWARE_ERROR_RECORD) { + StrCatS (AttributesStr, AttributesStrSize, L" HW-Error"); + Attributes ^=3D EFI_VARIABLE_HARDWARE_ERROR_RECORD; + } + + if ((Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) =3D=3D EFI_= VARIABLE_AUTHENTICATED_WRITE_ACCESS) { + StrCatS (AttributesStr, AttributesStrSize, L" Auth-WA"); + Attributes ^=3D EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS; + } + + if ((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) = =3D=3D EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) { + StrCatS (AttributesStr, AttributesStrSize, L" Auth-TIME-WA"); + Attributes ^=3D EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS; + } + + if ((Attributes & EFI_VARIABLE_APPEND_WRITE) =3D=3D EFI_VARIABLE_APPEN= D_WRITE) { + StrCatS (AttributesStr, AttributesStrSize, L" APPEND-W"); + Attributes ^=3D EFI_VARIABLE_APPEND_WRITE; + } + + if (Attributes !=3D 0) { + StrCatS (AttributesStr, AttributesStrSize, L" "); + } + } + + return EFI_SUCCESS; +} + +/** + Prints UEFI variable statistics information. + + @param[in] TotalVariables Total number of UEFI variables dis= covered. + @param[in] TotalVariablesSize Total size of UEFI variables disco= vered. + +**/ +VOID +PrintStats ( + IN UINTN TotalVariables, + IN UINTN TotalVariablesSize + ) +{ + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_STATS_HEADER_1)= , mVarPolicyShellCommandHiiHandle); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_STATS_HEADER_2)= , mVarPolicyShellCommandHiiHandle); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_STATS_HEADER_1)= , mVarPolicyShellCommandHiiHandle); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_STATS_TOTAL_VAR= S), mVarPolicyShellCommandHiiHandle, TotalVariables); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_STATS_TOTAL_SIZ= E), mVarPolicyShellCommandHiiHandle, TotalVariablesSize, TotalVariablesSize= ); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_STATS_HEADER_1)= , mVarPolicyShellCommandHiiHandle); +} + +/** + Returns information for the given variable namespace if available. + + @param[in] VariableGuid The UEFI variable vendor (namespace) GUID. + + @return Pointer to a namespace info structure on a GUID match. + @return NULL on lack of a GUID match. + +**/ +CONST VAR_POLICY_CMD_VAR_NAMESPACE * +GetNameSpaceInfo ( + IN EFI_GUID *VariableGuid + ) +{ + UINTN Index; + + if (VariableGuid =3D=3D NULL) { + ASSERT (VariableGuid !=3D NULL); + return NULL; + } + + for (Index =3D 0; Index < ARRAY_SIZE (mVarNamespaces); Index++) { + if (CompareGuid (mVarNamespaces[Index].VendorGuid, VariableGuid)) { + return &mVarNamespaces[Index]; + } + } + + return NULL; +} + +/** + Print non-verbose information about the variable. + + @param[in] VariableName A pointer the Unicode variable name. + @param[in] VariableGuid A pointer to the variable vendor GUI= D. + @param[in] VariableSize The size of the UEFI variable in byt= es. + @param[in] VariableAttributes The UEFI variable attributes. + + @retval EFI_SUCCESS The non-verbose variable information= was printed successfully. + @retval EFI_INVALID_PARAMETER A pointer argument passed to the fun= ction was NULL. + @retval EFI_OUT_OF_RESOURCES Insufficient memory resources to pri= nt the attributes. + +**/ +EFI_STATUS +PrintNonVerboseVarInfo ( + IN CHAR16 *VariableName, + IN EFI_GUID *VariableGuid, + IN UINTN VariableSize, + IN UINT32 VariableAttributes + ) +{ + EFI_STATUS Status; + CHAR16 *AttributesStr; + CHAR16 *DescriptionStr; + CONST VAR_POLICY_CMD_VAR_NAMESPACE *CmdVarNamespace; + + AttributesStr =3D NULL; + DescriptionStr =3D NULL; + + if ((VariableName =3D=3D NULL) || (VariableGuid =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + CmdVarNamespace =3D GetNameSpaceInfo (VariableGuid); + + if (CmdVarNamespace =3D=3D NULL) { + DescriptionStr =3D AllocatePages (1); + if (DescriptionStr =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Exit; + } + + ZeroMem ((VOID *)DescriptionStr, EFI_PAGES_TO_SIZE (1)); + UnicodeSPrint (DescriptionStr, EFI_PAGES_TO_SIZE (1), L"Unknown Vendor= (%g)", VariableGuid); + } else { + DescriptionStr =3D CmdVarNamespace->Description; + } + + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_VAR_TYPE), mVar= PolicyShellCommandHiiHandle, DescriptionStr); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_VAR_NAME), mVar= PolicyShellCommandHiiHandle, VariableName); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_VAR_SIZE), mVar= PolicyShellCommandHiiHandle, VariableSize, VariableSize); + + AttributesStr =3D AllocatePages (1); + if (AttributesStr =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Exit; + } + + ZeroMem ((VOID *)AttributesStr, EFI_PAGES_TO_SIZE (1)); + Status =3D GetAttributesString (VariableAttributes, EFI_PAGES_TO_SIZE (1= ), AttributesStr); + if (Status =3D=3D EFI_SUCCESS) { + ShellPrintHiiEx ( + -1, + -1, + NULL, + STRING_TOKEN (STR_VAR_POL_VAR_ATTR), + mVarPolicyShellCommandHiiHandle, + AttributesStr + ); + } + + Status =3D EFI_SUCCESS; + +Exit: + if (AttributesStr !=3D NULL) { + FreePages (AttributesStr, 1); + } + + if ((CmdVarNamespace =3D=3D NULL) && (DescriptionStr !=3D NULL)) { + FreePages (DescriptionStr, 1); + } + + return Status; +} + +/** + Print verbose information about the variable. + + @param[in] Data A pointer to the variable data buffe= r. + @param[in] DataSize The size of data, in bytes, in the v= ariable data buffer. + + @retval EFI_SUCCESS The verbose variable information was= printed successfully. + @retval EFI_INVALID_PARAMETER A pointer argument passed to the fun= ction was NULL. + +**/ +EFI_STATUS +PrintVerboseVarInfo ( + IN VOID *Data, + IN UINTN DataSize + ) +{ + if ((DataSize =3D=3D 0) || (Data =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + VAR_POLICY_CMD_SHELL_DUMP_HEX (0, Data, DataSize); + + return EFI_SUCCESS; +} + +/** + Prints variable policy information for the given variable. + + @param[in] VariableName A pointer to the Unicode string of the UEFI = variable name. + @param[in] VendorGuid A pointer to the UEFI variable vendor GUID. + + @return TRUE if a variable policy was found and printed for the variable. + @return FALSE if an error occurred and/or a variable policy was not foun= d and + printed for the variable. + +**/ +BOOLEAN +PrintVariablePolicyInfo ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid + ) +{ + EFI_STATUS Status; + VARIABLE_POLICY_ENTRY VariablePolicyEntry; + VARIABLE_LOCK_ON_VAR_STATE_POLICY LockOnVarStatePolicy; + UINTN VariablePolicyVariableNameBufferSize; + UINTN ReturnedVariableNameSize; + BOOLEAN PolicyHeaderPresent; + CHAR16 *VariablePolicyVariableName; + CHAR16 *VariableAttributesStr; + EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy; + + PolicyHeaderPresent =3D FALSE; + VariableAttributesStr =3D NULL; + VariablePolicyVariableName =3D NULL; + + if ((VariableName =3D=3D NULL) || (VendorGuid =3D=3D NULL)) { + ASSERT ((VariableName !=3D NULL) && (VendorGuid !=3D NULL)); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_INT_ER= R), mVarPolicyShellCommandHiiHandle); + return FALSE; + } + + Status =3D gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid, NULL,= (VOID **)&VariablePolicy); + if (EFI_ERROR (Status)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_NO_PRO= T), mVarPolicyShellCommandHiiHandle); + return FALSE; + } + + VariablePolicyVariableNameBufferSize =3D EFI_PAGES_TO_SIZE (1); + VariablePolicyVariableName =3D AllocatePages (EFI_SIZE_TO_PAGE= S (VariablePolicyVariableNameBufferSize)); + if (VariablePolicyVariableName =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + ASSERT_EFI_ERROR (Status); + goto Done; + } + + ZeroMem (VariablePolicyVariableName, VariablePolicyVariableNameBufferSiz= e); + ReturnedVariableNameSize =3D VariablePolicyVariableNameBufferSize; + Status =3D VariablePolicy->GetVariablePolicyInfo ( + VariableName, + VendorGuid, + &ReturnedVariableNameSize, + &VariablePolicyEntry, + VariablePolicyVariableName + ); + if (Status =3D=3D EFI_NOT_READY) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_NOT_IN= IT), mVarPolicyShellCommandHiiHandle); + } else if (Status =3D=3D EFI_NOT_FOUND) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_NOT_FO= UND), mVarPolicyShellCommandHiiHandle); + } else if (EFI_ERROR (Status)) { + // A different error return code is not expected + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_UNEXP_= ERR), mVarPolicyShellCommandHiiHandle, Status); + } else { + PolicyHeaderPresent =3D TRUE; + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_HEADER= _1), mVarPolicyShellCommandHiiHandle); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_HEADER= _2), mVarPolicyShellCommandHiiHandle); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_HEADER= _1), mVarPolicyShellCommandHiiHandle); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_VERSIO= N), mVarPolicyShellCommandHiiHandle, VariablePolicyEntry.Version); + + if ((ReturnedVariableNameSize > 0) && (VariablePolicyVariableName[0] != =3D CHAR_NULL)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_VARI= ABLE), mVarPolicyShellCommandHiiHandle, VariablePolicyVariableName); + } else { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_VARI= ABLE), mVarPolicyShellCommandHiiHandle, L""); + } + + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_NAMESP= ACE), mVarPolicyShellCommandHiiHandle, &VariablePolicyEntry.Namespace); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_MIN_SI= ZE), mVarPolicyShellCommandHiiHandle, VariablePolicyEntry.MinSize); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_MAX_SI= ZE), mVarPolicyShellCommandHiiHandle, VariablePolicyEntry.MaxSize); + + switch (VariablePolicyEntry.LockPolicyType) { + case VARIABLE_POLICY_TYPE_NO_LOCK: + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_LO= CK_TYPE), mVarPolicyShellCommandHiiHandle, L"No Lock"); + break; + case VARIABLE_POLICY_TYPE_LOCK_NOW: + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_LO= CK_TYPE), mVarPolicyShellCommandHiiHandle, L"Lock Now"); + break; + case VARIABLE_POLICY_TYPE_LOCK_ON_CREATE: + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_LO= CK_TYPE), mVarPolicyShellCommandHiiHandle, L"On Create"); + break; + case VARIABLE_POLICY_TYPE_LOCK_ON_VAR_STATE: + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_LO= CK_TYPE), mVarPolicyShellCommandHiiHandle, L"On Variable State"); + + ZeroMem (VariablePolicyVariableName, VariablePolicyVariableNameBuf= ferSize); + ReturnedVariableNameSize =3D VariablePolicyVariableNameBufferSize; + Status =3D VariablePolicy->GetLockOnVariableSta= teVariablePolicyInfo ( + VariableName, + VendorGuid, + &ReturnedVariableNam= eSize, + &LockOnVarStatePolic= y, + VariablePolicyVariab= leName + ); + if (EFI_ERROR (Status)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_= UNEXP_ERR), mVarPolicyShellCommandHiiHandle, Status); + goto Done; + } else { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_= STATE_NS), mVarPolicyShellCommandHiiHandle, &LockOnVarStatePolicy.Namespace= ); + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_= STATE_VAL), mVarPolicyShellCommandHiiHandle, LockOnVarStatePolicy.Value); + if ((ReturnedVariableNameSize > 0) && (VariablePolicyVariableNam= e[0] !=3D CHAR_NULL)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLIC= Y_STATE_NAME), mVarPolicyShellCommandHiiHandle, VariablePolicyVariableName); + } else { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLIC= Y_STATE_NAME), mVarPolicyShellCommandHiiHandle, L""); + } + } + + break; + default: + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_LO= CK_TYPE), mVarPolicyShellCommandHiiHandle, L"Unknown"); + break; + } + + VariableAttributesStr =3D AllocatePages (1); + if (VariableAttributesStr =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + ASSERT_EFI_ERROR (Status); + goto Done; + } + + ZeroMem (VariableAttributesStr, EFI_PAGES_TO_SIZE (1)); + Status =3D GetAttributesString (VariablePolicyEntry.AttributesMustHave= , EFI_PAGES_TO_SIZE (1), VariableAttributesStr); + if (Status =3D=3D EFI_SUCCESS) { + ShellPrintHiiEx ( + -1, + -1, + NULL, + STRING_TOKEN (STR_VAR_POL_POLICY_ATTR_MUST), + mVarPolicyShellCommandHiiHandle + ); + ShellPrintHiiEx ( + -1, + -1, + NULL, + STRING_TOKEN (STR_VAR_POL_POLICY_ATTR_GEN), + mVarPolicyShellCommandHiiHandle, + VariableAttributesStr + ); + } + + ZeroMem (VariableAttributesStr, EFI_PAGES_TO_SIZE (1)); + Status =3D GetAttributesString (VariablePolicyEntry.AttributesCantHave= , EFI_PAGES_TO_SIZE (1), VariableAttributesStr); + if (Status =3D=3D EFI_SUCCESS) { + ShellPrintHiiEx ( + -1, + -1, + NULL, + STRING_TOKEN (STR_VAR_POL_POLICY_ATTR_NOT), + mVarPolicyShellCommandHiiHandle + ); + ShellPrintHiiEx ( + -1, + -1, + NULL, + STRING_TOKEN (STR_VAR_POL_POLICY_ATTR_GEN), + mVarPolicyShellCommandHiiHandle, + VariableAttributesStr + ); + } + } + +Done: + if (PolicyHeaderPresent) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VAR_POL_POLICY_HEADER= _1), mVarPolicyShellCommandHiiHandle); + } + + if (VariableAttributesStr !=3D NULL) { + FreePages (VariableAttributesStr, 1); + } + + if (VariablePolicyVariableName !=3D NULL) { + FreePages (VariablePolicyVariableName, 1); + } + + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_LINE_BREAK), mVarPo= licyShellCommandHiiHandle); + + return Status =3D=3D EFI_SUCCESS; +} + +/** + Gets the next UEFI variable name. + + This buffer manages the UEFI variable name buffer, performing memory rea= llocations as necessary. + + Note: The first time this function is called, VariableNameBufferSize mus= t be 0 and + the VariableName buffer pointer must point to NULL. + + @param[in,out] VariableNameBufferSize On input, a pointer to a buffer = that holds the current + size of the VariableName buffer = in bytes. + On output, a pointer to a buffer= that holds the updated + size of the VariableName buffer = in bytes. + @param[in,out] VariableName On input, a pointer to a pointer= to a buffer that holds the + current UEFI variable name. + On output, a pointer to a pointe= r to a buffer that holds the + next UEFI variable name. + @param[in,out] VariableGuid On input, a pointer to a buffer = that holds the current UEFI + variable GUID. + On output, a pointer to a buffer= that holds the next UEFI + variable GUID. + + @retval EFI_SUCCESS The next UEFI variable name was foun= d successfully. + @retval EFI_INVALID_PARAMETER A pointer argument is NULL or initia= l input values are invalid. + @retval EFI_OUT_OF_RESOURCES Insufficient memory resources to all= ocate a required buffer. + @retval Others Return status codes from the UEFI sp= ec define GetNextVariableName() interface. + +**/ +EFI_STATUS +GetNextVariableNameWithDynamicReallocation ( + IN OUT UINTN *VariableNameBufferSize, + IN OUT CHAR16 **VariableName, + IN OUT EFI_GUID *VariableGuid + ) +{ + EFI_STATUS Status; + UINTN NextVariableNameBufferSize; + + if ((VariableNameBufferSize =3D=3D NULL) || (VariableName =3D=3D NULL) |= | (VariableGuid =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + if (*VariableNameBufferSize =3D=3D 0) { + if (*VariableName !=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Allocate a buffer to temporarily hold variable names. To reduce mem= ory + // allocations, the default buffer size is 256 characters. The buffer = can + // be reallocated if expansion is necessary (should be very rare). + // + *VariableNameBufferSize =3D sizeof (CHAR16) * 256; + *VariableName =3D AllocateZeroPool (*VariableNameBufferSize); + if (*VariableName =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + ZeroMem ((VOID *)VariableGuid, sizeof (EFI_GUID)); + } + + NextVariableNameBufferSize =3D *VariableNameBufferSize; + Status =3D gRT->GetNextVariableName ( + &NextVariableNameBufferSize, + *VariableName, + VariableGuid + ); + if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { + *VariableName =3D ReallocatePool ( + *VariableNameBufferSize, + NextVariableNameBufferSize, + *VariableName + ); + if (*VariableName =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + *VariableNameBufferSize =3D NextVariableNameBufferSize; + + Status =3D gRT->GetNextVariableName ( + &NextVariableNameBufferSize, + *VariableName, + VariableGuid + ); + ASSERT (Status !=3D EFI_BUFFER_TOO_SMALL); + } + + return Status; +} + +/** + Dumps UEFI variable information. + + This is the main function that enumerates UEFI variables and prints the = information + selected by the user. + + @param[in] Verbose Whether to print verbose information. + @param[in] Stats Whether to print statistical information. + @param[in] PolicyCheck Whether to print variable policy related i= nformation. + + + @retval EFI_SUCCESS The UEFI variable information was du= mped successfully. + @retval EFI_DEVICE_ERROR An error occurred attempting to get = UEFI variable information. + @retval EFI_OUT_OF_RESOURCES Insufficient memory resources to all= ocate a required buffer. + +**/ +EFI_STATUS +DumpVars ( + IN BOOLEAN Verbose, + IN BOOLEAN Stats, + IN BOOLEAN PolicyCheck + ) +{ + EFI_STATUS Status; + EFI_STATUS GetNextVariableStatus; + UINT32 Attributes; + UINTN CurrentVariableDataBufferSize; + UINTN DataSize; + UINTN TotalDataSize; + UINTN TotalVariables; + UINTN TotalVariablesWithPolicy; + UINTN VariableNameBufferSize; + EFI_GUID VariableGuid; + CHAR16 *VariableName; + VOID *Data; + + Status =3D EFI_SUCCESS; + Data =3D NULL; + VariableName =3D NULL; + CurrentVariableDataBufferSize =3D 0; + TotalDataSize =3D 0; + TotalVariables =3D 0; + TotalVariablesWithPolicy =3D 0; + VariableNameBufferSize =3D 0; + + do { + GetNextVariableStatus =3D GetNextVariableNameWithDynamicReallocation ( + &VariableNameBufferSize, + &VariableName, + &VariableGuid + ); + + if (!EFI_ERROR (GetNextVariableStatus)) { + DataSize =3D 0; + Status =3D gRT->GetVariable ( + VariableName, + &VariableGuid, + &Attributes, + &DataSize, + NULL + ); + if (Status !=3D EFI_BUFFER_TOO_SMALL) { + // If the variable exists, a zero size buffer should be too small + Status =3D EFI_DEVICE_ERROR; + goto DeallocateAndExit; + } + + TotalDataSize +=3D DataSize; + TotalVariables++; + + if (!Stats || Verbose) { + Status =3D PrintNonVerboseVarInfo (VariableName, &VariableGuid, Da= taSize, Attributes); + if (!EFI_ERROR (Status)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_LINE_BREAK)= , mVarPolicyShellCommandHiiHandle); + } + } + + if (PolicyCheck || Verbose) { + if (PrintVariablePolicyInfo (VariableName, &VariableGuid)) { + TotalVariablesWithPolicy++; + } + } + + if (Verbose) { + if (CurrentVariableDataBufferSize < DataSize) { + if (Data !=3D NULL) { + FreePool (Data); + } + + Data =3D AllocateZeroPool (DataSize); + if (Data =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto DeallocateAndExit; + } + + CurrentVariableDataBufferSize =3D DataSize; + } + + Status =3D gRT->GetVariable ( + VariableName, + &VariableGuid, + NULL, + &DataSize, + Data + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto DeallocateAndExit; + } + + Status =3D PrintVerboseVarInfo (Data, DataSize); + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto DeallocateAndExit; + } + } + } + } while (!EFI_ERROR (GetNextVariableStatus)); + + if (TotalVariables =3D=3D 0) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VARS), mVarPol= icyShellCommandHiiHandle); + } else { + if (Verbose || Stats) { + PrintStats (TotalVariables, TotalDataSize); + } + + if (Verbose || PolicyCheck) { + ASSERT (TotalVariablesWithPolicy <=3D TotalVariables); + + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_LINE_BREAK), mV= arPolicyShellCommandHiiHandle); + if (TotalVariablesWithPolicy =3D=3D TotalVariables) { + ShellPrintHiiEx ( + -1, + -1, + NULL, + STRING_TOKEN (STR_VAR_POL_POLICY_STATS_PASS), + mVarPolicyShellCommandHiiHandle, + TotalVariablesWithPolicy, + TotalVariables + ); + } else { + ShellPrintHiiEx ( + -1, + -1, + NULL, + STRING_TOKEN (STR_VAR_POL_POLICY_STATS_FAIL), + mVarPolicyShellCommandHiiHandle, + TotalVariablesWithPolicy, + TotalVariables + ); + } + + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_LINE_BREAK), mV= arPolicyShellCommandHiiHandle); + } + } + + Status =3D EFI_SUCCESS; + +DeallocateAndExit: + if (VariableName !=3D NULL) { + FreePool (VariableName); + } + + if (Data !=3D NULL) { + FreePool (Data); + } + + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** + Main entry function for the "varpolicy" command/app. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). + + @retval SHELL_SUCCESS The "varpolicy" shell command exec= uted successfully. + @retval SHELL_ABORTED Failed to initialize the shell lib= rary. + @retval SHELL_INVALID_PARAMETER An argument passed to the shell co= mmand is invalid. + @retval Others A different error occurred. + +**/ +SHELL_STATUS +EFIAPI +RunVarPolicy ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + SHELL_STATUS ShellStatus; + BOOLEAN PolicyCheck; + BOOLEAN StatsDump; + BOOLEAN VerboseDump; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + + Package =3D NULL; + ShellStatus =3D SHELL_INVALID_PARAMETER; + Status =3D EFI_SUCCESS; + PolicyCheck =3D FALSE; + StatsDump =3D FALSE; + VerboseDump =3D FALSE; + + Status =3D ShellInitialize (); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return SHELL_ABORTED; + } + + Status =3D ShellCommandLineParse (ParamList, &Package, &ProblemParam, TR= UE); + if (EFI_ERROR (Status)) { + if ((Status =3D=3D EFI_VOLUME_CORRUPTED) && (ProblemParam !=3D NULL)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), mVarP= olicyShellCommandHiiHandle, VAR_POLICY_COMMAND_NAME, ProblemParam); + FreePool (ProblemParam); + ShellStatus =3D SHELL_INVALID_PARAMETER; + goto Done; + } else { + ASSERT (FALSE); + } + } else { + if (ShellCommandLineGetCount (Package) > 1) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), mVar= PolicyShellCommandHiiHandle, VAR_POLICY_COMMAND_NAME); + ShellStatus =3D SHELL_INVALID_PARAMETER; + goto Done; + } + + PolicyCheck =3D ShellCommandLineGetFlag (Package, VAR_POLICY_FLAG_POLI= CY_STR); + StatsDump =3D ShellCommandLineGetFlag (Package, VAR_POLICY_FLAG_STAT= S_STR); + VerboseDump =3D ShellCommandLineGetFlag (Package, VAR_POLICY_FLAG_VERB= OSE_STR); + + Status =3D DumpVars (VerboseDump, StatsDump, PolicyCheck); + ASSERT_EFI_ERROR (Status); + } + +Done: + if (Package !=3D NULL) { + ShellCommandLineFreeVarList (Package); + } + + return ShellStatus; +} + +/** + Retrieve HII package list from ImageHandle and publish to HII database. + + @param[in] ImageHandle The image handle of the process. + + @return HII handle. + +**/ +EFI_HII_HANDLE +InitializeHiiPackage ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + EFI_HII_PACKAGE_LIST_HEADER *PackageList; + EFI_HII_HANDLE HiiHandle; + + // + // Retrieve HII package list from ImageHandle + // + Status =3D gBS->OpenProtocol ( + ImageHandle, + &gEfiHiiPackageListProtocolGuid, + (VOID **)&PackageList, + ImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return NULL; + } + + // + // Publish HII package list to HII Database. + // + Status =3D gHiiDatabase->NewPackageList ( + gHiiDatabase, + PackageList, + NULL, + &HiiHandle + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return NULL; + } + + return HiiHandle; +} diff --git a/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariableP= olicyApp.c b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariableP= olicyApp.c new file mode 100644 index 000000000000..f3ab45de6ae8 --- /dev/null +++ b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyAp= p.c @@ -0,0 +1,59 @@ +/** @file + Functionality specific for standalone UEFI application support. + + This application can provide detailed UEFI variable policy configuration + information in the UEFI shell. + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "VariablePolicy.h" + +#include +#include + +extern EFI_HII_HANDLE mVarPolicyShellCommandHiiHandle; + +// +// String token ID of help message text. +// Shell supports finding the help message in the resource section of an +// application image if a .MAN file is not found. This global variable is = added +// to make the build tool recognize that the help string is consumed by th= e user and +// then the build tool will add the string into the resource section. Thus= the +// application can use '-?' option to show help message in Shell. +// +GLOBAL_REMOVE_IF_UNREFERENCED EFI_STRING_ID mStringHelpTokenId =3D STRING= _TOKEN (STR_GET_HELP_VAR_POLICY); + +/** + Entry of the UEFI variable policy application. + + @param ImageHandle The image handle of the process. + @param SystemTable The EFI System Table pointer. + + @retval EFI_SUCCESS The application successfully initialized. + @retval EFI_ABORTED The application failed to initialize. + @retval Others A different error occurred. + +**/ +EFI_STATUS +EFIAPI +VariablePolicyAppInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + mVarPolicyShellCommandHiiHandle =3D InitializeHiiPackage (ImageHandle); + if (mVarPolicyShellCommandHiiHandle =3D=3D NULL) { + return EFI_ABORTED; + } + + Status =3D (EFI_STATUS)RunVarPolicy (ImageHandle, SystemTable); + + HiiRemovePackages (mVarPolicyShellCommandHiiHandle); + + return Status; +} diff --git a/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariableP= olicyDynamicCommand.c b/ShellPkg/DynamicCommand/VariablePolicyDynamicComman= d/VariablePolicyDynamicCommand.c new file mode 100644 index 000000000000..c1e309ad078f --- /dev/null +++ b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDy= namicCommand.c @@ -0,0 +1,157 @@ +/** @file + Functionality specific for dynamic UEFI shell command support. + + This command can provide detailed UEFI variable policy configuration + information in the UEFI shell. + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "VariablePolicy.h" + +#include +#include +#include +#include +#include +#include + +#include + +extern EFI_HII_HANDLE mVarPolicyShellCommandHiiHandle; + +/** + This is the shell command handler function pointer callback type. + + This function handles the command when it is invoked in the shell. + + @param[in] This The instance of the + EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL. + @param[in] SystemTable The pointer to the system table. + @param[in] ShellParameters The parameters associated with the com= mand. + @param[in] Shell The instance of the shell protocol use= d in + the context of processing this command. + + @return EFI_SUCCESS the operation was successful + @return other the operation failed. + +**/ +SHELL_STATUS +EFIAPI +VarPolicyCommandHandler ( + IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This, + IN EFI_SYSTEM_TABLE *SystemTable, + IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, + IN EFI_SHELL_PROTOCOL *Shell + ) +{ + gEfiShellParametersProtocol =3D ShellParameters; + gEfiShellProtocol =3D Shell; + + return RunVarPolicy (gImageHandle, SystemTable); +} + +/** + This is the command help handler function pointer callback type. This + function is responsible for displaying help information for the associat= ed + command. + + @param[in] This The instance of the + EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL. + @param[in] Language The pointer to the language string to = use. + + @return string Pool allocated help string, must be fr= eed + by caller. + +**/ +STATIC +CHAR16 * +EFIAPI +VarPolicyCommandGetHelp ( + IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This, + IN CONST CHAR8 *Language + ) +{ + return HiiGetString ( + mVarPolicyShellCommandHiiHandle, + STRING_TOKEN (STR_GET_HELP_VAR_POLICY), + Language + ); +} + +STATIC EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mVarPolicyDynamicCommand =3D { + VAR_POLICY_COMMAND_NAME, + VarPolicyCommandHandler, + VarPolicyCommandGetHelp +}; + +/** + Entry point of the UEFI variable policy dynamic shell command. + + Produce the Dynamic Command Protocol to handle the "varpolicy" command. + + @param[in] ImageHandle The image handle of the process. + @param[in] SystemTable The EFI System Table pointer. + + @retval EFI_SUCCESS The "varpolicy" command executed successfu= lly. + @retval EFI_ABORTED HII package failed to initialize. + @retval others Other errors when executing "varpolicy" co= mmand. + +**/ +EFI_STATUS +EFIAPI +VariablePolicyDynamicCommandEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + mVarPolicyShellCommandHiiHandle =3D InitializeHiiPackage (ImageHandle); + if (mVarPolicyShellCommandHiiHandle =3D=3D NULL) { + return EFI_ABORTED; + } + + Status =3D gBS->InstallProtocolInterface ( + &ImageHandle, + &gEfiShellDynamicCommandProtocolGuid, + EFI_NATIVE_INTERFACE, + &mVarPolicyDynamicCommand + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** + Unload the dynamic "varpolicy" UEFI Shell command. + + @param[in] ImageHandle The image handle of the process. + + @retval EFI_SUCCESS The image is unloaded. + @retval Others Failed to unload the image. + +**/ +EFI_STATUS +EFIAPI +VariablePolicyDynamicCommandUnload ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + + Status =3D gBS->UninstallProtocolInterface ( + ImageHandle, + &gEfiShellDynamicCommandProtocolGuid, + &mVarPolicyDynamicCommand + ); + if (EFI_ERROR (Status)) { + return Status; + } + + HiiRemovePackages (mVarPolicyShellCommandHiiHandle); + + return EFI_SUCCESS; +} diff --git a/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariableP= olicy.h b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePoli= cy.h new file mode 100644 index 000000000000..049823242659 --- /dev/null +++ b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicy.h @@ -0,0 +1,129 @@ +/** @file + Internal header file for the module. + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef VAR_POLICY_DYNAMIC_SHELL_COMMAND_H_ +#define VAR_POLICY_DYNAMIC_SHELL_COMMAND_H_ + +#include +#include + +#define VAR_POLICY_COMMAND_NAME L"varpolicy" + +typedef enum { + VariableVendorCapsule, + VariableVendorCapsuleReport, + VariableVendorGlobal, + VariableVendorMemoryTypeInfo, + VariableVendorMonotonicCounter, + VariableVendorMorControl, + VariableVendorShell, + VariableVendorGuidMax +} VAR_POLICY_CMD_VENDOR_GUID_TYPE; + +typedef struct { + VAR_POLICY_CMD_VENDOR_GUID_TYPE VendorGuidType; + EFI_GUID *VendorGuid; + CHAR16 *Description; +} VAR_POLICY_CMD_VAR_NAMESPACE; + +/** + Log a formatted console message. + + This is not specific to this shell command but scoped so to prevent glob= al + name conflicts. + + The hex dump is split into lines of 16 dumped bytes. + + The full hex dump is bracketed, and its byte ascii char also print. + If the byte value is not an ascii code, it will print as '.' + + @param[in] Offset Offset to be display after PrefixFormat. + Offset will be increased for each print lin= e. + @param[in] Data The data to dump. + @param[in] DataSize Number of bytes in Data. + +**/ +#define VAR_POLICY_CMD_SHELL_DUMP_HEX(Offset, = \ + Data, = \ + DataSize = \ + ) = \ + { = \ + UINT8 *_DataToDump; = \ + UINT8 _Val[50]; = \ + UINT8 _Str[20]; = \ + UINT8 _TempByte; = \ + UINTN _Size; = \ + UINTN _DumpHexIndex; = \ + UINTN _LocalOffset; = \ + UINTN _LocalDataSize; = \ + CONST CHAR8 *_Hex =3D "0123456789ABCDEF"; = \ + _LocalOffset =3D (Offset); = \ + _LocalDataSize =3D (DataSize); = \ + _DataToDump =3D (UINT8 *)(Data); = \ + = \ + ASSERT (_DataToDump !=3D NULL); = \ + = \ + while (_LocalDataSize !=3D 0) { = \ + _Size =3D 16; = \ + if (_Size > _LocalDataSize) { = \ + _Size =3D _LocalDataSize; = \ + } = \ + = \ + for (_DumpHexIndex =3D 0; _DumpHexIndex < _Size; _DumpHexIndex= +=3D 1) { \ + _TempByte =3D (UINT8) _DataToDump[_DumpHexIndex];= \ + _Val[_DumpHexIndex * 3 + 0] =3D (UINT8) _Hex[_TempByte >> 4= ]; \ + _Val[_DumpHexIndex * 3 + 1] =3D (UINT8) _Hex[_TempByte & 0x= F]; \ + _Val[_DumpHexIndex * 3 + 2] =3D = \ + (CHAR8) ((_DumpHexIndex =3D=3D 7) ? '-' : ' '); = \ + _Str[_DumpHexIndex] =3D = \ + (CHAR8) ((_TempByte < ' ' || _TempByte > '~') ? '.' : _Tem= pByte); \ + } = \ + = \ + _Val[_DumpHexIndex * 3] =3D 0; = \ + _Str[_DumpHexIndex] =3D 0; = \ + = \ + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_HEX_DUMP_= LINE), mVarPolicyShellCommandHiiHandle, _LocalOffset, _Val, _Str); \ + _DataToDump =3D (UINT8 *)(((UINTN)_DataToDump) + _Size); = \ + _LocalOffset +=3D _Size; = \ + _LocalDataSize -=3D _Size; = \ + } = \ + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_LINE_BREAK)= , mVarPolicyShellCommandHiiHandle); \ + } + +/** + Retrieve HII package list from ImageHandle and publish to HII database. + + @param[in] ImageHandle The image handle of the process. + + @return HII handle. + +**/ +EFI_HII_HANDLE +InitializeHiiPackage ( + IN EFI_HANDLE ImageHandle + ); + +/** + Main entry function for the "varpolicy" command/app. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). + + @retval SHELL_SUCCESS The "varpolicy" shell command exec= uted successfully. + @retval SHELL_INVALID_PARAMETER An argument passed to the shell co= mmand is invalid. + @retval Others A different error occurred. + +**/ +SHELL_STATUS +EFIAPI +RunVarPolicy ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +#endif diff --git a/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariableP= olicy.uni b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePo= licy.uni new file mode 100644 index 000000000000..194468285609 --- /dev/null +++ b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicy.u= ni @@ -0,0 +1,86 @@ +// /** +// String definitions for the Variable Policy ("varpolicy") shell command/= app. +// +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +/=3D# + +#langdef en-US "english" + +// General Strings +#string STR_GEN_PROBLEM #language en-US "%H%s%N: Unknown fla= g - '%H%s%N'\r\n" +#string STR_GEN_TOO_MANY #language en-US "%H%s%N: Too many ar= guments.\r\n" +#string STR_GEN_NO_VARS #language en-US "No UEFI variables f= ound!\r\n" +#string STR_GEN_LINE_BREAK #language en-US "\r\n" + +#string STR_GEN_HEX_DUMP_LINE #language en-US "%B%08X%N: %-48a %V*= %a*%N\r\n" + +#string STR_VAR_POL_POLICY_INT_ERR #language en-US "%EInternal Applica= tion Error Getting Policy Info!%N\r\n" +#string STR_VAR_POL_POLICY_NO_PROT #language en-US "%EVariable Policy = Protocol Was Not Found!%N\r\n" +#string STR_VAR_POL_POLICY_NOT_INIT #language en-US "%EUEFI Variable Po= licy is Not Initialized!%N\r\n" +#string STR_VAR_POL_POLICY_NOT_FOUND #language en-US "%EVariable Policy = Not Found for This Variable!%N\r\n" +#string STR_VAR_POL_POLICY_UNEXP_ERR #language en-US "%EUnexpected Error= Getting Policy Info!%N - %H%r%N\r\n" +#string STR_VAR_POL_POLICY_HEADER_1 #language en-US "+-----------------= ------------------------------------------------------------+\r\n" +#string STR_VAR_POL_POLICY_HEADER_2 #language en-US "| Variable Policy = Info |\r\n" +#string STR_VAR_POL_POLICY_VERSION #language en-US "| Version: 0x%-8x = |\r\n" +#string STR_VAR_POL_POLICY_VARIABLE #language en-US "| Variable: % -64s= |\r\n" +#string STR_VAR_POL_POLICY_NAMESPACE #language en-US "| Namespace: {%g} = |\r\n" +#string STR_VAR_POL_POLICY_MIN_SIZE #language en-US "| Minimum Size: 0x= %-8x |\r\n" +#string STR_VAR_POL_POLICY_MAX_SIZE #language en-US "| Maximum Size: 0x= %-8x |\r\n" +#string STR_VAR_POL_POLICY_ATTR_MUST #language en-US "| Required Attribu= tes: |\r\n" +#string STR_VAR_POL_POLICY_ATTR_NOT #language en-US "| Disallowed Attri= butes: |\r\n" +#string STR_VAR_POL_POLICY_ATTR_GEN #language en-US "| %73-.73s |\r\n" +#string STR_VAR_POL_POLICY_LOCK_TYPE #language en-US "| Lock Type: % -64= s |\r\n" +#string STR_VAR_POL_POLICY_STATE_NS #language en-US "| Namespace: {%g= } |\r\n" +#string STR_VAR_POL_POLICY_STATE_VAL #language en-US "| Value: 0x%-8x = |\r\n" +#string STR_VAR_POL_POLICY_STATE_NAME #language en-US "| Name: % -64s = |\r\n" +#string STR_VAR_POL_POLICY_STATS_PASS #language en-US " %V%d/%d UEFI var= iables have policy%N\r\n" +#string STR_VAR_POL_POLICY_STATS_FAIL #language en-US " %E%d/%d UEFI var= iables have policy%N\r\n" + +#string STR_VAR_POL_VAR_TYPE #language en-US "%H% -70s%N\r\n" +#string STR_VAR_POL_VAR_NAME #language en-US "Name: % -70s\r\n" +#string STR_VAR_POL_VAR_SIZE #language en-US "Size: 0x%-16x (%-,d)= bytes\r\n" +#string STR_VAR_POL_VAR_ATTR #language en-US "Attributes: % -60s\r= \n" + +#string STR_VAR_POL_STATS_HEADER_1 #language en-US "+-------------------= ---------------------------------------------+\r\n" +#string STR_VAR_POL_STATS_HEADER_2 #language en-US "| UEFI Variable Stat= istics |\r\n" +#string STR_VAR_POL_STATS_TOTAL_VARS #language en-US " Total UEFI Variabl= es: %,d\r\n" +#string STR_VAR_POL_STATS_TOTAL_SIZE #language en-US " Total UEFI Variabl= e Size: 0x%x (%,d) bytes\r\n" + +#string STR_GET_HELP_VAR_POLICY #language en-US "" +".TH varpolicy 0 "Lists UEFI variable policy information."\r\n" +".SH NAME\r\n" +"Lists UEFI variable policy information.\r\n" +".SH SYNOPSIS\r\n" +" \r\n" +"VARPOLICY [-p] [-s] [-v]\r\n" +".SH OPTIONS\r\n" +" \r\n" +" -p - The policy flag will print variable policy info for each variable.= \r\n" +" \r\n" +" -s - The stats flag will print overall UEFI variable policy statistics.= \r\n" +" \r\n" +" -v - The verbose flag indicates all known information should be printed= .\r\n" +" \r\n" +" This includes a dump of the corresponding UEFI variable data in\r\= n" +" addition to all other UEFI variable policy information.\r\n" +".SH DESCRIPTION\r\n" +" \r\n" +".SH EXAMPLES\r\n" +" \r\n" +"EXAMPLES:\r\n" +" * To dump all active UEFI variables:\r\n" +" fs0:\> varpolicy\r\n" +"\r\n" +" * To include UEFI variable policy information:\r\n" +" fs0:\> varpolicy -p\r\n" +"\r\n" +" * To include UEFI variable statistics:\r\n" +" fs0:\> varpolicy -s\r\n" +"\r\n" +" * To include a hexadecimal dump of data for each variable\r\n" +" and all other variable information:\r\n" +" fs0:\> varpolicy -v\r\n" diff --git a/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariableP= olicyApp.inf b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/Variabl= ePolicyApp.inf new file mode 100644 index 000000000000..1e8abe0923d1 --- /dev/null +++ b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyAp= p.inf @@ -0,0 +1,62 @@ +## @file +# A UEFI variable policy application that displays information +# about UEFI variable policy configuration on the system. +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010006 + BASE_NAME =3D varpolicy + FILE_GUID =3D CA3D995F-3291-45AF-B50A-7C8AE584D857 + MODULE_TYPE =3D UEFI_APPLICATION + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D VariablePolicyAppInitialize + # Note: GetHelpText() in the EFI shell protocol will associate the help = text + # for the app if the app name (command) matches the .TH section na= me in + # the Unicode help text. That name is "varpolicy". + UEFI_HII_RESOURCE_SECTION =3D TRUE + +[Sources.common] + VariablePolicy.uni + VariablePolicy.h + VariablePolicy.c + VariablePolicyApp.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ShellPkg/ShellPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + HiiLib + MemoryAllocationLib + PrintLib + ShellLib + UefiApplicationEntryPoint + UefiBootServicesTableLib + UefiHiiServicesLib + UefiRuntimeServicesTableLib + +[Protocols] + gEdkiiVariablePolicyProtocolGuid ## SOMETIMES_CONSUMES + gEfiHiiPackageListProtocolGuid ## CONSUMES + +[Guids] + ## SOMETIMES_CONSUMES ## Variables in Vendor Namespace + gEfiCapsuleReportGuid + gEfiCapsuleVendorGuid + gEfiGlobalVariableGuid + gEfiMemoryOverwriteRequestControlLockGuid + gEfiMemoryTypeInformationGuid + gMtcVendorGuid + gShellAliasGuid + gShellVariableGuid + +[DEPEX] + TRUE diff --git a/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariableP= olicyDynamicCommand.inf b/ShellPkg/DynamicCommand/VariablePolicyDynamicComm= and/VariablePolicyDynamicCommand.inf new file mode 100644 index 000000000000..120e7339daa3 --- /dev/null +++ b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDy= namicCommand.inf @@ -0,0 +1,61 @@ +## @file +# A UEFI variable policy dynamic shell command that displays information +# about UEFI variable policy configuration on the system. +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D VariablePolicyDynamicCommand + FILE_GUID =3D 17D0EF2A-5933-4007-8950-5749169D3DC5 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D VariablePolicyDynamicCommandEntryPoint + UNLOAD_IMAGE =3D VariablePolicyDynamicCommandUnload + UEFI_HII_RESOURCE_SECTION =3D TRUE + +[Sources.common] + VariablePolicy.uni + VariablePolicy.h + VariablePolicy.c + VariablePolicyDynamicCommand.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ShellPkg/ShellPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + HiiLib + MemoryAllocationLib + PrintLib + ShellLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiHiiServicesLib + UefiRuntimeServicesTableLib + +[Protocols] + gEdkiiVariablePolicyProtocolGuid ## SOMETIMES_CONSUMES + gEfiHiiPackageListProtocolGuid ## CONSUMES + gEfiShellDynamicCommandProtocolGuid ## PRODUCES + +[Guids] + ## SOMETIMES_CONSUMES ## Variables in Vendor Namespace + gEfiCapsuleReportGuid + gEfiCapsuleVendorGuid + gEfiGlobalVariableGuid + gEfiMemoryOverwriteRequestControlLockGuid + gEfiMemoryTypeInformationGuid + gMtcVendorGuid + gShellAliasGuid + gShellVariableGuid + +[DEPEX] + TRUE diff --git a/ShellPkg/ShellPkg.dsc b/ShellPkg/ShellPkg.dsc index dd0d88603f11..557b0ec0f3d6 100644 --- a/ShellPkg/ShellPkg.dsc +++ b/ShellPkg/ShellPkg.dsc @@ -154,6 +154,11 @@ [Components] gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.inf + ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynam= icCommand.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } + ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyApp.i= nf ShellPkg/Application/AcpiViewApp/AcpiViewApp.inf =20 [BuildOptions] --=20 2.42.0.windows.2 -=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 (#110341): https://edk2.groups.io/g/devel/message/110341 Mute This Topic: https://groups.io/mt/102284384/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- From nobody Wed May 15 05:22:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+110342+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110342+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1698697907; cv=none; d=zohomail.com; s=zohoarc; b=XaaolUlWcbSj3XioLwXeT6ThFYK7s0zaY0X1/xOwParKWTBc+/fhhrAkUsfYobD3E0sWLj8klKOeYR8Nw/htZsCF7MXZ/hhmyD2YQCfqs03LaXKb8KbngnsrU41Dl1pZHQzcWqs4jn5AqSNmZroHt+y4f08w3p76U/NYe4+yOaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698697907; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=ilQhEITXw0pXkAEFXSaK3CDm512EweO2gMZry+YVKOg=; b=ZCT7079/2S2E84JB45KlgbIRddCBAwR6qENf7DZOex3IVFyKFH8lYKb5aUg32ybZvw0Y3EgpwTpPXTW8H6DoKemtwvvbThKyN3BwqUP8OuvNEGStua5Epl8PjVZr1qyZwW1ulf+N/EL2iwP9ONlGLRB7mmzDNFUiBds/mEWO59A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110342+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1698697907604778.6054432793527; Mon, 30 Oct 2023 13:31:47 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=AWJbg4YfrIaDW3ZXxBu0b5KCJz0p9gZaPIcGPqGi4eg=; c=relaxed/simple; d=groups.io; h=DKIM-Filter:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1698697907; v=1; b=n/po0XVmRkbEhIRfWkatgeyLCCUbS47FOjAke3BBOlPtv7DRAzHSbEkXiwLPaCZ3EA/mKDB8 3njI8H1LTwk6VQLpdkSqnoNpTNjXD0HmPgR0EGBOh8Rlqw+pvn5vd9j4bHMmmYLk3iwjPEf2zl7 bnQA3nIebZnN1VC1dEYBH9lw= X-Received: by 127.0.0.2 with SMTP id 5sezYY1788612xYnY5YwxOoS; Mon, 30 Oct 2023 13:31:47 -0700 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web10.169263.1698697906699784434 for ; Mon, 30 Oct 2023 13:31:46 -0700 X-Received: from localhost.localdomain (unknown [47.201.241.95]) by linux.microsoft.com (Postfix) with ESMTPSA id 0E34120B74C1; Mon, 30 Oct 2023 13:31:44 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0E34120B74C1 From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Anatol Belski , Anthony Perard , Gerd Hoffmann , Jianyong Wu , Jiewen Yao , Jordan Justen , Julien Grall , Jiewen Yao , Ard Biesheuvel , Michael D Kinney Subject: [edk2-devel] [PATCH v3 3/4] OvmfPkg: Add varpolicy shell command Date: Mon, 30 Oct 2023 16:31:11 -0400 Message-ID: <20231030203112.736-4-mikuback@linux.microsoft.com> In-Reply-To: <20231030203112.736-1-mikuback@linux.microsoft.com> References: <20231030203112.736-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: 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,mikuback@linux.microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: iU4rGdTYexnvRZW7BRTqlXOvx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1698697909490100003 Content-Type: text/plain; charset="utf-8" From: Michael Kubacki Adds the varpolicy EFI shell command to all DSC files that currently include other dynamic shell commands from ShellPkg. This command allows variable policies to be dumped in the EFI shell for convenient auditing and debug. Use the command in QEMU EFI shell as follows: - `"varpolicy"` dumps platform variables - `"varpolicy -?"` shows help text - `"varpolicy -b"` pages output as expected - `"varpolicy -s"` shows accurate variable statistic information - `"varpolicy -p"` shows accurate UEFI variable policy information - `"varpolicy-v -b"` dumps all information including variable data hex dump Cc: Anatol Belski Cc: Anthony Perard Cc: Gerd Hoffmann Cc: Jianyong Wu Cc: Jiewen Yao Cc: Jordan Justen Cc: Julien Grall Signed-off-by: Michael Kubacki Acked-by: Jiewen Yao Reviewed-by: Ard Biesheuvel Reviewed-by: Michael D Kinney --- OvmfPkg/CloudHv/CloudHvX64.dsc | 4 ++++ OvmfPkg/Microvm/MicrovmX64.dsc | 4 ++++ OvmfPkg/OvmfPkgIa32.dsc | 4 ++++ OvmfPkg/OvmfPkgIa32X64.dsc | 4 ++++ OvmfPkg/OvmfPkgX64.dsc | 4 ++++ OvmfPkg/OvmfXen.dsc | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index 35942e02df93..c23c7eaf6cc2 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -837,6 +837,10 @@ [Components] gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } + ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynam= icCommand.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.in= f { gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc index 0f26f2a9a97d..ea1fa3e2963f 100644 --- a/OvmfPkg/Microvm/MicrovmX64.dsc +++ b/OvmfPkg/Microvm/MicrovmX64.dsc @@ -849,6 +849,10 @@ [Components] gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } + ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynam= icCommand.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.in= f { gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index fcd3a3fda5f2..ed3a19feebe6 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -915,6 +915,10 @@ [Components] gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } + ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynam= icCommand.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.in= f { gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index d0ae0b996d66..16ca139b2973 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -933,6 +933,10 @@ [Components.X64] gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } + ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynam= icCommand.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.in= f { gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index a6811eee557e..dc1a0942aa8b 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -1001,6 +1001,10 @@ [Components] gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } + ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynam= icCommand.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.in= f { gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index ccd3a873c714..0063245b5659 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -722,6 +722,10 @@ [Components] gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } + ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynam= icCommand.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.in= f { gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE --=20 2.42.0.windows.2 -=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 (#110342): https://edk2.groups.io/g/devel/message/110342 Mute This Topic: https://groups.io/mt/102284385/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- From nobody Wed May 15 05:22:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+110343+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110343+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1698697913; cv=none; d=zohomail.com; s=zohoarc; b=X6EQDSHAdD5oymKvE/vxYvziwpfkK7S4zG7SgVfCJ5Egz77JAlhkDIxXxMnec9Vup9xjaZoXUrCgoBB2oAnaD8dRev+RAK+4DCeJHVkyIqyCWW66wr2Ldme7sIja2MjUspZIfK/8ZTejJ6acHTcGtl3ugR+ZU24HvwEi6o7GmeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698697913; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=RMY/LdLtjbxu4tOwjo3nmRb2UAAub6yBPIQFDllG78w=; b=Wlep03kWwjyxC/HJWlNF42zCY+BDfYehEkXcXNAj5JYmGD1XsjbvgpNx/LfkF+zZnCz4WRd9QLpRuJWM/Tpg5ncvQdTiwpJaTSQPhaP4p0E32t8oPZx2hQ9pQP0yUve6KZ2IXiyoOI5RwQnSXGgTJbuJ3CH5aWneD8g4IVw5QGo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110343+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1698697913089318.74610719613656; Mon, 30 Oct 2023 13:31:53 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=YlX83QXD22jmcfA/xe1zQGhD7J4MrrNlbBc/qxW/MNI=; c=relaxed/simple; d=groups.io; h=DKIM-Filter:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1698697912; v=1; b=PgXzkaYqfQ9/yZLCzETgo/X89f+tMAP82Agk4bnV+bLDCP1AfbSUDql11bVNjM5+Get7GryK i3zefFntXZTVEf9OvRH8lQyHK2l28aPRzPwLNnKrHoxERKgSS9aheX15AV30WVkcVGO0aKU/mZK 8lcddvhDQlj3SzYmd4isWh9U= X-Received: by 127.0.0.2 with SMTP id uVYiYY1788612xaTGGxrafZI; Mon, 30 Oct 2023 13:31:52 -0700 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.169641.1698697912145805163 for ; Mon, 30 Oct 2023 13:31:52 -0700 X-Received: from localhost.localdomain (unknown [47.201.241.95]) by linux.microsoft.com (Postfix) with ESMTPSA id 0C75220B74C0; Mon, 30 Oct 2023 13:31:50 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0C75220B74C0 From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Gerd Hoffmann , Julien Grall , Laszlo Ersek , Leif Lindholm , Sami Mujawar Subject: [edk2-devel] [PATCH v3 4/4] ArmVirtPkg: Add varpolicy shell command Date: Mon, 30 Oct 2023 16:31:12 -0400 Message-ID: <20231030203112.736-5-mikuback@linux.microsoft.com> In-Reply-To: <20231030203112.736-1-mikuback@linux.microsoft.com> References: <20231030203112.736-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: 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,mikuback@linux.microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: J8pEm9m99fEyNdKYb94p39EYx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1698697913702100001 Content-Type: text/plain; charset="utf-8" From: Michael Kubacki Adds the varpolicy EFI shell command to all DSC files that currently include other dynamic shell commands from ShellPkg. This command allows variable policies to be dumped in the EFI shell for convenient auditing and debug. Use the command in the EFI shell as follows: - `"varpolicy"` dumps platform variables - `"varpolicy -?"` shows help text - `"varpolicy -b"` pages output as expected - `"varpolicy -s"` shows accurate variable statistic information - `"varpolicy -p"` shows accurate UEFI variable policy information - `"varpolicy-v -b"` dumps all information including variable data hex dump Cc: Ard Biesheuvel Cc: Gerd Hoffmann Cc: Julien Grall Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Sami Mujawar Signed-off-by: Michael Kubacki Reviewed-by: Ard Biesheuvel --- ArmVirtPkg/ArmVirt.dsc.inc | 4 ++++ ArmVirtPkg/ArmVirtCloudHv.fdf | 1 + ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 1 + ArmVirtPkg/ArmVirtXen.fdf | 1 + 4 files changed, 7 insertions(+) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index 4ed86b979e1a..fe6488ee9910 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -393,6 +393,10 @@ [Components.common] gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } + ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynam= icCommand.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.in= f { gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE diff --git a/ArmVirtPkg/ArmVirtCloudHv.fdf b/ArmVirtPkg/ArmVirtCloudHv.fdf index a5f172d79bfc..56d1ea6e8c1b 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.fdf +++ b/ArmVirtPkg/ArmVirtCloudHv.fdf @@ -169,6 +169,7 @@ [FV.FvMain] INF ShellPkg/Application/Shell/Shell.inf INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf + INF ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyD= ynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellComman= d.inf =20 # diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc b/ArmVirtPkg/ArmVirtQemuF= vMain.fdf.inc index 2894bc853a46..9b3e37d5c998 100644 --- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc +++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc @@ -103,6 +103,7 @@ [FV.FvMain] INF ShellPkg/Application/Shell/Shell.inf INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf + INF ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyD= ynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellComman= d.inf =20 # diff --git a/ArmVirtPkg/ArmVirtXen.fdf b/ArmVirtPkg/ArmVirtXen.fdf index 770fbf7289be..ea835551b375 100644 --- a/ArmVirtPkg/ArmVirtXen.fdf +++ b/ArmVirtPkg/ArmVirtXen.fdf @@ -180,6 +180,7 @@ [FV.FvMain] INF ShellPkg/Application/Shell/Shell.inf INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf INF ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf + INF ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyD= ynamicCommand.inf INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellComman= d.inf =20 # --=20 2.42.0.windows.2 -=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 (#110343): https://edk2.groups.io/g/devel/message/110343 Mute This Topic: https://groups.io/mt/102284388/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-