MdeModulePkg/EmuRuntimeDxe: skip console NVRAM variables

Tianocore currently reads/writes a lot of NVRAM variables that
don't actually need to be saved. Occasionally some, specifically
related to the graphical/serial consoles, can become corrupted,
leading to a bricked device. To avoid this, temporarily restrict
the reading/writing of variables to skip console related ones
(starting with 'Con') until a better solution can be found.

Test: build/boot google/eve, inject "bad" NVRAM data, observe
device boots normally instead of hanging with no display detected.

Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
This commit is contained in:
Matt DeVillier
2020-03-17 13:34:40 -05:00
committed by Tim Crawford
parent e3e4f6ddd5
commit e10ad1c874

View File

@@ -1100,13 +1100,14 @@ UpdateVariable (
Store: Store:
// If the store is initialized // If the store is initialized
// And we are storing or deleting a non volatile variable // And we are storing or deleting a non volatile variable
// And variable name doesn't start with 'Con'
// Send the new data to SMMSTORE // Send the new data to SMMSTORE
if (storeInitialized && ( if (storeInitialized && (
(Attributes & EFI_VARIABLE_NON_VOLATILE) != 0 || ( (Attributes & EFI_VARIABLE_NON_VOLATILE) != 0 || (
Delete && Delete &&
(Variable->CurrPtr->Attributes & EFI_VARIABLE_NON_VOLATILE) != 0 (Variable->CurrPtr->Attributes & EFI_VARIABLE_NON_VOLATILE) != 0
) )) && (StrnCmp(L"Con", VariableName, StrLen(L"Con")))
)) { ) {
/* TODO: add hook for logging nv changes here */ /* TODO: add hook for logging nv changes here */
@@ -1978,23 +1979,27 @@ VariableCommonInitialize (
EFI_GUID *guid = (EFI_GUID *)(buf + i + 8); EFI_GUID *guid = (EFI_GUID *)(buf + i + 8);
VOID *data = (VOID *)(buf + i + 8 + keysz); VOID *data = (VOID *)(buf + i + 8 + keysz);
DEBUG ((DEBUG_WARN, "Fetching variable: %s\n", varname)); // don't update console variables
DEBUG ((DEBUG_WARN, "buf: %p, buf+i: %p, guid: %p, varname: %p, data: %p\n", buf, buf + i, guid, varname, data)); if (StrnCmp(L"Con", varname, StrLen(L"Con"))) {
VARIABLE_POINTER_TRACK Variable; DEBUG ((DEBUG_WARN, "Fetching variable: %s\n", varname));
FindVariable (varname, guid, &Variable, (VARIABLE_GLOBAL *)mVariableModuleGlobal); DEBUG ((DEBUG_WARN, "buf: %p, buf+i: %p, guid: %p, varname: %p, data: %p\n", buf, buf + i, guid, varname, data));
VARIABLE_POINTER_TRACK Variable;
FindVariable (varname, guid, &Variable, (VARIABLE_GLOBAL *)mVariableModuleGlobal);
DEBUG ((DEBUG_WARN, "Updating variable: %s\n", varname)); DEBUG ((DEBUG_WARN, "Updating variable: %s\n", varname));
UpdateVariable ( UpdateVariable (
varname, varname,
guid, guid,
data, data,
valsz, valsz,
// all of these variables are nv // all of these variables are nv
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
&Variable &Variable
); );
} else {
DEBUG ((DEBUG_WARN, "Skipping console variable: %s\n", varname));
}
} }
DEBUG ((DEBUG_WARN, "Added variable: 0x%x, val size: %x\n", keysz, valsz));
// no UEFI variable since it's at most the GUID part, so skip // no UEFI variable since it's at most the GUID part, so skip
i += 8 + keysz + valsz + 1; i += 8 + keysz + valsz + 1;
i = (i + 3) & ~3; i = (i + 3) & ~3;