From nobody Thu May 2 18:08:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+44936+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+44936+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1565075916; cv=none; d=zoho.com; s=zohoarc; b=gk8YfeXUuwO39jYG+BUvgeI0nJTIR4yulcFxs3g1lCBtxuUaZqBxFPyLlIUYbqO0L3o52yLYQcFcd91XlRDIA0Ji98GblGkI+cO7UKycY+JulebF4HHo5z9nBdxQIeZSFzBqqzWLSjpR5+arv7fqwNeE507xbO7ZTjDTWR3V9eA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565075916; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=iKL6HPRGeBVFg7D8BISbfxGDIJg1CZADr3ODwng+HMM=; b=FwEY/bp+vYAX4G0o9eH2ln3dsDN6OZ5r1cEMR4nwTmLpPzajdWWmp3VeF7nNRGTsQmW2upXGZuVdwh1QetdrAlT53EkPiVLJlHaI7IPvx6RA7dn/M9satc/Z7AR9ua2H+pZmZmwExXNL9lHQXKX+eAxhhpll9Zu1HczCHUySmR8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+44936+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 156507591608560.87167909196751; Tue, 6 Aug 2019 00:18:36 -0700 (PDT) Return-Path: X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by groups.io with SMTP; Tue, 06 Aug 2019 00:18:35 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Aug 2019 00:18:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,352,1559545200"; d="scan'208";a="198227076" X-Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.8]) by fmsmga004.fm.intel.com with ESMTP; 06 Aug 2019 00:18:34 -0700 From: "Wu, Hao A" To: devel@edk2.groups.io Cc: Hao A Wu , Liming Gao , Jian J Wang Subject: [edk2-devel] [PATCH v1] MdeModulePkg/Variable/RuntimeDxe: Not copy SMM pointers in comm buffer Date: Tue, 6 Aug 2019 15:18:32 +0800 Message-Id: <20190806071832.30108-1-hao.a.wu@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,hao.a.wu@intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1565075915; bh=/ctBWqXdQX4I8F6+5qO6+cYxLRlyZs7omyDjjlcWtmM=; h=Cc:Date:From:Reply-To:Subject:To; b=wa6/KZgt3alGukfD1B6PSSJpjOPUFiuTEg3nlWGQ2j2NSlZmZvH0A3u7F7iDWq7i/Ci zPYkl8tYIqhXwAik4HjBW/nUZo+6Oc/eq+E76vsSWz4dVLLcojqfYFg+FxctZM7clbNWk 7EvH3dr8WeGPfHN/vNnsfZbQLXm5lvXYmkU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 race 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/Mde= ModulePkg/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 ( =20 =20 /** + Copy only the meaningful fields of the variable statistics information f= rom + source buffer to the destination buffer. Other fields are filled with ze= ro. + + @param[in] DstInfoEntry A pointer to the buffer of destination varia= ble + information entry. + @param[in] SrcInfoEntry A pointer to the buffer of source variable + 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 poin= ted by gVariableInfo. =20 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; } =20 - CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY)); + CopyVarInfoEntry (InfoEntry, VariableInfo); CopyMem (InfoName, VariableInfo->Name, NameSize); *InfoSize =3D StatisticsInfoSize; =20 --=20 2.12.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#44936): https://edk2.groups.io/g/devel/message/44936 Mute This Topic: https://groups.io/mt/32740915/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-