]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/ReportStatusCodeRouter: Revert end pointer on out of resources
authorMichael Kubacki <michael.kubacki@microsoft.com>
Fri, 10 Apr 2020 20:49:43 +0000 (04:49 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 21 Apr 2020 02:20:51 +0000 (02:20 +0000)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2665

ReportDispatcher() is called by a software module to report a status code.
The interface is generic and can be called frequently throughout the boot
under various conditions. A certain set of conditions can cause the
currently implemented algorithm for resource exhaustion to fail. A sample
scenario:

1. ReportStatusCode() is called at a TPL higher than one of the registered
   status code listeners making the call to the listener deferred until
   TPL is lowered.
2. Additional calls to ReportStatusCode() occur, so the data buffer
   continues to expand.
3. A call to ReportStatusCode() is made from within a memory allocation
   call (e.g. CoreAllocatePoolPages ()) which is protected from re-
   entrancy with mPoolMemoryLock. This will cause the ReallocatePool()
   call in ReportDispatcher() to fail. Because the end pointer was already
   moved to account for the data size, the end pointer is now moved
   beyond the buffer and invalid.

This commit saves the original end pointer value into a local variable
called "FailSafeEndPointer" which tracks a safe end pointer to revert to
in the case the allocated buffer size (CallbackEntry->EndPointer -
CallbackEntry->StatusCodeDataBuffer) is still not large enough for the
data.

Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Kun Qin <Kun.Qin@microsoft.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Dandan Bi <dandan.bi@intel.com>
MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.c

index 5df83027c62db821988bd8e7bf28c1af4ce005fb..27939235dc004c310eadc473c558e853ce11331b 100644 (file)
@@ -238,6 +238,7 @@ ReportDispatcher (
   RSC_DATA_ENTRY                *RscData;\r
   EFI_STATUS                    Status;\r
   VOID                          *NewBuffer;\r
+  EFI_PHYSICAL_ADDRESS          FailSafeEndPointer;\r
 \r
   //\r
   // Use atom operation to avoid the reentant of report.\r
@@ -268,6 +269,7 @@ ReportDispatcher (
     // If callback is registered with TPL lower than TPL_HIGH_LEVEL, event must be signaled at boot time to possibly wait for\r
     // allowed TPL to report status code. Related data should also be stored in data buffer.\r
     //\r
+    FailSafeEndPointer = CallbackEntry->EndPointer;\r
     CallbackEntry->EndPointer  = ALIGN_VARIABLE (CallbackEntry->EndPointer);\r
     RscData = (RSC_DATA_ENTRY *) (UINTN) CallbackEntry->EndPointer;\r
     CallbackEntry->EndPointer += sizeof (RSC_DATA_ENTRY);\r
@@ -286,6 +288,7 @@ ReportDispatcher (
                       (VOID *) (UINTN) CallbackEntry->StatusCodeDataBuffer\r
                       );\r
         if (NewBuffer != NULL) {\r
+          FailSafeEndPointer = (EFI_PHYSICAL_ADDRESS) (UINTN) NewBuffer + (FailSafeEndPointer - CallbackEntry->StatusCodeDataBuffer);\r
           CallbackEntry->EndPointer = (EFI_PHYSICAL_ADDRESS) (UINTN) NewBuffer + (CallbackEntry->EndPointer - CallbackEntry->StatusCodeDataBuffer);\r
           CallbackEntry->StatusCodeDataBuffer = (EFI_PHYSICAL_ADDRESS) (UINTN) NewBuffer;\r
           CallbackEntry->BufferSize *= 2;\r
@@ -297,6 +300,7 @@ ReportDispatcher (
     // If data buffer is used up, do not report for this time.\r
     //\r
     if (CallbackEntry->EndPointer > (CallbackEntry->StatusCodeDataBuffer + CallbackEntry->BufferSize)) {\r
+      CallbackEntry->EndPointer = FailSafeEndPointer;\r
       continue;\r
     }\r
 \r