[PATCH v7 10/14] MdeModulePkg: Allow VariablePolicy state to delete protected variables


Bret Barkelew
 

https://bugzilla.tianocore.org/show_bug.cgi?id=3D2522

TcgMorLockSmm provides special protections for
the TCG MOR variables. This will check
IsVariablePolicyEnabled() before enforcing
them to allow variable deletion when policy
engine is disabled.

Only allows deletion, not modification.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Bret Barkelew <brbarkel@microsoft.com>
Signed-off-by: Bret Barkelew <brbarkel@microsoft.com>
---
MdeModulePkg/Universal/Variable/RuntimeDxe/TcgMorLockSmm.c | 10 +=
+++++++++
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf | 2 ++
2 files changed, 12 insertions(+)

diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/TcgMorLockSmm.c b/M=
deModulePkg/Universal/Variable/RuntimeDxe/TcgMorLockSmm.c
index 6d80eb64341a..085f82035f4b 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/TcgMorLockSmm.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/TcgMorLockSmm.c
@@ -5,6 +5,7 @@
This module adds Variable Hook and check MemoryOverwriteRequestControlLo=
ck.=0D
=0D
Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+Copyright (c) Microsoft Corporation.=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
=0D
**/=0D
@@ -17,6 +18,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/BaseMemoryLib.h>=0D
#include "Variable.h"=0D
=0D
+#include <Protocol/VariablePolicy.h>=0D
+=0D
+#include <Library/VariablePolicyLib.h>=0D
+=0D
typedef struct {=0D
CHAR16 *VariableName;=0D
EFI_GUID *VendorGuid;=0D
@@ -341,6 +346,11 @@ SetVariableCheckHandlerMor (
return EFI_SUCCESS;=0D
}=0D
=0D
+ // Permit deletion when policy is disabled.=0D
+ if (!IsVariablePolicyEnabled() && ((Attributes =3D=3D 0) || (DataSize =
=3D=3D 0))) {=0D
+ return EFI_SUCCESS;=0D
+ }=0D
+=0D
//=0D
// MorLock variable=0D
//=0D
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneM=
m.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
index 6e17f6cdf588..d8f480be27cc 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
@@ -20,6 +20,7 @@
#=0D
# Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>=0D
# Copyright (c) 2018, Linaro, Ltd. All rights reserved.<BR>=0D
+# Copyright (c) Microsoft Corporation.=0D
# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
#=0D
##=0D
@@ -74,6 +75,7 @@ [LibraryClasses]
StandaloneMmDriverEntryPoint=0D
SynchronizationLib=0D
VarCheckLib=0D
+ VariablePolicyLib=0D
=0D
[Protocols]=0D
gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES=0D
--=20
2.28.0.windows.1

Join devel@edk2.groups.io to automatically receive all group messages.