From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: eric.dong@intel.com) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by groups.io with SMTP; Mon, 26 Aug 2019 18:43:50 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 18:43:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,435,1559545200"; d="scan'208";a="180061052" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga008.fm.intel.com with ESMTP; 26 Aug 2019 18:43:48 -0700 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 26 Aug 2019 18:43:48 -0700 Received: from shsmsx105.ccr.corp.intel.com (10.239.4.158) by fmsmsx109.amr.corp.intel.com (10.18.116.9) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 26 Aug 2019 18:43:48 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.19]) by SHSMSX105.ccr.corp.intel.com ([169.254.11.15]) with mapi id 14.03.0439.000; Tue, 27 Aug 2019 09:43:46 +0800 From: "Dong, Eric" To: "Ni, Ray" , "devel@edk2.groups.io" CC: "Yao, Jiewen" , Laszlo Ersek Subject: Re: [PATCH 3/5] UefiCpuPkg/PiSmmCpu: Restrict access per PcdCpuSmmRestrictedMemoryAccess Thread-Topic: [PATCH 3/5] UefiCpuPkg/PiSmmCpu: Restrict access per PcdCpuSmmRestrictedMemoryAccess Thread-Index: AQHVW5bvPxLLqOmbskaaWZyxID8UP6cOOofg Date: Tue, 27 Aug 2019 01:43:46 +0000 Message-ID: References: <20190825224513.171572-1-ray.ni@intel.com> <20190825224513.171572-4-ray.ni@intel.com> In-Reply-To: <20190825224513.171572-4-ray.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: eric.dong@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Eric Dong > -----Original Message----- > From: Ni, Ray > Sent: Monday, August 26, 2019 6:45 AM > To: devel@edk2.groups.io > Cc: Dong, Eric ; Yao, Jiewen ; > Laszlo Ersek > Subject: [PATCH 3/5] UefiCpuPkg/PiSmmCpu: Restrict access per > PcdCpuSmmRestrictedMemoryAccess >=20 > Today's behavior is to always restrict access to non-SMRAM regardless the > value of PcdCpuSmmRestrictedMemoryAccess. >=20 > Because RAS components require to access all non-SMRAM memory, the > patch changes the code logic to honor PcdCpuSmmRestrictedMemoryAccess > so that only when the PCD is true, the restriction takes affect and page = table > memory is also protected. >=20 > Because IA32 build doesn't reference this PCD, such restriction always ta= kes > affect in IA32 build. >=20 > Signed-off-by: Ray Ni > Cc: Eric Dong > Cc: Jiewen Yao > Cc: Laszlo Ersek > --- > UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c | 14 ++++++++++++++ > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 18 ++++++++++-------- > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 11 +++++++++++ > UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 14 ++++++++++++++ > 4 files changed, 49 insertions(+), 8 deletions(-) >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > index 05fb455936..f891a81112 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > @@ -336,3 +336,17 @@ RestoreCr2 ( > { > return ; > } > + > +/** > + Return whether access to non-SMRAM is restricted. > + > + @retval TRUE Access to non-SMRAM is restricted. > + @retval FALSE Access to non-SMRAM is not restricted. > +*/ > +BOOLEAN > +IsRestrictedMemoryAccess ( > + VOID > + ) > +{ > + return TRUE; > +} > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c > index 69a04dfb23..723fd5042f 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c > @@ -1431,15 +1431,17 @@ PerformRemainingTasks ( > // > SetMemMapAttributes (); >=20 > - // > - // For outside SMRAM, we only map SMM communication buffer or MMIO. > - // > - SetUefiMemMapAttributes (); > + if (IsRestrictedMemoryAccess ()) { > + // > + // For outside SMRAM, we only map SMM communication buffer or MMIO= . > + // > + SetUefiMemMapAttributes (); >=20 > - // > - // Set page table itself to be read-only > - // > - SetPageTableAttributes (); > + // > + // Set page table itself to be read-only > + // > + SetPageTableAttributes (); > + } >=20 > // > // Configure SMM Code Access Check feature if available. > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > index 8c29f1a558..daf977f654 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > @@ -1450,4 +1450,15 @@ InitializeDataForMmMp ( > VOID > ); >=20 > +/** > + Return whether access to non-SMRAM is restricted. > + > + @retval TRUE Access to non-SMRAM is restricted. > + @retval FALSE Access to non-SMRAM is not restricted. > +*/ > +BOOLEAN > +IsRestrictedMemoryAccess ( > + VOID > + ); > + > #endif > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > index 7516f35055..733d107efd 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > @@ -1252,3 +1252,17 @@ RestoreCr2 ( > AsmWriteCr2 (Cr2); > } > } > + > +/** > + Return whether access to non-SMRAM is restricted. > + > + @retval TRUE Access to non-SMRAM is restricted. > + @retval FALSE Access to non-SMRAM is not restricted. > +*/ > +BOOLEAN > +IsRestrictedMemoryAccess ( > + VOID > + ) > +{ > + return mCpuSmmRestrictedMemoryAccess; } > -- > 2.21.0.windows.1