From nobody Sun Feb 8 12:39:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1532064407859417.43287733689317; Thu, 19 Jul 2018 22:26:47 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 231452098EAC0; Thu, 19 Jul 2018 22:26:38 -0700 (PDT) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id AC2F32098EAB3 for ; Thu, 19 Jul 2018 22:26:36 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jul 2018 22:26:36 -0700 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.19]) by orsmga002.jf.intel.com with ESMTP; 19 Jul 2018 22:26:33 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,377,1526367600"; d="scan'208";a="76331904" From: Hao Wu To: edk2-devel@lists.01.org Date: Fri, 20 Jul 2018 13:26:24 +0800 Message-Id: <20180720052626.24932-5-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20180720052626.24932-1-hao.a.wu@intel.com> References: <20180720052626.24932-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 4/6] MdePkg/SmmMemLib: Check EFI_MEMORY_RO in UEFI mem attrib table. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jiewen Yao , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Jiewen Yao It treats the UEFI runtime page with EFI_MEMORY_RO attribute as invalid SMM communication buffer. Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jiewen Yao --- MdePkg/Library/SmmMemLib/SmmMemLib.c | 58 +++++++++++++++++++- MdePkg/Library/SmmMemLib/SmmMemLib.inf | 4 ++ 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/MdePkg/Library/SmmMemLib/SmmMemLib.c b/MdePkg/Library/SmmMemLi= b/SmmMemLib.c index 3f79e46d46..3409ddf87c 100644 --- a/MdePkg/Library/SmmMemLib/SmmMemLib.c +++ b/MdePkg/Library/SmmMemLib/SmmMemLib.c @@ -27,10 +27,12 @@ #include #include #include +#include #include #include #include #include +#include =20 // // attributes for reserved memory before it is promoted to system memory @@ -39,9 +41,6 @@ #define EFI_MEMORY_INITIALIZED 0x0200000000000000ULL #define EFI_MEMORY_TESTED 0x0400000000000000ULL =20 -#define NEXT_MEMORY_DESCRIPTOR(MemoryDescriptor, Size) \ - ((EFI_MEMORY_DESCRIPTOR *)((UINT8 *)(MemoryDescriptor) + (Size))) - EFI_SMRAM_DESCRIPTOR *mSmmMemLibInternalSmramRanges; UINTN mSmmMemLibInternalSmramCount; =20 @@ -57,6 +56,8 @@ UINTN mDescriptorSize; EFI_GCD_MEMORY_SPACE_DESCRIPTOR *mSmmMemLibGcdMemSpace =3D NULL; UINTN mSmmMemLibGcdMemNumberOfDesc =3D 0; =20 +EFI_MEMORY_ATTRIBUTES_TABLE *mSmmMemLibMemoryAttributesTable =3D NULL; + VOID *mRegistrationEndOfDxe; VOID *mRegistrationReadyToLock; =20 @@ -204,6 +205,32 @@ SmmIsBufferOutsideSmmValid ( return FALSE; } } + + // + // Check UEFI runtime memory with EFI_MEMORY_RO as invalid communicati= on buffer. + // + if (mSmmMemLibMemoryAttributesTable !=3D NULL) { + EFI_MEMORY_DESCRIPTOR *Entry; + + Entry =3D (EFI_MEMORY_DESCRIPTOR *)(mSmmMemLibMemoryAttributesTable = + 1); + for (Index =3D 0; Index < mSmmMemLibMemoryAttributesTable->NumberOfE= ntries; Index++) { + if (Entry->Type =3D=3D EfiRuntimeServicesCode || Entry->Type =3D= =3D EfiRuntimeServicesData) { + if ((Entry->Attribute & EFI_MEMORY_RO) !=3D 0) { + if (((Buffer >=3D Entry->PhysicalStart) && (Buffer < Entry->Ph= ysicalStart + LShiftU64 (Entry->NumberOfPages, EFI_PAGE_SHIFT))) || + ((Entry->PhysicalStart >=3D Buffer) && (Entry->PhysicalSta= rt < Buffer + Length))) { + DEBUG (( + EFI_D_ERROR, + "SmmIsBufferOutsideSmmValid: In RuntimeCode Region: Buffer= (0x%lx) - Length (0x%lx)\n", + Buffer, + Length + )); + return FALSE; + } + } + } + Entry =3D NEXT_MEMORY_DESCRIPTOR (Entry, mSmmMemLibMemoryAttribute= sTable->DescriptorSize); + } + } } return TRUE; } @@ -399,6 +426,26 @@ SmmMemLibInternalGetGcdMemoryMap ( gBS->FreePool (MemSpaceMap); } =20 +/** + Get UEFI MemoryAttributesTable. +**/ +VOID +SmmMemLibInternalGetUefiMemoryAttributesTable ( + VOID + ) +{ + EFI_STATUS Status; + EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable; + UINTN MemoryAttributesTableSize; + + Status =3D EfiGetSystemConfigurationTable (&gEfiMemoryAttributesTableGui= d, (VOID **)&MemoryAttributesTable); + if (!EFI_ERROR (Status)) { + MemoryAttributesTableSize =3D sizeof(EFI_MEMORY_ATTRIBUTES_TABLE) + Me= moryAttributesTable->DescriptorSize * MemoryAttributesTable->NumberOfEntrie= s; + mSmmMemLibMemoryAttributesTable =3D AllocateCopyPool (MemoryAttributes= TableSize, MemoryAttributesTable); + ASSERT (mSmmMemLibMemoryAttributesTable !=3D NULL); + } +} + /** Notification for SMM EndOfDxe protocol. =20 @@ -502,6 +549,11 @@ SmmLibInternalEndOfDxeNotify ( // SmmMemLibInternalGetGcdMemoryMap (); =20 + // + // Get UEFI memory attributes table. + // + SmmMemLibInternalGetUefiMemoryAttributesTable (); + return EFI_SUCCESS; } =20 diff --git a/MdePkg/Library/SmmMemLib/SmmMemLib.inf b/MdePkg/Library/SmmMem= Lib/SmmMemLib.inf index 36576a4f2f..525449c25c 100644 --- a/MdePkg/Library/SmmMemLib/SmmMemLib.inf +++ b/MdePkg/Library/SmmMemLib/SmmMemLib.inf @@ -48,11 +48,15 @@ BaseMemoryLib HobLib MemoryAllocationLib + UefiLib =20 [Protocols] gEfiSmmAccess2ProtocolGuid ## CONSUMES gEfiSmmReadyToLockProtocolGuid ## CONSUMES gEfiSmmEndOfDxeProtocolGuid ## CONSUMES =20 +[Guids] + gEfiMemoryAttributesTableGuid ## CONSUMES ## SystemTable + [Depex] gEfiSmmAccess2ProtocolGuid --=20 2.16.2.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel