From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Permerror (SPF Permanent Error: Void lookup limit of 2 exceeded) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 6596D222DDBF0 for ; Mon, 15 Jan 2018 02:13:23 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jan 2018 02:18:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,363,1511856000"; d="scan'208";a="10335608" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga008.fm.intel.com with ESMTP; 15 Jan 2018 02:18:41 -0800 Received: from fmsmsx111.amr.corp.intel.com (10.18.116.5) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 15 Jan 2018 02:18:40 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx111.amr.corp.intel.com (10.18.116.5) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 15 Jan 2018 02:18:40 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.189]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.93]) with mapi id 14.03.0319.002; Mon, 15 Jan 2018 18:18:38 +0800 From: "Zeng, Star" To: "Wang, Jian J" , "edk2-devel@lists.01.org" CC: "Yao, Jiewen" , "Ni, Ruiyu" , "Dong, Eric" , "Zeng, Star" Thread-Topic: [PATCH 6/6] MdeModulePkg/BootScriptExecutorDxe: remove NX attr for FfsBuffer Thread-Index: AQHTjd6M9kOuxd9qc0acjA2IX+G6k6N0uKeQ Date: Mon, 15 Jan 2018 10:18:37 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103B9FC325@shsmsx102.ccr.corp.intel.com> References: <20180115085433.25008-1-jian.j.wang@intel.com> <20180115085433.25008-7-jian.j.wang@intel.com> In-Reply-To: <20180115085433.25008-7-jian.j.wang@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 6/6] MdeModulePkg/BootScriptExecutorDxe: remove NX attr for FfsBuffer X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Jan 2018 10:13:23 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Star Zeng -----Original Message----- From: Wang, Jian J=20 Sent: Monday, January 15, 2018 4:55 PM To: edk2-devel@lists.01.org Cc: Yao, Jiewen ; Ni, Ruiyu ; Don= g, Eric ; Zeng, Star Subject: [PATCH 6/6] MdeModulePkg/BootScriptExecutorDxe: remove NX attr for= FfsBuffer If PcdDxeNxMemoryProtectionPolicy is set to enable protection for memory of= EfiReservedMemoryType, the BIOS will hang at a page fault exception trigge= red by BootScriptExecutorDxe. The root cause is that this driver will allocate memory of EfiReservedMemor= yType and relocate itself into this new memory. Since EfiReservedMemoryType= of memory is marked non-executable, re-start this driver after relocation = will cause exception. The fix is removing the NX attribute after memory all= ocation. Cc: Jiewen Yao Cc: Ruiyu Ni Cc: Eric Dong Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- .../Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf | 1 + .../Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c | 14 ++++++++++= ++++ .../Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.h | 1 + 3 files changed, 16 insertions(+) diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptEx= ecutorDxe.inf b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScrip= tExecutorDxe.inf index 29af7f55ec..aac132122c 100644 --- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorD= xe.inf +++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecut +++ orDxe.inf @@ -68,6 +68,7 @@ LockBoxLib CpuExceptionHandlerLib DevicePathLib + DxeServicesTableLib =20 [Guids] gEfiBootScriptExecutorVariableGuid ## PRODUCES ## UNDEFINED # SaveLoc= kBox diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecut= e.c b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c index 4545d6e581..263a282188 100644 --- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c +++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c @@ -273,6 +273,7 @@ ReadyToLockEventNotify ( UINTN Pages; EFI_PHYSICAL_ADDRESS FfsBuffer; PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc; =20 Status =3D gBS->LocateProtocol (&gEfiDxeSmmReadyToLockProtocolGuid, NULL= , &Interface); if (EFI_ERROR (Status)) { @@ -322,6 +323,19 @@ ReadyToLockEventNotify ( &FfsBuffer ); ASSERT_EFI_ERROR (Status); + + // + // Make sure that the buffer can be used to store code. + // + Status =3D gDS->GetMemorySpaceDescriptor (FfsBuffer, &MemDesc); if=20 + (!EFI_ERROR (Status) && (MemDesc.Attributes & EFI_MEMORY_XP) !=3D 0) { + gDS->SetMemorySpaceAttributes ( + FfsBuffer, + EFI_PAGES_TO_SIZE (Pages), + MemDesc.Attributes & (~EFI_MEMORY_XP) + ); + } + ImageContext.ImageAddress =3D (PHYSICAL_ADDRESS)(UINTN)FfsBuffer; // // Align buffer on section boundary diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecut= e.h b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.h index 75327569d7..94deae87e6 100644 --- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.h +++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.h @@ -38,6 +38,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. #include #include #include +#include =20 #include #include -- 2.15.1.windows.2