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=hao.a.wu@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 0935B2115C31D for ; Fri, 28 Sep 2018 23:21:13 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Sep 2018 23:21:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,318,1534834800"; d="scan'208";a="93122047" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga004.fm.intel.com with ESMTP; 28 Sep 2018 23:21:04 -0700 Received: from fmsmsx158.amr.corp.intel.com (10.18.116.75) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 28 Sep 2018 23:21:04 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by fmsmsx158.amr.corp.intel.com (10.18.116.75) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 28 Sep 2018 23:21:03 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.183]) by shsmsx102.ccr.corp.intel.com ([169.254.2.140]) with mapi id 14.03.0319.002; Sat, 29 Sep 2018 14:21:01 +0800 From: "Wu, Hao A" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Yao, Jiewen" Thread-Topic: [PATCH v2 2/5] MdeModulePkg/FaultTolerantWrite:[CVE-2017-5753]Fix bounds check bypass Thread-Index: AQHUVJbXp5gMsd1IskqVZ1lOeB/C0KUGRzSAgACHwYA= Date: Sat, 29 Sep 2018 06:21:00 +0000 Message-ID: References: <20180925061259.31680-1-hao.a.wu@intel.com> <20180925061259.31680-3-hao.a.wu@intel.com> <0C09AFA07DD0434D9E2A0C6AEB0483103BBF5E78@shsmsx102.ccr.corp.intel.com> In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483103BBF5E78@shsmsx102.ccr.corp.intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2 2/5] MdeModulePkg/FaultTolerantWrite:[CVE-2017-5753]Fix bounds check bypass X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Sep 2018 06:21:14 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Zeng, Star > Sent: Saturday, September 29, 2018 2:11 PM > To: Wu, Hao A; edk2-devel@lists.01.org > Cc: Yao, Jiewen; Zeng, Star > Subject: RE: [PATCH v2 2/5] MdeModulePkg/FaultTolerantWrite:[CVE-2017- > 5753]Fix bounds check bypass >=20 > Please double check whether the AsmLfence calling should be before the li= ne > below. >=20 > PrivateData =3D (VOID *)&SmmFtwWriteHeader->Data[Length]; Hi, The above code is getting the address of a possible cross bounday access during the speculative execution. I also checked that the subsequent usage of 'PrivateData' does not have a code pattern of the 'Bounds check bypass' issue. So I think the AsmLfence() is not needed here. Best Regards, Hao Wu >=20 >=20 > Thanks, > Star > -----Original Message----- > From: Wu, Hao A > Sent: Tuesday, September 25, 2018 2:13 PM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A ; Yao, Jiewen ; > Zeng, Star > Subject: [PATCH v2 2/5] MdeModulePkg/FaultTolerantWrite:[CVE-2017- > 5753]Fix bounds check bypass >=20 > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D1194 >=20 > Speculative execution is used by processor to avoid having to wait for da= ta to > arrive from memory, or for previous operations to finish, the processor m= ay > speculate as to what will be executed. >=20 > If the speculation is incorrect, the speculatively executed instructions = might > leave hints such as which memory locations have been brought into cache. > Malicious actors can use the bounds check bypass method (code gadgets wit= h > controlled external inputs) to infer data values that have been used in > speculative operations to reveal secrets which should not otherwise be > accessed. >=20 > This commit will focus on the SMI handler(s) registered within the > FaultTolerantWriteDxe driver and insert AsmLfence API to mitigate the bou= nds > check bypass issue. >=20 > For SMI handler SmmFaultTolerantWriteHandler(): >=20 > Under "case FTW_FUNCTION_WRITE:", 'SmmFtwWriteHeader->Length' can be > a potential cross boundary access of the 'CommBuffer' (controlled externa= l > inputs) during speculative execution. This cross boundary access is later= passed > as parameter 'Length' into function FtwWrite(). >=20 > Within function FtwWrite(), the value of 'Length' can be inferred by code= : > "CopyMem (MyBuffer + Offset, Buffer, Length);". One can observe which par= t > of the content within 'Buffer' was brought into cache to possibly reveal = the > value of 'Length'. >=20 > Hence, this commit adds a AsmLfence() after the boundary/range checks of > 'CommBuffer' to prevent the speculative execution. >=20 > A more detailed explanation of the purpose of commit is under the 'Bounds > check bypass mitigation' section of the below link: > https://software.intel.com/security-software-guidance/insights/host-firmw= are- > speculative-execution-side-channel-mitigation >=20 > And the document at: > https://software.intel.com/security-software-guidance/api- > app/sites/default/files/337879-analyzing-potential-bounds-Check-bypass- > vulnerabilities.pdf >=20 > Cc: Jiewen Yao > Cc: Star Zeng > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Hao Wu > --- > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c > | 7 +++++++ > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf > | 1 + > 2 files changed, 8 insertions(+) >=20 > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c > index 632313f076..27fcab19b6 100644 > --- > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c > +++ > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm > +++ .c > @@ -57,6 +57,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY > KIND, EITHER EXPRESS OR IMPLIED. > #include > #include #include > +#include > #include #include > "FaultTolerantWrite.h" > #include "FaultTolerantWriteSmmCommon.h" > @@ -417,6 +418,12 @@ SmmFaultTolerantWriteHandler ( > &SmmFvbHandle > ); > if (!EFI_ERROR (Status)) { > + // > + // The AsmLfence() call here is to ensure the previous range/con= tent > + // checks for the CommBuffer have been completed before calling = into > + // FtwWrite(). > + // > + AsmLfence (); > Status =3D FtwWrite( > &mFtwDevice->FtwInstance, > SmmFtwWriteHeader->Lba, diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.in > f > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.in > f > index 85d109e8d9..606cc2266b 100644 > --- > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.in > f > +++ > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm > +++ .inf > @@ -55,6 +55,7 @@ > PcdLib > ReportStatusCodeLib > SmmMemLib > + BaseLib >=20 > [Guids] > # > -- > 2.12.0.windows.1