diff options
author | vanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524> | 2010-11-11 06:31:17 +0000 |
---|---|---|
committer | vanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524> | 2010-11-11 06:31:17 +0000 |
commit | 0c2097bd769c6de45996e66eb2acd57a16f1588e (patch) | |
tree | 81a4ac65586242b12c6687b2096f131886ac7cb4 | |
parent | 0d42be9eb148862cc9990cf51a3bdc7d169d2d48 (diff) | |
download | edk2-0c2097bd769c6de45996e66eb2acd57a16f1588e.tar.gz |
sync patch r11013, r11022, r11023 from main trunk.
1. 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.
2. Replaced MAX_EXTENDED_DATA_SIZE by EFI_STATUS_CODE_DATA_MAX_SIZE.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/branches/UDK2010@11039 6f19259b-4bc3-4df7-8a09-765794883524
3 files changed, 65 insertions, 17 deletions
diff --git a/IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/ReportStatusCodeLib.c b/IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/ReportStatusCodeLib.c index ac29009c74..90e631e5dd 100644 --- a/IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/ReportStatusCodeLib.c +++ b/IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/ReportStatusCodeLib.c @@ -487,6 +487,8 @@ ReportStatusCodeEx ( {
EFI_STATUS Status;
EFI_STATUS_CODE_DATA *StatusCodeData;
+ EFI_TPL Tpl;
+ UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)];
ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));
ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
@@ -496,12 +498,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 > (EFI_STATUS_CODE_DATA_MAX_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;
}
//
@@ -532,7 +554,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/DxeReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c index 8c456bebf4..ae24f487d3 100644 --- a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c +++ b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c @@ -1,7 +1,7 @@ /** @file
Report Status Code Library for DXE Phase.
- Copyright (c) 2006 - 2009, Intel Corporation<BR>
+ Copyright (c) 2006 - 2010, Intel Corporation<BR>
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -484,6 +484,8 @@ ReportStatusCodeEx ( {
EFI_STATUS Status;
EFI_STATUS_CODE_DATA *StatusCodeData;
+ EFI_TPL Tpl;
+ UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)];
ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));
ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
@@ -493,12 +495,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 > (EFI_STATUS_CODE_DATA_MAX_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 +551,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 42b1ddb758..3c2b2130b5 100644 --- a/MdeModulePkg/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c +++ b/MdeModulePkg/Library/PeiReportStatusCodeLib/ReportStatusCodeLib.c @@ -1,7 +1,7 @@ /** @file
Instance of Report Status Code Library for PEI Phase.
- Copyright (c) 2006 - 2009, Intel Corporation<BR>
+ Copyright (c) 2006 - 2010, Intel Corporation<BR>
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -23,11 +23,6 @@ #include <Library/OemHookStatusCodeLib.h>
#include <Library/PcdLib.h>
-//
-// Define the maximum extended data size that is supported in the PEI phase
-//
-#define MAX_EXTENDED_DATA_SIZE 0x200
-
/**
Internal worker function that reports a status code through the PEI Status Code Service or
OEM Hook Status Code Library.
@@ -458,7 +453,7 @@ ReportStatusCodeEx ( )
{
EFI_STATUS_CODE_DATA *StatusCodeData;
- UINT64 Buffer[MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)];
+ UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)];
//
// If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
@@ -469,7 +464,12 @@ ReportStatusCodeEx ( //
ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
- if (ExtendedDataSize > (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {
+ if (ExtendedDataSize > (EFI_STATUS_CODE_DATA_MAX_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;
|