From 29658445a7191bcb68881f05722a2568bbbc6d2b Mon Sep 17 00:00:00 2001 From: Star Zeng Date: Wed, 29 Jun 2016 15:45:33 +0800 Subject: SecurityPkg VariableInfo: Use fixed buffer for smm comm buffer (This commit integrate changes in faf3de9bd036cd2a387c1e44d403d24386fadb49 from master.) Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng --- .../Application/VariableInfo/VariableInfo.c | 87 +++++++++++++--------- .../Application/VariableInfo/VariableInfo.inf | 7 +- 2 files changed, 55 insertions(+), 39 deletions(-) diff --git a/SecurityPkg/Application/VariableInfo/VariableInfo.c b/SecurityPkg/Application/VariableInfo/VariableInfo.c index 0c1ee4b0f8..e03d024140 100644 --- a/SecurityPkg/Application/VariableInfo/VariableInfo.c +++ b/SecurityPkg/Application/VariableInfo/VariableInfo.c @@ -3,7 +3,7 @@ this utility will print out the statistics information. You can use console redirection to capture the data. -Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -26,6 +26,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include +#include #include #include @@ -72,8 +73,8 @@ GetVariableStatisticsData ( /** - This function get and print the variable statistics data from SMM variable driver. - + This function get and print the variable statistics data from SMM variable driver. + @retval EFI_SUCCESS Print the statistics information successfully. @retval EFI_NOT_FOUND Not found the statistics information. @@ -90,7 +91,11 @@ PrintInfoFromSmm ( UINTN CommSize; SMM_VARIABLE_COMMUNICATE_HEADER *FunctionHeader; EFI_SMM_VARIABLE_PROTOCOL *Smmvariable; - + EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *PiSmmCommunicationRegionTable; + UINT32 Index; + EFI_MEMORY_DESCRIPTOR *Entry; + UINTN Size; + UINTN MaxSize; Status = gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **) &Smmvariable); if (EFI_ERROR (Status)) { @@ -100,39 +105,56 @@ PrintInfoFromSmm ( Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication); if (EFI_ERROR (Status)) { return Status; - } + } - CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE; - RealCommSize = CommSize; - CommBuffer = AllocateZeroPool (CommSize); + CommBuffer = NULL; + Status = EfiGetSystemConfigurationTable ( + &gEdkiiPiSmmCommunicationRegionTableGuid, + (VOID **) &PiSmmCommunicationRegionTable + ); + if (EFI_ERROR (Status)) { + return Status; + } + ASSERT (PiSmmCommunicationRegionTable != NULL); + Entry = (EFI_MEMORY_DESCRIPTOR *) (PiSmmCommunicationRegionTable + 1); + Size = 0; + MaxSize = 0; + for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) { + if (Entry->Type == EfiConventionalMemory) { + Size = EFI_PAGES_TO_SIZE ((UINTN) Entry->NumberOfPages); + if (Size > (SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (VARIABLE_INFO_ENTRY))) { + if (Size > MaxSize) { + MaxSize = Size; + RealCommSize = MaxSize; + CommBuffer = (EFI_SMM_COMMUNICATE_HEADER *) (UINTN) Entry->PhysicalStart; + } + } + } + Entry = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) Entry + PiSmmCommunicationRegionTable->DescriptorSize); + } ASSERT (CommBuffer != NULL); - + ZeroMem (CommBuffer, RealCommSize); + Print (L"Non-Volatile SMM Variables:\n"); do { + CommSize = RealCommSize; Status = GetVariableStatisticsData (CommBuffer, &CommSize); if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (CommBuffer); - CommBuffer = AllocateZeroPool (CommSize); - ASSERT (CommBuffer != NULL); - RealCommSize = CommSize; - Status = GetVariableStatisticsData (CommBuffer, &CommSize); + Print (L"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n"); + return Status; } - if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) { + if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) { break; } - if (CommSize < RealCommSize) { - CommSize = RealCommSize; - } - FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) CommBuffer->Data; VariableInfo = (VARIABLE_INFO_ENTRY *) FunctionHeader->Data; if (!VariableInfo->Volatile) { Print ( - L"%g R%03d(%03d) W%03d D%03d:%s\n", - &VariableInfo->VendorGuid, + L"%g R%03d(%03d) W%03d D%03d:%s\n", + &VariableInfo->VendorGuid, VariableInfo->ReadCount, VariableInfo->CacheCount, VariableInfo->WriteCount, @@ -141,34 +163,28 @@ PrintInfoFromSmm ( ); } } while (TRUE); - + Print (L"Volatile SMM Variables:\n"); - ZeroMem (CommBuffer, CommSize); + ZeroMem (CommBuffer, RealCommSize); do { + CommSize = RealCommSize; Status = GetVariableStatisticsData (CommBuffer, &CommSize); if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (CommBuffer); - CommBuffer = AllocateZeroPool (CommSize); - ASSERT (CommBuffer != NULL); - RealCommSize = CommSize; - Status = GetVariableStatisticsData (CommBuffer, &CommSize); + Print (L"The generic SMM communication buffer provided by SmmCommunicationRegionTable is too small\n"); + return Status; } - if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) { + if (EFI_ERROR (Status) || (CommSize <= SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)) { break; } - if (CommSize < RealCommSize) { - CommSize = RealCommSize; - } - FunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) CommBuffer->Data; VariableInfo = (VARIABLE_INFO_ENTRY *) FunctionHeader->Data; if (VariableInfo->Volatile) { Print ( - L"%g R%03d(%03d) W%03d D%03d:%s\n", - &VariableInfo->VendorGuid, + L"%g R%03d(%03d) W%03d D%03d:%s\n", + &VariableInfo->VendorGuid, VariableInfo->ReadCount, VariableInfo->CacheCount, VariableInfo->WriteCount, @@ -178,7 +194,6 @@ PrintInfoFromSmm ( } } while (TRUE); - FreePool (CommBuffer); return Status; } diff --git a/SecurityPkg/Application/VariableInfo/VariableInfo.inf b/SecurityPkg/Application/VariableInfo/VariableInfo.inf index d4a771a908..b2dc7e6ddc 100644 --- a/SecurityPkg/Application/VariableInfo/VariableInfo.inf +++ b/SecurityPkg/Application/VariableInfo/VariableInfo.inf @@ -6,7 +6,7 @@ # Note that if Variable Dxe driver doesn't enable the feature by setting PcdVariableCollectStatistics # as TRUE, the application will not display variable statistical information. # -# Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -55,8 +55,9 @@ gEfiSmmVariableProtocolGuid [Guids] - gEfiAuthenticatedVariableGuid ## SOMETIMES_CONSUMES ## SystemTable - gEfiVariableGuid ## CONSUMES ## SystemTable + gEfiAuthenticatedVariableGuid ## SOMETIMES_CONSUMES ## SystemTable + gEfiVariableGuid ## SOMETIMES_CONSUMES ## SystemTable + gEdkiiPiSmmCommunicationRegionTableGuid ## SOMETIMES_CONSUMES ## SystemTable [UserExtensions.TianoCore."ExtraFiles"] VariableInfoExtra.uni -- cgit