From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: hao.a.wu@intel.com) 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 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" 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: [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> X-Mailer: git-send-email 2.12.0.windows.1 REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2002 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/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 fields 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 variable + information entry. + +**/ +static +VOID +CopyVarInfoEntry ( + IN VARIABLE_INFO_ENTRY *DstInfoEntry, + IN VARIABLE_INFO_ENTRY *SrcInfoEntry + ) +{ + DstInfoEntry->Next = NULL; + DstInfoEntry->Name = NULL; + + CopyGuid (&DstInfoEntry->VendorGuid, &SrcInfoEntry->VendorGuid); + DstInfoEntry->Attributes = SrcInfoEntry->Attributes; + DstInfoEntry->ReadCount = SrcInfoEntry->ReadCount; + DstInfoEntry->WriteCount = SrcInfoEntry->WriteCount; + DstInfoEntry->DeleteCount = SrcInfoEntry->DeleteCount; + DstInfoEntry->CacheCount = SrcInfoEntry->CacheCount; + DstInfoEntry->Volatile = 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 = StatisticsInfoSize; return EFI_BUFFER_TOO_SMALL; } - CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY)); + CopyVarInfoEntry (InfoEntry, VariableInfo); CopyMem (InfoName, VariableInfo->Name, NameSize); *InfoSize = 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 = StatisticsInfoSize; -- 2.12.0.windows.1