From 466f2f0c5fc0f30e8e7157172ab7fb74e85640c6 Mon Sep 17 00:00:00 2001 From: Nhi Pham Date: Thu, 23 Nov 2023 11:48:54 +0700 Subject: MdeModulePkg/DxeCapsuleLibFmp: Fix crash with VirtualAddressMap omitted If the SetVirtualAddressMap() is not called, mIsVirtualAddrConverted is FALSE and the kernel crash occurs in IsNestedFmpCapsule() when executing gBS->LocateProtocol () in the else case. To serve the omitted SetVirtualAddressMap() call, we could just check mEsrtTable presence instead of relying on mIsVirtualAddrConverted. Signed-off-by: Nhi Pham Reviewed-by: Ard Biesheuvel Reviewed-by: Liming Gao --- MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c | 17 +++++++---------- .../Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c | 2 -- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c index 197af267af..2433c76a8c 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c @@ -41,8 +41,7 @@ #include #include -EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable = NULL; -BOOLEAN mIsVirtualAddrConverted = FALSE; +EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable = NULL; BOOLEAN mDxeCapsuleLibEndOfDxe = FALSE; EFI_EVENT mDxeCapsuleLibEndOfDxeEvent = NULL; @@ -1394,14 +1393,12 @@ IsNestedFmpCapsule ( EFI_SYSTEM_RESOURCE_ENTRY Entry; EsrtGuidFound = FALSE; - if (mIsVirtualAddrConverted) { - if (mEsrtTable != NULL) { - EsrtEntry = (EFI_SYSTEM_RESOURCE_ENTRY *)(mEsrtTable + 1); - for (Index = 0; Index < mEsrtTable->FwResourceCount; Index++, EsrtEntry++) { - if (CompareGuid (&EsrtEntry->FwClass, &CapsuleHeader->CapsuleGuid)) { - EsrtGuidFound = TRUE; - break; - } + if (mEsrtTable != NULL) { + EsrtEntry = (EFI_SYSTEM_RESOURCE_ENTRY *)(mEsrtTable + 1); + for (Index = 0; Index < mEsrtTable->FwResourceCount; Index++, EsrtEntry++) { + if (CompareGuid (&EsrtEntry->FwClass, &CapsuleHeader->CapsuleGuid)) { + EsrtGuidFound = TRUE; + break; } } } else { diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c index 9ceb44fe4d..44f30c16c2 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c @@ -21,7 +21,6 @@ #include extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable; -extern BOOLEAN mIsVirtualAddrConverted; EFI_EVENT mDxeRuntimeCapsuleLibVirtualAddressChangeEvent = NULL; EFI_EVENT mDxeRuntimeCapsuleLibReadyToBootEvent = NULL; @@ -40,7 +39,6 @@ DxeCapsuleLibVirtualAddressChangeEvent ( ) { gRT->ConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mEsrtTable); - mIsVirtualAddrConverted = TRUE; } /** -- cgit v1.2.3