Skip to content

Commit

Permalink
IntelSiliconPkg MicrocodeUpdateDxe: TotalSize must be multiples of 1KB
Browse files Browse the repository at this point in the history
TotalSize must be multiples of 1024 bytes (1 KBytes) according to SDM.

Also enhance the debug message for DataSize that must be
multiples of DWORDs.

Cc: Jiewen Yao <[email protected]>
Cc: Rangasai V Chaganty <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <[email protected]>
Reviewed-by: Jiewen Yao <[email protected]>
  • Loading branch information
lzeng14 committed Jan 26, 2018
1 parent 74f3318 commit 1db271d
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
MicrocodeWrite() and VerifyMicrocode() will receive untrusted input and do basic validation.
Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
Expand Down Expand Up @@ -421,7 +421,7 @@ VerifyMicrocode (
return EFI_INCOMPATIBLE_VERSION;
}
//
// Check Size
// Check TotalSize
//
if (MicrocodeEntryPoint->DataSize == 0) {
TotalSize = 2048;
Expand All @@ -436,6 +436,14 @@ VerifyMicrocode (
}
return EFI_VOLUME_CORRUPTED;
}
if ((TotalSize & (SIZE_1KB - 1)) != 0) {
DEBUG((DEBUG_ERROR, "VerifyMicrocode - TotalSize is not multiples of 1024 bytes (1 KBytes)\n"));
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
if (AbortReason != NULL) {
*AbortReason = AllocateCopyPool(sizeof(L"InvalidTotalSize"), L"InvalidTotalSize");
}
return EFI_VOLUME_CORRUPTED;
}
if (TotalSize != ImageSize) {
DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on TotalSize\n"));
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
Expand All @@ -445,7 +453,7 @@ VerifyMicrocode (
return EFI_VOLUME_CORRUPTED;
}
//
// Check CheckSum32
// Check DataSize
//
if (MicrocodeEntryPoint->DataSize == 0) {
DataSize = 2048 - sizeof(CPU_MICROCODE_HEADER);
Expand All @@ -461,13 +469,16 @@ VerifyMicrocode (
return EFI_VOLUME_CORRUPTED;
}
if ((DataSize & 0x3) != 0) {
DEBUG((DEBUG_ERROR, "VerifyMicrocode - DataSize not aligned\n"));
DEBUG((DEBUG_ERROR, "VerifyMicrocode - DataSize is not multiples of DWORDs\n"));
*LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
if (AbortReason != NULL) {
*AbortReason = AllocateCopyPool(sizeof(L"InvalidDataSize"), L"InvalidDataSize");
}
return EFI_VOLUME_CORRUPTED;
}
//
// Check CheckSum32
//
CheckSum32 = CalculateSum32((UINT32 *)MicrocodeEntryPoint, DataSize + sizeof(CPU_MICROCODE_HEADER));
if (CheckSum32 != 0) {
DEBUG((DEBUG_ERROR, "VerifyMicrocode - fail on CheckSum32\n"));
Expand Down

0 comments on commit 1db271d

Please sign in to comment.