You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
280 lines
13 KiB
280 lines
13 KiB
6 months ago
|
From ac25c501c8d97c7520a7c75ae708fb4c43bae035 Mon Sep 17 00:00:00 2001
|
||
|
From: Jon Maloy <jmaloy@redhat.com>
|
||
|
Date: Tue, 13 Feb 2024 16:30:10 -0500
|
||
|
Subject: [PATCH 12/17] SecurityPkg: DxeTpmMeasureBootLib: SECURITY PATCH
|
||
|
4117/4118 symbol rename
|
||
|
|
||
|
RH-Author: Jon Maloy <jmaloy@redhat.com>
|
||
|
RH-MergeRequest: 44: edk2: heap buffer overflow in Tcg2MeasureGptTable()
|
||
|
RH-Jira: RHEL-21154 RHEL-21156
|
||
|
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
||
|
RH-Commit: [12/13] 6ef41050fb68f984a5ae6104ccc102afb5290f9f (jmaloy/jons_fork)
|
||
|
|
||
|
JIRA: https://issues.redhat.com/browse/RHEL-21156
|
||
|
CVE: CVE-2022-36764
|
||
|
Upstream: Merged
|
||
|
|
||
|
commit 326db0c9072004dea89427ea3a44393a84966f2b
|
||
|
Author: Doug Flick <dougflick@microsoft.com>
|
||
|
Date: Wed Jan 17 14:47:21 2024 -0800
|
||
|
|
||
|
SecurityPkg: DxeTpmMeasureBootLib: SECURITY PATCH 4117/4118 symbol rename
|
||
|
|
||
|
Updates the sanitation function names to be lib unique names
|
||
|
|
||
|
Cc: Jiewen Yao <jiewen.yao@intel.com>
|
||
|
Cc: Rahul Kumar <rahul1.kumar@intel.com>
|
||
|
|
||
|
Signed-off-by: Doug Flick [MSFT] <doug.edk2@gmail.com>
|
||
|
Message-Id: <355aa846a99ca6ac0f7574cf5982661da0d9fea6.1705529990.git.doug.edk2@gmail.com>
|
||
|
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
|
||
|
|
||
|
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
|
||
|
---
|
||
|
.../DxeTpmMeasureBootLib.c | 8 +++---
|
||
|
.../DxeTpmMeasureBootLibSanitization.c | 10 +++----
|
||
|
.../DxeTpmMeasureBootLibSanitization.h | 8 +++---
|
||
|
.../DxeTpmMeasureBootLibSanitizationTest.c | 26 +++++++++----------
|
||
|
4 files changed, 26 insertions(+), 26 deletions(-)
|
||
|
|
||
|
diff --git a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c
|
||
|
index 1598015176..c39018d7e4 100644
|
||
|
--- a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c
|
||
|
+++ b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c
|
||
|
@@ -171,7 +171,7 @@ TcgMeasureGptTable (
|
||
|
BlockIo->Media->BlockSize,
|
||
|
(UINT8 *)PrimaryHeader
|
||
|
);
|
||
|
- if (EFI_ERROR (Status) || EFI_ERROR (SanitizeEfiPartitionTableHeader (PrimaryHeader, BlockIo))) {
|
||
|
+ if (EFI_ERROR (Status) || EFI_ERROR (TpmSanitizeEfiPartitionTableHeader (PrimaryHeader, BlockIo))) {
|
||
|
DEBUG ((DEBUG_ERROR, "Failed to read Partition Table Header or invalid Partition Table Header!\n"));
|
||
|
FreePool (PrimaryHeader);
|
||
|
return EFI_DEVICE_ERROR;
|
||
|
@@ -179,7 +179,7 @@ TcgMeasureGptTable (
|
||
|
//
|
||
|
// Read the partition entry.
|
||
|
//
|
||
|
- Status = SanitizePrimaryHeaderAllocationSize (PrimaryHeader, &AllocSize);
|
||
|
+ Status = TpmSanitizePrimaryHeaderAllocationSize (PrimaryHeader, &AllocSize);
|
||
|
if (EFI_ERROR (Status)) {
|
||
|
FreePool (PrimaryHeader);
|
||
|
return EFI_DEVICE_ERROR;
|
||
|
@@ -218,7 +218,7 @@ TcgMeasureGptTable (
|
||
|
//
|
||
|
// Prepare Data for Measurement
|
||
|
//
|
||
|
- Status = SanitizePrimaryHeaderGptEventSize (PrimaryHeader, NumberOfPartition, &EventSize);
|
||
|
+ Status = TpmSanitizePrimaryHeaderGptEventSize (PrimaryHeader, NumberOfPartition, &EventSize);
|
||
|
TcgEvent = (TCG_PCR_EVENT *)AllocateZeroPool (EventSize);
|
||
|
if (TcgEvent == NULL) {
|
||
|
FreePool (PrimaryHeader);
|
||
|
@@ -344,7 +344,7 @@ TcgMeasurePeImage (
|
||
|
|
||
|
// Determine destination PCR by BootPolicy
|
||
|
//
|
||
|
- Status = SanitizePeImageEventSize (FilePathSize, &EventSize);
|
||
|
+ Status = TpmSanitizePeImageEventSize (FilePathSize, &EventSize);
|
||
|
if (EFI_ERROR (Status)) {
|
||
|
return EFI_UNSUPPORTED;
|
||
|
}
|
||
|
diff --git a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLibSanitization.c b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLibSanitization.c
|
||
|
index bcf8c6de6f..7f17af56cd 100644
|
||
|
--- a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLibSanitization.c
|
||
|
+++ b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLibSanitization.c
|
||
|
@@ -1,5 +1,5 @@
|
||
|
/** @file
|
||
|
- The library instance provides security service of TPM2 measure boot and
|
||
|
+ The library instance provides security service of TPM measure boot and
|
||
|
Confidential Computing (CC) measure boot.
|
||
|
|
||
|
Caution: This file requires additional review when modified.
|
||
|
@@ -63,7 +63,7 @@
|
||
|
**/
|
||
|
EFI_STATUS
|
||
|
EFIAPI
|
||
|
-SanitizeEfiPartitionTableHeader (
|
||
|
+TpmSanitizeEfiPartitionTableHeader (
|
||
|
IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader,
|
||
|
IN CONST EFI_BLOCK_IO_PROTOCOL *BlockIo
|
||
|
)
|
||
|
@@ -145,7 +145,7 @@ SanitizeEfiPartitionTableHeader (
|
||
|
**/
|
||
|
EFI_STATUS
|
||
|
EFIAPI
|
||
|
-SanitizePrimaryHeaderAllocationSize (
|
||
|
+TpmSanitizePrimaryHeaderAllocationSize (
|
||
|
IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader,
|
||
|
OUT UINT32 *AllocationSize
|
||
|
)
|
||
|
@@ -194,7 +194,7 @@ SanitizePrimaryHeaderAllocationSize (
|
||
|
One of the passed parameters was invalid.
|
||
|
**/
|
||
|
EFI_STATUS
|
||
|
-SanitizePrimaryHeaderGptEventSize (
|
||
|
+TpmSanitizePrimaryHeaderGptEventSize (
|
||
|
IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader,
|
||
|
IN UINTN NumberOfPartition,
|
||
|
OUT UINT32 *EventSize
|
||
|
@@ -258,7 +258,7 @@ SanitizePrimaryHeaderGptEventSize (
|
||
|
One of the passed parameters was invalid.
|
||
|
**/
|
||
|
EFI_STATUS
|
||
|
-SanitizePeImageEventSize (
|
||
|
+TpmSanitizePeImageEventSize (
|
||
|
IN UINT32 FilePathSize,
|
||
|
OUT UINT32 *EventSize
|
||
|
)
|
||
|
diff --git a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLibSanitization.h b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLibSanitization.h
|
||
|
index 2248495813..db6e9c3752 100644
|
||
|
--- a/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLibSanitization.h
|
||
|
+++ b/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLibSanitization.h
|
||
|
@@ -53,7 +53,7 @@
|
||
|
**/
|
||
|
EFI_STATUS
|
||
|
EFIAPI
|
||
|
-SanitizeEfiPartitionTableHeader (
|
||
|
+TpmSanitizeEfiPartitionTableHeader (
|
||
|
IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader,
|
||
|
IN CONST EFI_BLOCK_IO_PROTOCOL *BlockIo
|
||
|
);
|
||
|
@@ -77,7 +77,7 @@ SanitizeEfiPartitionTableHeader (
|
||
|
**/
|
||
|
EFI_STATUS
|
||
|
EFIAPI
|
||
|
-SanitizePrimaryHeaderAllocationSize (
|
||
|
+TpmSanitizePrimaryHeaderAllocationSize (
|
||
|
IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader,
|
||
|
OUT UINT32 *AllocationSize
|
||
|
);
|
||
|
@@ -105,7 +105,7 @@ SanitizePrimaryHeaderAllocationSize (
|
||
|
One of the passed parameters was invalid.
|
||
|
**/
|
||
|
EFI_STATUS
|
||
|
-SanitizePrimaryHeaderGptEventSize (
|
||
|
+TpmSanitizePrimaryHeaderGptEventSize (
|
||
|
IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader,
|
||
|
IN UINTN NumberOfPartition,
|
||
|
OUT UINT32 *EventSize
|
||
|
@@ -129,7 +129,7 @@ SanitizePrimaryHeaderGptEventSize (
|
||
|
One of the passed parameters was invalid.
|
||
|
**/
|
||
|
EFI_STATUS
|
||
|
-SanitizePeImageEventSize (
|
||
|
+TpmSanitizePeImageEventSize (
|
||
|
IN UINT32 FilePathSize,
|
||
|
OUT UINT32 *EventSize
|
||
|
);
|
||
|
diff --git a/SecurityPkg/Library/DxeTpmMeasureBootLib/InternalUnitTest/DxeTpmMeasureBootLibSanitizationTest.c b/SecurityPkg/Library/DxeTpmMeasureBootLib/InternalUnitTest/DxeTpmMeasureBootLibSanitizationTest.c
|
||
|
index c41498be45..de1740af41 100644
|
||
|
--- a/SecurityPkg/Library/DxeTpmMeasureBootLib/InternalUnitTest/DxeTpmMeasureBootLibSanitizationTest.c
|
||
|
+++ b/SecurityPkg/Library/DxeTpmMeasureBootLib/InternalUnitTest/DxeTpmMeasureBootLibSanitizationTest.c
|
||
|
@@ -83,27 +83,27 @@ TestSanitizeEfiPartitionTableHeader (
|
||
|
PrimaryHeader.Header.CRC32 = CalculateCrc32 ((UINT8 *)&PrimaryHeader, PrimaryHeader.Header.HeaderSize);
|
||
|
|
||
|
// Test that a normal PrimaryHeader passes validation
|
||
|
- Status = SanitizeEfiPartitionTableHeader (&PrimaryHeader, &BlockIo);
|
||
|
+ Status = TpmSanitizeEfiPartitionTableHeader (&PrimaryHeader, &BlockIo);
|
||
|
UT_ASSERT_NOT_EFI_ERROR (Status);
|
||
|
|
||
|
// Test that when number of partition entries is 0, the function returns EFI_DEVICE_ERROR
|
||
|
// Should print "Invalid Partition Table Header NumberOfPartitionEntries!""
|
||
|
PrimaryHeader.NumberOfPartitionEntries = 0;
|
||
|
- Status = SanitizeEfiPartitionTableHeader (&PrimaryHeader, &BlockIo);
|
||
|
+ Status = TpmSanitizeEfiPartitionTableHeader (&PrimaryHeader, &BlockIo);
|
||
|
UT_ASSERT_EQUAL (Status, EFI_DEVICE_ERROR);
|
||
|
PrimaryHeader.NumberOfPartitionEntries = DEFAULT_PRIMARY_TABLE_HEADER_SIZE_OF_PARTITION_ENTRY;
|
||
|
|
||
|
// Test that when the header size is too small, the function returns EFI_DEVICE_ERROR
|
||
|
// Should print "Invalid Partition Table Header Size!"
|
||
|
PrimaryHeader.Header.HeaderSize = 0;
|
||
|
- Status = SanitizeEfiPartitionTableHeader (&PrimaryHeader, &BlockIo);
|
||
|
+ Status = TpmSanitizeEfiPartitionTableHeader (&PrimaryHeader, &BlockIo);
|
||
|
UT_ASSERT_EQUAL (Status, EFI_DEVICE_ERROR);
|
||
|
PrimaryHeader.Header.HeaderSize = sizeof (EFI_PARTITION_TABLE_HEADER);
|
||
|
|
||
|
// Test that when the SizeOfPartitionEntry is too small, the function returns EFI_DEVICE_ERROR
|
||
|
// should print: "SizeOfPartitionEntry shall be set to a value of 128 x 2^n where n is an integer greater than or equal to zero (e.g., 128, 256, 512, etc.)!"
|
||
|
PrimaryHeader.SizeOfPartitionEntry = 1;
|
||
|
- Status = SanitizeEfiPartitionTableHeader (&PrimaryHeader, &BlockIo);
|
||
|
+ Status = TpmSanitizeEfiPartitionTableHeader (&PrimaryHeader, &BlockIo);
|
||
|
UT_ASSERT_EQUAL (Status, EFI_DEVICE_ERROR);
|
||
|
|
||
|
DEBUG ((DEBUG_INFO, "%a: Test passed\n", __func__));
|
||
|
@@ -136,7 +136,7 @@ TestSanitizePrimaryHeaderAllocationSize (
|
||
|
PrimaryHeader.NumberOfPartitionEntries = 5;
|
||
|
PrimaryHeader.SizeOfPartitionEntry = DEFAULT_PRIMARY_TABLE_HEADER_SIZE_OF_PARTITION_ENTRY;
|
||
|
|
||
|
- Status = SanitizePrimaryHeaderAllocationSize (&PrimaryHeader, &AllocationSize);
|
||
|
+ Status = TpmSanitizePrimaryHeaderAllocationSize (&PrimaryHeader, &AllocationSize);
|
||
|
UT_ASSERT_NOT_EFI_ERROR (Status);
|
||
|
|
||
|
// Test that the allocation size is correct compared to the existing logic
|
||
|
@@ -145,19 +145,19 @@ TestSanitizePrimaryHeaderAllocationSize (
|
||
|
// Test that an overflow is detected
|
||
|
PrimaryHeader.NumberOfPartitionEntries = MAX_UINT32;
|
||
|
PrimaryHeader.SizeOfPartitionEntry = 5;
|
||
|
- Status = SanitizePrimaryHeaderAllocationSize (&PrimaryHeader, &AllocationSize);
|
||
|
+ Status = TpmSanitizePrimaryHeaderAllocationSize (&PrimaryHeader, &AllocationSize);
|
||
|
UT_ASSERT_EQUAL (Status, EFI_BAD_BUFFER_SIZE);
|
||
|
|
||
|
// Test the inverse
|
||
|
PrimaryHeader.NumberOfPartitionEntries = 5;
|
||
|
PrimaryHeader.SizeOfPartitionEntry = MAX_UINT32;
|
||
|
- Status = SanitizePrimaryHeaderAllocationSize (&PrimaryHeader, &AllocationSize);
|
||
|
+ Status = TpmSanitizePrimaryHeaderAllocationSize (&PrimaryHeader, &AllocationSize);
|
||
|
UT_ASSERT_EQUAL (Status, EFI_BAD_BUFFER_SIZE);
|
||
|
|
||
|
// Test the worst case scenario
|
||
|
PrimaryHeader.NumberOfPartitionEntries = MAX_UINT32;
|
||
|
PrimaryHeader.SizeOfPartitionEntry = MAX_UINT32;
|
||
|
- Status = SanitizePrimaryHeaderAllocationSize (&PrimaryHeader, &AllocationSize);
|
||
|
+ Status = TpmSanitizePrimaryHeaderAllocationSize (&PrimaryHeader, &AllocationSize);
|
||
|
UT_ASSERT_EQUAL (Status, EFI_BAD_BUFFER_SIZE);
|
||
|
|
||
|
DEBUG ((DEBUG_INFO, "%a: Test passed\n", __func__));
|
||
|
@@ -195,7 +195,7 @@ TestSanitizePrimaryHeaderGptEventSize (
|
||
|
NumberOfPartition = 13;
|
||
|
|
||
|
// that the primary event size is correct
|
||
|
- Status = SanitizePrimaryHeaderGptEventSize (&PrimaryHeader, NumberOfPartition, &EventSize);
|
||
|
+ Status = TpmSanitizePrimaryHeaderGptEventSize (&PrimaryHeader, NumberOfPartition, &EventSize);
|
||
|
UT_ASSERT_NOT_EFI_ERROR (Status);
|
||
|
|
||
|
// Calculate the existing logic event size
|
||
|
@@ -206,12 +206,12 @@ TestSanitizePrimaryHeaderGptEventSize (
|
||
|
UT_ASSERT_EQUAL (EventSize, ExistingLogicEventSize);
|
||
|
|
||
|
// Tests that the primary event size may not overflow
|
||
|
- Status = SanitizePrimaryHeaderGptEventSize (&PrimaryHeader, MAX_UINT32, &EventSize);
|
||
|
+ Status = TpmSanitizePrimaryHeaderGptEventSize (&PrimaryHeader, MAX_UINT32, &EventSize);
|
||
|
UT_ASSERT_EQUAL (Status, EFI_BAD_BUFFER_SIZE);
|
||
|
|
||
|
// Test that the size of partition entries may not overflow
|
||
|
PrimaryHeader.SizeOfPartitionEntry = MAX_UINT32;
|
||
|
- Status = SanitizePrimaryHeaderGptEventSize (&PrimaryHeader, NumberOfPartition, &EventSize);
|
||
|
+ Status = TpmSanitizePrimaryHeaderGptEventSize (&PrimaryHeader, NumberOfPartition, &EventSize);
|
||
|
UT_ASSERT_EQUAL (Status, EFI_BAD_BUFFER_SIZE);
|
||
|
|
||
|
DEBUG ((DEBUG_INFO, "%a: Test passed\n", __func__));
|
||
|
@@ -269,7 +269,7 @@ TestSanitizePeImageEventSize (
|
||
|
FilePathSize = 255;
|
||
|
|
||
|
// Test that a normal PE image passes validation
|
||
|
- Status = SanitizePeImageEventSize (FilePathSize, &EventSize);
|
||
|
+ Status = TpmSanitizePeImageEventSize (FilePathSize, &EventSize);
|
||
|
if (EFI_ERROR (Status)) {
|
||
|
UT_LOG_ERROR ("SanitizePeImageEventSize failed with %r\n", Status);
|
||
|
goto Exit;
|
||
|
@@ -285,7 +285,7 @@ TestSanitizePeImageEventSize (
|
||
|
}
|
||
|
|
||
|
// Test that the event size may not overflow
|
||
|
- Status = SanitizePeImageEventSize (MAX_UINT32, &EventSize);
|
||
|
+ Status = TpmSanitizePeImageEventSize (MAX_UINT32, &EventSize);
|
||
|
if (Status != EFI_BAD_BUFFER_SIZE) {
|
||
|
UT_LOG_ERROR ("SanitizePeImageEventSize succeded when it was supposed to fail with %r\n", Status);
|
||
|
goto Exit;
|
||
|
--
|
||
|
2.41.0
|
||
|
|