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.100; helo=mga07.intel.com; envelope-from=eric.dong@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 ED28C203B99C2 for ; Mon, 16 Jul 2018 01:17:41 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2018 01:17:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,360,1526367600"; d="scan'208";a="57183519" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga008.jf.intel.com with ESMTP; 16 Jul 2018 01:17:41 -0700 Received: from fmsmsx158.amr.corp.intel.com (10.18.116.75) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 16 Jul 2018 01:17:40 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx158.amr.corp.intel.com (10.18.116.75) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 16 Jul 2018 01:17:41 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.57]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.81]) with mapi id 14.03.0319.002; Mon, 16 Jul 2018 16:17:39 +0800 From: "Dong, Eric" To: "Wang, Jian J" , "edk2-devel@lists.01.org" CC: Laszlo Ersek , "Yao, Jiewen" , "Zeng, Star" Thread-Topic: [PATCH] UefiCpuPkg/CpuDxe: fix incorrect check of SMM mode Thread-Index: AQHUGm3ueFobeNPN1EW8hZpkBROa16SRhe5Q Date: Mon, 16 Jul 2018 08:17:38 +0000 Message-ID: References: <20180713055357.4196-1-jian.j.wang@intel.com> In-Reply-To: <20180713055357.4196-1-jian.j.wang@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 Subject: Re: [PATCH] UefiCpuPkg/CpuDxe: fix incorrect check of SMM mode X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Jul 2018 08:17:42 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Eric Dong > -----Original Message----- > From: Wang, Jian J > Sent: Friday, July 13, 2018 1:54 PM > To: edk2-devel@lists.01.org > Cc: Dong, Eric ; Laszlo Ersek ; > Yao, Jiewen ; Zeng, Star > Subject: [PATCH] UefiCpuPkg/CpuDxe: fix incorrect check of SMM mode >=20 > Current IsInSmm() method makes use of gEfiSmmBase2ProtocolGuid.InSmm() > to check if current processor is in SMM mode or not. But this is not corr= ect > because gEfiSmmBase2ProtocolGuid.InSmm() can only detect if the caller is > running in SMRAM or from SMM driver. It cannot guarantee if the caller is > running in SMM mode. Because SMM mode will load its own page table, > adding an extra check of saved DXE page table base address against curren= t > CR3 register value can help to get the correct answer for sure (in SMM mo= de > or not in SMM mode). >=20 > This is an issue caused by check-in at >=20 > d106cf71eabaacff63c14626a4a87346b93074dd >=20 > Cc: Eric Dong > Cc: Laszlo Ersek > Cc: Jiewen Yao > Cc: Star Zeng > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jian J Wang > --- > UefiCpuPkg/CpuDxe/CpuPageTable.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) >=20 > diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c > b/UefiCpuPkg/CpuDxe/CpuPageTable.c > index 850eed60e7..df021798c0 100644 > --- a/UefiCpuPkg/CpuDxe/CpuPageTable.c > +++ b/UefiCpuPkg/CpuDxe/CpuPageTable.c > @@ -136,7 +136,14 @@ IsInSmm ( > mSmmBase2->InSmm (mSmmBase2, &InSmm); > } >=20 > - return InSmm; > + // > + // mSmmBase2->InSmm() can only detect if the caller is running in > + SMRAM // or from SMM driver. It cannot tell if the caller is running i= n > SMM mode. > + // Check page table base address to guarantee that because SMM mode > + willl // load its own page table. > + // > + return (InSmm && > + mPagingContext.ContextData.X64.PageTableBase !=3D > + (UINT64)AsmReadCr3()); > } >=20 > /** > -- > 2.16.2.windows.1