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.151; helo=mga17.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 C2D0A22393648 for ; Wed, 31 Jan 2018 17:09:05 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2018 17:14:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,442,1511856000"; d="scan'208";a="200264652" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga005.fm.intel.com with ESMTP; 31 Jan 2018 17:14:41 -0800 Received: from fmsmsx117.amr.corp.intel.com (10.18.116.17) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 31 Jan 2018 17:14:41 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx117.amr.corp.intel.com (10.18.116.17) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 31 Jan 2018 17:14:40 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.145]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.116]) with mapi id 14.03.0319.002; Thu, 1 Feb 2018 09:14:39 +0800 From: "Wang, Jian J" To: "Yao, Jiewen" , "edk2-devel@lists.01.org" CC: "Zeng, Star" , "Dong, Eric" , "Ni, Ruiyu" Thread-Topic: [PATCH] MdeModulePkg/Core: fix feature conflict between NX and NULL detection Thread-Index: AQHTmW9QZIghs1kYF0CwOmXp1A8btaOOwIrw Date: Thu, 1 Feb 2018 01:14:38 +0000 Message-ID: References: <20180129110950.24212-1-jian.j.wang@intel.com> <74D8A39837DF1E4DA445A8C0B3885C503AA9EDA0@shsmsx102.ccr.corp.intel.com> In-Reply-To: <74D8A39837DF1E4DA445A8C0B3885C503AA9EDA0@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiOTY5Zjg3NzAtOGZjMi00ZmZiLWFkMmUtODQyNDJlODc3ODgzIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJ0cGdsdEdmdUtUdDA0NjVBTXdFaEtaT0c1M0xsa3ZNbXVrMVB5a0hDOUdnUk5lSWQyUkxYb2JlV1pkaWlcLzZpRiJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 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 01:09:06 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable gCpu->SetMemoryAttributes() called by SetUefiImageMemoryAttributes() will r= eturn without any problem if Length is 0. Regards, Jian > -----Original Message----- > From: Yao, Jiewen > Sent: Tuesday, January 30, 2018 10:09 AM > To: Wang, Jian J ; edk2-devel@lists.01.org > Cc: Zeng, Star ; Dong, Eric ; N= i, > Ruiyu > Subject: RE: [PATCH] MdeModulePkg/Core: fix feature conflict between NX a= nd > NULL detection >=20 > Hi Jian > May I know how we handle MemoryMapEntry->NumberOfPages is 1? > The lengh will be 0 in that case. Should we add additional check? >=20 > > + SetUefiImageMemoryAttributes ( > > + MemoryMapEntry->PhysicalStart + EFI_PAGE_SIZE, > > + LShiftU64 (MemoryMapEntry->NumberOfPages - 1, > > EFI_PAGE_SHIFT), > > + Attributes); >=20 > > -----Original Message----- > > From: Wang, Jian J > > Sent: Monday, January 29, 2018 7:10 PM > > To: edk2-devel@lists.01.org > > Cc: Zeng, Star ; Dong, Eric ;= Yao, > > Jiewen ; Ni, Ruiyu > > Subject: [PATCH] MdeModulePkg/Core: fix feature conflict between NX and > > NULL detection > > > > If enabled, NX memory protection feature will mark all free memory as > > NX (non-executable), including page 0. This will overwrite the attribut= es > > 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 enabl= ed. > > > > 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 =3D GetPermissionAttributeForMemoryType > > (MemoryMapEntry->Type); > > if (Attributes !=3D 0) { > > - SetUefiImageMemoryAttributes ( > > - MemoryMapEntry->PhysicalStart, > > - LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT), > > - Attributes); > > + if (MemoryMapEntry->PhysicalStart =3D=3D 0 && > > + PcdGet8 (PcdNullPointerDetectionPropertyMask) !=3D 0) { > > + // > > + // Skip page 0 if NULL pointer detection is enabled to avoid a= ttributes > > + // 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 =3D NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, > > DescriptorSize); > > } > > -- > > 2.14.1.windows.1