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.20; helo=mga02.intel.com; envelope-from=jiewen.yao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 4EA3E21E48F20 for ; Mon, 29 Jan 2018 18:03:37 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jan 2018 18:09:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,433,1511856000"; d="scan'208";a="26489235" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga001.fm.intel.com with ESMTP; 29 Jan 2018 18:09:11 -0800 Received: from fmsmsx112.amr.corp.intel.com (10.18.116.6) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 29 Jan 2018 18:09:10 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX112.amr.corp.intel.com (10.18.116.6) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 29 Jan 2018 18:09:09 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.124]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.130]) with mapi id 14.03.0319.002; Tue, 30 Jan 2018 10:09:08 +0800 From: "Yao, Jiewen" To: "Wang, Jian J" , "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: AQHTmPG5RDFnQMbj5kuaA9Qnt0peuqOLrGAA Date: Tue, 30 Jan 2018 02:09:07 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503AA9EDA0@shsmsx102.ccr.corp.intel.com> References: <20180129110950.24212-1-jian.j.wang@intel.com> In-Reply-To: <20180129110950.24212-1-jian.j.wang@intel.com> Accept-Language: zh-CN, 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: Tue, 30 Jan 2018 02:03:37 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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? > + SetUefiImageMemoryAttributes ( > + MemoryMapEntry->PhysicalStart + EFI_PAGE_SIZE, > + LShiftU64 (MemoryMapEntry->NumberOfPages - 1, > EFI_PAGE_SHIFT), > + Attributes); > -----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 ; Y= ao, > Jiewen ; Ni, Ruiyu > Subject: [PATCH] MdeModulePkg/Core: fix feature conflict between NX and > NULL detection >=20 > 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= . >=20 > 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(-) >=20 > 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 ( >=20 > 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 att= ributes > + // 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