From nobody Mon May 6 08:08:09 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+44959+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+44959+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1565137074; cv=none; d=zoho.com; s=zohoarc; b=dbrFhhvnlLoRJ+XzFXbs5x2K+6m80+ol68j1qMTFh6S2a0e4Bc2TmN3wcu7iJaQIb3pntmxIwZjrfaFV+hwPqaK9hecjw5lC4whUZBKmhIZkmZMO0ocKf7pavy5XzlA1Rtyi+zjQELFLrrsy6eX5QYXRau4Hk7UtIWNuwqBeMiI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565137074; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=qX2MDyxncDDp5e4wWXG3YX5T65XNSxW5dWyrNHrRY08=; b=J9Ba//tBfESST1I9Iu0zTT+McanJaHI4pWn7Tyiv5m7oLeLTUcNNmC5FZiKrBT1+G4+3GngfqeXv734k5d4XnPM45eomycwfDNEY80VIrm7sfamwYo0xH0Jozife0DI4pvicozs7WivVRPcDAjcthwFa35+ksf3BWaojotApRqg= 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+44959+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 1565137074770868.0249529518006; Tue, 6 Aug 2019 17:17:54 -0700 (PDT) Return-Path: X-Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by groups.io with SMTP; Tue, 06 Aug 2019 17:17:53 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Aug 2019 17:17:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,353,1559545200"; d="scan'208";a="174333672" X-Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.8]) by fmsmga008.fm.intel.com with ESMTP; 06 Aug 2019 17:17:51 -0700 From: "Wu, Hao A" To: devel@edk2.groups.io Cc: Hao A Wu , Star Zeng , Liming Gao , Jian J Wang Subject: [edk2-devel] [PATCH v2] MdeModulePkg/Variable/RuntimeDxe: Not copy SMM pointers in comm buffer Date: Wed, 7 Aug 2019 08:17:49 +0800 Message-Id: <20190807001749.28220-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=1565137074; bh=NBwKhleb7hekMlQY1hbiJ7A/nn9K5S2lL9YaqbtTmdc=; h=Cc:Date:From:Reply-To:Subject:To; b=cJcyrGCoRzT7m5TKIr43i7IxpvSq7URxsr+mDHjs8C6tH/chPL+i9eGvfcffsa+pFtl Xv7J0EkK1hLzgBDUFvj749YDZkoHown+O0SEpkIp5KKaaLSyHpwF2Bzkz0unOydFQW89D /xzcDF2Ou0JLgvDmYsHVVnIT17pzUnsVmuE= 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: Star Zeng Cc: Liming Gao Cc: Jian J Wang Signed-off-by: Hao A Wu Reviewed-by: Jian J Wang --- V2 patch updates the type of parameter 'DstInfoEntry' from 'in' to 'out' for the newly added function CopyVarInfoEntry(). 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..9b59387e58 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[out] DstInfoEntry A pointer to the buffer of destination vari= able + information entry. + @param[in] SrcInfoEntry A pointer to the buffer of source variable + information entry. + +**/ +static +VOID +CopyVarInfoEntry ( + OUT 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 (#44959): https://edk2.groups.io/g/devel/message/44959 Mute This Topic: https://groups.io/mt/32749592/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-