From nobody Mon May 6 05:00:11 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+68966+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+68966+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1608128525; cv=none; d=zohomail.com; s=zohoarc; b=gjWXW9khjPdv5TOuXVM315BIqH1WSteTb94CyIw5oLmigmdUo/qEPUCmSHBYZ+yt76/Vwh6flI12s7fRzOV+euxtv1XQCsPc+LnXS/GVMsa4Ty0xzyn2Eqbxz86Mxkcs+nua7mJoJI0w9mnAkEKWaNYI4cHBzqYUw/9yS5PNB4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608128525; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=q1AeHzh30BpR1GFilTzsHjy9Al6prw95dAw3GpcpZM0=; b=DbMnu1nLI4kd2hfT1hkATByb6tbR323+9ZpoRSZkufZMggB4HM7eM6gg2MdPloB6IAZ829LOsbUGfH2IuAcnbAyeRGq3Gto2n9RkOTcTDlV1iIN+p2Ia2cdmMqE53kR1uP4m5ymZLnqh3774pspkbhYPHRXFch/d7e+SFcRqeX0= 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+68966+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608128525468505.4119998644694; Wed, 16 Dec 2020 06:22:05 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id YjA1YY1788612xVDJZ8sXTrq; Wed, 16 Dec 2020 06:22:02 -0800 X-Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by mx.groups.io with SMTP id smtpd.web09.8470.1608128342417846809 for ; Wed, 16 Dec 2020 06:19:02 -0800 X-Received: by mail-pl1-f181.google.com with SMTP id e2so5845864plt.12 for ; Wed, 16 Dec 2020 06:19:02 -0800 (PST) X-Gm-Message-State: cLj18pACRjEHCkdYzRU3seNFx1787277AA= X-Google-Smtp-Source: ABdhPJxUevWVQTQE57E/mSLCUq9BSfnmzAVomQpWPHbZwyw9NNdJmDt3FUb+xvWxCeSS12mKcImH9Q== X-Received: by 2002:a17:902:8bcc:b029:dc:1aa4:25a3 with SMTP id r12-20020a1709028bccb02900dc1aa425a3mr1854087plo.39.1608128341521; Wed, 16 Dec 2020 06:19:01 -0800 (PST) X-Received: from localhost ([121.95.100.191]) by smtp.gmail.com with ESMTPSA id iq3sm2276597pjb.57.2020.12.16.06.18.59 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Dec 2020 06:19:00 -0800 (PST) From: "Masahisa Kojima" To: devel@edk2.groups.io Cc: Kun Qin , Masahisa Kojima , Jian J Wang , Hao A Wu , Liming Gao , Ard Biesheuvel , Sami Mujawar , Jiewen Yao , Supreeth Venkatesh , Bret Barkelew Subject: [edk2-devel] [PATCH 1/1] MdeModulePkg/VarCheckPolicyLib: implement standalone MM version Date: Wed, 16 Dec 2020 23:19:19 +0900 Message-Id: <20201216141919.23262-2-masahisa.kojima@linaro.org> In-Reply-To: <20201216141919.23262-1-masahisa.kojima@linaro.org> References: <20201216141919.23262-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,masahisa.kojima@linaro.org Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608128522; bh=B6kNbxYIFda0OP3sTpHClnE1AIn/P2qmSMgSFa6Sdyo=; h=Cc:Date:From:Reply-To:Subject:To; b=N+QrCjX4PhWaqYlfBagmY4lMH36QOPvlsk+IM67qRoLESoxddP/mQ1pOfTl9njgLsYF 3RKPNjkPyM3myqsykHfnTVwehnFcpvUpJeyVHmER6dSd/3Ylx5NlDlwaS99xxFyozhbii 3DpQTruF1gaCG+wfZhQBRllVoZZYEKrYLRk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This commit adds the VarCheckPolicyLib that will be able to execute in the context of standalone MM. Signed-off-by: Masahisa Kojima Co-authored-by: Kun Qin Cc: Jian J Wang Cc: Hao A Wu Cc: Liming Gao Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Jiewen Yao Cc: Supreeth Venkatesh Cc: Bret Barkelew --- MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.inf = | 5 +- MdeModulePkg/Library/VarCheckPolicyLib/{VarCheckPolicyLib.inf =3D> VarChec= kPolicyLibStandaloneMm.inf} | 23 +++++---- MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.h = | 42 ++++++++++++++++ MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.c = | 14 +++--- MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibStandaloneMm.c = | 50 ++++++++++++++++++++ MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibTraditional.c = | 50 ++++++++++++++++++++ 6 files changed, 165 insertions(+), 19 deletions(-) diff --git a/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.inf b= /MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.inf index 077bcc8990ca..9af436d25f81 100644 --- a/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.inf +++ b/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.inf @@ -13,11 +13,13 @@ [Defines] MODULE_TYPE =3D DXE_RUNTIME_DRIVER VERSION_STRING =3D 1.0 LIBRARY_CLASS =3D NULL|DXE_RUNTIME_DRIVER DXE_SMM_DRIVER - CONSTRUCTOR =3D VarCheckPolicyLibConstructor + CONSTRUCTOR =3D VarCheckPolicyLibTraditionalConstruct= or =20 =20 [Sources] VarCheckPolicyLib.c + VarCheckPolicyLibTraditional.c + VarCheckPolicyLib.h =20 =20 [Packages] @@ -29,7 +31,6 @@ [LibraryClasses] BaseLib DebugLib BaseMemoryLib - DxeServicesLib MemoryAllocationLib VarCheckLib VariablePolicyLib diff --git a/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.inf b= /MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibStandaloneMm.inf similarity index 51% copy from MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.inf copy to MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibStandaloneM= m.inf index 077bcc8990ca..ab427f189a3d 100644 --- a/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.inf +++ b/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibStandaloneMm.= inf @@ -1,35 +1,41 @@ -## @file VarCheckPolicyLib.inf +## @file VarCheckPolicyLibStandaloneMm.inf # This is an instance of a VarCheck lib that leverages the business logic = behind # the VariablePolicy code to make its decisions. # -# Copyright (c) Microsoft Corporation. +## +# Copyright (c) Microsoft Corporation. All rights reserved. # SPDX-License-Identifier: BSD-2-Clause-Patent +# ## =20 [Defines] INF_VERSION =3D 0x00010005 - BASE_NAME =3D VarCheckPolicyLib - FILE_GUID =3D 9C28A48F-C884-4B1F-8B95-DEF125448023 - MODULE_TYPE =3D DXE_RUNTIME_DRIVER + BASE_NAME =3D VarCheckPolicyLibStandaloneMm + FILE_GUID =3D 44B09E3D-5EDA-4673-ABCF-C8AE4560C8EC + MODULE_TYPE =3D MM_STANDALONE + PI_SPECIFICATION_VERSION =3D 0x00010032 VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D NULL|DXE_RUNTIME_DRIVER DXE_SMM_DRIVER - CONSTRUCTOR =3D VarCheckPolicyLibConstructor + LIBRARY_CLASS =3D NULL|MM_STANDALONE + CONSTRUCTOR =3D VarCheckPolicyLibStandaloneConstructor =20 =20 [Sources] VarCheckPolicyLib.c + VarCheckPolicyLibStandaloneMm.c + VarCheckPolicyLib.h =20 =20 [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + StandaloneMmPkg/StandaloneMmPkg.dec =20 =20 [LibraryClasses] BaseLib DebugLib BaseMemoryLib - DxeServicesLib + MemLib MemoryAllocationLib VarCheckLib VariablePolicyLib @@ -37,6 +43,5 @@ [LibraryClasses] SafeIntLib MmServicesTableLib =20 - [Guids] gVarCheckPolicyLibMmiHandlerGuid ## CONSUME ## Used to register f= or MM Communication events. diff --git a/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.h b/M= deModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.h new file mode 100644 index 000000000000..2226c8a19fec --- /dev/null +++ b/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.h @@ -0,0 +1,42 @@ +/** @file -- VarCheckPolicyLib.h +This internal header file defines the common interface of constructor for +VarCheckPolicyLib. + +Copyright (c) Microsoft Corporation. All rights reserved. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _VAR_CHECK_POLICY_LIB_H_ +#define _VAR_CHECK_POLICY_LIB_H_ + +/** + Common constructor function of VarCheckPolicyLib to register VarCheck ha= ndler + and SW MMI handlers. + + @retval EFI_SUCCESS The constructor executed correctly. + +**/ +EFI_STATUS +EFIAPI +VarCheckPolicyLibCommonConstructor ( + VOID + ); + +/** + This function is wrapper function to validate the buffer. + + @param Buffer The buffer start address to be checked. + @param Length The buffer length to be checked. + + @retval TRUE This buffer is valid per processor architecture and not ov= erlap with SMRAM/MMRAM. + @retval FALSE This buffer is not valid per processor architecture or ove= rlap with SMRAM/MMRAM. +**/ +BOOLEAN +EFIAPI +VarCheckPolicyIsBufferOutsideValid ( + IN EFI_PHYSICAL_ADDRESS Buffer, + IN UINT64 Length + ); + +#endif // _VAR_CHECK_POLICY_LIB_H_ diff --git a/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.c b/M= deModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.c index 257aa9591303..14e1904e96d3 100644 --- a/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.c +++ b/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.c @@ -12,7 +12,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include -#include #include #include =20 @@ -23,6 +22,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include =20 +#include "VarCheckPolicyLib.h" + //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D // As a VarCheck library, we're linked into the VariableServices // and may not be able to call them indirectly. To get around this, @@ -102,7 +103,8 @@ VarCheckPolicyLibMmiHandler ( // Make sure that the buffer does not overlap SMM. // This should be covered by the SmiManage infrastructure, but just to b= e safe... InternalCommBufferSize =3D *CommBufferSize; - if (InternalCommBufferSize > VAR_CHECK_POLICY_MM_COMM_BUFFER_SIZE || !Sm= mIsBufferOutsideSmmValid((UINTN)CommBuffer, (UINT64)InternalCommBufferSize)= ) { + if (InternalCommBufferSize > VAR_CHECK_POLICY_MM_COMM_BUFFER_SIZE || + !VarCheckPolicyIsBufferOutsideValid((UINTN)CommBuffer, (UINT64)Inter= nalCommBufferSize)) { DEBUG ((DEBUG_ERROR, "%a - Invalid CommBuffer supplied! 0x%016lX[0x%01= 6lX]\n", __FUNCTION__, CommBuffer, InternalCommBufferSize)); return EFI_INVALID_PARAMETER; } @@ -305,17 +307,13 @@ VarCheckPolicyLibMmiHandler ( Constructor function of VarCheckPolicyLib to register VarCheck handler a= nd SW MMI handlers. =20 - @param[in] ImageHandle The firmware allocated handle for the EFI imag= e. - @param[in] SystemTable A pointer to the EFI System Table. - @retval EFI_SUCCESS The constructor executed correctly. =20 **/ EFI_STATUS EFIAPI -VarCheckPolicyLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +VarCheckPolicyLibCommonConstructor ( + VOID ) { EFI_STATUS Status; diff --git a/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibStanda= loneMm.c b/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibStandalo= neMm.c new file mode 100644 index 000000000000..b283ced9d4e3 --- /dev/null +++ b/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibStandaloneMm.c @@ -0,0 +1,50 @@ +/** @file -- VarCheckPolicyLibStandaloneMm.c +This is an instance of a VarCheck lib constructor for Standalone MM. + +Copyright (c) Microsoft Corporation. All rights reserved. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include "VarCheckPolicyLib.h" + +/** + Standalone MM constructor function of VarCheckPolicyLib to invoke common + constructor routine. + + @param[in] ImageHandle The firmware allocated handle for the EFI imag= e. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor executed correctly. + +**/ +EFI_STATUS +EFIAPI +VarCheckPolicyLibStandaloneConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_MM_SYSTEM_TABLE *SystemTable + ) +{ + return VarCheckPolicyLibCommonConstructor (); +} + +/** + This function is wrapper function to validate the buffer. + + @param Buffer The buffer start address to be checked. + @param Length The buffer length to be checked. + + @retval TRUE This buffer is valid per processor architectureand not ove= rlap with MMRAM. + @retval FALSE This buffer is not valid per processor architecture or ove= rlap with MMRAM. +**/ +BOOLEAN +EFIAPI +VarCheckPolicyIsBufferOutsideValid ( + IN EFI_PHYSICAL_ADDRESS Buffer, + IN UINT64 Length + ) +{ + return MmIsBufferOutsideMmValid (Buffer, Length); +} diff --git a/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibTradit= ional.c b/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibTradition= al.c new file mode 100644 index 000000000000..f404aaaa470c --- /dev/null +++ b/MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibTraditional.c @@ -0,0 +1,50 @@ +/** @file -- VarCheckPolicyLibTraditional.c +This is an instance of a VarCheck lib constructor for traditional SMM. + +Copyright (c) Microsoft Corporation. All rights reserved. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include "VarCheckPolicyLib.h" + +/** + Traditional constructor function of VarCheckPolicyLib to invoke common + constructor routine. + + @param[in] ImageHandle The firmware allocated handle for the EFI imag= e. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor executed correctly. + +**/ +EFI_STATUS +EFIAPI +VarCheckPolicyLibTraditionalConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return VarCheckPolicyLibCommonConstructor (); +} + +/** + This function is wrapper function to validate the buffer. + + @param Buffer The buffer start address to be checked. + @param Length The buffer length to be checked. + + @retval TRUE This buffer is valid per processor architecture and not ov= erlap with SMRAM. + @retval FALSE This buffer is not valid per processor architecture or ove= rlap with SMRAM. +**/ +BOOLEAN +EFIAPI +VarCheckPolicyIsBufferOutsideValid ( + IN EFI_PHYSICAL_ADDRESS Buffer, + IN UINT64 Length + ) +{ + return SmmIsBufferOutsideSmmValid (Buffer, Length); +} --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#68966): https://edk2.groups.io/g/devel/message/68966 Mute This Topic: https://groups.io/mt/79001243/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-