Make it possible to delete SMMSTORE variable by appending it with size 0

This commit is contained in:
Jeremy Soller
2019-10-02 16:01:00 -06:00
committed by Tim Crawford
parent 0eca9e3c1a
commit 7050fc3a26

View File

@@ -944,6 +944,7 @@ UpdateVariable (
UINTN VarSize; UINTN VarSize;
VARIABLE_GLOBAL *Global; VARIABLE_GLOBAL *Global;
UINTN NonVolatileVarableStoreSize; UINTN NonVolatileVarableStoreSize;
BOOLEAN Delete = FALSE;
Global = &mVariableModuleGlobal->VariableGlobal[Physical]; Global = &mVariableModuleGlobal->VariableGlobal[Physical];
@@ -976,10 +977,8 @@ UpdateVariable (
// specified causes it to be deleted. // specified causes it to be deleted.
// //
if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) { if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {
Variable->CurrPtr->State &= VAR_DELETED; DataSize = 0;
UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FALSE, FALSE, TRUE, FALSE); Delete = TRUE;
Status = EFI_SUCCESS;
goto Done;
} }
// //
@@ -989,8 +988,12 @@ UpdateVariable (
if (Variable->CurrPtr->DataSize == DataSize && if (Variable->CurrPtr->DataSize == DataSize &&
CompareMem (Data, GetVariableDataPtr (Variable->CurrPtr), DataSize) == 0 CompareMem (Data, GetVariableDataPtr (Variable->CurrPtr), DataSize) == 0
) { ) {
Status = EFI_SUCCESS; if (Delete) {
goto Done; goto Update;
} else {
Status = EFI_SUCCESS;
goto Done;
}
} else if (Variable->CurrPtr->State == VAR_ADDED) { } else if (Variable->CurrPtr->State == VAR_ADDED) {
// //
// Mark the old variable as in delete transition // Mark the old variable as in delete transition
@@ -1032,6 +1035,10 @@ UpdateVariable (
VarDataOffset = VarNameOffset + VarNameSize + GET_PAD_SIZE (VarNameSize); VarDataOffset = VarNameOffset + VarNameSize + GET_PAD_SIZE (VarNameSize);
VarSize = VarDataOffset + DataSize + GET_PAD_SIZE (DataSize); VarSize = VarDataOffset + DataSize + GET_PAD_SIZE (DataSize);
if (Delete) {
goto Store;
}
if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) { if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) {
NonVolatileVarableStoreSize = ((VARIABLE_STORE_HEADER *)(UINTN)(Global->NonVolatileVariableBase))->Size; NonVolatileVarableStoreSize = ((VARIABLE_STORE_HEADER *)(UINTN)(Global->NonVolatileVariableBase))->Size;
if ((((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0) if ((((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0)
@@ -1089,7 +1096,16 @@ UpdateVariable (
DataSize DataSize
); );
if (storeInitialized && ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0)) { Store:
// If the store is initialized
// And we are storing or deleting a non volatile variable
// Send the new data to SMMSTORE
if (storeInitialized && (
(Attributes & EFI_VARIABLE_NON_VOLATILE) != 0 || (
Delete &&
(Variable->CurrPtr->Attributes & EFI_VARIABLE_NON_VOLATILE) != 0
)
)) {
/* TODO: add hook for logging nv changes here */ /* TODO: add hook for logging nv changes here */
@@ -1116,6 +1132,7 @@ UpdateVariable (
*/ */
} }
Update:
// //
// Mark the old variable as deleted // Mark the old variable as deleted
// //
@@ -1123,7 +1140,11 @@ UpdateVariable (
Variable->CurrPtr->State &= VAR_DELETED; Variable->CurrPtr->State &= VAR_DELETED;
} }
UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FALSE, TRUE, FALSE, FALSE); if (Delete) {
UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FALSE, FALSE, TRUE, FALSE);
} else {
UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FALSE, TRUE, FALSE, FALSE);
}
Status = EFI_SUCCESS; Status = EFI_SUCCESS;