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.20, mailfrom: hao.a.wu@intel.com) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by groups.io with SMTP; Tue, 06 Aug 2019 17:07:16 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Aug 2019 17:07:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,353,1559545200"; d="scan'208";a="258191327" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga001.jf.intel.com with ESMTP; 06 Aug 2019 17:07:16 -0700 Received: from fmsmsx605.amr.corp.intel.com (10.18.126.85) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 6 Aug 2019 17:07:15 -0700 Received: from fmsmsx605.amr.corp.intel.com (10.18.126.85) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 6 Aug 2019 17:07:15 -0700 Received: from shsmsx153.ccr.corp.intel.com (10.239.6.53) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Tue, 6 Aug 2019 17:07:14 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.112]) by SHSMSX153.ccr.corp.intel.com ([169.254.12.215]) with mapi id 14.03.0439.000; Wed, 7 Aug 2019 08:07:14 +0800 From: "Wu, Hao A" To: "Zeng, Star" , "devel@edk2.groups.io" CC: "Gao, Liming" , "Wang, Jian J" Subject: Re: [edk2-devel] [PATCH v1] MdeModulePkg/Variable/RuntimeDxe: Not copy SMM pointers in comm buffer Thread-Topic: [edk2-devel] [PATCH v1] MdeModulePkg/Variable/RuntimeDxe: Not copy SMM pointers in comm buffer Thread-Index: AQHVTCcrzA/G/O3et0KmAvzlmkH+p6btr6oAgAEf7TA= Date: Wed, 7 Aug 2019 00:07:14 +0000 Message-ID: References: <20190806071832.30108-1-hao.a.wu@intel.com> <0C09AFA07DD0434D9E2A0C6AEB0483104038E284@shsmsx102.ccr.corp.intel.com> In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483104038E284@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 Return-Path: hao.a.wu@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Zeng, Star > Sent: Tuesday, August 06, 2019 10:56 PM > To: devel@edk2.groups.io; Wu, Hao A > Cc: Gao, Liming; Wang, Jian J; Zeng, Star > Subject: RE: [edk2-devel] [PATCH v1] MdeModulePkg/Variable/RuntimeDxe: > Not copy SMM pointers in comm buffer >=20 > The DstInfoEntry is better to have identifer [out] instead of [in]? Yes, good point. I will update it and send out the V2 patch. Best Regards, Hao Wu >=20 > Thanks, > Star >=20 > > -----Original Message----- > > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of > Wu, > > Hao A > > Sent: Tuesday, August 6, 2019 3:19 PM > > To: devel@edk2.groups.io > > Cc: Wu, Hao A ; Gao, Liming > ; > > Wang, Jian J > > Subject: [edk2-devel] [PATCH v1] MdeModulePkg/Variable/RuntimeDxe: > Not > > copy SMM pointers in comm buffer > > > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2002 > > > > This commit will update the logic in function SmmVariableGetStatistics= () so > > that the pointer fields ('Next' and 'Name') in structure > > VARIABLE_INFO_ENTRY will not be copied into the SMM communication > > buffer. > > > > Doing so will prevent SMM pointers address from being leaked into non- > > SMM environment. > > > > Please note that newly introduced internal function CopyVarInfoEntry()= will > > not use CopyMem() to copy the whole VARIABLE_INFO_ENTRY structure > and > > then zero out the 'Next' and 'Name' fields. This is for preventing rac= e > > conditions where the pointers value might still be read. > > > > Cc: Liming Gao > > Cc: Jian J Wang > > Signed-off-by: Hao A Wu > > --- > > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 33 > > ++++++++++++++++++-- > > 1 file changed, 31 insertions(+), 2 deletions(-) > > > > diff --git > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > > index ec463d063e..81a9c9e849 100644 > > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > > @@ -312,6 +312,35 @@ GetFvbCountAndBuffer ( > > > > > > /** > > + Copy only the meaningful fields of the variable statistics > > + information from source buffer to the destination buffer. Other fie= lds > are > > filled with zero. > > + > > + @param[in] DstInfoEntry A pointer to the buffer of destination > variable > > + information entry. > > + @param[in] SrcInfoEntry A pointer to the buffer of source varia= ble > > + information entry. > > + > > +**/ > > +static > > +VOID > > +CopyVarInfoEntry ( > > + IN VARIABLE_INFO_ENTRY *DstInfoEntry, > > + IN VARIABLE_INFO_ENTRY *SrcInfoEntry > > + ) > > +{ > > + DstInfoEntry->Next =3D NULL; > > + DstInfoEntry->Name =3D NULL; > > + > > + CopyGuid (&DstInfoEntry->VendorGuid, &SrcInfoEntry->VendorGuid); > > + DstInfoEntry->Attributes =3D SrcInfoEntry->Attributes; > > + DstInfoEntry->ReadCount =3D SrcInfoEntry->ReadCount; > > + DstInfoEntry->WriteCount =3D SrcInfoEntry->WriteCount; > > + DstInfoEntry->DeleteCount =3D SrcInfoEntry->DeleteCount; > > + DstInfoEntry->CacheCount =3D SrcInfoEntry->CacheCount; > > + DstInfoEntry->Volatile =3D SrcInfoEntry->Volatile; > > +} > > + > > +/** > > Get the variable statistics information from the information buffer > pointed > > by gVariableInfo. > > > > Caution: This function may be invoked at SMM runtime. > > @@ -373,7 +402,7 @@ SmmVariableGetStatistics ( > > *InfoSize =3D StatisticsInfoSize; > > return EFI_BUFFER_TOO_SMALL; > > } > > - CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY)); > > + CopyVarInfoEntry (InfoEntry, VariableInfo); > > CopyMem (InfoName, VariableInfo->Name, NameSize); > > *InfoSize =3D StatisticsInfoSize; > > return EFI_SUCCESS; > > @@ -413,7 +442,7 @@ SmmVariableGetStatistics ( > > return EFI_BUFFER_TOO_SMALL; > > } > > > > - CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY)); > > + CopyVarInfoEntry (InfoEntry, VariableInfo); > > CopyMem (InfoName, VariableInfo->Name, NameSize); > > *InfoSize =3D StatisticsInfoSize; > > > > -- > > 2.12.0.windows.1 > > > > > >=20