summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>2010-11-04 20:58:23 +0000
committermdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>2010-11-04 20:58:23 +0000
commitc5e0de8794346f0e11ae63f1e7705e784dcd5f81 (patch)
tree993fd44a366cea6d4afe634ef48a40a98988486d
parent9be899c5cc644d710e3392dedb672bf67b84b9c1 (diff)
downloadedk2-platforms-c5e0de8794346f0e11ae63f1e7705e784dcd5f81.tar.xz
Prevent infinite recursion when ASSERT(), DEBUG(), or any other use of ReportStatusCode is performed at > TPL_NOTIFY or there is not enough memory to allocate a buffer for the ExtendedData associated with the status code being reported
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11003 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c38
-rw-r--r--MdeModulePkg/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c5
2 files changed, 39 insertions, 4 deletions
diff --git a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c
index f5789c1a71..70b40b9c8a 100644
--- a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c
+++ b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c
@@ -25,6 +25,12 @@
#include <Guid/StatusCodeDataTypeId.h>
#include <Guid/StatusCodeDataTypeDebug.h>
+//
+// Define the maximum extended data size that is supported when a status code is
+// reported at TPL_HIGH_LEVEL.
+//
+#define MAX_EXTENDED_DATA_SIZE 0x200
+
EFI_STATUS_CODE_PROTOCOL *mReportStatusCodeLibStatusCodeProtocol = NULL;
/**
@@ -484,6 +490,8 @@ ReportStatusCodeEx (
{
EFI_STATUS Status;
EFI_STATUS_CODE_DATA *StatusCodeData;
+ EFI_TPL Tpl;
+ UINT64 Buffer[MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)];
ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));
ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
@@ -493,12 +501,32 @@ ReportStatusCodeEx (
}
//
- // Allocate space for the Status Code Header and its buffer
+ // Retrieve the current TPL
//
+ Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
+ gBS->RestoreTPL (Tpl);
+
StatusCodeData = NULL;
- gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);
+ if (Tpl <= TPL_NOTIFY) {
+ //
+ // Allocate space for the Status Code Header and its buffer
+ //
+ gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);
+ }
+
if (StatusCodeData == NULL) {
- return EFI_OUT_OF_RESOURCES;
+ //
+ // If a buffer could not be allocated, then see if the local variable Buffer can be used
+ //
+ if (ExtendedDataSize > (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {
+ //
+ // The local variable Buffer not large enough to hold the extended data associated
+ // with the status code being reported.
+ //
+ ASSERT (FALSE);
+ return EFI_OUT_OF_RESOURCES;
+ }
+ StatusCodeData = (EFI_STATUS_CODE_DATA *)Buffer;
}
//
@@ -529,7 +557,9 @@ ReportStatusCodeEx (
//
// Free the allocated buffer
//
- gBS->FreePool (StatusCodeData);
+ if (StatusCodeData != (EFI_STATUS_CODE_DATA *)Buffer) {
+ gBS->FreePool (StatusCodeData);
+ }
return Status;
}
diff --git a/MdeModulePkg/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c
index 896c286834..176c7ada4d 100644
--- a/MdeModulePkg/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c
+++ b/MdeModulePkg/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c
@@ -470,6 +470,11 @@ ReportStatusCodeEx (
ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
if (ExtendedDataSize > (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {
+ //
+ // The local variable Buffer not large enough to hold the extended data associated
+ // with the status code being reported.
+ //
+ ASSERT (FALSE);
return EFI_OUT_OF_RESOURCES;
}
StatusCodeData = (EFI_STATUS_CODE_DATA *) Buffer;