From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (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 4C5E42239362A for ; Wed, 31 Jan 2018 21:28:19 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2018 21:33:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,443,1511856000"; d="scan'208";a="14166178" Received: from ray-dev.ccr.corp.intel.com (HELO [10.239.9.19]) ([10.239.9.19]) by orsmga007.jf.intel.com with ESMTP; 31 Jan 2018 21:33:54 -0800 To: "Wang, Jian J" , "edk2-devel@lists.01.org" Cc: "Zeng, Star" , "Dong, Eric" , "Yao, Jiewen" References: <20180129110950.24212-1-jian.j.wang@intel.com> From: "Ni, Ruiyu" Message-ID: <741a5893-0537-6bee-17b6-6a60f75fd532@Intel.com> Date: Thu, 1 Feb 2018 13:33:53 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Subject: Re: [PATCH] MdeModulePkg/Core: fix feature conflict between NX and NULL detection 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: Thu, 01 Feb 2018 05:28:19 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 2/1/2018 9:17 AM, Wang, Jian J wrote: > You're right. Using a mask or separating the API into two (SetMemoryAttributes/ClearMemoryAttributes) > is much better and can avoid many potential issues. > > Regards, > Jian > For now the patch is good enough to leave NULL pointer detection feature enabled. Reviewed-by: Ruiyu Ni > >> -----Original Message----- >> From: Ni, Ruiyu >> Sent: Tuesday, January 30, 2018 12:38 PM >> To: Wang, Jian J ; edk2-devel@lists.01.org >> Cc: Zeng, Star ; Dong, Eric ; Yao, >> Jiewen >> Subject: Re: [PATCH] MdeModulePkg/Core: fix feature conflict between NX and >> NULL detection >> >> On 1/29/2018 7:09 PM, Jian J Wang wrote: >>> If enabled, NX memory protection feature will mark all free memory as >>> NX (non-executable), including page 0. This will overwrite the attributes >>> of page 0 if NULL pointer detection feature is also enabled and then >>> compromise the functionality of it. The solution is skipping the NX >>> attributes setting to page 0 if NULL pointer detection feature is enabled. >>> >>> Cc: Star Zeng >>> Cc: Eric Dong >>> Cc: Jiewen Yao >>> Cc: Ruiyu Ni >>> Contributed-under: TianoCore Contribution Agreement 1.1 >>> Signed-off-by: Jian J Wang >>> --- >>> MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 20 >> ++++++++++++++++---- >>> 1 file changed, 16 insertions(+), 4 deletions(-) >>> >>> diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c >> b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c >>> index 862593f562..150167bf66 100644 >>> --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c >>> +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c >>> @@ -845,10 +845,22 @@ InitializeDxeNxMemoryProtectionPolicy ( >>> >>> Attributes = GetPermissionAttributeForMemoryType (MemoryMapEntry- >>> Type); >>> if (Attributes != 0) { >>> - SetUefiImageMemoryAttributes ( >>> - MemoryMapEntry->PhysicalStart, >>> - LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT), >>> - Attributes); >>> + if (MemoryMapEntry->PhysicalStart == 0 && >>> + PcdGet8 (PcdNullPointerDetectionPropertyMask) != 0) { >>> + // >>> + // Skip page 0 if NULL pointer detection is enabled to avoid attributes >>> + // overwritten. >>> + // >>> + SetUefiImageMemoryAttributes ( >>> + MemoryMapEntry->PhysicalStart + EFI_PAGE_SIZE, >>> + LShiftU64 (MemoryMapEntry->NumberOfPages - 1, EFI_PAGE_SHIFT), >>> + Attributes); >>> + } else { >>> + SetUefiImageMemoryAttributes ( >>> + MemoryMapEntry->PhysicalStart, >>> + LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT), >>> + Attributes); >>> + } >>> } >>> MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, >> DescriptorSize); >>> } >>> >> Does this bug expose an API-level issue? >> SetUefiImageMemoryAttributes () should also accept a Mask value? >> >> -- >> Thanks, >> Ray -- Thanks, Ray