36#define GPT_HEADER_REVISION_V1 0x00010000
72 if (PrimaryHeader ==
NULL) {
73 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header!\n"));
74 return EFI_INVALID_PARAMETER;
77 if ((BlockIo ==
NULL) || (BlockIo->Media ==
NULL)) {
78 DEBUG ((DEBUG_ERROR,
"Invalid BlockIo!\n"));
79 return EFI_INVALID_PARAMETER;
84 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header!\n"));
85 return EFI_DEVICE_ERROR;
89 if (PrimaryHeader->Header.Revision != GPT_HEADER_REVISION_V1) {
90 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header Revision!\n"));
91 return EFI_DEVICE_ERROR;
95 if ((PrimaryHeader->Header.HeaderSize < sizeof (
EFI_PARTITION_TABLE_HEADER)) || (PrimaryHeader->Header.HeaderSize > BlockIo->Media->BlockSize)) {
96 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header HeaderSize!\n"));
97 return EFI_DEVICE_ERROR;
102 if (PrimaryHeader->PartitionEntryLBA >
DivU64x32 (MAX_UINT64, BlockIo->Media->BlockSize)) {
103 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header PartitionEntryLBA!\n"));
104 return EFI_DEVICE_ERROR;
108 if (PrimaryHeader->NumberOfPartitionEntries == 0) {
109 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header NumberOfPartitionEntries!\n"));
110 return EFI_DEVICE_ERROR;
114 if ((PrimaryHeader->SizeOfPartitionEntry < 128) || ((PrimaryHeader->SizeOfPartitionEntry & (PrimaryHeader->SizeOfPartitionEntry - 1)) != 0)) {
115 DEBUG ((DEBUG_ERROR,
"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.)!\n"));
116 return EFI_DEVICE_ERROR;
121 if (PrimaryHeader->NumberOfPartitionEntries >
DivU64x32 (MAX_UINT64, PrimaryHeader->SizeOfPartitionEntry)) {
122 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header NumberOfPartitionEntries!\n"));
123 return EFI_DEVICE_ERROR;
150 OUT UINT32 *AllocationSize
155 if (PrimaryHeader ==
NULL) {
156 return EFI_INVALID_PARAMETER;
159 if (AllocationSize ==
NULL) {
160 return EFI_INVALID_PARAMETER;
165 Status =
SafeUint32Mult (PrimaryHeader->NumberOfPartitionEntries, PrimaryHeader->SizeOfPartitionEntry, AllocationSize);
166 if (EFI_ERROR (Status)) {
167 DEBUG ((DEBUG_ERROR,
"Allocation Size would have overflowed!\n"));
168 return EFI_BAD_BUFFER_SIZE;
200 OUT UINT32 *EventSize
204 UINT32 SafeNumberOfPartitions;
206 if (PrimaryHeader ==
NULL) {
207 return EFI_INVALID_PARAMETER;
210 if (EventSize ==
NULL) {
211 return EFI_INVALID_PARAMETER;
216 if (EFI_ERROR (Status)) {
217 DEBUG ((DEBUG_ERROR,
"NumberOfPartition would have overflowed!\n"));
218 return EFI_INVALID_PARAMETER;
223 Status =
SafeUint32Mult (SafeNumberOfPartitions, PrimaryHeader->SizeOfPartitionEntry, EventSize);
224 if (EFI_ERROR (Status)) {
225 DEBUG ((DEBUG_ERROR,
"Event Size would have overflowed!\n"));
226 return EFI_BAD_BUFFER_SIZE;
235 if (EFI_ERROR (Status)) {
236 DEBUG ((DEBUG_ERROR,
"Event Size would have overflowed because of GPTData!\n"));
237 return EFI_BAD_BUFFER_SIZE;
262 IN UINT32 FilePathSize,
263 OUT UINT32 *EventSize
271 if (EFI_ERROR (Status)) {
272 DEBUG ((DEBUG_ERROR,
"EventSize would overflow!\n"));
273 return EFI_BAD_BUFFER_SIZE;
279 if (EFI_ERROR (Status)) {
280 DEBUG ((DEBUG_ERROR,
"EventSize would overflow!\n"));
281 return EFI_BAD_BUFFER_SIZE;
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
EFI_STATUS EFIAPI TpmSanitizePrimaryHeaderAllocationSize(IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader, OUT UINT32 *AllocationSize)
EFI_STATUS TpmSanitizePrimaryHeaderGptEventSize(IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader, IN UINTN NumberOfPartition, OUT UINT32 *EventSize)
EFI_STATUS EFIAPI TpmSanitizeEfiPartitionTableHeader(IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader, IN CONST EFI_BLOCK_IO_PROTOCOL *BlockIo)
EFI_STATUS TpmSanitizePeImageEventSize(IN UINT32 FilePathSize, OUT UINT32 *EventSize)
#define OFFSET_OF(TYPE, Field)
#define DEBUG(Expression)
RETURN_STATUS EFIAPI SafeUint32Add(IN UINT32 Augend, IN UINT32 Addend, OUT UINT32 *Result)
RETURN_STATUS EFIAPI SafeUint32Mult(IN UINT32 Multiplicand, IN UINT32 Multiplier, OUT UINT32 *Result)
RETURN_STATUS EFIAPI SafeUintnToUint32(IN UINTN Operand, OUT UINT32 *Result)
#define EFI_PTAB_HEADER_ID