Skip to content

Commit 892111a

Browse files
committed
Add new fields into Intel Microcode header
1 parent 7cea8ee commit 892111a

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

common/ffsparser.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,17 +1340,6 @@ USTATUS FfsParser::parseVolumeHeader(const UByteArray & volume, const UINT32 loc
13401340
bool FfsParser::microcodeHeaderValid(const INTEL_MICROCODE_HEADER* ucodeHeader)
13411341
{
13421342
bool reservedBytesValid = true;
1343-
1344-
// Check CpuFlags reserved bytes to be zero
1345-
for (UINT32 i = 0; i < sizeof(ucodeHeader->ProcessorFlagsReserved); i++) {
1346-
if (ucodeHeader->ProcessorFlagsReserved[i] != 0x00) {
1347-
reservedBytesValid = false;
1348-
break;
1349-
}
1350-
}
1351-
if (!reservedBytesValid) {
1352-
return false;
1353-
}
13541343

13551344
// Check data size to be multiple of 4 and less than 0x1000000
13561345
if (ucodeHeader->DataSize % 4 != 0 ||
@@ -1389,8 +1378,8 @@ bool FfsParser::microcodeHeaderValid(const INTEL_MICROCODE_HEADER* ucodeHeader)
13891378
ucodeHeader->DateYear > 0x2049) {
13901379
return FALSE;
13911380
}
1392-
// Check HeaderVersion to be 1.
1393-
if (ucodeHeader->HeaderVersion != 1) {
1381+
// Check HeaderType to be 1.
1382+
if (ucodeHeader->HeaderType != 1) {
13941383
return FALSE;
13951384
}
13961385
// Check LoaderRevision to be 1.
@@ -4268,13 +4257,13 @@ USTATUS FfsParser::parseIntelMicrocodeHeader(const UByteArray & microcode, const
42684257

42694258
// Recalculate checksum after patching
42704259
tempUcodeHeader->Checksum = 0;
4271-
tempUcodeHeader->ProcessorFlags = entry->ProcessorFlags;
4260+
tempUcodeHeader->PlatformIds = entry->PlatformIds;
42724261
tempUcodeHeader->ProcessorSignature = entry->ProcessorSignature;
42734262
UINT32 entryCalculated = calculateChecksum32((const UINT32*)tempMicrocode.constData(), sizeof(INTEL_MICROCODE_HEADER) + dataSize);
42744263

4275-
extendedHeaderInfo += usprintf("\nCPU signature #%u: %08Xh\nCPU flags #%u: %02Xh\nChecksum #%u: %08Xh, ",
4264+
extendedHeaderInfo += usprintf("\nCPU signature #%u: %08Xh\nCPU platform Id #%u: %08Xh\nChecksum #%u: %08Xh, ",
42764265
i + 1, entry->ProcessorSignature,
4277-
i + 1, entry->ProcessorFlags,
4266+
i + 1, entry->PlatformIds,
42784267
i + 1, entry->Checksum)
42794268
+ (entry->Checksum == entryCalculated ? UString("valid") : usprintf("invalid, should be %08Xh", entryCalculated));
42804269
}
@@ -4293,15 +4282,16 @@ USTATUS FfsParser::parseIntelMicrocodeHeader(const UByteArray & microcode, const
42934282
// Add info
42944283
UString name("Intel microcode");
42954284
UString info = usprintf("Full size: %Xh (%u)\nHeader size: 0h (0u)\nBody size: %Xh (%u)\nTail size: 0h (0u)\n"
4296-
"Date: %02X.%02X.%04x\nCPU signature: %08Xh\nRevision: %08Xh\nCPU flags: %02Xh\nChecksum: %08Xh, ",
4285+
"Date: %02X.%02X.%04x\nCPU signature: %08Xh\nRevision: %08Xh\nMinimal update revision: %08Xh\nCPU platform Id: %08Xh\nChecksum: %08Xh, ",
42974286
(UINT32)microcodeBinary.size(), (UINT32)microcodeBinary.size(),
42984287
(UINT32)microcodeBinary.size(), (UINT32)microcodeBinary.size(),
42994288
ucodeHeader->DateDay,
43004289
ucodeHeader->DateMonth,
43014290
ucodeHeader->DateYear,
43024291
ucodeHeader->ProcessorSignature,
43034292
ucodeHeader->UpdateRevision,
4304-
ucodeHeader->ProcessorFlags,
4293+
ucodeHeader->UpdateRevisionMin,
4294+
ucodeHeader->PlatformIds,
43054295
ucodeHeader->Checksum)
43064296
+ (ucodeHeader->Checksum == calculated ? UString("valid") : usprintf("invalid, should be %08Xh", calculated))
43074297
+ extendedHeaderInfo;

common/intel_microcode.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
2121

2222
// This structure is described in Section 9.11.1 of the Intel Software Developer manual Volume 3A Part 1
2323
typedef struct INTEL_MICROCODE_HEADER_ {
24-
UINT32 HeaderVersion; // 0x00000001
24+
UINT32 HeaderType; // 0x00000001 for Microcode (we do not need to support IFS yet)
2525
UINT32 UpdateRevision;
2626
UINT16 DateYear; // BCD
2727
UINT8 DateDay; // BCD
@@ -31,16 +31,17 @@ typedef struct INTEL_MICROCODE_HEADER_ {
3131
// Checksum is correct when the summation of all the DWORDs (including the extended Processor Signature Table)
3232
// that comprise the microcode update result in 00000000H.
3333
UINT32 LoaderRevision; // 0x00000001
34-
UINT8 ProcessorFlags;
35-
UINT8 ProcessorFlagsReserved[3]; // Zeroes
34+
UINT32 PlatformIds; // Platform Ids
3635
UINT32 DataSize; // Specifies the size of the encrypted data in bytes, and must be a multiple of DWORDs.
3736
// If this value is 00000000H, then the microcode update encrypted data is 2000 bytes (or 500 DWORDs).
3837
// Sane values are less than 0x1000000
3938
UINT32 TotalSize; // Specifies the total size of the microcode update in bytes.
4039
// It is the summation of the header size, the encrypted data size and the size of the optional extended signature table.
4140
// This value is always a multiple of 1024 according to the spec, but Intel already breached it several times.
4241
// Sane values are less than 0x1000000
43-
UINT8 Reserved[12]; // Zeroes
42+
UINT32 MetadataSize; // Reserved in Microcode headers
43+
UINT32 UpdateRevisionMin; // Minimum required version for OS Kernel Late Loading
44+
UINT32 Reserved; // Zeroes
4445
} INTEL_MICROCODE_HEADER;
4546

4647
#define INTEL_MICROCODE_REAL_DATA_SIZE_ON_ZERO 2000
@@ -57,8 +58,8 @@ typedef struct INTEL_MICROCODE_EXTENDED_HEADER_ {
5758

5859
typedef struct INTEL_MICROCODE_EXTENDED_HEADER_ENTRY_ {
5960
UINT32 ProcessorSignature;
60-
UINT32 ProcessorFlags;
61-
UINT32 Checksum; // To calculate the Checksum, substitute the Primary Processor Signature entry and the Processor Flags entry with the corresponding Extended Patch entry.
61+
UINT32 PlatformIds;
62+
UINT32 Checksum; // To calculate the Checksum, substitute the Primary Processor Signature entry and the Platform Ids entry with the corresponding Extended Patch entry.
6263
// Delete the Extended Processor Signature Table entries.
6364
// Checksum is correct when the summation of all DWORDs that comprise the created Extended Processor Patch results in 00000000H.
6465
} INTEL_MICROCODE_EXTENDED_HEADER_ENTRY;

0 commit comments

Comments
 (0)