From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 EAD892215BDAE for ; Mon, 29 Jan 2018 20:32:38 -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 orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jan 2018 20:38:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,433,1511856000"; d="scan'208";a="13597063" Received: from ray-dev.ccr.corp.intel.com (HELO [10.239.9.19]) ([10.239.9.19]) by orsmga007.jf.intel.com with ESMTP; 29 Jan 2018 20:38:11 -0800 To: Jian J Wang , edk2-devel@lists.01.org Cc: Star Zeng , Eric Dong , Jiewen Yao References: <20180129110950.24212-1-jian.j.wang@intel.com> From: "Ni, Ruiyu" Message-ID: Date: Tue, 30 Jan 2018 12:38:11 +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: <20180129110950.24212-1-jian.j.wang@intel.com> 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: Tue, 30 Jan 2018 04:32:39 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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