From 8befdb144193f0fe10c39ab0c21e138c59018b05 Mon Sep 17 00:00:00 2001 From: Jiaxin Wu Date: Fri, 31 May 2024 12:11:53 +0800 Subject: MdeModulePkg/VariableSmm: Add func for Primary Buffer valid check Add a new function (VariableSmmIsPrimaryBufferValid) to check Primary Buffer valid or not. original function (VariableSmmIsBufferOutsideSmmValid) is used to check the buffer outside MMRAM. Signed-off-by: Jiaxin Wu Cc: Liming Gao Cc: Ray Ni Cc: Star Zeng Cc: Hongbin1 Zhang Cc: Wei6 Xu Cc: Dun Tan Cc: Yuanhao Xie --- .../Variable/RuntimeDxe/PrivilegePolymorphic.h | 17 ++++++++++++++++- .../Universal/Variable/RuntimeDxe/VariableSmm.c | 6 +++--- .../Variable/RuntimeDxe/VariableStandaloneMm.c | 20 +++++++++++++++++++- .../Variable/RuntimeDxe/VariableTraditionalMm.c | 20 +++++++++++++++++++- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/PrivilegePolymorphic.h b/MdeModulePkg/Universal/Variable/RuntimeDxe/PrivilegePolymorphic.h index 065c75a..23e950a 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/PrivilegePolymorphic.h +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/PrivilegePolymorphic.h @@ -7,7 +7,7 @@ vs. non-privileged driver code. Copyright (c) 2017, Red Hat, Inc.
- Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2024, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -123,6 +123,21 @@ MmVariableServiceInitialize ( ); /** + This function checks if the communication buffer is valid. + + @param Buffer The buffer start address to be checked. + @param Length The buffer length to be checked. + + @retval TRUE This buffer is valid. + @retval FALSE This buffer is not valid. +**/ +BOOLEAN +VariableSmmIsPrimaryBufferValid ( + IN EFI_PHYSICAL_ADDRESS Buffer, + IN UINT64 Length + ); + +/** This function checks if the buffer is valid per processor architecture and does not overlap with SMRAM. diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c index 5253c32..189880c 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c @@ -14,7 +14,7 @@ VariableServiceSetVariable(), VariableServiceQueryVariableInfo(), ReclaimForOS(), SmmVariableGetStatistics() should also do validation based on its own knowledge. -Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.
+Copyright (c) 2010 - 2024, Intel Corporation. All rights reserved.
Copyright (c) 2018, Linaro, Ltd. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -497,8 +497,8 @@ SmmVariableHandler ( return EFI_SUCCESS; } - if (!VariableSmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) { - DEBUG ((DEBUG_ERROR, "SmmVariableHandler: SMM communication buffer in SMRAM or overflow!\n")); + if (!VariableSmmIsPrimaryBufferValid ((UINTN)CommBuffer, TempCommBufferSize)) { + DEBUG ((DEBUG_ERROR, "SmmVariableHandler: SMM Primary Buffer (CommBuffer) is not valid!\n")); return EFI_SUCCESS; } diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.c index 943993e..1e1e933 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.c @@ -2,7 +2,7 @@ Parts of the SMM/MM implementation that are specific to standalone MM -Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2024, Intel Corporation. All rights reserved.
Copyright (c) 2018, Linaro, Ltd. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -11,6 +11,24 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "Variable.h" /** + This function checks if the Primary Buffer (CommBuffer) is valid. + + @param Buffer The buffer start address to be checked. + @param Length The buffer length to be checked. + + @retval TRUE This buffer is valid. + @retval FALSE This buffer is not valid. +**/ +BOOLEAN +VariableSmmIsPrimaryBufferValid ( + IN EFI_PHYSICAL_ADDRESS Buffer, + IN UINT64 Length + ) +{ + return TRUE; +} + +/** This function checks if the buffer is valid per processor architecture and does not overlap with SMRAM. diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableTraditionalMm.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableTraditionalMm.c index 0369c3c..35f6f4b 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableTraditionalMm.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableTraditionalMm.c @@ -2,7 +2,7 @@ Parts of the SMM/MM implementation that are specific to traditional MM -Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2024, Intel Corporation. All rights reserved.
Copyright (c) 2018, Linaro, Ltd. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -13,6 +13,24 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "Variable.h" /** + This function checks if the Primary Buffer (CommBuffer) is valid. + + @param Buffer The buffer start address to be checked. + @param Length The buffer length to be checked. + + @retval TRUE This buffer is valid. + @retval FALSE This buffer is not valid. +**/ +BOOLEAN +VariableSmmIsPrimaryBufferValid ( + IN EFI_PHYSICAL_ADDRESS Buffer, + IN UINT64 Length + ) +{ + return SmmIsBufferOutsideSmmValid (Buffer, Length); +} + +/** This function checks if the buffer is valid per processor architecture and does not overlap with SMRAM. -- cgit v1.1