36#define GPT_HEADER_REVISION_V1 0x00010000
74 if (PrimaryHeader ==
NULL) {
75 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header!\n"));
76 return EFI_INVALID_PARAMETER;
79 if ((BlockIo ==
NULL) || (BlockIo->Media ==
NULL)) {
80 DEBUG ((DEBUG_ERROR,
"Invalid BlockIo!\n"));
81 return EFI_INVALID_PARAMETER;
88 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header!\n"));
89 return EFI_DEVICE_ERROR;
95 if (PrimaryHeader->Header.Revision != GPT_HEADER_REVISION_V1) {
96 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header Revision!\n"));
97 return EFI_DEVICE_ERROR;
103 if ((PrimaryHeader->Header.HeaderSize < sizeof (
EFI_PARTITION_TABLE_HEADER)) || (PrimaryHeader->Header.HeaderSize > BlockIo->Media->BlockSize)) {
104 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header HeaderSize!\n"));
105 return EFI_DEVICE_ERROR;
111 if (PrimaryHeader->FirstUsableLBA <= PrimaryHeader->PartitionEntryLBA) {
112 DEBUG ((DEBUG_ERROR,
"GPT PartitionEntryLBA is not less than FirstUsableLBA!\n"));
113 return EFI_DEVICE_ERROR;
120 if (PrimaryHeader->PartitionEntryLBA >
DivU64x32 (MAX_UINT64, BlockIo->Media->BlockSize)) {
121 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header PartitionEntryLBA!\n"));
122 return EFI_DEVICE_ERROR;
128 if (PrimaryHeader->NumberOfPartitionEntries == 0) {
129 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header NumberOfPartitionEntries!\n"));
130 return EFI_DEVICE_ERROR;
136 if ((PrimaryHeader->SizeOfPartitionEntry < 128) || ((PrimaryHeader->SizeOfPartitionEntry & (PrimaryHeader->SizeOfPartitionEntry - 1)) != 0)) {
137 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"));
138 return EFI_DEVICE_ERROR;
145 if (PrimaryHeader->NumberOfPartitionEntries >
DivU64x32 (MAX_UINT64, PrimaryHeader->SizeOfPartitionEntry)) {
146 DEBUG ((DEBUG_ERROR,
"Invalid Partition Table Header NumberOfPartitionEntries!\n"));
147 return EFI_DEVICE_ERROR;
174 OUT UINT32 *AllocationSize
179 if (PrimaryHeader ==
NULL) {
180 return EFI_INVALID_PARAMETER;
183 if (AllocationSize ==
NULL) {
184 return EFI_INVALID_PARAMETER;
191 Status =
SafeUint32Mult (PrimaryHeader->NumberOfPartitionEntries, PrimaryHeader->SizeOfPartitionEntry, AllocationSize);
192 if (EFI_ERROR (Status)) {
193 DEBUG ((DEBUG_ERROR,
"Allocation Size would have overflowed!\n"));
194 return EFI_BAD_BUFFER_SIZE;
227 OUT UINT32 *EventSize
231 UINT32 SafeNumberOfPartitions;
233 if (PrimaryHeader ==
NULL) {
234 return EFI_INVALID_PARAMETER;
237 if (EventSize ==
NULL) {
238 return EFI_INVALID_PARAMETER;
245 if (EFI_ERROR (Status)) {
246 DEBUG ((DEBUG_ERROR,
"NumberOfPartition would have overflowed!\n"));
247 return EFI_INVALID_PARAMETER;
254 Status =
SafeUint32Mult (SafeNumberOfPartitions, PrimaryHeader->SizeOfPartitionEntry, EventSize);
255 if (EFI_ERROR (Status)) {
256 DEBUG ((DEBUG_ERROR,
"Event Size would have overflowed!\n"));
257 return EFI_BAD_BUFFER_SIZE;
269 if (EFI_ERROR (Status)) {
270 DEBUG ((DEBUG_ERROR,
"Event Size would have overflowed because of GPTData!\n"));
271 return EFI_BAD_BUFFER_SIZE;
296 IN UINT32 FilePathSize,
297 OUT UINT32 *EventSize
305 if (EFI_ERROR (Status)) {
306 DEBUG ((DEBUG_ERROR,
"EventSize would overflow!\n"));
307 return EFI_BAD_BUFFER_SIZE;
313 if (EFI_ERROR (Status)) {
314 DEBUG ((DEBUG_ERROR,
"EventSize would overflow!\n"));
315 return EFI_BAD_BUFFER_SIZE;
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
EFI_STATUS EFIAPI Tpm2SanitizeEfiPartitionTableHeader(IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader, IN CONST EFI_BLOCK_IO_PROTOCOL *BlockIo)
EFI_STATUS EFIAPI Tpm2SanitizePrimaryHeaderAllocationSize(IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader, OUT UINT32 *AllocationSize)
EFI_STATUS Tpm2SanitizePeImageEventSize(IN UINT32 FilePathSize, OUT UINT32 *EventSize)
EFI_STATUS Tpm2SanitizePrimaryHeaderGptEventSize(IN CONST EFI_PARTITION_TABLE_HEADER *PrimaryHeader, IN UINTN NumberOfPartition, 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