Skip to content

Commit 0e72e87

Browse files
mxu9mergify[bot]
authored andcommitted
OvmfPkg/PeilessStartupLib: Delete TdxValidateCfv
TdxValidateCfv is used to validate the integrity of FlashNvVarStore (PcdOvmfFlashNvStorageVariableBase) and it is not Tdx specific. So it will be moved to PlatformInitLib and be renamed to PlatformValidateNvVarStore in the following patch. And it will be called before EmuVaribleNvStore is initialized with the content in FlashNvVarStore. Cc: Erdem Aktas <erdemaktas@google.com> Cc: James Bottomley <jejb@linux.ibm.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Min Xu <min.m.xu@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
1 parent fb008db commit 0e72e87

File tree

3 files changed

+0
-178
lines changed

3 files changed

+0
-178
lines changed

OvmfPkg/Library/PeilessStartupLib/IntelTdx.c

Lines changed: 0 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include <Library/BaseLib.h>
88
#include <Library/BaseMemoryLib.h>
99
#include <Library/DebugLib.h>
10-
#include <Guid/VariableFormat.h>
11-
#include <Guid/SystemNvDataGuid.h>
1210
#include <IndustryStandard/Tpm20.h>
1311
#include <IndustryStandard/UefiTcgPlatform.h>
1412
#include <Library/HobLib.h>
@@ -37,157 +35,6 @@ typedef struct {
3735

3836
#pragma pack()
3937

40-
/**
41-
Check padding data all bit should be 1.
42-
43-
@param[in] Buffer - A pointer to buffer header
44-
@param[in] BufferSize - Buffer size
45-
46-
@retval TRUE - The padding data is valid.
47-
@retval TRUE - The padding data is invalid.
48-
49-
**/
50-
BOOLEAN
51-
CheckPaddingData (
52-
IN UINT8 *Buffer,
53-
IN UINT32 BufferSize
54-
)
55-
{
56-
UINT32 index;
57-
58-
for (index = 0; index < BufferSize; index++) {
59-
if (Buffer[index] != 0xFF) {
60-
return FALSE;
61-
}
62-
}
63-
64-
return TRUE;
65-
}
66-
67-
/**
68-
Check the integrity of CFV data.
69-
70-
@param[in] TdxCfvBase - A pointer to CFV header
71-
@param[in] TdxCfvSize - CFV data size
72-
73-
@retval TRUE - The CFV data is valid.
74-
@retval FALSE - The CFV data is invalid.
75-
76-
**/
77-
BOOLEAN
78-
EFIAPI
79-
TdxValidateCfv (
80-
IN UINT8 *TdxCfvBase,
81-
IN UINT32 TdxCfvSize
82-
)
83-
{
84-
UINT16 Checksum;
85-
UINTN VariableBase;
86-
UINT32 VariableOffset;
87-
UINT32 VariableOffsetBeforeAlign;
88-
EFI_FIRMWARE_VOLUME_HEADER *CfvFvHeader;
89-
VARIABLE_STORE_HEADER *CfvVariableStoreHeader;
90-
AUTHENTICATED_VARIABLE_HEADER *VariableHeader;
91-
92-
static EFI_GUID FvHdrGUID = EFI_SYSTEM_NV_DATA_FV_GUID;
93-
static EFI_GUID VarStoreHdrGUID = EFI_AUTHENTICATED_VARIABLE_GUID;
94-
95-
VariableOffset = 0;
96-
97-
if (TdxCfvBase == NULL) {
98-
DEBUG ((DEBUG_ERROR, "TDX CFV: CFV pointer is NULL\n"));
99-
return FALSE;
100-
}
101-
102-
//
103-
// Verify the header zerovetor, filesystemguid,
104-
// revision, signature, attributes, fvlength, checksum
105-
// HeaderLength cannot be an odd number
106-
//
107-
CfvFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)TdxCfvBase;
108-
109-
if ((!IsZeroBuffer (CfvFvHeader->ZeroVector, 16)) ||
110-
(!CompareGuid (&FvHdrGUID, &CfvFvHeader->FileSystemGuid)) ||
111-
(CfvFvHeader->Signature != EFI_FVH_SIGNATURE) ||
112-
(CfvFvHeader->Attributes != 0x4feff) ||
113-
(CfvFvHeader->Revision != EFI_FVH_REVISION) ||
114-
(CfvFvHeader->FvLength != TdxCfvSize)
115-
)
116-
{
117-
DEBUG ((DEBUG_ERROR, "TDX CFV: Basic FV headers were invalid\n"));
118-
return FALSE;
119-
}
120-
121-
//
122-
// Verify the header checksum
123-
//
124-
Checksum = CalculateSum16 ((VOID *)CfvFvHeader, CfvFvHeader->HeaderLength);
125-
126-
if (Checksum != 0) {
127-
DEBUG ((DEBUG_ERROR, "TDX CFV: FV checksum was invalid\n"));
128-
return FALSE;
129-
}
130-
131-
//
132-
// Verify the header signature, size, format, state
133-
//
134-
CfvVariableStoreHeader = (VARIABLE_STORE_HEADER *)(TdxCfvBase + CfvFvHeader->HeaderLength);
135-
if ((!CompareGuid (&VarStoreHdrGUID, &CfvVariableStoreHeader->Signature)) ||
136-
(CfvVariableStoreHeader->Format != VARIABLE_STORE_FORMATTED) ||
137-
(CfvVariableStoreHeader->State != VARIABLE_STORE_HEALTHY) ||
138-
(CfvVariableStoreHeader->Size > (CfvFvHeader->FvLength - CfvFvHeader->HeaderLength)) ||
139-
(CfvVariableStoreHeader->Size < sizeof (VARIABLE_STORE_HEADER))
140-
)
141-
{
142-
DEBUG ((DEBUG_ERROR, "TDX CFV: Variable Store header was invalid\n"));
143-
return FALSE;
144-
}
145-
146-
//
147-
// Verify the header startId, state
148-
// Verify data to the end
149-
//
150-
VariableBase = (UINTN)TdxCfvBase + CfvFvHeader->HeaderLength + sizeof (VARIABLE_STORE_HEADER);
151-
while (VariableOffset < (CfvVariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER))) {
152-
VariableHeader = (AUTHENTICATED_VARIABLE_HEADER *)(VariableBase + VariableOffset);
153-
if (VariableHeader->StartId != VARIABLE_DATA) {
154-
if (!CheckPaddingData ((UINT8 *)VariableHeader, CfvVariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER) - VariableOffset)) {
155-
DEBUG ((DEBUG_ERROR, "TDX CFV: Variable header was invalid\n"));
156-
return FALSE;
157-
}
158-
159-
VariableOffset = CfvVariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER);
160-
} else {
161-
if (!((VariableHeader->State == VAR_IN_DELETED_TRANSITION) ||
162-
(VariableHeader->State == VAR_DELETED) ||
163-
(VariableHeader->State == VAR_HEADER_VALID_ONLY) ||
164-
(VariableHeader->State == VAR_ADDED)))
165-
{
166-
DEBUG ((DEBUG_ERROR, "TDX CFV: Variable header was invalid\n"));
167-
return FALSE;
168-
}
169-
170-
VariableOffset += sizeof (AUTHENTICATED_VARIABLE_HEADER) + VariableHeader->NameSize + VariableHeader->DataSize;
171-
// Verify VariableOffset should be less than or equal CfvVariableStoreHeader->Size - sizeof(VARIABLE_STORE_HEADER)
172-
if (VariableOffset > (CfvVariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER))) {
173-
DEBUG ((DEBUG_ERROR, "TDX CFV: Variable header was invalid\n"));
174-
return FALSE;
175-
}
176-
177-
VariableOffsetBeforeAlign = VariableOffset;
178-
// 4 byte align
179-
VariableOffset = (VariableOffset + 3) & (UINTN)(~3);
180-
181-
if (!CheckPaddingData ((UINT8 *)(VariableBase + VariableOffsetBeforeAlign), VariableOffset - VariableOffsetBeforeAlign)) {
182-
DEBUG ((DEBUG_ERROR, "TDX CFV: Variable header was invalid\n"));
183-
return FALSE;
184-
}
185-
}
186-
}
187-
188-
return TRUE;
189-
}
190-
19138
/**
19239
Measure the Hoblist passed from the VMM.
19340

OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,6 @@ PeilessStartup (
179179
CpuDeadLoop ();
180180
}
181181

182-
//
183-
// Validate Tdx CFV
184-
//
185-
if (!TdxValidateCfv (CfvBase, FixedPcdGet32 (PcdCfvRawDataSize))) {
186-
ASSERT (FALSE);
187-
CpuDeadLoop ();
188-
}
189-
190182
//
191183
// Measure Tdx CFV
192184
//

OvmfPkg/Library/PeilessStartupLib/PeilessStartupInternal.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,6 @@ EFIAPI
5252
ConstructSecHobList (
5353
);
5454

55-
/**
56-
Check the integrity of CFV data.
57-
58-
@param[in] TdxCfvBase - A pointer to CFV header
59-
@param[in] TdxCfvSize - CFV data size
60-
61-
@retval TRUE - The CFV data is valid.
62-
@retval FALSE - The CFV data is invalid.
63-
64-
**/
65-
BOOLEAN
66-
EFIAPI
67-
TdxValidateCfv (
68-
IN UINT8 *TdxCfvBase,
69-
IN UINT32 TdxCfvSize
70-
);
71-
7255
/**
7356
Measure the Hoblist passed from the VMM.
7457

0 commit comments

Comments
 (0)